1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const index = require('./index-dd4b7ba3.js');
|
6 |
|
7 | let Radio = class {
|
8 | constructor(hostRef) {
|
9 | index.registerInstance(this, hostRef);
|
10 | this.onChange = index.createEvent(this, "radiochange", 7);
|
11 | this.value = '';
|
12 | this.checked = false;
|
13 | this.disabled = false;
|
14 | this.nativeProps = {};
|
15 | this.isWillLoadCalled = false;
|
16 | this.handleClick = () => {
|
17 | if (this.disabled)
|
18 | return;
|
19 | if (!this.checked)
|
20 | this.checked = true;
|
21 | };
|
22 | }
|
23 | watchChecked(newVal) {
|
24 | if (!this.isWillLoadCalled)
|
25 | return;
|
26 | newVal && this.onChange.emit({ value: this.value });
|
27 | }
|
28 | watchId(newVal) {
|
29 | if (!this.isWillLoadCalled)
|
30 | return;
|
31 | if (newVal)
|
32 | this.inputEl.setAttribute('id', newVal);
|
33 | }
|
34 | componentDidRender() {
|
35 | this.id && this.el.removeAttribute('id');
|
36 | }
|
37 | componentWillLoad() {
|
38 | this.isWillLoadCalled = true;
|
39 | }
|
40 | render() {
|
41 | const { checked, name, value, disabled, nativeProps } = this;
|
42 | return (index.h(index.Host, { className: 'weui-cells_checkbox', onClick: this.handleClick }, index.h("input", Object.assign({ ref: dom => {
|
43 | if (!dom)
|
44 | return;
|
45 | this.inputEl = dom;
|
46 | if (this.id)
|
47 | dom.setAttribute('id', this.id);
|
48 | }, type: 'radio', name: name, value: value, class: 'weui-check', checked: checked, disabled: disabled, onChange: e => e.stopPropagation() }, nativeProps)), index.h("i", { class: 'weui-icon-checked' }), index.h("slot", null)));
|
49 | }
|
50 | get el() { return index.getElement(this); }
|
51 | static get watchers() { return {
|
52 | "checked": ["watchChecked"],
|
53 | "id": ["watchId"]
|
54 | }; }
|
55 | };
|
56 |
|
57 | let RadioGroup = class {
|
58 | constructor(hostRef) {
|
59 | index.registerInstance(this, hostRef);
|
60 | this.onChange = index.createEvent(this, "change", 7);
|
61 | this.uniqueName = Date.now().toString(36);
|
62 | }
|
63 | function(e) {
|
64 | e.stopPropagation();
|
65 | if (e.target.tagName !== 'TARO-RADIO-CORE')
|
66 | return;
|
67 | const target = e.target;
|
68 | if (target.checked) {
|
69 | const childList = this.el.querySelectorAll('taro-radio-core');
|
70 | childList.forEach(element => {
|
71 | if (element !== target) {
|
72 | element.checked = false;
|
73 | }
|
74 | });
|
75 | this.value = e.detail.value;
|
76 | this.onChange.emit({
|
77 | value: this.value
|
78 | });
|
79 | }
|
80 | }
|
81 | componentDidLoad() {
|
82 | const childList = this.el.querySelectorAll('taro-radio-core');
|
83 | childList.forEach((element) => {
|
84 | element.setAttribute('name', this.name || this.uniqueName);
|
85 | });
|
86 | Object.defineProperty(this.el, 'value', {
|
87 | get: () => {
|
88 | if (!this.value) {
|
89 | const childList = this.el.querySelectorAll('taro-radio-core');
|
90 | this.value = this.getValues(childList);
|
91 | }
|
92 | return this.value;
|
93 | },
|
94 | configurable: true
|
95 | });
|
96 | }
|
97 | getValues(childList) {
|
98 | let val = '';
|
99 | Array.from(childList)
|
100 | .forEach(element => {
|
101 | const checkbox = element.querySelector('input');
|
102 | if (checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked) {
|
103 | val = checkbox.value || '';
|
104 | }
|
105 | });
|
106 | return val;
|
107 | }
|
108 | render() {
|
109 | return (index.h(index.Host, { class: 'weui-cells_radiogroup' }));
|
110 | }
|
111 | get el() { return index.getElement(this); }
|
112 | };
|
113 |
|
114 | exports.taro_radio_core = Radio;
|
115 | exports.taro_radio_group_core = RadioGroup;
|