switch.d.ts.map 2.1 KB

1
  1. {"version":3,"sources":["../src/switch/switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOlE,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,cAAc;IAChD,eAAe,WAA+D;IAE9E,SAAS,WAAuB;IAEhC,UAAU,iCAAS;IAGnB,IAAI;;;;MAIF;IAaF,eAAe;;;QAKb;IAEF,SAAS;;MASP;IAEF,OAAO;;;;;MAyBL;CACH","file":"switch.d.ts","sourcesContent":["import { wxComponent, SuperComponent } from '../common/src/index';\nimport config from '../common/config';\nimport props from './props';\n\nconst { prefix } = config;\nconst name = `${prefix}-switch`;\n@wxComponent()\nexport default class Switch extends SuperComponent {\n externalClasses = ['t-class', 't-class-label', 't-class-body', 't-class-dot'];\n\n behaviors = ['wx://form-field'];\n\n properties = props;\n\n // 组件的内部数据\n data = {\n classPrefix: name,\n isActive: false,\n bodyStyle: '',\n };\n\n // lifetimes = {\n // attached() {\n // const { value, customValue } = this.data;\n // const [activeValue] = customValue;\n\n // this.setData({\n // isActive: value === activeValue,\n // });\n\n // },\n // };\n controlledProps = [\n {\n key: 'value',\n event: 'change',\n },\n ];\n\n observers = {\n value(val) {\n const [activeValue] = this.data.customValue;\n\n this.setData({\n isActive: val === activeValue,\n });\n this.handleColorChange();\n },\n };\n\n methods = {\n switchChange() {\n const { disabled, value, customValue } = this.data;\n const [activeValue, inactiveValue] = customValue;\n if (disabled) return;\n\n this._trigger('change', {\n value: value === activeValue ? inactiveValue : activeValue,\n });\n },\n handleColorChange() {\n const { disabled, colors = [] } = this.data;\n const [activedColor = '#0052d9', inactivedColor = 'rgba(0, 0, 0, .26)'] = colors;\n if (!disabled) {\n this.setData({\n bodyStyle: `background-color: ${this.data.isActive ? activedColor : inactivedColor}`,\n });\n }\n },\n onTapBackground() {\n this.switchChange();\n },\n onTapDot() {\n this.switchChange();\n },\n };\n}\n"]}