11# Tooltip 文字提示
22
3- 常用于展示鼠标 hover 时的提示信息 。
3+ 常用于展示鼠标悬浮、点击时的提示信息 。
44
55可用来代替系统默认的 ` title ` 提示,通常用于针对一个图标按钮的鼠标悬浮显示简单说明
66
7- 该提示使用纯 ` CSS ` 实现,所以气泡框位置通常需要手动设置
7+ 该提示基于 [ popover ] ( /components/popover ) 实现,只是对样式进行了简单修改。
88
9- ### 基础用法
10-
11- 使用 ` title ` 属性来决定 ` hover ` 时的提示信息。 由 ` placement ` 属性决定展示位置: ` topStart ` 、` top[默认] ` 、` topEnd ` 、` bottomStart ` 、` bottom ` 、` bottomEnd `
12-
13- <ClientOnly ><CodePreview >
14- <textarea lang =" vue-html " >
15-
16- <div class="flex-between">
17- <nt-tooltip placement="topStart" title="prompt text">
18- <nt-button>topStart</nt-button>
19- </nt-tooltip>
20- <nt-tooltip placement="top" title="prompt text">
21- <nt-button>top</nt-button>
22- </nt-tooltip>
23- <nt-tooltip placement="topEnd" title="prompt text">
24- <nt-button>topEnd</nt-button>
25- </nt-tooltip>
26- </div>
27- <div class="flex-between mt-15">
28- <nt-tooltip placement="bottomStart" title="prompt text">
29- <nt-button>bottomStart</nt-button>
30- </nt-tooltip>
31- <nt-tooltip placement="bottom" title="prompt text">
32- <nt-button>bottom</nt-button>
33- </nt-tooltip>
34- <nt-tooltip placement="bottomEnd" title="prompt text">
35- <nt-button>bottomEnd</nt-button>
36- </nt-tooltip>
37- </div>
38- </textarea >
39- </CodePreview ></ClientOnly >
40-
41- ### 自定义提示
42-
43- 通过使用 ` title ` 插槽来渲染自定义的提示; 如果同时传递 ` title ` 和 插槽,则 ` title ` 属性为准
9+ ## 演示
4410
4511<script setup >
46- import { Tooltip , Button } from ' ../../src'
12+ import { Tooltip } from ' ../../src'
4713</script >
4814
49- <ClientOnly >
50- <CodePreview >
51- <textarea lang =" vue-html " >
52- <nt-tooltip>
53- <nt-button>自定义提示</nt-button>
54- <template v-slot:title>
55- <span style="color:red;">custome propmt text</span>
56- </template>
57- </nt-tooltip>
58- </textarea >
59- <template #preview>
60- <Tooltip >
61- <Button >自定义提示</Button >
62- <template #title>
63- <span style =" color :red ;" >custome propmt text</span >
64- </template >
65- </Tooltip >
66- </template >
67- </CodePreview >
68- </ClientOnly >
69-
70- ### 受控模式
71-
72- 通过 ` visible ` 属性来控制提示框的显示与隐藏
73-
74- <ClientOnly >
75- <CodePreview >
76- <textarea lang =" vue-html " >
77- <nt-tooltip :visible="true" title="Content">
78- <span>受控模式</span>
79- </nt-tooltip>
80- </textarea >
81- <template #preview>
82- <Tooltip :visible =" true " title =" Content " >
83- <span >受控模式</span >
84- </Tooltip >
85- </template >
86- </CodePreview >
87- </ClientOnly >
88-
89- ### 自定义风格
90-
91- 通过 ` styleName ` 属性来设置提示框的风格名称,然后自定义 ` .nt-tooltip--xx ` 来定义风格样式,` xx ` 就是传递的 ` styleName ` 的值;例如从 [ css-generators] ( https://css-generators.com/tooltip-speech-bubble/ ) 复制一段样式,改名称为 ` nt-tooltip--demo `
92-
93- <ClientOnly >
94- <CodePreview >
95- <textarea lang =" vue " >
96- <template>
97- <nt-tooltip title="Content" style-name="demo" placement="bottom">
98- <span>自定义风格</span>
99- </nt-tooltip>
100- </template>
101- <style>
102- .nt-tooltip--demo {
103- color: #fff;
104- font-size: 18px;
105- max-width: 28ch;
106- text-align: center;
107- }
108- .nt-tooltip--demo {
109- /* triangle dimension */
110- --b: 2em; /* base */
111- --h: 1em; /* height */
112- --p: 50%; /* triangle position (0%:left 100%:right) */
113- --r: 1.2em; /* the radius */
114- --c: #6a4a3c;
115- padding: 1em;
116- border-radius: min(var(--r), var(--p) - var(--b) / 2)
117- min(var(--r), 100% - var(--p) - var(--b) / 2) var(--r) var(--r) / var(--r);
118- clip-path: polygon(
119- 0 0,
120- 0 100%,
121- 100% 100%,
122- 100% 0,
123- min(100%, var(--p) + var(--b) / 2) 0,
124- var(--p) calc(-1 * var(--h)),
125- max(0%, var(--p) - var(--b) / 2) 0
126- );
127- background: var(--c);
128- border-image: conic-gradient(var(--c) 0 0) fill 0/ 0 calc(
129- 100% - var(--p) - var(--b) / 2
130- ) var(--r) calc(var(--p) - var(--b) / 2) / var(--h) 0 0 0;
131- }
132- .nt-tooltip-bottom.nt-tooltip--demo {
133- top: calc(100% + 20px);
134- }
135- </style>
136- </textarea >
137- <template #preview>
138- <Tooltip title =" Content " style-name =" demo " placement =" bottom " >
139- <span >自定义风格</span >
140- </Tooltip >
141- </template >
142- </CodePreview >
143- </ClientOnly >
144-
145- > 可以通过配合 ` nt-tooltip-top ` 、` nt-tooltip-start ` 等调整箭头或者提示框的位置
146-
147- ### 触发方式
15+ ### 基础用法
14816
149- 默认是悬浮触发,可以通过修改 ` trigger ` 属性来改变触发方式
17+ 传递 ` content ` 属性为提示内容
15018
15119<ClientOnly >
15220 <CodePreview >
15321 <textarea lang =" vue-html " >
154- <script setup>
155- </script>
156- <template>
157- <hr />
158- </template>
22+ <nt-tooltip content="提示内容">
23+ <span>显示提示</span>
24+ </nt-tooltip>
15925 </textarea >
16026 <template #preview>
161- <Tooltip title =" prompt text " >
162- <Button >悬浮</Button >
163- </Tooltip >
164- <Tooltip title =" prompt text " trigger =" click " class =" ml-10 " >
165- <Button >点击</Button >
27+ <Tooltip content =" 提示内容 " >
28+ <span >显示提示</span >
16629 </Tooltip >
16730 </template >
16831 </CodePreview >
@@ -172,16 +35,11 @@ import { Tooltip, Button } from '../../src'
17235
17336### Tooltip Props
17437
175- | 参数 | 说明 | 类型 | 可选值 | 默认值 |
176- | -------------- | ------------------------ | --------- | ----------------------------------------------------------------- | --------- |
177- | ` title ` | 提示文字 | ` string ` | - | - |
178- | ` placement ` | 提示框出现位置 | ` string ` | ` topStart ` 、` top ` 、` topEnd ` 、` bottomStart ` 、` bottom ` 、` bottomEnd ` | ` top ` |
179- | ` styleName ` | 风格, 可以自定义风格 | ` string ` | - | ` default ` |
180- | ` visible ` | 是否显示提示框[ 受控模式] | ` boolean ` | - | ` false ` |
181- | ` contentClass ` | Tooltip Content 样式 | ` string ` | - | - |
38+ 参数与 [ popover-props] ( /components/popover#popover-props ) 一致
18239
18340### Tooltip Slots
18441
185- | 参数 | 说明 | 参数 |
186- | ------- | ---------------------- | ---- |
187- | ` title ` | 自定义提示内容以及样式 | ` () ` |
42+ | 参数 | 说明 |
43+ | --------- | -------------- |
44+ | ` default ` | 触发提示的元素 |
45+ | ` content ` | 自定义提示内容 |
0 commit comments