@tangible/ui 0.2.44 → 0.2.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ColorPicker/ColorPicker.js +1 -1
- package/components/GradientPicker/GradientPicker.js +1 -1
- package/components/PasswordInput/PasswordInput.d.ts +7 -0
- package/components/PasswordInput/PasswordInput.js +64 -0
- package/components/PasswordInput/index.d.ts +3 -0
- package/components/PasswordInput/index.js +2 -0
- package/components/PasswordInput/types.d.ts +45 -0
- package/components/PasswordInput/types.js +6 -0
- package/components/SecretInput/SecretInput.js +10 -33
- package/components/Tooltip/Tooltip.d.ts +1 -1
- package/components/Tooltip/Tooltip.js +302 -19
- package/components/Tooltip/types.d.ts +30 -0
- package/components/index.d.ts +2 -0
- package/components/index.js +1 -0
- package/figma-tokens.json +1 -1
- package/icons/icons.svg +1 -1
- package/icons/sprite-version.js +1 -1
- package/icons/sprite.php +1 -1
- package/package.json +5 -1
- package/skills/building-with-tui/SKILL.md +9 -3
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +51 -0
- package/styles/all.expanded.unlayered.css +51 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +5 -1
- package/styles/components/password-input.scss +24 -0
- package/styles/components/secret-input.scss +1 -65
- package/styles/system/_reveal.scss +82 -0
- package/styles/system/index.scss +1 -0
- package/tui-manifest.json +93 -2
- package/utils/reveal/RevealToggle.d.ts +32 -0
- package/utils/reveal/RevealToggle.js +57 -0
- package/utils/reveal/index.d.ts +3 -0
- package/utils/reveal/index.js +4 -0
- package/utils/reveal/useReveal.d.ts +26 -0
- package/utils/reveal/useReveal.js +55 -0
|
@@ -9,6 +9,45 @@ import { getElementRef } from '../../utils/compose-refs.js';
|
|
|
9
9
|
import { TooltipContext, TooltipProviderContext, useTooltipContext, useTooltipProviderContext, } from './TooltipContext.js';
|
|
10
10
|
import { toPlacement } from './types.js';
|
|
11
11
|
// =============================================================================
|
|
12
|
+
// Press and popup helpers
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/** Elements whose press does something, so it closes the tooltip. */
|
|
15
|
+
const ACTIVATABLE = 'button, a[href], input, select, textarea, summary, [role="button"], [role="link"], ' +
|
|
16
|
+
'[role="combobox"], [role="menuitem"], [role="tab"], [role="switch"], [role="checkbox"], ' +
|
|
17
|
+
'[role="radio"], [aria-haspopup]:not([aria-haspopup="false"])';
|
|
18
|
+
/** A disabled control: pressing it does nothing, so it isn't a press. */
|
|
19
|
+
const DISABLED = ':disabled, [aria-disabled="true"]';
|
|
20
|
+
/** Links: Space scrolls the page rather than following one. */
|
|
21
|
+
const LINK = 'a[href], [role="link"]';
|
|
22
|
+
/**
|
|
23
|
+
* Where Enter and Space are typing, not activation; a pointer press here is
|
|
24
|
+
* click-to-focus, not a press either.
|
|
25
|
+
*/
|
|
26
|
+
const TEXT_ENTRY = 'textarea, select, [contenteditable]:not([contenteditable="false"]), ' +
|
|
27
|
+
'input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"])' +
|
|
28
|
+
':not([type="radio"]):not([type="image"]):not([type="file"]):not([type="color"])';
|
|
29
|
+
/**
|
|
30
|
+
* An open popup trigger. aria-expanded alone also means "this section is
|
|
31
|
+
* expanded" (Accordion, Sidebar.Toggle, a NavMenu toggle), and those keep
|
|
32
|
+
* their tooltips, so it counts only on an element that says it has a popup:
|
|
33
|
+
* aria-haspopup (Popover, Dropdown, Select, the pickers) or a combobox.
|
|
34
|
+
*/
|
|
35
|
+
const OPEN_POPUP_TRIGGER = '[aria-expanded="true"]:is([aria-haspopup]:not([aria-haspopup="false"]), [role="combobox"])';
|
|
36
|
+
/**
|
|
37
|
+
* The trigger's popup is open: on the trigger, or (for the wrapper span) on
|
|
38
|
+
* a control inside it.
|
|
39
|
+
*/
|
|
40
|
+
function isPopupOpen(trigger) {
|
|
41
|
+
if (!trigger)
|
|
42
|
+
return false;
|
|
43
|
+
return trigger.matches(OPEN_POPUP_TRIGGER) || trigger.querySelector(OPEN_POPUP_TRIGGER) !== null;
|
|
44
|
+
}
|
|
45
|
+
/** Strictly inside the element's border box (a zero-size box contains nothing). */
|
|
46
|
+
function isInsideBox(el, x, y) {
|
|
47
|
+
const r = el.getBoundingClientRect();
|
|
48
|
+
return x > r.left && x < r.right && y > r.top && y < r.bottom;
|
|
49
|
+
}
|
|
50
|
+
// =============================================================================
|
|
12
51
|
// TooltipProvider
|
|
13
52
|
// =============================================================================
|
|
14
53
|
function TooltipProviderComponent({ delayDuration = 400, closeDelayDuration = 150, skipDelayDuration = 300, children, }) {
|
|
@@ -20,7 +59,7 @@ function TooltipProviderComponent({ delayDuration = 400, closeDelayDuration = 15
|
|
|
20
59
|
// =============================================================================
|
|
21
60
|
// Tooltip Root
|
|
22
61
|
// =============================================================================
|
|
23
|
-
function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false, delayDuration: localDelay, type = 'description', children, }) {
|
|
62
|
+
function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false, delayDuration: localDelay, type = 'description', closeOnPress = true, children, }) {
|
|
24
63
|
const providerContext = useTooltipProviderContext();
|
|
25
64
|
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
26
65
|
const isControlled = controlledOpen !== undefined;
|
|
@@ -56,15 +95,47 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
|
|
|
56
95
|
}
|
|
57
96
|
}, []);
|
|
58
97
|
const { warmth, skipDelayDuration, activeClose } = providerContext;
|
|
98
|
+
// A press on the trigger closes the tooltip and keeps it closed until the
|
|
99
|
+
// user moves on (Radix's behaviour). The trigger did something: it opened a
|
|
100
|
+
// popover, a menu, a drawer. The label has done its job, and left showing it
|
|
101
|
+
// paints over whatever just opened. 'pointer' clears when the pointer leaves
|
|
102
|
+
// the trigger, and deliberately survives blur: focus returning to the
|
|
103
|
+
// trigger when its popup closes, with the pointer still on it, must not
|
|
104
|
+
// bring the tooltip back. 'keyboard' clears on blur, so tabbing away and
|
|
105
|
+
// back shows it again.
|
|
106
|
+
const suppressedRef = useRef(null);
|
|
107
|
+
// Blocked: suppressed by a press, or the trigger's popup is open. The popup
|
|
108
|
+
// check reads the DOM at open time, because Popover, Dropdown, Select and
|
|
109
|
+
// Sidebar all publish their state as aria-expanded on the trigger element,
|
|
110
|
+
// whatever wraps it.
|
|
111
|
+
const isBlocked = useCallback(() => {
|
|
112
|
+
if (suppressedRef.current)
|
|
113
|
+
return true;
|
|
114
|
+
return isPopupOpen(triggerRef.current);
|
|
115
|
+
}, []);
|
|
59
116
|
const handleOpen = useCallback(() => {
|
|
117
|
+
if (isBlocked()) {
|
|
118
|
+
if (openTimeoutRef.current) {
|
|
119
|
+
clearTimeout(openTimeoutRef.current);
|
|
120
|
+
openTimeoutRef.current = null;
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
60
124
|
clearAllTimeouts();
|
|
61
125
|
// Warm group: a tooltip is showing, or one just closed. Open at once.
|
|
62
126
|
if (warmth && isWarm(warmth)) {
|
|
63
127
|
setOpen(true);
|
|
64
128
|
return;
|
|
65
129
|
}
|
|
66
|
-
openTimeoutRef.current = setTimeout(() =>
|
|
67
|
-
|
|
130
|
+
openTimeoutRef.current = setTimeout(() => {
|
|
131
|
+
openTimeoutRef.current = null;
|
|
132
|
+
// The popup may have opened during the delay (a keyboard shortcut, a
|
|
133
|
+
// click on something else that controls it).
|
|
134
|
+
if (isBlocked())
|
|
135
|
+
return;
|
|
136
|
+
setOpen(true);
|
|
137
|
+
}, resolvedDelay);
|
|
138
|
+
}, [clearAllTimeouts, isBlocked, resolvedDelay, setOpen, warmth]);
|
|
68
139
|
// Warmth membership. Open counts toward the group being warm; closing keeps
|
|
69
140
|
// it warm for skipDelayDuration, unless it was dismissed. One at a time: a
|
|
70
141
|
// tooltip opening in a warm group closes the previous one at once, rather
|
|
@@ -80,19 +151,19 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
|
|
|
80
151
|
return;
|
|
81
152
|
dismissedRef.current = false;
|
|
82
153
|
markOpen(warmth);
|
|
83
|
-
const
|
|
154
|
+
const closeForNext = () => {
|
|
84
155
|
clearAllTimeouts();
|
|
85
156
|
setOpenRef.current(false);
|
|
86
157
|
};
|
|
87
158
|
if (activeClose) {
|
|
88
159
|
const previous = activeClose.current;
|
|
89
|
-
activeClose.current =
|
|
160
|
+
activeClose.current = closeForNext;
|
|
90
161
|
if (previous)
|
|
91
162
|
previous();
|
|
92
163
|
}
|
|
93
164
|
return () => {
|
|
94
165
|
markClosed(warmth, dismissedRef.current ? 0 : skipDelayDuration);
|
|
95
|
-
if (activeClose?.current ===
|
|
166
|
+
if (activeClose?.current === closeForNext)
|
|
96
167
|
activeClose.current = null;
|
|
97
168
|
};
|
|
98
169
|
}, [open, warmth, activeClose, skipDelayDuration, clearAllTimeouts]);
|
|
@@ -110,10 +181,119 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
|
|
|
110
181
|
setOpen(false);
|
|
111
182
|
}
|
|
112
183
|
}, [clearAllTimeouts, resolvedCloseDelay, setOpen]);
|
|
184
|
+
// Close at once, without the close delay. Not a dismissal: the group stays
|
|
185
|
+
// warm (see handlePress). Read open through a ref so a press on a closed
|
|
186
|
+
// tooltip doesn't fire onOpenChange(false), and setOpen through setOpenRef
|
|
187
|
+
// so closeNow is stable (Content's popup observer subscribes with it).
|
|
188
|
+
const openRef = useRef(open);
|
|
189
|
+
openRef.current = open;
|
|
190
|
+
const closeNow = useCallback(() => {
|
|
191
|
+
clearAllTimeouts();
|
|
192
|
+
if (openRef.current)
|
|
193
|
+
setOpenRef.current(false);
|
|
194
|
+
}, [clearAllTimeouts]);
|
|
195
|
+
// A mouseleave isn't always the pointer leaving. When a modal's scrim
|
|
196
|
+
// opens over a resting pointer, the browser reports a leave because the
|
|
197
|
+
// trigger is covered, with the pointer still inside its box. Releasing then
|
|
198
|
+
// would bring the tooltip back the moment the scrim goes (the pointer
|
|
199
|
+
// "re-enters"). So a leave from inside the box releases only once the
|
|
200
|
+
// pointer actually moves out of it.
|
|
201
|
+
const stopLeaveWatchRef = useRef(null);
|
|
202
|
+
const stopTabWatchRef = useRef(null);
|
|
203
|
+
// Removes both document listeners: the leave watch and the Tab watch.
|
|
204
|
+
const stopLeaveWatch = useCallback(() => {
|
|
205
|
+
stopLeaveWatchRef.current?.();
|
|
206
|
+
stopLeaveWatchRef.current = null;
|
|
207
|
+
stopTabWatchRef.current?.();
|
|
208
|
+
stopTabWatchRef.current = null;
|
|
209
|
+
}, []);
|
|
210
|
+
// While a pointer press is held, a Tab arriving on the trigger releases it:
|
|
211
|
+
// click, Tab away, Tab back with the pointer parked, and the tooltip shows,
|
|
212
|
+
// as any Tab arrival does. Only a Tab: "last key was Tab" is cleared by any
|
|
213
|
+
// other key, so a focus restore after Escape stays suppressed (which is
|
|
214
|
+
// the point of a pointer press surviving blur). :focus-visible can't tell
|
|
215
|
+
// the two apart: after Escape, a restore matches it too.
|
|
216
|
+
const tabArrivalRef = useRef(false);
|
|
217
|
+
const watchTabArrival = useCallback(() => {
|
|
218
|
+
tabArrivalRef.current = false;
|
|
219
|
+
if (stopTabWatchRef.current)
|
|
220
|
+
return;
|
|
221
|
+
const onKey = (e) => {
|
|
222
|
+
tabArrivalRef.current = e.key === 'Tab';
|
|
223
|
+
};
|
|
224
|
+
const onPointer = () => {
|
|
225
|
+
tabArrivalRef.current = false;
|
|
226
|
+
};
|
|
227
|
+
document.addEventListener('keydown', onKey, true);
|
|
228
|
+
document.addEventListener('pointerdown', onPointer, true);
|
|
229
|
+
stopTabWatchRef.current = () => {
|
|
230
|
+
document.removeEventListener('keydown', onKey, true);
|
|
231
|
+
document.removeEventListener('pointerdown', onPointer, true);
|
|
232
|
+
};
|
|
233
|
+
}, []);
|
|
234
|
+
// A press is NOT a warmth dismissal, unlike Escape. Escape is aimed at the
|
|
235
|
+
// tooltip ("go away"); a press is aimed at the control, and the user is
|
|
236
|
+
// still working along this group. Click Bold, glide to Italic, and Italic's
|
|
237
|
+
// label shows at once, as it would have without the click (Radix keeps the
|
|
238
|
+
// group warm on press too). The trigger whose popup opened is blocked by
|
|
239
|
+
// aria-expanded either way; other triggers may still show their labels at
|
|
240
|
+
// once while a non-modal popup is open, as they would on any hover.
|
|
241
|
+
const closeOnPressRef = useRef(closeOnPress);
|
|
242
|
+
closeOnPressRef.current = closeOnPress;
|
|
243
|
+
const handlePress = useCallback((kind) => {
|
|
244
|
+
if (!closeOnPressRef.current)
|
|
245
|
+
return;
|
|
246
|
+
// A pointer press outranks the click that follows it.
|
|
247
|
+
if (suppressedRef.current !== 'pointer')
|
|
248
|
+
suppressedRef.current = kind;
|
|
249
|
+
if (kind === 'pointer')
|
|
250
|
+
watchTabArrival();
|
|
251
|
+
closeNow();
|
|
252
|
+
}, [closeNow, watchTabArrival]);
|
|
253
|
+
const clearPress = useCallback(() => {
|
|
254
|
+
suppressedRef.current = null;
|
|
255
|
+
tabArrivalRef.current = false;
|
|
256
|
+
stopLeaveWatch();
|
|
257
|
+
}, [stopLeaveWatch]);
|
|
258
|
+
const releasePress = useCallback((kind, at) => {
|
|
259
|
+
if (suppressedRef.current !== kind)
|
|
260
|
+
return;
|
|
261
|
+
const trigger = triggerRef.current;
|
|
262
|
+
if (kind === 'keyboard' || !at || !trigger || !isInsideBox(trigger, at.x, at.y)) {
|
|
263
|
+
clearPress();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (stopLeaveWatchRef.current)
|
|
267
|
+
return;
|
|
268
|
+
const onMove = (e) => {
|
|
269
|
+
if (isInsideBox(trigger, e.clientX, e.clientY))
|
|
270
|
+
return;
|
|
271
|
+
if (suppressedRef.current === 'pointer')
|
|
272
|
+
clearPress();
|
|
273
|
+
};
|
|
274
|
+
document.addEventListener('pointermove', onMove, true);
|
|
275
|
+
stopLeaveWatchRef.current = () => document.removeEventListener('pointermove', onMove, true);
|
|
276
|
+
}, [clearPress]);
|
|
277
|
+
// A touch that becomes a scroll ends in pointercancel: no click, no leave.
|
|
278
|
+
// Release, or the held press would outlive the gesture.
|
|
279
|
+
const cancelPress = useCallback(() => {
|
|
280
|
+
if (suppressedRef.current === 'pointer')
|
|
281
|
+
clearPress();
|
|
282
|
+
}, [clearPress]);
|
|
283
|
+
// Focus arrived on the trigger. A Tab arrival releases a held pointer press
|
|
284
|
+
// (see watchTabArrival); then open as usual.
|
|
285
|
+
const handleFocus = useCallback(() => {
|
|
286
|
+
if (suppressedRef.current === 'pointer' && tabArrivalRef.current)
|
|
287
|
+
clearPress();
|
|
288
|
+
handleOpen();
|
|
289
|
+
}, [clearPress, handleOpen]);
|
|
113
290
|
// Cleanup on unmount
|
|
114
291
|
useEffect(() => {
|
|
115
|
-
return () =>
|
|
116
|
-
|
|
292
|
+
return () => {
|
|
293
|
+
clearAllTimeouts();
|
|
294
|
+
stopLeaveWatch();
|
|
295
|
+
};
|
|
296
|
+
}, [clearAllTimeouts, stopLeaveWatch]);
|
|
117
297
|
const contextValue = useMemo(() => ({
|
|
118
298
|
open,
|
|
119
299
|
setOpen,
|
|
@@ -126,14 +306,19 @@ function TooltipRoot({ open: controlledOpen, onOpenChange, defaultOpen = false,
|
|
|
126
306
|
handleClose,
|
|
127
307
|
cancelClose,
|
|
128
308
|
dismiss,
|
|
129
|
-
|
|
309
|
+
closeNow,
|
|
310
|
+
handlePress,
|
|
311
|
+
releasePress,
|
|
312
|
+
cancelPress,
|
|
313
|
+
handleFocus,
|
|
314
|
+
}), [open, setOpen, contentId, type, resolvedDelay, resolvedCloseDelay, handleOpen, handleClose, cancelClose, dismiss, closeNow, handlePress, releasePress, cancelPress, handleFocus]);
|
|
130
315
|
return (_jsx(TooltipContext.Provider, { value: contextValue, children: children }));
|
|
131
316
|
}
|
|
132
317
|
// =============================================================================
|
|
133
318
|
// TooltipTrigger
|
|
134
319
|
// =============================================================================
|
|
135
320
|
function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, children, }) {
|
|
136
|
-
const { open, triggerRef, contentId, type, handleOpen, handleClose } = useTooltipContext();
|
|
321
|
+
const { open, triggerRef, contentId, type, handleOpen, handleClose, handlePress, releasePress, cancelPress, handleFocus, } = useTooltipContext();
|
|
137
322
|
// A label tooltip adds no ARIA, so the trigger has to be named already.
|
|
138
323
|
const warnedRef = useRef(false);
|
|
139
324
|
useEffect(() => {
|
|
@@ -169,11 +354,77 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
|
|
|
169
354
|
}
|
|
170
355
|
}
|
|
171
356
|
}, [asChild, children, triggerRef]);
|
|
357
|
+
// Pressing the trigger closes the tooltip (see handlePress). Only a press
|
|
358
|
+
// that activates something counts: one that lands on an enabled control,
|
|
359
|
+
// whether the trigger is that control (an asChild button) or holds it (the
|
|
360
|
+
// wrapper span around a Button). Not a press: a trigger that is plain
|
|
361
|
+
// content (an info icon in the wrapper, an asChild Avatar), so tapping it
|
|
362
|
+
// to read the tooltip on touch keeps working; a text field, where a press
|
|
363
|
+
// is click-to-focus and its help tooltip should then show; a disabled
|
|
364
|
+
// control, which does nothing.
|
|
365
|
+
const pressedControl = (target) => {
|
|
366
|
+
const trigger = triggerRef.current;
|
|
367
|
+
const control = target instanceof Element ? target.closest(ACTIVATABLE) : null;
|
|
368
|
+
if (!control || !trigger || !trigger.contains(control))
|
|
369
|
+
return null;
|
|
370
|
+
if (control.matches(TEXT_ENTRY) || control.matches(DISABLED))
|
|
371
|
+
return null;
|
|
372
|
+
return control;
|
|
373
|
+
};
|
|
374
|
+
const activates = (target) => pressedControl(target) !== null;
|
|
375
|
+
const onPointerDown = (e) => {
|
|
376
|
+
// Primary button only: not a right-click (context menu), a middle-click
|
|
377
|
+
// (new tab) or a pen eraser.
|
|
378
|
+
if (e.button !== 0)
|
|
379
|
+
return;
|
|
380
|
+
if (activates(e.target))
|
|
381
|
+
handlePress('pointer');
|
|
382
|
+
};
|
|
383
|
+
// Keyboard activation: Enter/Space, and the click they produce on a button
|
|
384
|
+
// or link (detail 0). Space on a link scrolls the page instead.
|
|
385
|
+
const onKeyDown = (e) => {
|
|
386
|
+
if (e.key !== 'Enter' && e.key !== ' ')
|
|
387
|
+
return;
|
|
388
|
+
const control = pressedControl(e.target);
|
|
389
|
+
if (!control)
|
|
390
|
+
return;
|
|
391
|
+
if (e.key === ' ' && control.matches(LINK))
|
|
392
|
+
return;
|
|
393
|
+
handlePress('keyboard');
|
|
394
|
+
};
|
|
395
|
+
const onClick = (e) => {
|
|
396
|
+
if (e.button !== 0 || !activates(e.target))
|
|
397
|
+
return;
|
|
398
|
+
if (e.detail > 0) {
|
|
399
|
+
handlePress('pointer');
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
// A detail-0 click is a keyboard press only when focus is on the trigger.
|
|
403
|
+
// A screen reader's virtual cursor (or code) can click without focusing,
|
|
404
|
+
// and a 'keyboard' press is released only by blur: it would stick, and
|
|
405
|
+
// block hover for sighted users. Such a click needs no suppression: a
|
|
406
|
+
// popup it opens blocks the tooltip through aria-expanded.
|
|
407
|
+
const trigger = triggerRef.current;
|
|
408
|
+
if (trigger && trigger.contains(document.activeElement))
|
|
409
|
+
handlePress('keyboard');
|
|
410
|
+
};
|
|
411
|
+
const onMouseLeave = (e) => {
|
|
412
|
+
releasePress('pointer', { x: e.clientX, y: e.clientY });
|
|
413
|
+
handleClose();
|
|
414
|
+
};
|
|
415
|
+
const onBlur = () => {
|
|
416
|
+
releasePress('keyboard');
|
|
417
|
+
handleClose();
|
|
418
|
+
};
|
|
172
419
|
const triggerProps = {
|
|
173
420
|
onMouseEnter: handleOpen,
|
|
174
|
-
onMouseLeave
|
|
175
|
-
onFocus:
|
|
176
|
-
onBlur
|
|
421
|
+
onMouseLeave,
|
|
422
|
+
onFocus: handleFocus,
|
|
423
|
+
onBlur,
|
|
424
|
+
onPointerDown,
|
|
425
|
+
onPointerCancel: cancelPress,
|
|
426
|
+
onKeyDown,
|
|
427
|
+
onClick,
|
|
177
428
|
'aria-describedby': open && type === 'description' ? contentId : undefined,
|
|
178
429
|
'data-tooltip-open': open || undefined,
|
|
179
430
|
};
|
|
@@ -183,12 +434,16 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
|
|
|
183
434
|
// preventDefault. Its own aria-describedby is kept, with the content id
|
|
184
435
|
// appended while a description tooltip is open; never an empty string.
|
|
185
436
|
const childProps = children.props;
|
|
186
|
-
|
|
437
|
+
//
|
|
438
|
+
// Press handling passes `always`: it runs whatever the child did. A child
|
|
439
|
+
// calling preventDefault on pointerdown is managing focus (the select
|
|
440
|
+
// family's Safari fix does), not opting out of the tooltip closing.
|
|
441
|
+
const compose = (theirs, ours, always = false) => {
|
|
187
442
|
if (typeof theirs !== 'function')
|
|
188
443
|
return ours;
|
|
189
444
|
return (e) => {
|
|
190
445
|
theirs(e);
|
|
191
|
-
if (!e.defaultPrevented)
|
|
446
|
+
if (always || !e.defaultPrevented)
|
|
192
447
|
ours(e);
|
|
193
448
|
};
|
|
194
449
|
};
|
|
@@ -199,9 +454,13 @@ function TooltipTriggerComponent({ asChild = false, 'aria-label': ariaLabel, chi
|
|
|
199
454
|
return cloneElement(children, {
|
|
200
455
|
...triggerProps,
|
|
201
456
|
onMouseEnter: compose(childProps.onMouseEnter, handleOpen),
|
|
202
|
-
onMouseLeave: compose(childProps.onMouseLeave,
|
|
203
|
-
onFocus: compose(childProps.onFocus,
|
|
204
|
-
onBlur: compose(childProps.onBlur,
|
|
457
|
+
onMouseLeave: compose(childProps.onMouseLeave, onMouseLeave),
|
|
458
|
+
onFocus: compose(childProps.onFocus, handleFocus),
|
|
459
|
+
onBlur: compose(childProps.onBlur, onBlur),
|
|
460
|
+
onPointerDown: compose(childProps.onPointerDown, onPointerDown, true),
|
|
461
|
+
onPointerCancel: compose(childProps.onPointerCancel, cancelPress, true),
|
|
462
|
+
onKeyDown: compose(childProps.onKeyDown, onKeyDown, true),
|
|
463
|
+
onClick: compose(childProps.onClick, onClick, true),
|
|
205
464
|
'aria-describedby': describedBy || undefined,
|
|
206
465
|
ref: setRefs,
|
|
207
466
|
});
|
|
@@ -223,8 +482,32 @@ function TooltipContentComponent(props) {
|
|
|
223
482
|
}
|
|
224
483
|
// Inner component: only mounted when open. All Floating UI hooks live here.
|
|
225
484
|
function TooltipContentInner({ side = 'top', align = 'center', sideOffset = 8, theme = 'dark', className, children, }) {
|
|
226
|
-
const { triggerRef, contentId, type, cancelClose, handleClose, dismiss } = useTooltipContext();
|
|
485
|
+
const { triggerRef, contentId, type, cancelClose, handleClose, dismiss, closeNow } = useTooltipContext();
|
|
227
486
|
const arrowRef = useRef(null);
|
|
487
|
+
// The trigger's popup opened while the tooltip was showing, by a route that
|
|
488
|
+
// isn't a press (ArrowDown on a Select, a shortcut, a parent's state): close.
|
|
489
|
+
// Otherwise the tooltip sits on top of the popup it labels, on layer-top.
|
|
490
|
+
useEffect(() => {
|
|
491
|
+
const trigger = triggerRef.current;
|
|
492
|
+
if (!trigger)
|
|
493
|
+
return;
|
|
494
|
+
if (isPopupOpen(trigger)) {
|
|
495
|
+
closeNow();
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
if (typeof MutationObserver === 'undefined')
|
|
499
|
+
return;
|
|
500
|
+
const observer = new MutationObserver(() => {
|
|
501
|
+
if (isPopupOpen(trigger))
|
|
502
|
+
closeNow();
|
|
503
|
+
});
|
|
504
|
+
observer.observe(trigger, {
|
|
505
|
+
attributes: true,
|
|
506
|
+
attributeFilter: ['aria-expanded', 'aria-haspopup', 'role'],
|
|
507
|
+
subtree: true,
|
|
508
|
+
});
|
|
509
|
+
return () => observer.disconnect();
|
|
510
|
+
}, [triggerRef, closeNow]);
|
|
228
511
|
const { refs, floatingStyles, context } = useFloating({
|
|
229
512
|
placement: toPlacement(side, align),
|
|
230
513
|
open: true, // Always true when mounted (gate handles the conditional)
|
|
@@ -67,6 +67,19 @@ export type TooltipProps = {
|
|
|
67
67
|
* @default 'description'
|
|
68
68
|
*/
|
|
69
69
|
type?: TooltipType;
|
|
70
|
+
/**
|
|
71
|
+
* Close when the trigger is pressed (pointerdown on the primary button,
|
|
72
|
+
* Enter or Space, or the click they produce), and stay closed until the
|
|
73
|
+
* pointer leaves or focus leaves and comes back. That keeps a label from
|
|
74
|
+
* sitting over the popover, menu or drawer its trigger just opened.
|
|
75
|
+
*
|
|
76
|
+
* Set `false` when the tooltip is the press's feedback, such as a copy
|
|
77
|
+
* button whose tooltip swaps to "Copied". The tooltip still never opens
|
|
78
|
+
* while the trigger's popup is open (`aria-expanded="true"` with
|
|
79
|
+
* `aria-haspopup`), whatever this is set to.
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
closeOnPress?: boolean;
|
|
70
83
|
children: React.ReactNode;
|
|
71
84
|
};
|
|
72
85
|
export type TooltipTriggerProps = {
|
|
@@ -135,6 +148,23 @@ export type TooltipContextValue = {
|
|
|
135
148
|
cancelClose: () => void;
|
|
136
149
|
/** Close now as a dismissal (Escape): it doesn't warm the group. */
|
|
137
150
|
dismiss: () => void;
|
|
151
|
+
/** Close now, skipping the close delay. Not a dismissal: the group stays warm. */
|
|
152
|
+
closeNow: () => void;
|
|
153
|
+
/** The trigger was pressed: close, and stay closed until the press is released. */
|
|
154
|
+
handlePress: (kind: 'pointer' | 'keyboard') => void;
|
|
155
|
+
/**
|
|
156
|
+
* The pointer left the trigger ('pointer', with where it was) or focus left
|
|
157
|
+
* it ('keyboard'). A pointer "leave" from inside the trigger's box (a scrim
|
|
158
|
+
* covered it) releases only once the pointer moves out.
|
|
159
|
+
*/
|
|
160
|
+
releasePress: (kind: 'pointer' | 'keyboard', at?: {
|
|
161
|
+
x: number;
|
|
162
|
+
y: number;
|
|
163
|
+
}) => void;
|
|
164
|
+
/** pointercancel on the trigger (a touch became a scroll): release a pointer press. */
|
|
165
|
+
cancelPress: () => void;
|
|
166
|
+
/** Focus arrived on the trigger: a Tab arrival releases a pointer press, then open. */
|
|
167
|
+
handleFocus: () => void;
|
|
138
168
|
};
|
|
139
169
|
/**
|
|
140
170
|
* Convert side + align to Floating UI placement.
|
package/components/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export { DataTable, BulkActionsBar, defaultDataTableLabels, defaultBulkActionsBa
|
|
|
41
41
|
export { CommandPalette, CommandPaletteItem, CommandPaletteGroup, CommandPaletteLabel, CommandPaletteTrigger, defaultCommandPaletteLabels, } from './CommandPalette';
|
|
42
42
|
export { SearchInput } from './SearchInput';
|
|
43
43
|
export { SecretInput, defaultSecretInputLabels } from './SecretInput';
|
|
44
|
+
export { PasswordInput, defaultPasswordInputLabels } from './PasswordInput';
|
|
44
45
|
export { SearchSelect, SearchSelectTrigger, SearchSelectContent, SearchSelectOption, SearchSelectGroup, SearchSelectLabel, useSearchSelect, } from './SearchSelect';
|
|
45
46
|
export { Switch } from './Switch';
|
|
46
47
|
export { Tabs } from './Tabs';
|
|
@@ -92,6 +93,7 @@ export type { CommandPaletteProps, CommandPaletteItemProps, CommandPaletteGroupP
|
|
|
92
93
|
export type { SearchInputProps } from './SearchInput';
|
|
93
94
|
export type { SliderProps } from './Slider';
|
|
94
95
|
export type { SecretInputProps, SecretInputLabels } from './SecretInput';
|
|
96
|
+
export type { PasswordInputProps, PasswordInputLabels, PasswordInputPurpose } from './PasswordInput';
|
|
95
97
|
export type { SearchSelectProps, SearchSelectTriggerProps, SearchSelectContentProps, SearchSelectOptionProps, SearchSelectGroupProps, SearchSelectLabelProps, SearchSelectLabels, } from './SearchSelect';
|
|
96
98
|
export type { SwitchProps } from './Switch';
|
|
97
99
|
export type { TextareaProps, TextareaResize } from './Textarea';
|
package/components/index.js
CHANGED
|
@@ -39,6 +39,7 @@ export { DataTable, BulkActionsBar, defaultDataTableLabels, defaultBulkActionsBa
|
|
|
39
39
|
export { CommandPalette, CommandPaletteItem, CommandPaletteGroup, CommandPaletteLabel, CommandPaletteTrigger, defaultCommandPaletteLabels, } from './CommandPalette/index.js';
|
|
40
40
|
export { SearchInput } from './SearchInput/index.js';
|
|
41
41
|
export { SecretInput, defaultSecretInputLabels } from './SecretInput/index.js';
|
|
42
|
+
export { PasswordInput, defaultPasswordInputLabels } from './PasswordInput/index.js';
|
|
42
43
|
export { SearchSelect, SearchSelectTrigger, SearchSelectContent, SearchSelectOption, SearchSelectGroup, SearchSelectLabel, useSearchSelect, } from './SearchSelect/index.js';
|
|
43
44
|
export { Switch } from './Switch/index.js';
|
|
44
45
|
export { Tabs } from './Tabs/index.js';
|
package/figma-tokens.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.46",
|
|
3
3
|
"source": "publish/styles/all.expanded.css",
|
|
4
4
|
"prefix": "tui-",
|
|
5
5
|
"note": "Layer 1 primitives only. Component API tokens (--tui-{component}-*) are never defined in CSS — they exist only as fallback reads — so they have no Figma representation. CONTRACT: consumers read TUI defaults from this file at build time (variables[].cssVar, the \"Light\"/\"Dark\" mode names, and alias chains into TUI/Primitives). Renaming a cssVar or a mode is a breaking change to those consumers even when the CSS value is unchanged — a rename silently becomes an undefined default downstream — so treat it as at least a minor bump and call it out in the CHANGELOG.",
|
package/icons/icons.svg
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" data-tui-icon-sprite="all" data-tui-icon-sprite-version="0.2.
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" data-tui-icon-sprite="all" data-tui-icon-sprite-version="0.2.46" aria-hidden="true" focusable="false" style="position:absolute;width:0;height:0;overflow:hidden">
|
|
2
2
|
<symbol id="tui-cred-badge-check" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M10.893 4.558a1.377 1.377 0 0 1 2.214 0c.381.515 1.068.7 1.656.444a1.377 1.377 0 0 1 1.917 1.106c.072.637.575 1.14 1.212 1.213a1.377 1.377 0 0 1 1.106 1.916 1.38 1.38 0 0 0 .444 1.656c.744.55.744 1.663 0 2.214a1.38 1.38 0 0 0-.444 1.656 1.377 1.377 0 0 1-1.106 1.917 1.38 1.38 0 0 0-1.212 1.212 1.377 1.377 0 0 1-1.917 1.106 1.38 1.38 0 0 0-1.656.444 1.377 1.377 0 0 1-2.214 0 1.38 1.38 0 0 0-1.656-.444 1.377 1.377 0 0 1-1.916-1.106 1.38 1.38 0 0 0-1.213-1.212 1.377 1.377 0 0 1-1.106-1.917 1.38 1.38 0 0 0-.444-1.656 1.377 1.377 0 0 1 0-2.214c.515-.381.7-1.068.444-1.656a1.377 1.377 0 0 1 1.106-1.916 1.38 1.38 0 0 0 1.213-1.213 1.377 1.377 0 0 1 1.916-1.106 1.38 1.38 0 0 0 1.656-.444m5.193 5.91a.75.75 0 0 0-1.172-.936l-3.531 4.414-1.914-1.532a.75.75 0 1 0-.937 1.172l3.085 2.468z" clip-rule="evenodd"/></symbol>
|
|
3
3
|
<symbol id="tui-cred-badge-ribbon" viewBox="0 0 24 24"><path d="M11.032 3.488a1.205 1.205 0 0 1 1.936 0c.334.451.935.612 1.45.388a1.205 1.205 0 0 1 1.677.969c.063.557.503.997 1.06 1.06.805.092 1.291.935.969 1.678a1.204 1.204 0 0 0 .388 1.449c.65.481.65 1.455 0 1.936a1.205 1.205 0 0 0-.388 1.45 1.205 1.205 0 0 1-.969 1.677 1.204 1.204 0 0 0-1.06 1.06 1.205 1.205 0 0 1-1.678.969 1.205 1.205 0 0 0-1.449.388c-.481.65-1.455.65-1.936 0a1.204 1.204 0 0 0-1.45-.388 1.205 1.205 0 0 1-1.677-.969 1.205 1.205 0 0 0-1.06-1.06 1.205 1.205 0 0 1-.969-1.678 1.205 1.205 0 0 0-.388-1.449 1.205 1.205 0 0 1 0-1.936c.451-.334.612-.935.388-1.45a1.205 1.205 0 0 1 .969-1.677 1.205 1.205 0 0 0 1.06-1.06 1.205 1.205 0 0 1 1.678-.969 1.205 1.205 0 0 0 1.449-.388M8 17.482c.442.175.953.185 1.437-.025a.88.88 0 0 1 1.054.282 1.877 1.877 0 0 0 3.018 0 .88.88 0 0 1 1.054-.282c.484.21.995.2 1.437.025V21l-4-2.286L8 21z"/></symbol>
|
|
4
4
|
<symbol id="tui-cred-badge" viewBox="0 0 24 24"><path d="M13.107 4.558a1.377 1.377 0 0 0-2.214 0c-.381.515-1.068.7-1.656.444a1.377 1.377 0 0 0-1.916 1.106 1.38 1.38 0 0 1-1.213 1.213 1.377 1.377 0 0 0-1.106 1.916 1.38 1.38 0 0 1-.444 1.656 1.377 1.377 0 0 0 0 2.214c.515.381.7 1.068.444 1.656a1.377 1.377 0 0 0 1.106 1.917c.637.072 1.14.575 1.213 1.212a1.377 1.377 0 0 0 1.916 1.106 1.38 1.38 0 0 1 1.656.444c.55.744 1.663.744 2.214 0a1.38 1.38 0 0 1 1.656-.444 1.377 1.377 0 0 0 1.917-1.106 1.38 1.38 0 0 1 1.212-1.212 1.377 1.377 0 0 0 1.106-1.917 1.38 1.38 0 0 1 .444-1.656 1.377 1.377 0 0 0 0-2.214 1.38 1.38 0 0 1-.444-1.656 1.377 1.377 0 0 0-1.106-1.916 1.38 1.38 0 0 1-1.212-1.213 1.377 1.377 0 0 0-1.917-1.106 1.38 1.38 0 0 1-1.656-.444"/></symbol>
|
package/icons/sprite-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SPRITE_VERSION = '0.2.
|
|
1
|
+
export const SPRITE_VERSION = '0.2.46';
|
package/icons/sprite.php
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
// Replaced with the package version at build time.
|
|
24
|
-
$GLOBALS['tangible_ui_icon_sprite_copies'][__DIR__] = '0.2.
|
|
24
|
+
$GLOBALS['tangible_ui_icon_sprite_copies'][__DIR__] = '0.2.46';
|
|
25
25
|
|
|
26
26
|
if (!function_exists('tangible_ui_print_icon_sprite')) {
|
|
27
27
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangible/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.46",
|
|
4
4
|
"description": "React design system for Tangible's products: standalone React apps and WordPress plugins. Components, CSS custom property tokens, cascade layers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./components/index.js",
|
|
@@ -188,6 +188,10 @@
|
|
|
188
188
|
"import": "./components/Pager/index.js",
|
|
189
189
|
"types": "./components/Pager/index.d.ts"
|
|
190
190
|
},
|
|
191
|
+
"./components/PasswordInput": {
|
|
192
|
+
"import": "./components/PasswordInput/index.js",
|
|
193
|
+
"types": "./components/PasswordInput/index.d.ts"
|
|
194
|
+
},
|
|
191
195
|
"./components/Popover": {
|
|
192
196
|
"import": "./components/Popover/index.js",
|
|
193
197
|
"types": "./components/Popover/index.d.ts"
|
|
@@ -737,9 +737,15 @@ together (same blue). `showLabels={false}` leaves sighted users with color alone
|
|
|
737
737
|
numbers elsewhere; `showPercent` replaces counts for screen readers too. Don't re-point
|
|
738
738
|
`--tui-progress-zN-fill` per position and pass a legend as children: plain `segments` without
|
|
739
739
|
`breakdown` stay cumulative ("Pending 100%").
|
|
740
|
-
**
|
|
741
|
-
|
|
742
|
-
|
|
740
|
+
**Sign-in or new password → `PasswordInput`** (a `TextInput` variant: masked, with a reveal toggle
|
|
741
|
+
named "Show password"; `purpose: 'current' | 'new'` is required and sets `autocomplete`, so password
|
|
742
|
+
managers fill or generate it; never autocorrected or spellchecked when shown; a native submit masks
|
|
743
|
+
it again, an app-handled one leaves it; for a second field on a page override all four `labels`,
|
|
744
|
+
"Show new password" / "New password shown."). **API key / token
|
|
745
|
+
field → `SecretInput`** (masked, with the same toggle, but it keeps password managers out; `isSet`
|
|
746
|
+
is a boolean so a stored secret never reaches the client, it shows a "Saved" placeholder and typing
|
|
747
|
+
replaces it; `locked` makes it read-only with no toggle). Don't use one for the other: SecretInput on
|
|
748
|
+
a login stops managers filling it. No Breadcrumb, no Skeleton, and no *standalone* time picker — but
|
|
743
749
|
`DatePicker` / `DateRangePicker` take `withTime` for an hour/minute field (12- or 24-hour via
|
|
744
750
|
`hour12`) plus a display-only `zoneLabel`; the value is a plain `Date` with wall-clock semantics,
|
|
745
751
|
so timezone interpretation stays yours. A range with a start and no end (a membership, a
|