| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import { defineComponent, computed, provide, toRefs, watch, openBlock, createBlock, resolveDynamicComponent, unref, normalizeClass, withCtx, renderSlot, createElementBlock, Fragment, renderList, mergeProps, nextTick } from 'vue';
- import { pick, isEqual } from 'lodash-unified';
- import { checkboxGroupProps, checkboxGroupEmits, checkboxDefaultProps } from './checkbox-group.mjs';
- import { checkboxGroupContextKey } from './constants.mjs';
- import Checkbox from './checkbox.mjs';
- import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
- import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
- import { useFormItem, useFormItemInputId } from '../../form/src/hooks/use-form-item.mjs';
- import { debugWarn } from '../../../utils/error.mjs';
- import { UPDATE_MODEL_EVENT, CHANGE_EVENT } from '../../../constants/event.mjs';
- const __default__ = defineComponent({
- name: "ElCheckboxGroup"
- });
- const _sfc_main = /* @__PURE__ */ defineComponent({
- ...__default__,
- props: checkboxGroupProps,
- emits: checkboxGroupEmits,
- setup(__props, { emit }) {
- const props = __props;
- const ns = useNamespace("checkbox");
- const { formItem } = useFormItem();
- const { inputId: groupId, isLabeledByFormItem } = useFormItemInputId(props, {
- formItemContext: formItem
- });
- const changeEvent = async (value) => {
- emit(UPDATE_MODEL_EVENT, value);
- await nextTick();
- emit(CHANGE_EVENT, value);
- };
- const modelValue = computed({
- get() {
- return props.modelValue;
- },
- set(val) {
- changeEvent(val);
- }
- });
- const aliasProps = computed(() => ({
- ...checkboxDefaultProps,
- ...props.props
- }));
- const getOptionProps = (option) => {
- const base = {
- label: option[aliasProps.value.label],
- value: option[aliasProps.value.value],
- disabled: option[aliasProps.value.disabled]
- };
- return { ...option, ...base };
- };
- provide(checkboxGroupContextKey, {
- ...pick(toRefs(props), [
- "size",
- "min",
- "max",
- "disabled",
- "validateEvent",
- "fill",
- "textColor"
- ]),
- modelValue,
- changeEvent
- });
- watch(() => props.modelValue, (newVal, oldValue) => {
- if (props.validateEvent && !isEqual(newVal, oldValue)) {
- formItem == null ? void 0 : formItem.validate("change").catch((err) => debugWarn());
- }
- });
- return (_ctx, _cache) => {
- var _a;
- return openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), {
- id: unref(groupId),
- class: normalizeClass(unref(ns).b("group")),
- role: "group",
- "aria-label": !unref(isLabeledByFormItem) ? _ctx.ariaLabel || "checkbox-group" : void 0,
- "aria-labelledby": unref(isLabeledByFormItem) ? (_a = unref(formItem)) == null ? void 0 : _a.labelId : void 0
- }, {
- default: withCtx(() => [
- renderSlot(_ctx.$slots, "default", {}, () => [
- (openBlock(true), createElementBlock(Fragment, null, renderList(props.options, (item, index) => {
- return openBlock(), createBlock(Checkbox, mergeProps({ key: index }, getOptionProps(item)), null, 16);
- }), 128))
- ])
- ]),
- _: 3
- }, 8, ["id", "class", "aria-label", "aria-labelledby"]);
- };
- }
- });
- var CheckboxGroup = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "checkbox-group.vue"]]);
- export { CheckboxGroup as default };
- //# sourceMappingURL=checkbox-group2.mjs.map
|