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