UNPKG

yanzhen-design-vue

Version:

59 lines (58 loc) 1.65 kB
import { ref, useAttrs, useSlots, computed, isVNode, createTextVNode, h, mergeProps, withCtx } from "vue"; import { isEmptyArray } from "@yanzhen-libs/utils"; import { useProxyProps, unref, isFunction } from "@yanzhen-libs/utils-vue"; import { pick, flattenDeep, isString } from "lodash-es"; import { Checkbox } from "ant-design-vue"; import { AntCheckbox } from "./checkbox.mjs"; function useCheckbox(props, emit) { const _ref = ref(null); const attrs = useAttrs(); const slots = useSlots(); const config = computed(() => { return pick(props, ...Object.keys(AntCheckbox.props)); }); const proxyProps = useProxyProps(config, AntCheckbox.emits, { emit, filter: true }); const createLabelVNode = () => { if (isVNode(props.label)) { return flattenDeep([props.label]); } else if (isString(props.label)) { return [createTextVNode(props.label)]; } return void 0; }; return [ { _ref, slots, proxyProps }, (props2) => { return h( Checkbox, mergeProps(unref(attrs), unref(proxyProps), props2, { ref: _ref }), { ...slots, default: withCtx(() => { var _a; const labelVNode = createLabelVNode(); if (isFunction(slots.default)) { return flattenDeep([(_a = slots == null ? void 0 : slots.default) == null ? void 0 : _a.call(slots), labelVNode ?? []]); } if (isEmptyArray(labelVNode)) { return void 0; } return labelVNode; }) } ); } ]; } export { useCheckbox };