123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { isPresetColor } from '../helpers/colors'
- Component({
- externalClasses: ['wux-class', 'wux-input-class'],
- options: {
- multipleSlots: true,
- },
- properties: {
- type: {
- type: String,
- value: 'checkbox',
- },
- value: {
- type: String,
- value: '',
- },
- defaultChecked: {
- type: Boolean,
- value: false,
- },
- checked: {
- type: Boolean,
- value: false,
- observer(newVal) {
- if (this.data.controlled) {
- this.updated(newVal)
- }
- },
- },
- disabled: {
- type: Boolean,
- value: false,
- },
- color: {
- type: String,
- value: 'balanced',
- observer(newVal) {
- this.setData({
- inputColor: isPresetColor(newVal),
- })
- },
- },
- controlled: {
- type: Boolean,
- value: false,
- },
- wrapStyle: {
- type: String,
- value: '',
- },
- },
- data: {
- inputChecked: false,
- inputColor: '',
- },
- methods: {
- updated(inputChecked) {
- if (this.data.inputChecked !== inputChecked) {
- this.setData({
- inputChecked,
- })
- }
- },
- onChange() {
- const { value, inputChecked, disabled, controlled } = this.data
- const item = {
- checked: !inputChecked,
- value,
- }
- if (disabled) return
- if (!controlled) {
- this.updated(!inputChecked)
- }
- this.triggerEvent('change', item)
- },
- },
- attached() {
- const { defaultChecked, checked, controlled } = this.data
- const inputChecked = controlled ? checked : defaultChecked
- const inputColor = isPresetColor(this.data.color)
- this.setData({
- inputChecked,
- inputColor,
- })
- },
- })
|