Tooltip
悬停提示是全局单例:整页只挂一个 XTooltip(挂两个就弹两层),元素上只声明属性、不给每个按钮包一层组件。比原生 title 快(不用等一秒)、跟主题走、能带快捷键。本站在布局里挂了一个,下面的 demo 都复用它。
vue
<!-- 宿主根组件或布局里挂一次 -->
<XTooltip :theme="resolved" :shortcut="(command, args) => keymap.chordOf(command, args)" />
| 属性 | 作用 |
|---|---|
data-tip | 不带值:名字型,取 aria-label(图标按钮的名字只写一份);带值:说明型,不进 aria-label。都没有字 = 不提示 |
data-tip-location | top / right / bottom(缺省)/ left,放不下自动翻面 |
data-tip-target="cursor" | 锚在指针处而不是元素上(大块区域用) |
data-shortcut | 命令名,由 shortcut 解析函数按宿主键位表查成键位写法;不传解析函数时直接当键位写法(如 Mod+S) |
data-shortcut-args | 带参数的命令另给 JSON 参数,原样交给解析函数 |
按下即收、指针离开前不再弹(点了按钮还挡着它的结果),但点完提示字变了(切换类按钮)会立刻以新字重弹;键盘 Tab 到元素上也提示,Esc、滚轮、按键拖动与切走窗口收起。明暗由宿主经 theme 传入,组件不自己读页面主题。
名字型与说明型
图标按钮取 aria-label,说明写在 data-tip 里
1920 × 1080
快捷键与锚在指针处
data-shortcut 与 data-tip-target=cursor
在这片区域里移动指针
API
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
shortcut | ((command: string, args?: unknown) => string | undefined) | undefined | — | 命令名(连同 `data-shortcut-args` 解析出的参数)→ 键位写法,查不到回 undefined;不给时 `data-shortcut` 的值直接当键位写法 |
theme | UiTheme | undefined | — | 当前明暗,由宿主传入,缺省浅色 |
Slots
| 插槽 | 说明 |
|---|---|
default | — |