ckgl/node_modules/vant/lib/checkbox-group/CheckboxGroup.js
2024-12-21 13:52:42 +08:00

92 lines
2.9 KiB
JavaScript

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
CHECKBOX_GROUP_KEY: () => CHECKBOX_GROUP_KEY,
checkboxGroupProps: () => checkboxGroupProps,
default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_utils = require("../utils");
var import_use = require("@vant/use");
var import_use_expose = require("../composables/use-expose");
const [name, bem] = (0, import_utils.createNamespace)("checkbox-group");
const checkboxGroupProps = {
max: import_utils.numericProp,
shape: (0, import_utils.makeStringProp)("round"),
disabled: Boolean,
iconSize: import_utils.numericProp,
direction: String,
modelValue: (0, import_utils.makeArrayProp)(),
checkedColor: String
};
const CHECKBOX_GROUP_KEY = Symbol(name);
var stdin_default = (0, import_vue.defineComponent)({
name,
props: checkboxGroupProps,
emits: ["change", "update:modelValue"],
setup(props, {
emit,
slots
}) {
const {
children,
linkChildren
} = (0, import_use.useChildren)(CHECKBOX_GROUP_KEY);
const updateValue = (value) => emit("update:modelValue", value);
const toggleAll = (options = {}) => {
if (typeof options === "boolean") {
options = {
checked: options
};
}
const {
checked,
skipDisabled
} = options;
const checkedChildren = children.filter((item) => {
if (!item.props.bindGroup) {
return false;
}
if (item.props.disabled && skipDisabled) {
return item.checked.value;
}
return checked != null ? checked : !item.checked.value;
});
const names = checkedChildren.map((item) => item.name);
updateValue(names);
};
(0, import_vue.watch)(() => props.modelValue, (value) => emit("change", value));
(0, import_use_expose.useExpose)({
toggleAll
});
(0, import_use.useCustomFieldValue)(() => props.modelValue);
linkChildren({
props,
updateValue
});
return () => {
var _a;
return (0, import_vue.createVNode)("div", {
"class": bem([props.direction])
}, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
};
}
});