UNPKG

@tarojs/components

Version:
120 lines (115 loc) 5.2 kB
import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-980f930f.js'; 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}"; const Checkbox = class { constructor(hostRef) { registerInstance(this, hostRef); this.onChange = createEvent(this, "checkboxchange", 7); this.handleChange = (e) => { e.stopPropagation(); this.onChange.emit({ value: this.value }); }; this.name = undefined; this.value = ''; this.color = undefined; this.id = undefined; this.checked = false; this.disabled = false; this.nativeProps = {}; this.isWillLoadCalled = false; } watchId(newVal) { if (!this.isWillLoadCalled) return; if (newVal) this.inputEl.setAttribute('id', newVal); } componentWillLoad() { this.isWillLoadCalled = true; } componentDidRender() { this.id && this.el.removeAttribute('id'); } render() { const { checked, name, color, value, disabled, nativeProps } = this; return (h(Host, { className: 'weui-cells_checkbox' }, h("input", Object.assign({ ref: dom => { if (!dom) return; this.inputEl = dom; if (this.id) dom.setAttribute('id', this.id); }, type: 'checkbox', value: value, name: name, class: 'taro-checkbox_checked', style: { color }, checked: checked, disabled: disabled, onChange: this.handleChange }, nativeProps)), h("slot", null))); } get el() { return getElement(this); } static get watchers() { return { "id": ["watchId"] }; } }; Checkbox.style = indexCss; var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _CheckboxGroup_value; const CheckboxGroup = class { constructor(hostRef) { registerInstance(this, hostRef); this.onChange = createEvent(this, "change", 7); this.uniqueName = Date.now().toString(36); _CheckboxGroup_value.set(this, void 0); this.name = undefined; } function(e) { e.stopPropagation(); if (e.target.tagName !== 'TARO-CHECKBOX-CORE') return; const childList = this.el.querySelectorAll('taro-checkbox-core'); __classPrivateFieldSet(this, _CheckboxGroup_value, this.getValues(childList), "f"); this.onChange.emit({ value: __classPrivateFieldGet(this, _CheckboxGroup_value, "f") }); } componentDidLoad() { const childList = this.el.querySelectorAll('taro-checkbox-core'); childList.forEach((element) => { element.setAttribute('name', this.name || this.uniqueName); }); Object.defineProperty(this.el, 'value', { get: () => { if (!__classPrivateFieldGet(this, _CheckboxGroup_value, "f")) { const childList = this.el.querySelectorAll('taro-checkbox-core'); __classPrivateFieldSet(this, _CheckboxGroup_value, this.getValues(childList), "f"); } return __classPrivateFieldGet(this, _CheckboxGroup_value, "f"); }, configurable: true }); } getValues(childList) { return Array.from(childList) .filter(element => { const checkbox = element.querySelector('input'); return checkbox === null || checkbox === void 0 ? void 0 : checkbox.checked; }) .map(element => element.value); } render() { return (h(Host, null)); } get el() { return getElement(this); } }; _CheckboxGroup_value = new WeakMap(); export { Checkbox as taro_checkbox_core, CheckboxGroup as taro_checkbox_group_core };