hongluan-ui
Version:
Hongluan Component Library for Vue 3
96 lines (93 loc) • 3.48 kB
JavaScript
import { defineComponent, nextTick, computed, provide, toRefs, watch, openBlock, createBlock, unref, normalizeClass, withCtx, renderSlot } from 'vue';
import { pick } from 'lodash-unified';
import '../../../constants/index.mjs';
import '../../../tokens/index.mjs';
import '../../../hooks/index.mjs';
import { HlGroup } from '../../group/index.mjs';
import '../../../utils/index.mjs';
import { checkboxGroupProps, checkboxGroupEmits } from './checkbox-group2.mjs';
import { useFormItem, useFormItemInputId } from '../../../hooks/use-form-item/index.mjs';
import { useConsistentProp } from '../../../hooks/use-consistent-prop/index.mjs';
import { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';
import { checkboxGroupContextKey } from '../../../tokens/checkbox.mjs';
import { FormItemEvents } from '../../../tokens/form.mjs';
import { debugWarn } from '../../../utils/error.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
const __default__ = defineComponent({
name: "CheckboxGroup"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: checkboxGroupProps,
emits: checkboxGroupEmits,
setup(__props, { emit }) {
const props = __props;
const { formItem } = useFormItem();
const { inputId: groupId, isLabeledByFormItem } = useFormItemInputId(props, {
formItemContext: formItem
});
const { size: checkboxGroupSize, disabled: checkboxGroupDisabled, fill: checkboxGroupFill } = useConsistentProp();
const changeEvent = async (value) => {
emit(UPDATE_MODEL_EVENT, value);
await nextTick();
emit("change", value);
};
const modelValue = computed({
get() {
return props.modelValue;
},
set(val) {
changeEvent(val);
}
});
provide(checkboxGroupContextKey, {
...pick(toRefs(props), [
"min",
"max",
"validateEvent",
"round",
"type",
"custom"
]),
size: checkboxGroupSize,
disabled: checkboxGroupDisabled,
fill: checkboxGroupFill,
modelValue,
changeEvent
});
watch(() => props.modelValue, () => {
var _a;
if (props.validateEvent) {
(_a = formItem == null ? void 0 : formItem.validate) == null ? void 0 : _a.call(formItem, FormItemEvents.change).catch((err) => debugWarn(err));
}
});
const { namespace } = useNamespace("checkbox-group");
return (_ctx, _cache) => {
var _a;
return openBlock(), createBlock(unref(HlGroup), {
id: unref(groupId),
class: normalizeClass([unref(namespace)]),
dir: _ctx.dir,
merge: _ctx.merge,
indent: _ctx.indent,
gap: _ctx.gap,
"gap-x": _ctx.gapX,
"gap-y": _ctx.gapY,
full: _ctx.full,
wrap: _ctx.wrap,
align: _ctx.align,
block: _ctx.block,
role: "group",
"aria-label": !unref(isLabeledByFormItem) ? _ctx.ariaLabel || _ctx.label || "checkbox-group" : void 0,
"aria-labelledby": unref(isLabeledByFormItem) ? (_a = unref(formItem)) == null ? void 0 : _a.labelId : void 0
}, {
default: withCtx(() => [
renderSlot(_ctx.$slots, "default")
]),
_: 3
}, 8, ["id", "class", "dir", "merge", "indent", "gap", "gap-x", "gap-y", "full", "wrap", "align", "block", "aria-label", "aria-labelledby"]);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=checkbox-group.mjs.map