CheckboxGroup.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. checkboxGroupProps: () => checkboxGroupProps,
  22. default: () => stdin_default
  23. });
  24. module.exports = __toCommonJS(stdin_exports);
  25. var import_vue = 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. shape: (0, import_utils.makeStringProp)("round"),
  33. disabled: Boolean,
  34. iconSize: import_utils.numericProp,
  35. direction: String,
  36. modelValue: (0, import_utils.makeArrayProp)(),
  37. checkedColor: String
  38. };
  39. const CHECKBOX_GROUP_KEY = Symbol(name);
  40. var stdin_default = (0, import_vue.defineComponent)({
  41. name,
  42. props: checkboxGroupProps,
  43. emits: ["change", "update:modelValue"],
  44. setup(props, {
  45. emit,
  46. slots
  47. }) {
  48. const {
  49. children,
  50. linkChildren
  51. } = (0, import_use.useChildren)(CHECKBOX_GROUP_KEY);
  52. const updateValue = (value) => emit("update:modelValue", value);
  53. const toggleAll = (options = {}) => {
  54. if (typeof options === "boolean") {
  55. options = {
  56. checked: options
  57. };
  58. }
  59. const {
  60. checked,
  61. skipDisabled
  62. } = options;
  63. const checkedChildren = children.filter((item) => {
  64. if (!item.props.bindGroup) {
  65. return false;
  66. }
  67. if (item.props.disabled && skipDisabled) {
  68. return item.checked.value;
  69. }
  70. return checked != null ? checked : !item.checked.value;
  71. });
  72. const names = checkedChildren.map((item) => item.name);
  73. updateValue(names);
  74. };
  75. (0, import_vue.watch)(() => props.modelValue, (value) => emit("change", value));
  76. (0, import_use_expose.useExpose)({
  77. toggleAll
  78. });
  79. (0, import_use.useCustomFieldValue)(() => props.modelValue);
  80. linkChildren({
  81. props,
  82. updateValue
  83. });
  84. return () => {
  85. var _a;
  86. return (0, import_vue.createVNode)("div", {
  87. "class": bem([props.direction])
  88. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
  89. };
  90. }
  91. });