1 | import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-8809c729.js';
|
2 |
|
3 | const indexCss = ".taro-checkbox{display:inline-block;position:relative}.taro-checkbox_checked{display:inline-block;position:relative;top:5px;border:1px solid #d1d1d1;border-radius:3px;width:23px;height:23px;min-height:0;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:0;background-color:#fff;vertical-align:0;font-size:23px;color:#1aad19}.taro-checkbox_checked:checked::before{display:inline-block;position:absolute;left:50%;top:50%;vertical-align:middle;text-decoration:inherit;text-align:center;text-transform:none;font-family:weui;font-style:normal;font-weight:normal;font-variant:normal;font-size:inherit;color:inherit;content:\"\\ea08\";-webkit-transform:translate(-50%, -48%) scale(0.73);transform:translate(-50%, -48%) scale(0.73);speak:none}";
|
4 |
|
5 | let Checkbox = class {
|
6 | constructor(hostRef) {
|
7 | registerInstance(this, hostRef);
|
8 | this.onChange = createEvent(this, "checkboxchange", 7);
|
9 | this.value = '';
|
10 | this.checked = false;
|
11 | this.disabled = false;
|
12 | this.nativeProps = {};
|
13 | this.isWillLoadCalled = false;
|
14 | this.handleChange = e => {
|
15 | e.stopPropagation();
|
16 | this.onChange.emit({
|
17 | value: this.value
|
18 | });
|
19 | };
|
20 | }
|
21 | watchId(newVal) {
|
22 | if (!this.isWillLoadCalled)
|
23 | return;
|
24 | if (newVal)
|
25 | this.inputEl.setAttribute('id', newVal);
|
26 | }
|
27 | componentWillLoad() {
|
28 | this.isWillLoadCalled = true;
|
29 | }
|
30 | componentDidRender() {
|
31 | this.id && this.el.removeAttribute('id');
|
32 | }
|
33 | render() {
|
34 | const { checked, name, color, value, disabled, nativeProps } = this;
|
35 | return (h(Host, { className: 'weui-cells_checkbox' }, h("input", Object.assign({ ref: dom => {
|
36 | if (!dom)
|
37 | return;
|
38 | this.inputEl = dom;
|
39 | if (this.id)
|
40 | dom.setAttribute('id', this.id);
|
41 | }, type: 'checkbox', value: value, name: name, class: 'taro-checkbox_checked', style: { color }, checked: checked, disabled: disabled, onChange: this.handleChange }, nativeProps)), h("slot", null)));
|
42 | }
|
43 | get el() { return getElement(this); }
|
44 | static get watchers() { return {
|
45 | "id": ["watchId"]
|
46 | }; }
|
47 | };
|
48 | Checkbox.style = indexCss;
|
49 |
|
50 | let CheckboxGroup = class {
|
51 | constructor(hostRef) {
|
52 | registerInstance(this, hostRef);
|
53 | this.onChange = createEvent(this, "change", 7);
|
54 | this.uniqueName = Date.now().toString(36);
|
55 | }
|
56 | function(e) {
|
57 | e.stopPropagation();
|
58 | if (e.target.tagName !== 'TARO-CHECKBOX-CORE')
|
59 | return;
|
60 | const childList = this.el.querySelectorAll('taro-checkbox-core');
|
61 | this.value = this.getValues(childList);
|
62 | this.onChange.emit({
|
63 | value: this.value
|
64 | });
|
65 | }
|
66 | componentDidLoad() {
|
67 | const childList = this.el.querySelectorAll('taro-checkbox-core');
|
68 | childList.forEach((element) => {
|
69 | element.setAttribute('name', this.name || this.uniqueName);
|
70 | });
|
71 | Object.defineProperty(this.el, 'value', {
|
72 | get: () => {
|
73 | if (!this.value) {
|
74 | const childList = this.el.querySelectorAll('taro-checkbox-core');
|
75 | this.value = this.getValues(childList);
|
76 | }
|
77 | return this.value;
|
78 | },
|
79 | configurable: true
|
80 | });
|
81 | }
|
82 | getValues(childList) {
|
83 | return Array.from(childList)
|
84 | .filter(element => {
|
85 | const checkbox = element.querySelector('input');
|
86 | return checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked;
|
87 | })
|
88 | .map(element => element.value);
|
89 | }
|
90 | render() {
|
91 | return (h(Host, null));
|
92 | }
|
93 | get el() { return getElement(this); }
|
94 | };
|
95 |
|
96 | export { Checkbox as taro_checkbox_core, CheckboxGroup as taro_checkbox_group_core };
|