fb2633ed4514f950bbd55123639b42533a2be3a6b4b851ecd8bd3b846a9222b45e8c6c1128f7ac6c0bbf63ec9ce62962803bb96a3877f1d28bbef0ed44f895 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var checkboxGroup = require('./checkbox-group.js');
  6. var constants = require('./constants.js');
  7. var checkbox = require('./checkbox.js');
  8. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  9. var index = require('../../../hooks/use-namespace/index.js');
  10. var useFormItem = require('../../form/src/hooks/use-form-item.js');
  11. var error = require('../../../utils/error.js');
  12. var event = require('../../../constants/event.js');
  13. const __default__ = vue.defineComponent({
  14. name: "ElCheckboxGroup"
  15. });
  16. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  17. ...__default__,
  18. props: checkboxGroup.checkboxGroupProps,
  19. emits: checkboxGroup.checkboxGroupEmits,
  20. setup(__props, { emit }) {
  21. const props = __props;
  22. const ns = index.useNamespace("checkbox");
  23. const { formItem } = useFormItem.useFormItem();
  24. const { inputId: groupId, isLabeledByFormItem } = useFormItem.useFormItemInputId(props, {
  25. formItemContext: formItem
  26. });
  27. const changeEvent = async (value) => {
  28. emit(event.UPDATE_MODEL_EVENT, value);
  29. await vue.nextTick();
  30. emit(event.CHANGE_EVENT, value);
  31. };
  32. const modelValue = vue.computed({
  33. get() {
  34. return props.modelValue;
  35. },
  36. set(val) {
  37. changeEvent(val);
  38. }
  39. });
  40. const aliasProps = vue.computed(() => ({
  41. ...checkboxGroup.checkboxDefaultProps,
  42. ...props.props
  43. }));
  44. const getOptionProps = (option) => {
  45. const base = {
  46. label: option[aliasProps.value.label],
  47. value: option[aliasProps.value.value],
  48. disabled: option[aliasProps.value.disabled]
  49. };
  50. return { ...option, ...base };
  51. };
  52. vue.provide(constants.checkboxGroupContextKey, {
  53. ...lodashUnified.pick(vue.toRefs(props), [
  54. "size",
  55. "min",
  56. "max",
  57. "disabled",
  58. "validateEvent",
  59. "fill",
  60. "textColor"
  61. ]),
  62. modelValue,
  63. changeEvent
  64. });
  65. vue.watch(() => props.modelValue, (newVal, oldValue) => {
  66. if (props.validateEvent && !lodashUnified.isEqual(newVal, oldValue)) {
  67. formItem == null ? void 0 : formItem.validate("change").catch((err) => error.debugWarn());
  68. }
  69. });
  70. return (_ctx, _cache) => {
  71. var _a;
  72. return vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.tag), {
  73. id: vue.unref(groupId),
  74. class: vue.normalizeClass(vue.unref(ns).b("group")),
  75. role: "group",
  76. "aria-label": !vue.unref(isLabeledByFormItem) ? _ctx.ariaLabel || "checkbox-group" : void 0,
  77. "aria-labelledby": vue.unref(isLabeledByFormItem) ? (_a = vue.unref(formItem)) == null ? void 0 : _a.labelId : void 0
  78. }, {
  79. default: vue.withCtx(() => [
  80. vue.renderSlot(_ctx.$slots, "default", {}, () => [
  81. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(props.options, (item, index) => {
  82. return vue.openBlock(), vue.createBlock(checkbox["default"], vue.mergeProps({ key: index }, getOptionProps(item)), null, 16);
  83. }), 128))
  84. ])
  85. ]),
  86. _: 3
  87. }, 8, ["id", "class", "aria-label", "aria-labelledby"]);
  88. };
  89. }
  90. });
  91. var CheckboxGroup = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "checkbox-group.vue"]]);
  92. exports["default"] = CheckboxGroup;
  93. //# sourceMappingURL=checkbox-group2.js.map