UNPKG

@tarojs/components

Version:

Taro 组件库

208 lines (207 loc) • 4.92 kB
import { h, Host } from '@stencil/core'; export class Checkbox { constructor() { 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))); } static get is() { return "taro-checkbox-core"; } static get originalStyleUrls() { return { "$": ["./style/index.scss"] }; } static get styleUrls() { return { "$": ["./style/index.css"] }; } static get properties() { return { "name": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "name", "reflect": false }, "value": { "type": "any", "mutable": true, "complexType": { "original": "string | number", "resolved": "number | string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "value", "reflect": false, "defaultValue": "''" }, "color": { "type": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "color", "reflect": false }, "id": { "type": "string", "mutable": true, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "id", "reflect": false }, "checked": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "checked", "reflect": false, "defaultValue": "false" }, "disabled": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "disabled", "reflect": false, "defaultValue": "false" }, "nativeProps": { "type": "unknown", "mutable": false, "complexType": { "original": "{}", "resolved": "{}", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "defaultValue": "{}" } }; } static get states() { return { "isWillLoadCalled": {} }; } static get events() { return [{ "method": "onChange", "name": "checkboxchange", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "" }, "complexType": { "original": "any", "resolved": "any", "references": {} } }]; } static get elementRef() { return "el"; } static get watchers() { return [{ "propName": "id", "methodName": "watchId" }]; } }