{"version":3,"sources":["../src/radio-group/radio-group.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAOlE,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,cAAc;IACpD,eAAe,WAAuB;IAEtC,IAAI;;;;MAIF;IAEF,SAAS;;;;;MAWP;IAEF,UAAU;;;;;;;;;;;;;;;;;;;;;;;MAER;IAEF,eAAe;;;QAKb;IAEF,SAAS;;MAIP;IAEF,SAAS;;MAQP;IAEF,OAAO;;;;;MAgDL;CACH","file":"radio-group.d.ts","sourcesContent":["import config from '../common/config';\nimport { SuperComponent, wxComponent } from '../common/src/index';\nimport Props from '../radio/radio-group-props';\n\nconst { prefix } = config;\nconst name = `${prefix}-radio-group`;\n\n@wxComponent()\nexport default class RadioGroup extends SuperComponent {\n externalClasses = [`${prefix}-class`];\n\n data = {\n prefix,\n classPrefix: name,\n radioOptions: [],\n };\n\n relations = {\n '../radio/radio': {\n type: 'descendant' as 'descendant',\n linked(target) {\n const { value, disabled } = this.data;\n target.setData({\n checked: value === target.data.value,\n });\n target.setDisabled(disabled);\n },\n },\n };\n\n properties = {\n ...Props,\n };\n\n controlledProps = [\n {\n key: 'value',\n event: 'change',\n },\n ];\n\n lifetimes = {\n attached() {\n this.initWithOptions();\n },\n };\n\n observers = {\n value() {\n this.getChilds().forEach((item) => {\n item.setData({\n checked: this.data.value === item.data.value,\n });\n });\n },\n };\n\n methods = {\n getChilds() {\n let items = this.getRelationNodes('../radio/radio');\n if (!items.length) {\n items = this.selectAllComponents(`.${prefix}-radio-option`);\n }\n return items;\n },\n\n updateValue(value) {\n this._trigger('change', { value });\n },\n\n handleRadioChange(e) {\n const { value } = e.target.dataset;\n\n this.updateValue(value);\n },\n\n // 支持自定义options\n initWithOptions() {\n const { options } = this.data;\n // 数字数组|字符串数组|对像数组\n if (!options?.length || !Array.isArray(options)) {\n return;\n }\n const optionsValue = [];\n try {\n options.forEach((element) => {\n const typeName = typeof element;\n if (typeName === 'number' || typeName === 'string') {\n optionsValue.push({\n label: `${element}`,\n value: element,\n });\n } else if (typeName === 'object') {\n optionsValue.push({\n ...element,\n });\n }\n });\n this.setData({\n radioOptions: optionsValue,\n });\n } catch (error) {\n console.error('error', error);\n }\n },\n };\n}\n"]}