mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: migrate Checkbox/CheckboxGroup
This commit is contained in:
parent
6f4c8f1e5b
commit
cef8daf717
@ -47,4 +47,6 @@ module.exports = [
|
|||||||
'dialog',
|
'dialog',
|
||||||
'toast',
|
'toast',
|
||||||
'calendar',
|
'calendar',
|
||||||
|
'checkbox',
|
||||||
|
'checkbox-group',
|
||||||
];
|
];
|
||||||
|
@ -13,14 +13,16 @@ export default createComponent({
|
|||||||
direction: String,
|
direction: String,
|
||||||
iconSize: [Number, String],
|
iconSize: [Number, String],
|
||||||
checkedColor: String,
|
checkedColor: String,
|
||||||
value: {
|
modelValue: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['change', 'update:modelValue'],
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
value(val) {
|
modelValue(val) {
|
||||||
this.$emit('change', val);
|
this.$emit('change', val);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -29,7 +31,7 @@ export default createComponent({
|
|||||||
// @exposed-api
|
// @exposed-api
|
||||||
toggleAll(checked) {
|
toggleAll(checked) {
|
||||||
if (checked === false) {
|
if (checked === false) {
|
||||||
this.$emit('input', []);
|
this.$emit('update:modelValue', []);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,11 +41,11 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const names = children.map((item) => item.name);
|
const names = children.map((item) => item.name);
|
||||||
this.$emit('input', names);
|
this.$emit('update:modelValue', names);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <div class={bem([this.direction])}>{this.slots()}</div>;
|
return <div class={bem([this.direction])}>{this.$slots.default?.()}</div>;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -12,27 +12,29 @@ export default createComponent({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
emits: ['click', 'change', 'update:modelValue'],
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
checked: {
|
checked: {
|
||||||
get() {
|
get() {
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
return this.parent.value.indexOf(this.name) !== -1;
|
return this.parent.modelValue.indexOf(this.name) !== -1;
|
||||||
}
|
}
|
||||||
return this.value;
|
return this.modelValue;
|
||||||
},
|
},
|
||||||
|
|
||||||
set(val) {
|
set(val) {
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
this.setParentValue(val);
|
this.setParentValue(val);
|
||||||
} else {
|
} else {
|
||||||
this.$emit('input', val);
|
this.$emit('update:modelValue', val);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
value(val) {
|
modelValue(val) {
|
||||||
this.$emit('change', val);
|
this.$emit('change', val);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -51,7 +53,7 @@ export default createComponent({
|
|||||||
|
|
||||||
setParentValue(val) {
|
setParentValue(val) {
|
||||||
const { parent } = this;
|
const { parent } = this;
|
||||||
const value = parent.value.slice();
|
const value = parent.modelValue.slice();
|
||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
if (parent.max && value.length >= parent.max) {
|
if (parent.max && value.length >= parent.max) {
|
||||||
@ -61,7 +63,7 @@ export default createComponent({
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (value.indexOf(this.name) === -1) {
|
if (value.indexOf(this.name) === -1) {
|
||||||
value.push(this.name);
|
value.push(this.name);
|
||||||
parent.$emit('input', value);
|
parent.$emit('update:modelValue', value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const index = value.indexOf(this.name);
|
const index = value.indexOf(this.name);
|
||||||
@ -69,7 +71,7 @@ export default createComponent({
|
|||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
value.splice(index, 1);
|
value.splice(index, 1);
|
||||||
parent.$emit('input', value);
|
parent.$emit('update:modelValue', value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -11,9 +11,9 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
|
|||||||
|
|
||||||
props: {
|
props: {
|
||||||
name: null,
|
name: null,
|
||||||
value: null,
|
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
iconSize: [Number, String],
|
iconSize: [Number, String],
|
||||||
|
modelValue: null,
|
||||||
checkedColor: String,
|
checkedColor: String,
|
||||||
labelPosition: String,
|
labelPosition: String,
|
||||||
labelDisabled: Boolean,
|
labelDisabled: Boolean,
|
||||||
@ -93,7 +93,9 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
|
|||||||
])}
|
])}
|
||||||
style={{ fontSize: addUnit(iconSize) }}
|
style={{ fontSize: addUnit(iconSize) }}
|
||||||
>
|
>
|
||||||
{this.slots('icon', { checked }) || (
|
{this.$slots.icon ? (
|
||||||
|
this.$slots.icon({ checked })
|
||||||
|
) : (
|
||||||
<Icon name="success" style={this.iconStyle} />
|
<Icon name="success" style={this.iconStyle} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -101,9 +103,7 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
genLabel() {
|
genLabel() {
|
||||||
const slot = this.slots();
|
if (this.$slots.default) {
|
||||||
|
|
||||||
if (slot) {
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
class={bem('label', [
|
class={bem('label', [
|
||||||
@ -111,7 +111,7 @@ export const CheckboxMixin = ({ parent, bem, role }) => ({
|
|||||||
{ disabled: this.isDisabled },
|
{ disabled: this.isDisabled },
|
||||||
])}
|
])}
|
||||||
>
|
>
|
||||||
{slot}
|
{this.$slots.default()}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,10 @@ module.exports = {
|
|||||||
path: 'calendar',
|
path: 'calendar',
|
||||||
title: 'Calendar 日历',
|
title: 'Calendar 日历',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: 'checkbox',
|
path: 'checkbox',
|
||||||
// title: 'Checkbox 复选框',
|
title: 'Checkbox 复选框',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'datetime-picker',
|
// path: 'datetime-picker',
|
||||||
// title: 'DatetimePicker 时间选择',
|
// title: 'DatetimePicker 时间选择',
|
||||||
@ -453,10 +453,10 @@ module.exports = {
|
|||||||
path: 'calendar',
|
path: 'calendar',
|
||||||
title: 'Calendar',
|
title: 'Calendar',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: 'checkbox',
|
path: 'checkbox',
|
||||||
// title: 'Checkbox',
|
title: 'Checkbox',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'datetime-picker',
|
// path: 'datetime-picker',
|
||||||
// title: 'DatetimePicker',
|
// title: 'DatetimePicker',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user