segmented-control.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import TComponent from '../common/component';
  2. import config from '../common/config';
  3. const { prefix } = config;
  4. const name = `${prefix}-segmented-control`;
  5. TComponent({
  6. properties: {
  7. value: {
  8. type: String,
  9. optionalTypes: [Number],
  10. value: '',
  11. observer: 'updateValue',
  12. },
  13. items: {
  14. type: Array,
  15. value: [],
  16. },
  17. },
  18. data: {
  19. currentValue: null,
  20. classPrefix: name,
  21. classBasePrefix: prefix,
  22. },
  23. methods: {
  24. onTap(event) {
  25. const { value } = event.currentTarget.dataset;
  26. this.updateValue(value);
  27. this.triggerEvent('change', value);
  28. },
  29. updateValue(value) {
  30. if ((this.data.items || []).some((item) => item.value === value)) {
  31. this.setData({ currentValue: value });
  32. }
  33. else {
  34. this.setData({ currentValue: +value });
  35. }
  36. },
  37. },
  38. });
  39. //# sourceMappingURL=segmented-control.js.map