| | |
| | | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
| | | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
| | | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
| | | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
| | | return c > 3 && r && Object.defineProperty(target, key, r), r; |
| | | }; |
| | | import { SuperComponent, wxComponent } from '../common/src/index'; |
| | | import config from '../common/config'; |
| | | import Props from './props'; |
| | | const { prefix } = config; |
| | | const name = `${prefix}-checkbox`; |
| | | let CheckBox = class CheckBox extends SuperComponent { |
| | | constructor() { |
| | | super(...arguments); |
| | | this.externalClasses = [ |
| | | `${prefix}-class`, |
| | | `${prefix}-class-label`, |
| | | `${prefix}-class-icon`, |
| | | `${prefix}-class-content`, |
| | | `${prefix}-class-border`, |
| | | ]; |
| | | this.behaviors = ['wx://form-field']; |
| | | this.relations = { |
| | | '../checkbox-group/checkbox-group': { |
| | | type: 'ancestor', |
| | | linked(parent) { |
| | | const { value, disabled, borderless } = parent.data; |
| | | const valueSet = new Set(value); |
| | | const data = { |
| | | disabled: disabled || this.data.disabled, |
| | | }; |
| | | if (borderless) { |
| | | data.borderless = true; |
| | | } |
| | | data.checked = valueSet.has(this.data.value); |
| | | if (this.data.checkAll) { |
| | | data.checked = valueSet.size > 0; |
| | | } |
| | | this.setData(data); |
| | | }, |
| | | }, |
| | | }; |
| | | this.options = { |
| | | multipleSlots: true, |
| | | }; |
| | | this.properties = Object.assign(Object.assign({}, Props), { theme: { |
| | | type: String, |
| | | value: 'default', |
| | | }, borderless: { |
| | | type: Boolean, |
| | | value: false, |
| | | } }); |
| | | this.data = { |
| | | prefix, |
| | | classPrefix: name, |
| | | }; |
| | | this.controlledProps = [ |
| | | { |
| | | key: 'checked', |
| | | event: 'change', |
| | | }, |
| | | ]; |
| | | this.methods = { |
| | | onChange(e) { |
| | | const { disabled, readonly } = this.data; |
| | | if (disabled || readonly) |
| | | return; |
| | | const { target } = e.currentTarget.dataset; |
| | | const { contentDisabled } = this.data; |
| | | if (target === 'text' && contentDisabled) { |
| | | return; |
| | | } |
| | | const checked = !this.data.checked; |
| | | const parent = this.$parent; |
| | | if (parent) { |
| | | parent.updateValue(Object.assign(Object.assign({}, this.data), { checked })); |
| | | } |
| | | else { |
| | | this._trigger('change', { checked }); |
| | | } |
| | | }, |
| | | }; |
| | | } |
| | | }; |
| | | CheckBox = __decorate([ |
| | | wxComponent() |
| | | ], CheckBox); |
| | | export default CheckBox; |
| | | import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import Props from"./props";const{prefix:prefix}=config,name=`${prefix}-checkbox`;let CheckBox=class extends SuperComponent{constructor(){super(...arguments),this.externalClasses=[`${prefix}-class`,`${prefix}-class-label`,`${prefix}-class-icon`,`${prefix}-class-content`,`${prefix}-class-border`],this.behaviors=["wx://form-field"],this.relations={"../checkbox-group/checkbox-group":{type:"ancestor",linked(e){const{value:t,disabled:s,borderless:a}=e.data,i=new Set(t),o=i.has(this.data.value),c={_disabled:null==this.data.disabled?s:this.data.disabled};a&&(c.borderless=!0),c.checked=this.data.checked||o,this.data.checked&&e.updateValue(this.data),this.data.checkAll&&(c.checked=i.size>0),this.setData(c)}}},this.options={multipleSlots:!0},this.properties=Object.assign(Object.assign({},Props),{theme:{type:String,value:"default"},tId:{type:String}}),this.data={prefix:prefix,classPrefix:name,_disabled:!1},this.observers={disabled(e){this.setData({_disabled:e})}},this.controlledProps=[{key:"checked",event:"change"}],this.methods={handleTap(e){const{_disabled:t,readonly:s,contentDisabled:a}=this.data,{target:i}=e.currentTarget.dataset;if(t||s||"text"===i&&a)return;const{value:o,label:c}=this.data,d=!this.data.checked,r=this.$parent;r?r.updateValue(Object.assign(Object.assign({},this.data),{checked:d,item:{label:c,value:o,checked:d}})):this._trigger("change",{context:{value:o,label:c},checked:d})},setDisabled(e){this.setData({_disabled:this.data.disabled||e})}}}};CheckBox=__decorate([wxComponent()],CheckBox);export default CheckBox; |