mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
import { createNamespace } from '../utils';
|
|
import { FieldMixin } from '../mixins/field';
|
|
import { ParentMixin } from '../mixins/relation';
|
|
|
|
const [createComponent, bem] = createNamespace('checkbox-group');
|
|
|
|
export default createComponent({
|
|
mixins: [ParentMixin('vanCheckbox'), FieldMixin],
|
|
|
|
props: {
|
|
max: [Number, String],
|
|
disabled: Boolean,
|
|
direction: String,
|
|
iconSize: [Number, String],
|
|
checkedColor: String,
|
|
modelValue: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
},
|
|
|
|
emits: ['change', 'update:modelValue'],
|
|
|
|
watch: {
|
|
modelValue(val) {
|
|
this.$emit('change', val);
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
// @exposed-api
|
|
toggleAll(checked) {
|
|
if (checked === false) {
|
|
this.$emit('update:modelValue', []);
|
|
return;
|
|
}
|
|
|
|
let { children } = this;
|
|
if (!checked) {
|
|
children = children.filter((item) => !item.checked);
|
|
}
|
|
|
|
const names = children.map((item) => item.name);
|
|
this.$emit('update:modelValue', names);
|
|
},
|
|
},
|
|
|
|
render() {
|
|
return <div class={bem([this.direction])}>{this.$slots.default?.()}</div>;
|
|
},
|
|
});
|