@tangible/ui 0.2.36 → 0.2.38
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/SearchInput/SearchInput.d.ts +2 -0
- package/components/SearchInput/SearchInput.js +34 -12
- package/components/SearchInput/types.d.ts +24 -0
- package/components/Tray/Tray.d.ts +79 -0
- package/components/Tray/Tray.js +229 -0
- package/components/Tray/index.d.ts +4 -0
- package/components/Tray/index.js +2 -0
- package/components/Tray/labels.d.ts +9 -0
- package/components/Tray/labels.js +6 -0
- package/components/index.d.ts +2 -0
- package/components/index.js +1 -0
- package/figma-tokens.json +1 -1
- package/icons/icons.svg +19 -1
- package/icons/manifest.json +144 -0
- package/icons/registry.d.ts +36 -0
- package/icons/registry.js +18 -0
- package/icons/sprite-registry.js +18 -0
- package/icons/sprite-version.js +1 -1
- package/icons/sprite.php +1 -1
- package/icons/system/index.d.ts +36 -0
- package/icons/system/index.js +198 -0
- package/icons/system.svg +18 -0
- package/package.json +5 -1
- package/skills/building-with-tui/SKILL.md +18 -0
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +184 -19
- package/styles/all.expanded.unlayered.css +184 -19
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +4 -0
- package/styles/components/card.scss +19 -13
- package/styles/components/nav-menu.scss +9 -3
- package/styles/components/search-input.scss +66 -0
- package/styles/components/table.scss +3 -2
- package/styles/components/tray.scss +186 -0
- package/tui-manifest.json +99 -5
|
@@ -8,4 +8,6 @@ export declare const SearchInput: import("react").ForwardRefExoticComponent<Omit
|
|
|
8
8
|
clearLabel?: string;
|
|
9
9
|
hideClear?: boolean;
|
|
10
10
|
searchIcon?: import("react").ReactNode;
|
|
11
|
+
suffix?: import("react").ReactNode;
|
|
12
|
+
shortcut?: string;
|
|
11
13
|
} & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useRef } from 'react';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
3
3
|
import { cx } from '../../utils/cx.js';
|
|
4
4
|
import { composeRefs } from '../../utils/compose-refs.js';
|
|
5
5
|
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
6
|
+
import { isDev } from '../../utils/is-dev.js';
|
|
6
7
|
import { Icon } from '../Icon/index.js';
|
|
7
8
|
import { TextInput } from '../TextInput/index.js';
|
|
8
9
|
import { CloseSmall as CloseSmallIcon, Search as SearchIcon } from '../../icons/system/index.js';
|
|
@@ -22,7 +23,7 @@ import { CloseSmall as CloseSmallIcon, Search as SearchIcon } from '../../icons/
|
|
|
22
23
|
// buttons); the field chrome is inherited from the shared input core.
|
|
23
24
|
//
|
|
24
25
|
// =============================================================================
|
|
25
|
-
export const SearchInput = forwardRef(function SearchInput({ value: valueProp, defaultValue, onValueChange, onClear, onSearch, searchLabel = 'Search', clearLabel = 'Clear search', hideClear = false, searchIcon, inputClassName, onKeyDown, disabled, ...rest }, forwardedRef) {
|
|
26
|
+
export const SearchInput = forwardRef(function SearchInput({ value: valueProp, defaultValue, onValueChange, onClear, onSearch, searchLabel = 'Search', clearLabel = 'Clear search', hideClear = false, searchIcon, suffix, shortcut, className, inputClassName, onKeyDown, disabled, ...rest }, forwardedRef) {
|
|
26
27
|
const innerRef = useRef(null);
|
|
27
28
|
const [value = '', setValue] = useControllableState({
|
|
28
29
|
value: valueProp,
|
|
@@ -59,19 +60,40 @@ export const SearchInput = forwardRef(function SearchInput({ value: valueProp, d
|
|
|
59
60
|
const prefix = onSearch && !disabled ? (_jsx("button", { type: "button", className: "tui-search-input__submit", "aria-label": searchLabel, onClick: submit,
|
|
60
61
|
// Keep pointerdown from stealing focus before the click fires.
|
|
61
62
|
onPointerDown: (e) => e.preventDefault(), children: icon })) : (icon);
|
|
63
|
+
// The shortcut hint stands in for the clear button while the field is empty:
|
|
64
|
+
// the two never show together, and the hint is pointless on a disabled field.
|
|
65
|
+
const hasShortcut = Boolean(shortcut) && !disabled;
|
|
66
|
+
const showShortcut = hasShortcut && value.length === 0;
|
|
67
|
+
// The hint is aria-hidden, so without aria-keyshortcuts a screen-reader user
|
|
68
|
+
// never learns the shortcut exists.
|
|
69
|
+
const warnedShortcut = useRef(false);
|
|
70
|
+
const hasKeyShortcuts = Boolean(rest['aria-keyshortcuts']);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (isDev() && shortcut && !hasKeyShortcuts && !warnedShortcut.current) {
|
|
73
|
+
warnedShortcut.current = true;
|
|
74
|
+
console.warn('[SearchInput] `shortcut` renders an aria-hidden hint. Pass ' +
|
|
75
|
+
'`aria-keyshortcuts` (e.g. "Meta+K") so assistive tech hears it too.');
|
|
76
|
+
}
|
|
77
|
+
}, [shortcut, hasKeyShortcuts]);
|
|
78
|
+
const clearButton = clearable ? (_jsx("button", { type: "button", className: "tui-search-input__clear", "aria-label": clearLabel, onClick: clear,
|
|
79
|
+
// Keep pointerdown from stealing focus before the click fires.
|
|
80
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
81
|
+
// Rendered even while empty so the slot reserves its width — the input
|
|
82
|
+
// never reflows as the button appears/disappears. `visibility: hidden`
|
|
83
|
+
// (vs. unmounting) also drops it from the tab order and the a11y tree.
|
|
84
|
+
style: showClear ? undefined : { visibility: 'hidden' }, children: _jsx(Icon, { name: CloseSmallIcon }) })) : null;
|
|
85
|
+
// Hint and clear button share one grid cell, so the slot is always as wide
|
|
86
|
+
// as the wider of the two and the input doesn't reflow on the first
|
|
87
|
+
// keystroke (a11y audit: the hint is wider than the button).
|
|
88
|
+
const trailingControl = hasShortcut || clearButton ? (_jsxs("span", { className: "tui-search-input__trailing", children: [hasShortcut && (_jsx("kbd", { className: "tui-search-input__shortcut", "aria-hidden": "true", style: showShortcut ? undefined : { visibility: 'hidden' }, children: shortcut })), clearButton] })) : null;
|
|
89
|
+
const hasSuffix = suffix != null && suffix !== false && suffix !== '';
|
|
90
|
+
const trailing = hasSuffix || trailingControl ? (_jsxs(_Fragment, { children: [hasSuffix && _jsx("span", { className: "tui-search-input__suffix", children: suffix }), trailingControl] })) : undefined;
|
|
62
91
|
return (_jsx(TextInput
|
|
63
92
|
// rest is spread first so SearchInput's own wiring below (value, the
|
|
64
93
|
// change handler, type) always wins — a stray value/onChange from a
|
|
65
94
|
// consumer can't clobber the controlled-value plumbing.
|
|
66
|
-
, { ...rest, ref: composeRefs(forwardedRef, innerRef), type: "search", value: value, onChange: handleChange, onKeyDown: handleKeyDown, disabled: disabled,
|
|
95
|
+
, { ...rest, ref: composeRefs(forwardedRef, innerRef), type: "search", className: cx('tui-search-input', className), value: value, onChange: handleChange, onKeyDown: handleKeyDown, disabled: disabled,
|
|
67
96
|
// tui-input-reset strips the native search decoration (WebKit cancel
|
|
68
97
|
// button, etc.); we render our own clear affordance.
|
|
69
|
-
inputClassName: cx('tui-input-reset', inputClassName), prefix: prefix, suffix:
|
|
70
|
-
// Keep pointerdown from stealing focus before the click fires.
|
|
71
|
-
onPointerDown: (e) => e.preventDefault(),
|
|
72
|
-
// Rendered even while empty so the suffix slot reserves its width —
|
|
73
|
-
// the input never reflows as the button appears/disappears.
|
|
74
|
-
// `visibility: hidden` (vs. unmounting) also drops the empty-state
|
|
75
|
-
// button from the tab order and the a11y tree.
|
|
76
|
-
style: showClear ? undefined : { visibility: 'hidden' }, children: _jsx(Icon, { name: CloseSmallIcon }) })) : undefined }));
|
|
98
|
+
inputClassName: cx('tui-input-reset', inputClassName), prefix: prefix, suffix: trailing }));
|
|
77
99
|
});
|
|
@@ -66,4 +66,28 @@ export type SearchInputProps = Omit<TextInputProps, 'type' | 'prefix' | 'suffix'
|
|
|
66
66
|
* Override the leading icon. Defaults to the `system/search` glyph.
|
|
67
67
|
*/
|
|
68
68
|
searchIcon?: ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* Trailing content, placed before the clear button (e.g. a filter toggle or a
|
|
71
|
+
* result count).
|
|
72
|
+
*
|
|
73
|
+
* @remarks Rendered as given and NOT hidden from assistive tech, so a control
|
|
74
|
+
* placed here must carry its own accessible name. Size a Button/IconButton one
|
|
75
|
+
* tier below the field. For a keyboard-shortcut hint use `shortcut` instead,
|
|
76
|
+
* which is decorative. A string renders as plain text beside the clear
|
|
77
|
+
* button, not as TextInput's boxed `.is-text` addon.
|
|
78
|
+
*/
|
|
79
|
+
suffix?: ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* Keyboard-shortcut hint shown at the trailing edge, e.g. `'⌘K'` or `'/'`.
|
|
82
|
+
*
|
|
83
|
+
* @remarks Decorative: rendered as an `aria-hidden` `<kbd>`, only while the
|
|
84
|
+
* field is empty and enabled; the clear button takes its place once there is
|
|
85
|
+
* a value. Announce the shortcut itself with `aria-keyshortcuts` on the field
|
|
86
|
+
* (e.g. `aria-keyshortcuts="Meta+K"`), which SearchInput passes through.
|
|
87
|
+
* Keep the two in step: nothing links them.
|
|
88
|
+
*
|
|
89
|
+
* SearchInput does not bind the key. Listen for it yourself and focus the
|
|
90
|
+
* field through its ref.
|
|
91
|
+
*/
|
|
92
|
+
shortcut?: string;
|
|
69
93
|
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode, RefObject } from 'react';
|
|
2
|
+
import type { SizeStandard } from '../../types/sizes';
|
|
3
|
+
import type { TraySaveLabels } from './labels';
|
|
4
|
+
export type TrayPlacement = 'sticky' | 'fixed';
|
|
5
|
+
type FocusTarget = RefObject<HTMLElement | null> | (() => HTMLElement | null);
|
|
6
|
+
export interface TrayProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role'> {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the tray is showing. Controlled only, like Modal: the state it
|
|
9
|
+
* reports (unsaved edits, a selection, an undo stack) is the app's, and the
|
|
10
|
+
* tray never asks to close itself, so there is no `onOpenChange`.
|
|
11
|
+
*/
|
|
12
|
+
open: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* `sticky` pins it to the bottom of its scroll container (the default);
|
|
15
|
+
* `fixed` pins it to the viewport. A fixed tray breaks out of the viewport's
|
|
16
|
+
* frame under a transformed, filtered or contained ancestor, as any
|
|
17
|
+
* `position: fixed` does; the page reserves room at its own bottom for it.
|
|
18
|
+
* @default 'sticky'
|
|
19
|
+
*/
|
|
20
|
+
placement?: TrayPlacement;
|
|
21
|
+
/**
|
|
22
|
+
* Where focus goes if the tray closes while focus is inside it. Read at close.
|
|
23
|
+
* Defaults to the element focus entered the tray from.
|
|
24
|
+
*/
|
|
25
|
+
restoreFocusTo?: FocusTarget;
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export interface TrayMessageProps extends HTMLAttributes<HTMLDivElement> {
|
|
29
|
+
/**
|
|
30
|
+
* What to announce, when the spoken sentence should differ from the visible
|
|
31
|
+
* message (e.g. visible `Approved "X"` styled in parts, spoken as one
|
|
32
|
+
* sentence). Defaults to the message's text.
|
|
33
|
+
*/
|
|
34
|
+
announcement?: string;
|
|
35
|
+
children?: ReactNode;
|
|
36
|
+
}
|
|
37
|
+
export interface TrayActionsProps extends HTMLAttributes<HTMLDivElement> {
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
export interface TraySaveActionsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
41
|
+
/** Discard the pending changes. The tray never discards on its own (no Escape). */
|
|
42
|
+
onDiscard: () => void;
|
|
43
|
+
/** Save. Alternatively pass `formId` to make Save submit that form; then `onSave` is not called. */
|
|
44
|
+
onSave?: () => void;
|
|
45
|
+
/** Id of the form Save submits (`type="submit" form={formId}`). Takes precedence over `onSave`. */
|
|
46
|
+
formId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* A save is in flight: Save shows a spinner and ignores activation, but keeps
|
|
49
|
+
* focus. Named for the domain; it drives Button's `loading`.
|
|
50
|
+
*/
|
|
51
|
+
saving?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Save is unavailable (e.g. the form is invalid). It stays focusable and is
|
|
54
|
+
* announced as dimmed (`aria-disabled`), so a keyboard user can still find it
|
|
55
|
+
* and hear why; activation does nothing. Pair with `saveDescription`.
|
|
56
|
+
*/
|
|
57
|
+
saveDisabled?: boolean;
|
|
58
|
+
/** Why Save is unavailable, e.g. "Fix 2 errors to save". Wired to Save via `aria-describedby`. */
|
|
59
|
+
saveDescription?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Button labels, for translation. Defaults are exported as
|
|
62
|
+
* {@link defaultTraySaveLabels}; a partial object overrides only its keys.
|
|
63
|
+
*/
|
|
64
|
+
labels?: TraySaveLabels;
|
|
65
|
+
/** Size of both buttons. @default 'md' */
|
|
66
|
+
size?: SizeStandard;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A non-modal bar at the bottom of its scroll container or the viewport,
|
|
70
|
+
* holding a short message and a few actions: unsaved changes
|
|
71
|
+
* (`Tray.SaveActions`), an undo stack, a bulk selection. Announced politely;
|
|
72
|
+
* never takes focus; returns focus if it closes with focus inside.
|
|
73
|
+
*/
|
|
74
|
+
export declare const Tray: import("react").ForwardRefExoticComponent<TrayProps & import("react").RefAttributes<HTMLDivElement>> & {
|
|
75
|
+
Message: import("react").ForwardRefExoticComponent<TrayMessageProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
76
|
+
Actions: import("react").ForwardRefExoticComponent<TrayActionsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
77
|
+
SaveActions: import("react").ForwardRefExoticComponent<TraySaveActionsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { composeRefs } from '../../utils/compose-refs.js';
|
|
5
|
+
import { isDev } from '../../utils/is-dev.js';
|
|
6
|
+
import { getTabbable, isTabbable } from '../../utils/tabbable.js';
|
|
7
|
+
import { Button } from '../Button/index.js';
|
|
8
|
+
import { defaultTraySaveLabels } from './labels.js';
|
|
9
|
+
const EXIT_FALLBACK_MS = 400;
|
|
10
|
+
const TrayContext = createContext(null);
|
|
11
|
+
function useTrayContext(part) {
|
|
12
|
+
const ctx = useContext(TrayContext);
|
|
13
|
+
if (!ctx)
|
|
14
|
+
throw new Error(`<Tray.${part}> must be rendered inside <Tray>.`);
|
|
15
|
+
return ctx;
|
|
16
|
+
}
|
|
17
|
+
function resolveTarget(target) {
|
|
18
|
+
if (!target)
|
|
19
|
+
return null;
|
|
20
|
+
return (typeof target === 'function' ? target() : target.current) ?? null;
|
|
21
|
+
}
|
|
22
|
+
function tryFocus(el) {
|
|
23
|
+
if (!el || !el.isConnected)
|
|
24
|
+
return false;
|
|
25
|
+
el.focus({ preventScroll: true });
|
|
26
|
+
return document.activeElement === el;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Last resort when neither `restoreFocusTo` nor the entry element can take
|
|
30
|
+
* focus (the field was disabled during the save, the selected rows were
|
|
31
|
+
* deleted): the nearest tabbable before the tray in DOM order, else after it.
|
|
32
|
+
*/
|
|
33
|
+
function neighbourOf(root) {
|
|
34
|
+
const outside = getTabbable(document.body).filter((el) => !root.contains(el));
|
|
35
|
+
const before = outside.filter((el) => root.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING);
|
|
36
|
+
return before.at(-1) ?? outside.find((el) => !before.includes(el)) ?? null;
|
|
37
|
+
}
|
|
38
|
+
const TrayRoot = forwardRef(function Tray({ open, placement = 'sticky', restoreFocusTo, className, children, onFocus, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ...rest }, forwardedRef) {
|
|
39
|
+
const rootRef = useRef(null);
|
|
40
|
+
const [state, setState] = useState(open ? 'open' : 'closed');
|
|
41
|
+
const [messageId, setMessageId] = useState(null);
|
|
42
|
+
const entryRef = useRef(null);
|
|
43
|
+
// --- Open / close -----------------------------------------------------
|
|
44
|
+
// Animate in only when it opens on the page, not when it's already open at
|
|
45
|
+
// mount (a page that loads with unsaved edits shouldn't slide anything in).
|
|
46
|
+
const [entering, setEntering] = useState(false);
|
|
47
|
+
const mountedRef = useRef(false);
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
const firstRun = !mountedRef.current;
|
|
50
|
+
mountedRef.current = true;
|
|
51
|
+
if (open) {
|
|
52
|
+
if (!firstRun)
|
|
53
|
+
setEntering(true);
|
|
54
|
+
setState('open');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setEntering(false);
|
|
58
|
+
setState((s) => (s === 'closed' ? s : 'closing'));
|
|
59
|
+
}, [open]);
|
|
60
|
+
const finishClose = useCallback(() => {
|
|
61
|
+
setState((s) => (s === 'closing' ? 'closed' : s));
|
|
62
|
+
}, []);
|
|
63
|
+
const restoreRef = useRef(restoreFocusTo);
|
|
64
|
+
restoreRef.current = restoreFocusTo;
|
|
65
|
+
// One layout effect, in this order: move focus out, THEN make the tray
|
|
66
|
+
// inert. Browsers blur a focused element the moment an ancestor goes inert,
|
|
67
|
+
// so the other order finds focus already on <body> and restores nothing.
|
|
68
|
+
// `inert` is set as a DOM property, as Tabs and Accordion do: React 18
|
|
69
|
+
// doesn't treat it as a boolean attribute.
|
|
70
|
+
useLayoutEffect(() => {
|
|
71
|
+
const root = rootRef.current;
|
|
72
|
+
if (!root)
|
|
73
|
+
return;
|
|
74
|
+
if (state === 'closing' && root.contains(document.activeElement)) {
|
|
75
|
+
const explicit = resolveTarget(restoreRef.current);
|
|
76
|
+
const entry = entryRef.current;
|
|
77
|
+
if (!tryFocus(explicit) &&
|
|
78
|
+
!(entry && isTabbable(entry) && tryFocus(entry)) &&
|
|
79
|
+
!tryFocus(neighbourOf(root))) {
|
|
80
|
+
if (isDev()) {
|
|
81
|
+
console.warn('[Tray] Closed while focus was inside it, and there was nowhere to ' +
|
|
82
|
+
'return focus. Pass `restoreFocusTo`.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
root.inert = state !== 'open';
|
|
87
|
+
}, [state]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (state !== 'closing')
|
|
90
|
+
return;
|
|
91
|
+
const root = rootRef.current;
|
|
92
|
+
// No animation to wait for (reduced motion, or the stylesheet missing).
|
|
93
|
+
if (!root || getComputedStyle(root).animationName === 'none') {
|
|
94
|
+
finishClose();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// Raced against a timeout: a tray in a hidden panel never animates.
|
|
98
|
+
const timer = setTimeout(finishClose, EXIT_FALLBACK_MS);
|
|
99
|
+
return () => clearTimeout(timer);
|
|
100
|
+
}, [state, finishClose]);
|
|
101
|
+
// --- Announcer -------------------------------------------------------
|
|
102
|
+
const [announcement, setAnnouncement] = useState('');
|
|
103
|
+
const seqRef = useRef(0);
|
|
104
|
+
const clearRef = useRef(null);
|
|
105
|
+
const announce = useCallback((text) => {
|
|
106
|
+
if (!text)
|
|
107
|
+
return;
|
|
108
|
+
seqRef.current += 1;
|
|
109
|
+
// Alternating trailing NBSP: identical consecutive text is still a DOM
|
|
110
|
+
// mutation, so it is still announced.
|
|
111
|
+
setAnnouncement(text + (seqRef.current % 2 ? '\u00a0' : ''));
|
|
112
|
+
if (clearRef.current)
|
|
113
|
+
clearTimeout(clearRef.current);
|
|
114
|
+
// Clear once spoken, so browse mode can't find stale text.
|
|
115
|
+
clearRef.current = setTimeout(() => setAnnouncement(''), 3000);
|
|
116
|
+
}, []);
|
|
117
|
+
useEffect(() => () => {
|
|
118
|
+
if (clearRef.current)
|
|
119
|
+
clearTimeout(clearRef.current);
|
|
120
|
+
}, []);
|
|
121
|
+
// --- Naming ----------------------------------------------------------
|
|
122
|
+
const warnedName = useRef(false);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (isDev() && open && !ariaLabel && !ariaLabelledBy && !messageId && !warnedName.current) {
|
|
125
|
+
warnedName.current = true;
|
|
126
|
+
console.warn('[Tray] Give it a <Tray.Message> or an `aria-label`: the region needs a name.');
|
|
127
|
+
}
|
|
128
|
+
}, [open, ariaLabel, ariaLabelledBy, messageId]);
|
|
129
|
+
const labelledBy = ariaLabel ? ariaLabelledBy : (ariaLabelledBy ?? messageId ?? undefined);
|
|
130
|
+
const handleAnimationEnd = (e) => {
|
|
131
|
+
if (e.target === e.currentTarget) {
|
|
132
|
+
if (state === 'closing')
|
|
133
|
+
finishClose();
|
|
134
|
+
else
|
|
135
|
+
setEntering(false);
|
|
136
|
+
}
|
|
137
|
+
rest.onAnimationEnd?.(e);
|
|
138
|
+
};
|
|
139
|
+
return (_jsxs(TrayContext.Provider, { value: { open, announce, registerMessage: setMessageId }, children: [_jsx("div", { className: "tui-tray__announcer", "aria-live": "polite", "aria-atomic": "true", children: announcement }), _jsx("div", { ...rest, ref: composeRefs(forwardedRef, rootRef), role: "region", "aria-label": ariaLabel, "aria-labelledby": labelledBy, className: cx('tui-tray', `is-placement-${placement}`, className), "data-state": state, "data-entering": entering && state === 'open' ? '' : undefined, onFocus: (e) => {
|
|
140
|
+
// Record where focus came from. From nowhere (null: the page, or a
|
|
141
|
+
// Safari click on a button) means there's no entry to return to; a
|
|
142
|
+
// stale one from an earlier visit would be worse than the fallback.
|
|
143
|
+
const from = e.relatedTarget;
|
|
144
|
+
if (!e.currentTarget.contains(from))
|
|
145
|
+
entryRef.current = from;
|
|
146
|
+
onFocus?.(e);
|
|
147
|
+
}, onAnimationEnd: handleAnimationEnd, children: children })] }));
|
|
148
|
+
});
|
|
149
|
+
/** The tray's message: names the region, and its text is announced on open and on change. */
|
|
150
|
+
const TrayMessage = forwardRef(function TrayMessage({ announcement, className, id: idProp, children, ...rest }, forwardedRef) {
|
|
151
|
+
const ctx = useTrayContext('Message');
|
|
152
|
+
const autoId = useId();
|
|
153
|
+
const id = idProp ?? `tui-tray-message-${autoId}`;
|
|
154
|
+
const ref = useRef(null);
|
|
155
|
+
const lastRef = useRef(null);
|
|
156
|
+
const { registerMessage, announce, open } = ctx;
|
|
157
|
+
useLayoutEffect(() => {
|
|
158
|
+
registerMessage(id);
|
|
159
|
+
return () => registerMessage(null);
|
|
160
|
+
}, [id, registerMessage]);
|
|
161
|
+
// Announce on open and whenever the spoken text changes while open.
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!open) {
|
|
164
|
+
lastRef.current = null;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const spoken = (announcement ?? ref.current?.textContent ?? '').trim();
|
|
168
|
+
if (spoken && spoken !== lastRef.current) {
|
|
169
|
+
lastRef.current = spoken;
|
|
170
|
+
announce(spoken);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return (_jsx("div", { ...rest, ref: composeRefs(forwardedRef, ref), id: id, className: cx('tui-tray__message', className), children: children }));
|
|
174
|
+
});
|
|
175
|
+
/** A row of actions, end-aligned. Use it for anything other than the save recipe. */
|
|
176
|
+
const TrayActions = forwardRef(function TrayActions({ className, children, ...rest }, ref) {
|
|
177
|
+
useTrayContext('Actions');
|
|
178
|
+
return (_jsx("div", { ...rest, ref: ref, className: cx('tui-tray__actions', className), children: children }));
|
|
179
|
+
});
|
|
180
|
+
/** The unsaved-changes recipe: Discard then Save, with busy and unavailable states. */
|
|
181
|
+
const TraySaveActions = forwardRef(function TraySaveActions({ onDiscard, onSave, formId, saving = false, saveDisabled = false, saveDescription, labels: labelsProp, size, className, ...rest }, ref) {
|
|
182
|
+
useTrayContext('SaveActions');
|
|
183
|
+
const labels = { ...defaultTraySaveLabels, ...labelsProp };
|
|
184
|
+
const descId = `tui-tray-save-desc-${useId()}`;
|
|
185
|
+
const blocked = saveDisabled && !saving;
|
|
186
|
+
const warnedAction = useRef(false);
|
|
187
|
+
const warnedDescription = useRef(false);
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
if (!isDev() || warnedAction.current)
|
|
190
|
+
return;
|
|
191
|
+
if (!onSave && !formId) {
|
|
192
|
+
warnedAction.current = true;
|
|
193
|
+
console.warn('[Tray.SaveActions] Pass `onSave` or `formId`, or Save does nothing.');
|
|
194
|
+
}
|
|
195
|
+
else if (onSave && formId) {
|
|
196
|
+
warnedAction.current = true;
|
|
197
|
+
console.warn('[Tray.SaveActions] Both `onSave` and `formId` given: Save submits the form and `onSave` is not called.');
|
|
198
|
+
}
|
|
199
|
+
}, [onSave, formId]);
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (isDev() && saveDisabled && !saveDescription && !warnedDescription.current) {
|
|
202
|
+
warnedDescription.current = true;
|
|
203
|
+
console.warn('[Tray.SaveActions] `saveDisabled` without `saveDescription`: say why Save is unavailable.');
|
|
204
|
+
}
|
|
205
|
+
}, [saveDisabled, saveDescription]);
|
|
206
|
+
return (
|
|
207
|
+
// DOM order matches visual order: Discard, then Save.
|
|
208
|
+
_jsxs("div", { ...rest, ref: ref, className: cx('tui-tray__actions', className), children: [_jsx(Button, { size: size, theme: "secondary", variant: "outline", label: labels.discard, onClick: onDiscard }), _jsx(Button, { size: size, theme: "primary", label: labels.save, loading: saving, loadingLabel: labels.saving, type: formId ? 'submit' : 'button', form: formId, "aria-disabled": blocked || undefined, "aria-describedby": saveDescription ? descId : undefined, onClick: (e) => {
|
|
209
|
+
// Enter, Space and implicit submission arrive as a click; one guard
|
|
210
|
+
// covers them, and preventDefault cancels a submit.
|
|
211
|
+
if (blocked) {
|
|
212
|
+
e.preventDefault();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (!formId)
|
|
216
|
+
onSave?.();
|
|
217
|
+
} }), saveDescription && (_jsx("span", { id: descId, className: "tui-tray__description", children: saveDescription }))] }));
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* A non-modal bar at the bottom of its scroll container or the viewport,
|
|
221
|
+
* holding a short message and a few actions: unsaved changes
|
|
222
|
+
* (`Tray.SaveActions`), an undo stack, a bulk selection. Announced politely;
|
|
223
|
+
* never takes focus; returns focus if it closes with focus inside.
|
|
224
|
+
*/
|
|
225
|
+
export const Tray = Object.assign(TrayRoot, {
|
|
226
|
+
Message: TrayMessage,
|
|
227
|
+
Actions: TrayActions,
|
|
228
|
+
SaveActions: TraySaveActions,
|
|
229
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type TraySaveLabels = {
|
|
2
|
+
/** @default 'Discard' */
|
|
3
|
+
discard?: string;
|
|
4
|
+
/** @default 'Save changes' */
|
|
5
|
+
save?: string;
|
|
6
|
+
/** Save's accessible name while `saving`. Defaults to Button's `'{save}, loading'`. */
|
|
7
|
+
saving?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const defaultTraySaveLabels: Required<Omit<TraySaveLabels, 'saving'>>;
|
package/components/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export { Tabs } from './Tabs';
|
|
|
45
45
|
export { Textarea } from './Textarea';
|
|
46
46
|
export { TextInput } from './TextInput';
|
|
47
47
|
export { Toast, ToastProvider, useToast } from './Toast';
|
|
48
|
+
export { Tray, defaultTraySaveLabels } from './Tray';
|
|
48
49
|
export { Toolbar } from './Toolbar';
|
|
49
50
|
export { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent } from './Tooltip';
|
|
50
51
|
export type { AccordionProps, AccordionSingleProps, AccordionMultipleProps, AccordionItemProps, AccordionTriggerProps, AccordionPanelProps, AccordionVariant, AccordionItemState, } from './Accordion';
|
|
@@ -90,6 +91,7 @@ export type { SwitchProps } from './Switch';
|
|
|
90
91
|
export type { TextareaProps, TextareaResize } from './Textarea';
|
|
91
92
|
export type { TextInputProps, TextInputType } from './TextInput';
|
|
92
93
|
export type { ToastProps, ToastHandle, ToastTheme, ToastAnnounce, ToastPlacement, ToastOptions, ToastContextValue, ToastProviderProps, } from './Toast';
|
|
94
|
+
export type { TrayProps, TrayPlacement, TrayMessageProps, TrayActionsProps, TraySaveActionsProps, TraySaveLabels, } from './Tray';
|
|
93
95
|
export type { ToolbarProps, ToolbarGroupProps, ToolbarItemProps, ToolbarOrientation } from './Toolbar';
|
|
94
96
|
export type { TooltipProps, TooltipProviderProps, TooltipTriggerProps, TooltipContentProps, TooltipType } from './Tooltip';
|
|
95
97
|
export { GENERATIVE_COLORS, stringToGenerativeColor } from '../utils/generative';
|
package/components/index.js
CHANGED
|
@@ -43,6 +43,7 @@ export { Tabs } from './Tabs/index.js';
|
|
|
43
43
|
export { Textarea } from './Textarea/index.js';
|
|
44
44
|
export { TextInput } from './TextInput/index.js';
|
|
45
45
|
export { Toast, ToastProvider, useToast } from './Toast/index.js';
|
|
46
|
+
export { Tray, defaultTraySaveLabels } from './Tray/index.js';
|
|
46
47
|
export { Toolbar } from './Toolbar/index.js';
|
|
47
48
|
export { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent } from './Tooltip/index.js';
|
|
48
49
|
// Generative colors (The Jellybean Bag) — deterministic identity colors
|
package/figma-tokens.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.38",
|
|
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.",
|