@opensig/opendesign
Version:
<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>
60 lines (59 loc) • 2 kB
JavaScript
import { defineComponent, ref, inject, watch, computed, provide, toRef, createElementBlock, openBlock, normalizeClass, renderSlot } from "vue";
import { checkboxGroupProps } from "./types.mjs";
import { checkboxGroupInjectKey } from "./provide.mjs";
import { isArray, isUndefined } from "../_utils/is.mjs";
import { formItemInjectKey } from "../form/provide.mjs";
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "OCheckboxGroup",
props: checkboxGroupProps,
emits: ["update:modelValue", "change"],
setup(__props, { emit: __emit }) {
const props = __props;
const emits = __emit;
const realValue = ref(isArray(props.modelValue) ? props.modelValue : props.defaultValue);
const formItemInjection = inject(formItemInjectKey, null);
watch(
() => props.modelValue,
(val) => {
if (isArray(val)) {
realValue.value = val;
}
}
);
const isMinimum = computed(() => isUndefined(props.min) ? false : realValue.value.length <= props.min);
const isMaximum = computed(() => isUndefined(props.max) ? false : realValue.value.length >= props.max);
const updateModelValue = (val) => {
realValue.value = val;
emits("update:modelValue", val);
};
const onChange = (val, ev) => {
var _a, _b;
emits("change", val, ev);
(_b = formItemInjection == null ? void 0 : (_a = formItemInjection.fieldHandlers).onChange) == null ? void 0 : _b.call(_a);
};
provide(checkboxGroupInjectKey, {
realValue,
disabled: toRef(props, "disabled"),
isMinimum,
isMaximum,
updateModelValue,
onChange
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock(
"div",
{
class: normalizeClass(["o-checkbox-group", `o-checkbox-group-${props.direction}`])
},
[
renderSlot(_ctx.$slots, "default")
],
2
/* CLASS */
);
};
}
});
export {
_sfc_main as default
};