Tooltip
Installation
import { Tooltip } from "@olab/components";Overview
滑過或點一下觸發元素時,浮出一段簡短說明。外框是品牌色細邊、12px 圓角,預設帶一個小箭頭指回觸發元素。
它同時吃 hover 和點擊:桌面滑過就開,手機點一下開、再點一下關,所以手機上也讀得到。
Interactive Demo
HOVER OR CLICK — tooltip opens with an arrow
This is a tooltip
State Matrix
OPEN STATE — static replica (same classes, rendered in place)
top arrow
placement = topright arrow
placement = rightbottom arrow
placement = bottomleft arrow
placement = leftNo arrow
showArrow = falseLong content wraps at the 320px max width instead of growing wider, so a sentence of two stays readable.
long content · max-w-xsExamples
PLACEMENT — top / right / bottom / left (live)
Top tooltip
Right tooltip
Bottom tooltip
Left tooltip
WITHOUT ARROW — showArrow=false (live)
No arrow tooltip
Spec
| Part | Value | Source class |
|---|---|---|
| Background | surface | bg-primary |
| Border | 1px brand | border border-[var(--color-bg-brand-solid)] |
| Text | 12px(bodyS) | text-bodyS text-primary |
| Radius | 12px | rounded-lg |
| Padding | 12px × 8px(左右 × 上下) | px-3 py-2 |
| Max width | 320px | max-w-xs |
| Arrow | 8px,底色同外框、邊框同品牌色 | --arrow-size:8px |
| Open / close delay | 0ms / 100ms |
數值為 2026-06-11 在 dark 模式下的實測(getComputedStyle);source class 對照目前的元件原始碼,色票隨目前的 dark / light 模式即時解析。完整量測、狀態細節與已知不一致見 live-ds-spec/tooltip.md。
Usage
Do
- 補充一句不放也看得懂、放了更清楚的說明,例如名詞解釋、數字的計算口徑。
- 內容保持一兩句;超過 320px 會自動換行,但長篇說明應該放進頁面或 Popover。
- 預設放在上方;靠近畫面邊緣時再換 placement。
Don't
- 不要把完成操作必需的資訊只放在 Tooltip 裡;有人不會去滑。
- 不要在 Tooltip 裡放按鈕或表單;需要互動內容請用 Popover。
- 不要用 className 改外框顏色或圓角;Tooltip 的品牌色細邊就是它的樣子。
Links
- Measured spec
- live-ds-spec/tooltip.md