UNPKG

yanzhen-design-vue

Version:

37 lines (36 loc) 905 B
import { buildProp, definePropType, optionType, buildProps } from "@yanzhen-libs/utils-vue"; import { isEmptyArray } from "@yanzhen-libs/utils"; import { uniq } from "lodash-es"; function optionProp() { return buildProp({ type: definePropType(Array) }); } function optionKeyProp(key, values) { return buildProp({ type: definePropType(String), values, default: key }); } function optionKeyProps(keys) { const types = isEmptyArray(keys) ? optionType : uniq(keys.concat(optionType)); return types.reduce((prev, key) => { prev[`${key}Key`] = optionKeyProp(key, [...keys ?? []]); return prev; }, {}); } function optionsProps(keys) { const keyProps = optionKeyProps(isEmptyArray(keys) ? [] : keys); const props = { options: optionProp(), ...keyProps }; return buildProps(props); } export { optionKeyProp, optionKeyProps, optionProp, optionsProps };