docs/.vitepress/theme/components/Tooltip.vue

2c1cf468ccc335a18f9e87c6d54aa47636cb795d
wotaku/docs/.vitepress/theme/components/Tooltip.vue history · blame · raw

97 lines · 2230 bytes

 1<!--
 2  All Rights Reserved
 3
 4  Copyright (c) 2025 taskylizard
 5
 6  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7-->
 8<script setup lang="ts">
 9import { ref } from 'vue'
10
11const isOpen = ref(false)
12
13withDefaults(
14  defineProps<{
15    title: string
16    icon: string
17  }>(),
18  {
19    title: 'Info',
20    // https://icon-sets.iconify.design/material-symbols/
21    icon: 'i-material-symbols-help'
22  }
23)
24</script>
25
26<template>
27  <VTooltip theme="vp-tooltip" @show="isOpen = true" @hide="isOpen = false">
28    <button
29      aria-label="Tooltip"
30      :class="[
31        'text-$vp-custom-block-tip-text-deep size-3 p-0 select-none font-bold cursor-pointer',
32        isOpen && 'tooltip-open-glow'
33      ]"
34    >
35      <div :class="icon" />
36    </button>
37
38    <template #popper>
39      <div class="border-$vp-c-divider bg-$vp-c-bg-alt b-rd-4 max-w-md max-h-md border-2 border-solid p-4 transition-all">
40        <h3
41          class="text-$vp-c-text-1 mb-2 text-lg font-semibold"
42          v-text="title"
43        />
44        <div class="text-$vp-c-text-2 text-sm content">
45          <slot />
46        </div>
47      </div>
48    </template>
49  </VTooltip>
50</template>
51
52<style>
53.v-popper__popper {
54  --uno: z-9999;
55}
56
57.v-popper {
58  display: inline-flex !important;
59  vertical-align: -0.125em;
60}
61
62.v-popper__popper .content ol {
63  list-style: decimal !important;
64}
65
66.v-popper__popper .content ul {
67  --uno: ml-4;
68  color: var(--vp-c-text-2);
69  list-style: disc !important;
70}
71
72.v-popper__popper .content table {
73  width: 100%;
74  border-collapse: collapse;
75  background-color: var(--vp-c-bg-soft);
76  color: var(--vp-c-text-1);
77  --uno: text-sm;
78}
79
80.v-popper__popper .content thead th {
81  background-color: var(--vp-c-bg-soft);
82  color: var(--vp-c-text-1);
83  font-weight: 600;
84  padding: 6px 8px;
85  border-bottom: 1px solid var(--vp-c-divider);
86}
87
88.v-popper__popper .content tbody td {
89  padding: 6px 8px;
90  border-bottom: 1px solid var(--vp-c-divider);
91}
92
93.tooltip-open-glow {
94  filter: drop-shadow(0 0 6px currentColor) drop-shadow(0 0 12px currentColor);
95  transition: filter 0.2s ease;
96}
97</style>