UNPKG

@tarojs/components

Version:

Taro 组件库

189 lines (188 loc) • 4.58 kB
import { h, Host } from '@stencil/core'; export class Radio { constructor() { this.handleClick = (e) => { e.stopPropagation(); if (this.disabled) return; if (!this.checked) this.checked = true; }; this.name = undefined; this.value = ''; this.id = undefined; this.checked = false; this.disabled = false; this.nativeProps = {}; this.isWillLoadCalled = false; } watchChecked(newVal) { if (!this.isWillLoadCalled) return; newVal && this.onChange.emit({ value: this.value }); } watchId(newVal) { if (!this.isWillLoadCalled) return; if (newVal) this.inputEl.setAttribute('id', newVal); } componentDidRender() { this.id && this.el.removeAttribute('id'); } componentWillLoad() { this.isWillLoadCalled = true; } render() { const { checked, name, value, disabled, nativeProps } = this; return (h(Host, { className: 'weui-cells_checkbox', onClick: this.handleClick }, h("input", Object.assign({ ref: dom => { if (!dom) return; this.inputEl = dom; if (this.id) dom.setAttribute('id', this.id); }, 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))); } static get is() { return "taro-radio-core"; } 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": "string", "mutable": false, "complexType": { "original": "string", "resolved": "string", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "value", "reflect": false, "defaultValue": "''" }, "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": true, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "attribute": "checked", "reflect": true, "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": "radiochange", "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": "checked", "methodName": "watchChecked" }, { "propName": "id", "methodName": "watchId" }]; } }