@tangible/ui 0.2.17 → 0.2.19
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/Notice/Notice.js +7 -0
- package/components/Sidebar/Sidebar.d.ts +19 -1
- package/components/Sidebar/Sidebar.js +110 -3
- package/components/Sidebar/index.d.ts +2 -1
- package/components/Sidebar/index.js +1 -0
- package/components/Sidebar/types.d.ts +68 -0
- package/components/Sidebar/types.js +4 -1
- package/components/Toast/Toast.d.ts +134 -0
- package/components/Toast/Toast.js +234 -0
- package/components/Toast/ToastContext.d.ts +11 -0
- package/components/Toast/ToastContext.js +9 -0
- package/components/Toast/index.d.ts +4 -0
- package/components/Toast/index.js +2 -0
- package/components/index.d.ts +4 -2
- package/components/index.js +2 -1
- package/figma-tokens.json +1 -1
- package/package.json +5 -1
- package/skills/building-with-tui/SKILL.md +2 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +120 -0
- package/styles/all.expanded.unlayered.css +120 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +5 -0
- package/styles/components/notice.scss +13 -0
- package/styles/components/sidebar.scss +83 -0
- package/styles/components/toast.scss +183 -0
- package/tui-manifest.json +133 -7
|
@@ -80,6 +80,13 @@ export const Notice = forwardRef(function Notice({ as = 'section', inline, eleva
|
|
|
80
80
|
el.setAttribute('role', 'status');
|
|
81
81
|
el.setAttribute('aria-live', 'polite');
|
|
82
82
|
el.className = 'tui-visually-hidden';
|
|
83
|
+
// The utility class is scoped under .tui-interface, but this element is
|
|
84
|
+
// appended to document.body — outside any interface wrapper — so the
|
|
85
|
+
// class matches nothing and the text painted visibly at the bottom of
|
|
86
|
+
// the page. Inline the visually-hidden treatment so it can't unscope.
|
|
87
|
+
el.style.cssText =
|
|
88
|
+
'position:absolute;width:1px;height:1px;padding:0;margin:-1px;' +
|
|
89
|
+
'overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;';
|
|
83
90
|
el.textContent = 'Notification dismissed';
|
|
84
91
|
document.body.appendChild(el);
|
|
85
92
|
setTimeout(() => el.remove(), 1000);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SidebarProps, SidebarHeaderProps, SidebarFooterProps, SidebarNavProps } from './types';
|
|
1
|
+
import type { SidebarProps, SidebarHeaderProps, SidebarFooterProps, SidebarNavProps, SidebarToggleProps } from './types';
|
|
2
2
|
declare function SidebarHeader(props: SidebarHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
declare namespace SidebarHeader {
|
|
4
4
|
var displayName: string;
|
|
@@ -11,12 +11,30 @@ declare function SidebarNav(props: SidebarNavProps): import("react/jsx-runtime")
|
|
|
11
11
|
declare namespace SidebarNav {
|
|
12
12
|
var displayName: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Collapses and expands the sidebar it sits in.
|
|
16
|
+
*
|
|
17
|
+
* Place it as a direct child of `Sidebar` rather than inside Header, Nav or
|
|
18
|
+
* Footer — those three are what the collapsed rail hides, and a button
|
|
19
|
+
* hidden with them could never bring the sidebar back. Anything else you
|
|
20
|
+
* put directly in the sidebar survives the collapse alongside it.
|
|
21
|
+
*
|
|
22
|
+
* The glyph reads as a direction, so it tracks `position`: on a left-hand
|
|
23
|
+
* sidebar collapsing moves content left (`sidebar-collapse`, arrow pointing
|
|
24
|
+
* left) and expanding moves it right. A right-hand sidebar wants the
|
|
25
|
+
* mirror of that, and the icon pair already is one.
|
|
26
|
+
*/
|
|
27
|
+
declare function SidebarToggle(props: SidebarToggleProps): import("react/jsx-runtime").JSX.Element | null;
|
|
28
|
+
declare namespace SidebarToggle {
|
|
29
|
+
var displayName: string;
|
|
30
|
+
}
|
|
14
31
|
type SidebarCompound = {
|
|
15
32
|
(props: SidebarProps): React.JSX.Element | null;
|
|
16
33
|
displayName?: string;
|
|
17
34
|
Header: typeof SidebarHeader;
|
|
18
35
|
Footer: typeof SidebarFooter;
|
|
19
36
|
Nav: typeof SidebarNav;
|
|
37
|
+
Toggle: typeof SidebarToggle;
|
|
20
38
|
};
|
|
21
39
|
export declare const Sidebar: SidebarCompound;
|
|
22
40
|
export {};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { defaultSidebarToggleLabels } from './types.js';
|
|
3
4
|
import { useFocusTrap, getInitialFocus } from '../../utils/focus-trap.js';
|
|
5
|
+
import { useControllableState } from '../../utils/use-controllable-state.js';
|
|
4
6
|
import { isDev } from '../../utils/is-dev.js';
|
|
7
|
+
import { IconButton } from '../IconButton/index.js';
|
|
5
8
|
const isBrowser = typeof document !== 'undefined';
|
|
9
|
+
const SidebarCollapseContext = createContext(null);
|
|
6
10
|
// =============================================================================
|
|
7
11
|
// Sidebar (Root)
|
|
8
12
|
// =============================================================================
|
|
@@ -12,7 +16,59 @@ function SidebarRoot(props) {
|
|
|
12
16
|
const drawer = props.drawer === true;
|
|
13
17
|
const open = props.drawer ? (props.open ?? false) : false;
|
|
14
18
|
const onClose = props.drawer ? props.onClose : undefined;
|
|
19
|
+
// Collapse is static-mode only, narrowed the same way. A drawer already
|
|
20
|
+
// shows and hides wholesale; a rail inside one would sit beside nothing.
|
|
21
|
+
const collapsible = !drawer && props.collapsible === true;
|
|
22
|
+
const [collapsedValue, setCollapsed] = useControllableState({
|
|
23
|
+
value: drawer ? undefined : props.collapsed,
|
|
24
|
+
defaultValue: (!drawer && props.defaultCollapsed) ?? false,
|
|
25
|
+
onChange: drawer ? undefined : props.onCollapsedChange,
|
|
26
|
+
});
|
|
27
|
+
// Only a collapsible sidebar can be collapsed — a stale `collapsed` left
|
|
28
|
+
// behind after `collapsible` is turned off must not shrink the rail.
|
|
29
|
+
const collapsed = collapsible && collapsedValue === true;
|
|
30
|
+
const toggleCollapsed = useCallback(() => {
|
|
31
|
+
setCollapsed((prev) => !prev);
|
|
32
|
+
}, [setCollapsed]);
|
|
15
33
|
const sidebarRef = useRef(null);
|
|
34
|
+
const toggleRef = useRef(null);
|
|
35
|
+
// Read inside an event handler, so it must be a ref rather than the
|
|
36
|
+
// render-closure value.
|
|
37
|
+
const collapsedRef = useRef(collapsed);
|
|
38
|
+
collapsedRef.current = collapsed;
|
|
39
|
+
/**
|
|
40
|
+
* Collapsing hides Header, Nav and Footer outright, so a collapse driven
|
|
41
|
+
* from outside — a controlled `collapsed`, an app-level shortcut — can pull
|
|
42
|
+
* the rendered element out from under the keyboard cursor. The browser then
|
|
43
|
+
* drops focus to `<body>`: no ring, no announcement, and the user's place in
|
|
44
|
+
* the page is simply gone (WCAG 2.4.3). Clicking the toggle is safe because
|
|
45
|
+
* focus is already on the one element that survives; every other route is
|
|
46
|
+
* not, which is why this hangs off the event rather than the toggle.
|
|
47
|
+
*
|
|
48
|
+
* Driven by `focusout` rather than an effect on `collapsed` deliberately:
|
|
49
|
+
* the browser fires it at the exact moment focus is actually lost, so there
|
|
50
|
+
* is no race against style recalculation to reason about — an effect has to
|
|
51
|
+
* guess whether `display: none` has been applied yet.
|
|
52
|
+
*
|
|
53
|
+
* The `offsetParent` check is what separates the two cases that both arrive
|
|
54
|
+
* with a null `relatedTarget`: an element hidden under the cursor has no
|
|
55
|
+
* offset parent, while one the user simply clicked away from is still laid
|
|
56
|
+
* out. Without it this would steal focus from anyone clicking dead space.
|
|
57
|
+
*/
|
|
58
|
+
const handleFocusOut = useCallback((event) => {
|
|
59
|
+
if (!collapsedRef.current)
|
|
60
|
+
return;
|
|
61
|
+
if (event.relatedTarget)
|
|
62
|
+
return;
|
|
63
|
+
const lost = event.target;
|
|
64
|
+
if (lost.isConnected && lost.offsetParent !== null)
|
|
65
|
+
return;
|
|
66
|
+
// The toggle is the one interactive element guaranteed to survive the
|
|
67
|
+
// collapse. Without one, the rail itself takes focus so the user lands
|
|
68
|
+
// on the landmark rather than at the top of the document.
|
|
69
|
+
(toggleRef.current ?? sidebarRef.current)?.focus();
|
|
70
|
+
}, []);
|
|
71
|
+
const collapseContext = useMemo(() => ({ collapsible, collapsed, position, toggle: toggleCollapsed, toggleRef }), [collapsible, collapsed, position, toggleCollapsed]);
|
|
16
72
|
const restoreRef = useRef(null);
|
|
17
73
|
// Exit animation: keep DOM mounted until slide-out animation completes.
|
|
18
74
|
// `visible` stays true after `open` goes false, until animationend fires.
|
|
@@ -115,7 +171,14 @@ function SidebarRoot(props) {
|
|
|
115
171
|
// Static mode: render directly
|
|
116
172
|
// ---------------------------------------------------------------------------
|
|
117
173
|
if (!drawer) {
|
|
118
|
-
return (_jsx("aside", { ref: sidebarRef, className: rootClassName, "data-position": position, "
|
|
174
|
+
return (_jsx(SidebarCollapseContext.Provider, { value: collapseContext, children: _jsx("aside", { ref: sidebarRef, className: rootClassName, "data-position": position, "data-collapsed": collapsible ? String(collapsed) : undefined,
|
|
175
|
+
// Focus target of last resort for the recovery above, for a
|
|
176
|
+
// collapsible sidebar driven by an external control with no
|
|
177
|
+
// `Sidebar.Toggle` of its own. Not in the tab order either way.
|
|
178
|
+
tabIndex: collapsible ? -1 : undefined,
|
|
179
|
+
// React maps this to `focusout`, which bubbles — so one handler on
|
|
180
|
+
// the landmark covers every descendant the collapse can hide.
|
|
181
|
+
onBlur: collapsible ? handleFocusOut : undefined, "aria-label": ariaLabel, children: children }) }));
|
|
119
182
|
}
|
|
120
183
|
// ---------------------------------------------------------------------------
|
|
121
184
|
// Drawer mode: render inline with fixed positioning (no portal needed)
|
|
@@ -130,7 +193,7 @@ function SidebarRoot(props) {
|
|
|
130
193
|
]
|
|
131
194
|
.filter(Boolean)
|
|
132
195
|
.join(' ');
|
|
133
|
-
return (_jsxs("div", { className: drawerClassName, "data-position": position, "data-state": drawerState, children: [_jsx("div", { className: "tui-sidebar-drawer__backdrop", onClick: onClose, "aria-hidden": "true" }), _jsx("div", { ref: panelRef, className: "tui-sidebar-drawer__panel", role: "dialog", "aria-modal": "true", "aria-label": ariaLabel, onAnimationEnd: handleAnimationEnd, children: _jsx("aside", { ref: sidebarRef, className: rootClassName, "data-position": position, tabIndex: -1, children: children }) })] }));
|
|
196
|
+
return (_jsx(SidebarCollapseContext.Provider, { value: collapseContext, children: _jsxs("div", { className: drawerClassName, "data-position": position, "data-state": drawerState, children: [_jsx("div", { className: "tui-sidebar-drawer__backdrop", onClick: onClose, "aria-hidden": "true" }), _jsx("div", { ref: panelRef, className: "tui-sidebar-drawer__panel", role: "dialog", "aria-modal": "true", "aria-label": ariaLabel, onAnimationEnd: handleAnimationEnd, children: _jsx("aside", { ref: sidebarRef, className: rootClassName, "data-position": position, tabIndex: -1, children: children }) })] }) }));
|
|
134
197
|
}
|
|
135
198
|
// =============================================================================
|
|
136
199
|
// Sidebar.Header
|
|
@@ -156,11 +219,55 @@ function SidebarNav(props) {
|
|
|
156
219
|
const navClassName = ['tui-sidebar__nav', className].filter(Boolean).join(' ');
|
|
157
220
|
return (_jsx("nav", { className: navClassName, "aria-label": navAriaLabel, "aria-labelledby": navAriaLabelledBy, children: children }));
|
|
158
221
|
}
|
|
222
|
+
// =============================================================================
|
|
223
|
+
// Sidebar.Toggle
|
|
224
|
+
// =============================================================================
|
|
225
|
+
/**
|
|
226
|
+
* Collapses and expands the sidebar it sits in.
|
|
227
|
+
*
|
|
228
|
+
* Place it as a direct child of `Sidebar` rather than inside Header, Nav or
|
|
229
|
+
* Footer — those three are what the collapsed rail hides, and a button
|
|
230
|
+
* hidden with them could never bring the sidebar back. Anything else you
|
|
231
|
+
* put directly in the sidebar survives the collapse alongside it.
|
|
232
|
+
*
|
|
233
|
+
* The glyph reads as a direction, so it tracks `position`: on a left-hand
|
|
234
|
+
* sidebar collapsing moves content left (`sidebar-collapse`, arrow pointing
|
|
235
|
+
* left) and expanding moves it right. A right-hand sidebar wants the
|
|
236
|
+
* mirror of that, and the icon pair already is one.
|
|
237
|
+
*/
|
|
238
|
+
function SidebarToggle(props) {
|
|
239
|
+
const { labels, className, ...rest } = props;
|
|
240
|
+
const text = { ...defaultSidebarToggleLabels, ...labels };
|
|
241
|
+
const context = useContext(SidebarCollapseContext);
|
|
242
|
+
const hasWarnedRef = useRef(false);
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
if (isDev() && context && !context.collapsible && !hasWarnedRef.current) {
|
|
245
|
+
console.warn('[TUI Sidebar] Sidebar.Toggle rendered inside a Sidebar without ' +
|
|
246
|
+
'`collapsible`. Add `collapsible` to the Sidebar, or drop the toggle.');
|
|
247
|
+
hasWarnedRef.current = true;
|
|
248
|
+
}
|
|
249
|
+
}, [context]);
|
|
250
|
+
// Outside a Sidebar there is nothing to collapse, and rendering a dead
|
|
251
|
+
// button would be worse than rendering none.
|
|
252
|
+
if (!context) {
|
|
253
|
+
if (isDev()) {
|
|
254
|
+
console.warn('[TUI Sidebar] Sidebar.Toggle must be rendered inside a Sidebar.');
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const { collapsed, position, toggle, toggleRef } = context;
|
|
259
|
+
const pointsInward = position === 'left' ? !collapsed : collapsed;
|
|
260
|
+
return (_jsx(IconButton, { ...rest, ref: (node) => {
|
|
261
|
+
toggleRef.current = node;
|
|
262
|
+
}, icon: pointsInward ? 'system/sidebar-collapse' : 'system/sidebar-expand', label: collapsed ? text.expand : text.collapse, className: ['tui-sidebar__toggle', className].filter(Boolean).join(' '), "aria-expanded": !collapsed, onClick: toggle }));
|
|
263
|
+
}
|
|
159
264
|
SidebarHeader.displayName = 'Sidebar.Header';
|
|
160
265
|
SidebarFooter.displayName = 'Sidebar.Footer';
|
|
161
266
|
SidebarNav.displayName = 'Sidebar.Nav';
|
|
267
|
+
SidebarToggle.displayName = 'Sidebar.Toggle';
|
|
162
268
|
export const Sidebar = SidebarRoot;
|
|
163
269
|
Sidebar.displayName = 'Sidebar';
|
|
164
270
|
Sidebar.Header = SidebarHeader;
|
|
165
271
|
Sidebar.Footer = SidebarFooter;
|
|
166
272
|
Sidebar.Nav = SidebarNav;
|
|
273
|
+
Sidebar.Toggle = SidebarToggle;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { Sidebar } from './Sidebar';
|
|
2
|
-
export
|
|
2
|
+
export { defaultSidebarToggleLabels } from './types';
|
|
3
|
+
export type { SidebarProps, SidebarHeaderProps, SidebarFooterProps, SidebarNavProps, SidebarToggleProps, SidebarToggleLabels, } from './types';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
import type { IconButtonAsButton } from '../IconButton/types';
|
|
2
3
|
type SidebarBaseProps = {
|
|
3
4
|
/**
|
|
4
5
|
* Sidebar position. Affects border placement and drawer slide direction.
|
|
@@ -27,6 +28,31 @@ type SidebarStaticProps = SidebarBaseProps & {
|
|
|
27
28
|
* @default false
|
|
28
29
|
*/
|
|
29
30
|
drawer?: false;
|
|
31
|
+
/**
|
|
32
|
+
* Opt into the collapsed rail: the sidebar can shrink to
|
|
33
|
+
* `--tui-sidebar-collapsed-width`, hiding Header, Nav and Footer while
|
|
34
|
+
* leaving any other child — a `Sidebar.Toggle`, an icon rail — visible.
|
|
35
|
+
*
|
|
36
|
+
* Deliberately absent from drawer mode: a drawer is already a
|
|
37
|
+
* show/hide overlay, and a rail inside one has nothing to sit beside.
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
collapsible?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Collapsed state (controlled). Pair with `onCollapsedChange`.
|
|
43
|
+
* Leave undefined to let the sidebar own the state.
|
|
44
|
+
*/
|
|
45
|
+
collapsed?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Initial collapsed state when uncontrolled.
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
defaultCollapsed?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Called with the next collapsed state whenever `Sidebar.Toggle` is
|
|
53
|
+
* pressed — in both controlled and uncontrolled mode.
|
|
54
|
+
*/
|
|
55
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
30
56
|
};
|
|
31
57
|
type SidebarDrawerProps = SidebarBaseProps & {
|
|
32
58
|
/**
|
|
@@ -68,6 +94,48 @@ export type SidebarFooterProps = {
|
|
|
68
94
|
*/
|
|
69
95
|
className?: string;
|
|
70
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* The toggle's accessible name flips with the state rather than staying
|
|
99
|
+
* constant, so each half is named for the action it will perform — the same
|
|
100
|
+
* call `SecretInput` makes for its reveal/hide button, and for the same
|
|
101
|
+
* reason: a name is announced reliably by every AT, where a state attribute
|
|
102
|
+
* is not.
|
|
103
|
+
*/
|
|
104
|
+
export type SidebarToggleLabels = {
|
|
105
|
+
/**
|
|
106
|
+
* Accessible name while the sidebar is expanded — i.e. what pressing it
|
|
107
|
+
* will do: collapse the sidebar.
|
|
108
|
+
* @default 'Collapse sidebar'
|
|
109
|
+
*/
|
|
110
|
+
collapse?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Accessible name while the sidebar is collapsed.
|
|
113
|
+
* @default 'Expand sidebar'
|
|
114
|
+
*/
|
|
115
|
+
expand?: string;
|
|
116
|
+
};
|
|
117
|
+
export declare const defaultSidebarToggleLabels: Required<SidebarToggleLabels>;
|
|
118
|
+
/**
|
|
119
|
+
* Everything IconButton takes as a `<button>`, minus the four props the
|
|
120
|
+
* toggle decides for itself: the glyph, its label, the pressed state and
|
|
121
|
+
* the click. Everything else — `theme`, `size`, `variant`, `showTooltip`,
|
|
122
|
+
* `data-*` — passes straight through, so a consumer can restyle the
|
|
123
|
+
* control without the Sidebar growing a prop for each.
|
|
124
|
+
*
|
|
125
|
+
* `label` is among the four because IconButton's `label` is one constant
|
|
126
|
+
* accessible name, and this button does not have one — it has two. Keeping
|
|
127
|
+
* the prop and quietly redefining it as "the expanded one" would read as
|
|
128
|
+
* the IconButton prop it no longer is; `labels` says there are two states
|
|
129
|
+
* and names both.
|
|
130
|
+
*/
|
|
131
|
+
export type SidebarToggleProps = Omit<IconButtonAsButton, 'icon' | 'label' | 'pressed' | 'onClick' | 'aria-expanded'> & {
|
|
132
|
+
/**
|
|
133
|
+
* Accessible names for the two states. Defaults are English and are
|
|
134
|
+
* exported as {@link defaultSidebarToggleLabels}; a partial object
|
|
135
|
+
* overrides only the keys it names.
|
|
136
|
+
*/
|
|
137
|
+
labels?: SidebarToggleLabels;
|
|
138
|
+
};
|
|
71
139
|
export type SidebarNavProps = {
|
|
72
140
|
/**
|
|
73
141
|
* Accessible label for the nav landmark.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// =============================================================================
|
|
2
2
|
// Sidebar Types
|
|
3
3
|
// =============================================================================
|
|
4
|
-
export {
|
|
4
|
+
export const defaultSidebarToggleLabels = {
|
|
5
|
+
collapse: 'Collapse sidebar',
|
|
6
|
+
expand: 'Expand sidebar',
|
|
7
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NoticeHandle } from '../Notice';
|
|
3
|
+
import type { SizeStandard, ThemeStatus } from '../../types';
|
|
4
|
+
export type ToastTheme = ThemeStatus | 'neutral';
|
|
5
|
+
export type ToastPlacement = 'top-start' | 'top' | 'top-end' | 'bottom-start' | 'bottom' | 'bottom-end';
|
|
6
|
+
export type ToastAnnounce = 'polite' | 'assertive';
|
|
7
|
+
/** Handle exposed via ref — the underlying Notice handle (element + exit). */
|
|
8
|
+
export type ToastHandle = NoticeHandle;
|
|
9
|
+
export type ToastProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title' | 'children'> & {
|
|
10
|
+
/** Visual intent. Default 'neutral' — the plain dark surface. */
|
|
11
|
+
theme?: ToastTheme;
|
|
12
|
+
/**
|
|
13
|
+
* Density preset (Notice's size scale). Default 'sm' — toasts are dense;
|
|
14
|
+
* 'md'/'lg' restore Notice's roomier panel spacing.
|
|
15
|
+
*/
|
|
16
|
+
size?: SizeStandard;
|
|
17
|
+
/** Icon content, rendered leading the text. Colored by theme via Notice. */
|
|
18
|
+
icon?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Title text — a styled `<div>`, never a heading: a toast lives in a
|
|
21
|
+
* portal outside the document outline, so a heading would be an orphan
|
|
22
|
+
* for screen-reader heading navigation.
|
|
23
|
+
*/
|
|
24
|
+
title?: React.ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Screen-reader announcement politeness.
|
|
27
|
+
* Defaults to 'assertive' (role="alert") for danger, 'polite'
|
|
28
|
+
* (role="status") otherwise.
|
|
29
|
+
*/
|
|
30
|
+
announce?: ToastAnnounce;
|
|
31
|
+
/** Renders a dismiss (×) button. Default true. */
|
|
32
|
+
dismissible?: boolean;
|
|
33
|
+
/** Called after the exit animation completes (× button path). */
|
|
34
|
+
onDismiss?: () => void;
|
|
35
|
+
/** Accessible label for the dismiss button. Default 'Dismiss'. */
|
|
36
|
+
dismissLabel?: string;
|
|
37
|
+
/** Action content (e.g. a Button), rendered in the foot. */
|
|
38
|
+
actions?: React.ReactNode;
|
|
39
|
+
className?: string;
|
|
40
|
+
style?: React.CSSProperties;
|
|
41
|
+
/** Body/description content. */
|
|
42
|
+
children?: React.ReactNode;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Presentational toast — an inline-layout Notice dressed for the toast stack
|
|
46
|
+
* (shadow, enter animation, icon | text | actions | × in one row).
|
|
47
|
+
*
|
|
48
|
+
* The toast root is also a nested `.tui-interface` with `data-theme="dark"`:
|
|
49
|
+
* a dark surface by default (following Tooltip's inverted treatment), done as
|
|
50
|
+
* a theme SCOPE rather than a token remap — the toast accepts arbitrary
|
|
51
|
+
* children, and everything inside (action Buttons, the dismiss IconButton,
|
|
52
|
+
* icons, consumer content) resolves dark tokens for free. Pass
|
|
53
|
+
* `data-theme="light"` (or "auto") through rest to opt out.
|
|
54
|
+
*
|
|
55
|
+
* The DOM carries both `tui-toast` and `tui-notice` classes, so Notice's
|
|
56
|
+
* component API tokens (`--tui-notice-bg`, `--tui-notice-padding`, …) can be
|
|
57
|
+
* re-pointed per toast context: `.tui-toast { --tui-notice-bg: …; }`.
|
|
58
|
+
*/
|
|
59
|
+
export declare const Toast: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "title"> & {
|
|
60
|
+
/** Visual intent. Default 'neutral' — the plain dark surface. */
|
|
61
|
+
theme?: ToastTheme;
|
|
62
|
+
/**
|
|
63
|
+
* Density preset (Notice's size scale). Default 'sm' — toasts are dense;
|
|
64
|
+
* 'md'/'lg' restore Notice's roomier panel spacing.
|
|
65
|
+
*/
|
|
66
|
+
size?: SizeStandard;
|
|
67
|
+
/** Icon content, rendered leading the text. Colored by theme via Notice. */
|
|
68
|
+
icon?: React.ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* Title text — a styled `<div>`, never a heading: a toast lives in a
|
|
71
|
+
* portal outside the document outline, so a heading would be an orphan
|
|
72
|
+
* for screen-reader heading navigation.
|
|
73
|
+
*/
|
|
74
|
+
title?: React.ReactNode;
|
|
75
|
+
/**
|
|
76
|
+
* Screen-reader announcement politeness.
|
|
77
|
+
* Defaults to 'assertive' (role="alert") for danger, 'polite'
|
|
78
|
+
* (role="status") otherwise.
|
|
79
|
+
*/
|
|
80
|
+
announce?: ToastAnnounce;
|
|
81
|
+
/** Renders a dismiss (×) button. Default true. */
|
|
82
|
+
dismissible?: boolean;
|
|
83
|
+
/** Called after the exit animation completes (× button path). */
|
|
84
|
+
onDismiss?: () => void;
|
|
85
|
+
/** Accessible label for the dismiss button. Default 'Dismiss'. */
|
|
86
|
+
dismissLabel?: string;
|
|
87
|
+
/** Action content (e.g. a Button), rendered in the foot. */
|
|
88
|
+
actions?: React.ReactNode;
|
|
89
|
+
className?: string;
|
|
90
|
+
style?: React.CSSProperties;
|
|
91
|
+
/** Body/description content. */
|
|
92
|
+
children?: React.ReactNode;
|
|
93
|
+
} & React.RefAttributes<NoticeHandle>>;
|
|
94
|
+
export type ToastOptions = Pick<ToastProps, 'theme' | 'size' | 'icon' | 'title' | 'announce' | 'dismissible' | 'onDismiss' | 'dismissLabel' | 'actions' | 'className' | 'style'> & {
|
|
95
|
+
/**
|
|
96
|
+
* Stable id. Calling toast() again with the same id updates that toast in
|
|
97
|
+
* place (remounting it, so it re-animates and re-announces) and restarts
|
|
98
|
+
* its timer. Omit for a generated id.
|
|
99
|
+
*/
|
|
100
|
+
id?: string;
|
|
101
|
+
/** Body content — maps to the presentational `<Toast>`'s children. */
|
|
102
|
+
description?: React.ReactNode;
|
|
103
|
+
/**
|
|
104
|
+
* Auto-dismiss delay in ms. `null` persists until dismissed.
|
|
105
|
+
* Defaults to the provider's `duration` — unless the toast has `actions`,
|
|
106
|
+
* in which case it persists (the user needs time to act; WCAG 2.2.1).
|
|
107
|
+
*/
|
|
108
|
+
duration?: number | null;
|
|
109
|
+
/** Playwright hook — lands on the toast root, per house testid policy. */
|
|
110
|
+
'data-testid'?: string;
|
|
111
|
+
};
|
|
112
|
+
export type ToastProviderProps = {
|
|
113
|
+
children?: React.ReactNode;
|
|
114
|
+
/** Where the toast stack anchors. Default 'bottom-end'. */
|
|
115
|
+
placement?: ToastPlacement;
|
|
116
|
+
/** Default auto-dismiss delay in ms. Default 5000. */
|
|
117
|
+
duration?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Accessible name for the toast region landmark. Default 'Notifications'.
|
|
120
|
+
* If a page hosts multiple providers (e.g. several independent
|
|
121
|
+
* `.tui-interface` widgets), give each a unique label — duplicate region
|
|
122
|
+
* landmark names are ambiguous for AT users.
|
|
123
|
+
*/
|
|
124
|
+
regionLabel?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Most toasts the stack shows at once — older ones are dismissed to make
|
|
127
|
+
* room. Default 5; pass Infinity to disable.
|
|
128
|
+
*/
|
|
129
|
+
max?: number;
|
|
130
|
+
/** Optional portal target (mirrors Modal). Defaults to the portal root of
|
|
131
|
+
* the nearest `.tui-interface`. */
|
|
132
|
+
container?: Element | null;
|
|
133
|
+
};
|
|
134
|
+
export declare function ToastProvider({ children, placement, duration, regionLabel, max, container, }: ToastProviderProps): import("react/jsx-runtime").JSX.Element;
|