UNPKG

yanzhen-design-vue

Version:

72 lines (71 loc) 1.95 kB
import { ref, useAttrs, computed, mergeProps } from "vue"; import { isObject, unref, useProxyProps } from "@yanzhen-libs/utils-vue"; import { isString, isFunction, isBoolean, omit } from "lodash-es"; import { dividerOptions, AntDivider, dividerEmits } from "./divider.mjs"; const { ns } = dividerOptions; function useDivider(props, emit) { const _ref = ref(null); const attrs = useAttrs(); const textRef = computed(() => props.text); const titleRef = computed(() => { const defStyle = {}; if (typeof props.title === "string") { return { text: props.title, style: defStyle }; } else if (isObject(props.title)) { return mergeProps( { ...props.title }, { style: defStyle } ); } return { style: defStyle }; }); const titleBoldRef = computed(() => { if (isString(props.titleFontBold)) { return ns.is(props.titleFontBold); } return void 0; }); const dividerBoldRef = computed(() => { if (isString(props.dividerBold)) { return ns.is(props.dividerBold); } return void 0; }); const hiddenTitle = computed(() => { const { hidden, text } = unref(titleRef); if (isFunction(hidden)) { return hidden(text) ?? false; } if (isBoolean(hidden)) { return hidden; } const hiddenTitle2 = props.hiddenTitle; if (isFunction(hiddenTitle2)) { return hiddenTitle2(text) ?? false; } if (isBoolean(hiddenTitle2)) { return hiddenTitle2; } return false; }); const config = computed(() => omit(props, ...Object.keys(AntDivider.props))); const proxyProps = useProxyProps(config, dividerEmits, { emit }); const propsRef = computed(() => { return mergeProps(unref(attrs), unref(proxyProps)); }); return { _ref, propsRef, textRef, titleRef, hiddenTitle, titleBoldRef, dividerBoldRef }; } export { useDivider };