2022-01-10 12:43:04 +08:00
|
|
|
<template>
|
|
|
|
<div v-if="showTooltip">
|
|
|
|
<n-tooltip :placement="placement" trigger="hover">
|
|
|
|
<template #trigger>
|
2022-04-29 15:53:12 +08:00
|
|
|
<div class="flex-center h-full cursor-pointer dark:hover:bg-[#333]" :class="computedClass">
|
2022-01-10 12:43:04 +08:00
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
{{ tooltipContent }}
|
|
|
|
</n-tooltip>
|
|
|
|
</div>
|
2022-04-29 15:53:12 +08:00
|
|
|
<div v-else class="flex-center cursor-pointer dark:hover:bg-[#333]" :class="computedClass">
|
2022-01-10 12:43:04 +08:00
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed } from 'vue';
|
|
|
|
import type { FollowerPlacement } from 'vueuc';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
/** tooltip显示文本 */
|
|
|
|
tooltipContent?: string;
|
|
|
|
/** tooltip的位置 */
|
|
|
|
placement?: FollowerPlacement;
|
|
|
|
/** class类 */
|
|
|
|
contentClass?: string;
|
2022-04-29 15:53:12 +08:00
|
|
|
/** 反转模式下 */
|
|
|
|
inverted?: boolean;
|
2022-01-10 12:43:04 +08:00
|
|
|
}
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
|
|
|
tooltipContent: '',
|
|
|
|
placement: 'bottom',
|
2022-04-29 15:53:12 +08:00
|
|
|
contentClass: '',
|
|
|
|
inverted: false
|
2022-01-10 12:43:04 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const showTooltip = computed(() => Boolean(props.tooltipContent));
|
2022-04-29 15:53:12 +08:00
|
|
|
|
|
|
|
const computedClass = computed(() =>
|
|
|
|
[props.contentClass, props.inverted ? 'hover:bg-primary' : 'hover:bg-[#f6f6f6]'].join(' ')
|
|
|
|
);
|
2022-01-10 12:43:04 +08:00
|
|
|
</script>
|
|
|
|
<style scoped></style>
|