CheckboxGroup.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. CHECKBOX_GROUP_KEY: () => CHECKBOX_GROUP_KEY,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_use = require("@vant/use");
  28. var import_use_expose = require("../composables/use-expose");
  29. const [name, bem] = (0, import_utils.createNamespace)("checkbox-group");
  30. const checkboxGroupProps = {
  31. max: import_utils.numericProp,
  32. disabled: Boolean,
  33. iconSize: import_utils.numericProp,
  34. direction: String,
  35. modelValue: (0, import_utils.makeArrayProp)(),
  36. checkedColor: String
  37. };
  38. const CHECKBOX_GROUP_KEY = Symbol(name);
  39. var stdin_default = (0, import_vue2.defineComponent)({
  40. name,
  41. props: checkboxGroupProps,
  42. emits: ["change", "update:modelValue"],
  43. setup(props, {
  44. emit,
  45. slots
  46. }) {
  47. const {
  48. children,
  49. linkChildren
  50. } = (0, import_use.useChildren)(CHECKBOX_GROUP_KEY);
  51. const updateValue = (value) => emit("update:modelValue", value);
  52. const toggleAll = (options = {}) => {
  53. if (typeof options === "boolean") {
  54. options = {
  55. checked: options
  56. };
  57. }
  58. const {
  59. checked,
  60. skipDisabled
  61. } = options;
  62. const checkedChildren = children.filter((item) => {
  63. if (!item.props.bindGroup) {
  64. return false;
  65. }
  66. if (item.props.disabled && skipDisabled) {
  67. return item.checked.value;
  68. }
  69. return checked != null ? checked : !item.checked.value;
  70. });
  71. const names = checkedChildren.map((item) => item.name);
  72. updateValue(names);
  73. };
  74. (0, import_vue2.watch)(() => props.modelValue, (value) => emit("change", value));
  75. (0, import_use_expose.useExpose)({
  76. toggleAll
  77. });
  78. (0, import_use.useCustomFieldValue)(() => props.modelValue);
  79. linkChildren({
  80. props,
  81. updateValue
  82. });
  83. return () => {
  84. var _a;
  85. return (0, import_vue.createVNode)("div", {
  86. "class": bem([props.direction])
  87. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
  88. };
  89. }
  90. });