1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
use *;
use ;
use component_doc;
use inject_style;
use tooltip_styles;
use ;
use crate;
use crateMaterialElevation;
/// `Tooltip` shows a brief hint when the wrapped control is hovered or focused — ideal for
/// icon-only buttons and truncated labels. Set `content` to a short phrase; pick `position`
/// and `appearance` for contrast. Always give icon-only triggers an accessible name too;
/// never put required information only in a tooltip.
///
/// # When to use
///
/// - Icon-only buttons, truncated labels, clarifying a control with minimal visible text
/// - One short phrase on hover or focus — not interactive content
/// - Rich panels, pickers, or action lists — use [`Popover`](crate::Popover) or [`Menu`](crate::Menu)
///
/// # Overlay surfaces
///
/// - **Brief non-interactive hint** — `Tooltip` (this component)
/// - **Floating panel with content or inputs** — [`Popover`](crate::Popover)
/// - **List of actions from a trigger** — [`Menu`](crate::Menu)
/// - **Block the page or trap focus** — [`Dialog`](crate::Dialog)
///
/// # Usage
///
/// 1. Wrap the trigger (e.g. [`crate::Button`]) as children.
/// 2. Set `content` to the hint string (or `Signal` for dynamic text).
/// 3. Optional: `position` (`Top` default), `appearance` (`Normal` / `Inverted`).
/// 4. On disabled buttons that must stay focusable, set `disabled_focusable=true` on the
/// wrapped [`Button`](crate::Button) so keyboard users can reach the tooltip.
///
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <Tooltip content="Save changes" position=TooltipPosition::Bottom>
/// <Button appearance=ButtonAppearance::Subtle icon=icondata::AiSaveOutlined />
/// </Tooltip>
/// }
/// ```
///
/// # Best Practices
///
/// ## Do's
///
/// * Keep content to one short phrase * Use `TooltipAppearance::Inverted` on dark surfaces when contrast needs a boost * Provide `aria-label` on icon-only triggers in addition to the tooltip
///
/// ## Don'ts
///
/// * Do not hide essential information only in a tooltip * Do not use tooltips for interactive content — use [`Popover`](crate::Popover) or [`Dialog`](crate::Dialog)
///
/// # TooltipPosition variants
///
/// | Variant | Placement |
/// |---------|-----------|
/// | `Top` (default) | Above trigger, centered |
/// | `Bottom` | Below trigger, centered |
/// | `Left` | Left of trigger, centered |
/// | `Right` | Right of trigger, centered |
/// | `TopStart` / `TopEnd` | Above, aligned to start/end edge |
/// | `BottomStart` / `BottomEnd` | Below, aligned to start/end edge |
/// | `LeftStart` / `LeftEnd` | Left, aligned to start/end edge |
/// | `RightStart` / `RightEnd` | Right, aligned to start/end edge |
///
/// Optional `show_delay_ms` / `hide_delay_ms` control hover timing (defaults: `0` / `100`).
///
/// # Examples
///
/// ## Basic tooltip (top)
/// Short hint on hover or focus for controls with minimal visible labeling. Top is the default when space allows above the trigger.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-preview">
/// <Tooltip content="More information">
/// <Button appearance=ButtonAppearance::Subtle>"Hover me"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Inverted appearance
/// Dark tooltip body on light triggers or when extra contrast is needed on tinted surfaces.
/// <!-- preview -->
/// ```rust
/// use crate::Button;
/// view! {
/// <div data-testid="tooltip-inverted">
/// <Tooltip content="Dark tooltip" appearance=TooltipAppearance::Inverted>
/// <Button>"Target"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Bottom placement
/// Opens below the trigger when the control sits under headers or near the top viewport edge.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-bottom">
/// <Tooltip content="Below" position=TooltipPosition::Bottom>
/// <Button appearance=ButtonAppearance::Subtle>"Bottom"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Left placement
/// Positions the hint to the left of icon-only toolbar buttons or triggers on the right side of the layout.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-left">
/// <Tooltip content="To the left" position=TooltipPosition::Left>
/// <Button appearance=ButtonAppearance::Subtle>"Left"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Right placement
/// Positions the hint to the right when the trigger sits on the left margin or left-aligned controls.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-right">
/// <Tooltip content="To the right" position=TooltipPosition::Right>
/// <Button appearance=ButtonAppearance::Subtle>"Right"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Top start (aligned to start edge)
/// Aligns the tooltip with the start edge of wide triggers—multi-word buttons or split controls.
/// <!-- preview -->
/// ```rust
/// use crate::Button;
/// view! {
/// <div data-testid="tooltip-top-start">
/// <Tooltip content="Top start" position=TooltipPosition::TopStart>
/// <Button>"Top start"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Bottom end
/// Aligns with the end edge when the trigger spans most of a row or sits flush to the trailing margin.
/// <!-- preview -->
/// ```rust
/// use crate::Button;
/// view! {
/// <div data-testid="tooltip-bottom-end">
/// <Tooltip content="Bottom end" position=TooltipPosition::BottomEnd>
/// <Button>"Bottom end"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Disabled focusable button
/// Wrap a disabled button with `disabled_focusable=true` so keyboard users can focus it and read the tooltip.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-disabled-focusable">
/// <Tooltip content="Save is unavailable until you fix validation errors">
/// <Button appearance=ButtonAppearance::Primary disabled=true disabled_focusable=true>
/// "Save"
/// </Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Show delay
/// Tooltip opens only after hovering for the configured show delay.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-show-delay">
/// <Tooltip content="Delayed hint" show_delay_ms=400>
/// <Button appearance=ButtonAppearance::Subtle>"Hover and wait"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```
///
/// ## Theme token
/// Tooltip surface inherits neutral background tokens from the Orbital theme provider.
/// <!-- preview -->
/// ```rust
/// use crate::{Button, ButtonAppearance};
/// view! {
/// <div data-testid="tooltip-theme">
/// <Tooltip content="Themed tooltip">
/// <Button appearance=ButtonAppearance::Subtle>"Theme"</Button>
/// </Tooltip>
/// </div>
/// }
/// ```