UNPKG

yanzhen-design-vue

Version:

66 lines (65 loc) 1.8 kB
import { ref, useAttrs, useSlots, computed, mergeProps, isVNode, createTextVNode, createVNode, h, withCtx } from "vue"; import { useProxyProps, unref } from "@yanzhen-libs/utils-vue"; import { pick, isString, isFunction, flattenDeep } from "lodash-es"; import { Tag, Tooltip } from "ant-design-vue"; import { AntTooltip } from "./tooltip.mjs"; function useTooltip(props, emit) { const _ref = ref(null); const attrs = useAttrs(); const slots = useSlots(); const config = computed(() => { return pick(props, ...Object.keys(AntTooltip.props)); }); const proxyProps = useProxyProps(config, AntTooltip.emits, { emit, exclude: [] }); const propsRef = computed(() => { return mergeProps(unref(attrs), unref(proxyProps)); }); function handleTextVNode() { if (isVNode(props.text)) { return props.text; } else if (isString(props.text)) { return createTextVNode(props.text); } } function handleTagVNode() { if (isVNode(props.tagName)) { return props.tagName; } else if (isString(props.tagName)) { return createVNode( Tag, { color: props.tagColor }, props.tagName ); } } function handleDefaultVNode(props2) { const defaultVNodes = [handleTextVNode(), handleTagVNode()].filter((value) => isVNode(value)); if (isFunction(slots.default)) { return flattenDeep([slots.default(props2), defaultVNodes]); } return flattenDeep(defaultVNodes); } return [ { _ref, propsRef }, (props2) => { return h( Tooltip, mergeProps(unref(attrs), unref(props2) ?? {}, { ref: _ref }), { ...slots, default: withCtx(handleDefaultVNode) } ); } ]; } export { useTooltip };