BasicHelp.vue
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script lang="ts" setup>
import { Tooltip } from 'ant-design-vue'
import { Icon } from '@iconify/vue'
import type { CSSProperties, RendererElement } from 'vue'
import { computed, useSlots } from 'vue'
import type { TooltipPlacement } from 'ant-design-vue/es/tooltip/Tooltip'
import { isString } from 'lodash-es'
import { getSlot } from '@/utils/slotsHelp'
import { useDesign } from '@/hooks/useDesign'
const props = withDefaults(
defineProps<{
maxWidth?: string
showIndex?: boolean
color?: string
fontSize?: string
placement?: TooltipPlacement
text?: string | string[]
}>(), {
maxWidth: '600px',
color: '#fff',
fontSize: '14px',
text: () => [],
},
)
const slots = useSlots()
const slot = getSlot(slots)
const { prefixCls } = useDesign('basic-help')
const getOverlayStyle = computed<CSSProperties>(() => ({ maxWidth: props.maxWidth }))
const getTooltipStyle = computed<CSSProperties>(() => ({ color: props.color, fontSize: props.fontSize }))
const getTitle = computed(() => {
const { text } = props
if (isString(text)) return [{ title: text, index: 1 }]
return text.map((item, index) => ({ title: item, index: index + 1 }))
})
</script>
<template>
<Tooltip
:overlay-class-name="`${prefixCls}__wrap`" :auto-adjust-overflow="true" :overlay-style="getOverlayStyle"
:placement="placement"
>
<template #title>
<div :style="getTooltipStyle">
<p v-for="item in getTitle" :key="item.index">
{{ item.title }}
</p>
</div>
</template>
<span :class="prefixCls" class="flex items-center">
<component :is="slot as RendererElement" v-if="slots?.default" />
<Icon v-if="!slots?.default" icon="ph:question" class="cursor-pointer text-base" />
</span>
</Tooltip>
</template>