@gooddata/sdk-ui-kit 11.62.0-alpha.0 → 11.62.0-alpha.2
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/esm/@ui/@types/icon.d.ts +1 -1
- package/esm/@ui/@types/icon.d.ts.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableHeader.d.ts.map +1 -1
- package/esm/@ui/UiAsyncTable/UiAsyncTable/UiAsyncTableHeader.js +38 -5
- package/esm/@ui/UiAsyncTable/types.d.ts +4 -0
- package/esm/@ui/UiAsyncTable/types.d.ts.map +1 -1
- package/esm/@ui/UiChip/ChipActionButton.d.ts.map +1 -1
- package/esm/@ui/UiChip/ChipActionButton.js +5 -3
- package/esm/@ui/UiFocusManager/utils.js +2 -2
- package/esm/@ui/UiIcon/icons.d.ts.map +1 -1
- package/esm/@ui/UiIcon/icons.js +4 -1
- package/esm/@ui/UiModalDialog/UiModalDialog.js +2 -2
- package/esm/@ui/UiResizableSidebar/UiResizableSidebarNavigation.d.ts +52 -0
- package/esm/@ui/UiResizableSidebar/UiResizableSidebarNavigation.d.ts.map +1 -0
- package/esm/@ui/UiResizableSidebar/UiResizableSidebarNavigation.js +449 -0
- package/esm/@ui/UiResizableSidebar/types.d.ts +70 -1
- package/esm/@ui/UiResizableSidebar/types.d.ts.map +1 -1
- package/esm/@ui/UiResizableSidebar/useUiResizableSidebarState.d.ts +1 -1
- package/esm/@ui/UiResizableSidebar/useUiResizableSidebarState.d.ts.map +1 -1
- package/esm/@ui/UiResizableSidebar/useUiResizableSidebarState.js +5 -4
- package/esm/@ui/UiToolbarInput/UiToolbarInput.d.ts +71 -0
- package/esm/@ui/UiToolbarInput/UiToolbarInput.d.ts.map +1 -0
- package/esm/@ui/UiToolbarInput/UiToolbarInput.js +78 -0
- package/esm/@ui/UiToolbarPagination/UiToolbarPagination.d.ts +58 -0
- package/esm/@ui/UiToolbarPagination/UiToolbarPagination.d.ts.map +1 -0
- package/esm/@ui/UiToolbarPagination/UiToolbarPagination.js +56 -0
- package/esm/@ui/UiToolbarStepper/UiToolbarStepper.d.ts +7 -11
- package/esm/@ui/UiToolbarStepper/UiToolbarStepper.d.ts.map +1 -1
- package/esm/@ui/UiToolbarStepper/UiToolbarStepper.js +6 -10
- package/esm/Header/generateHeaderMenuItemsGroups.d.ts +1 -5
- package/esm/Header/generateHeaderMenuItemsGroups.d.ts.map +1 -1
- package/esm/Header/generateHeaderMenuItemsGroups.js +3 -21
- package/esm/Overlay/Overlay.d.ts.map +1 -1
- package/esm/Overlay/Overlay.js +2 -2
- package/esm/Overlay/OverlayContext.d.ts +15 -0
- package/esm/Overlay/OverlayContext.d.ts.map +1 -1
- package/esm/Overlay/OverlayContext.js +18 -1
- package/esm/index.d.ts +6 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +5 -2
- package/esm/sdk-ui-kit.d.ts +284 -20
- package/package.json +11 -11
- package/src/@ui/UiButtonSegmentedControl/UiButtonSegmentedControl.scss +13 -1
- package/src/@ui/UiIconButton/UiIconButton.scss +8 -1
- package/src/@ui/UiResizableSidebar/UiResizableSidebarNavigation.scss +205 -0
- package/src/@ui/UiToolbar/UiToolbar.scss +1 -1
- package/src/@ui/UiToolbar/toolbarItem.scss +9 -1
- package/src/@ui/UiToolbarInput/UiToolbarInput.scss +82 -0
- package/src/@ui/UiToolbarPagination/UiToolbarPagination.scss +63 -0
- package/src/@ui/UiToolbarStepper/UiToolbarStepper.scss +25 -10
- package/src/@ui/defaultTheme.scss +4 -1
- package/src/@ui/index.scss +3 -0
- package/styles/css/main.css +313 -18
- package/styles/css/main.css.map +1 -1
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// (C) 2026 GoodData Corporation
|
|
3
|
+
import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
4
|
+
import { FloatingFocusManager, FloatingPortal, safePolygon, useDismiss, useHover, useInteractions, } from "@floating-ui/react";
|
|
5
|
+
import cx from "classnames";
|
|
6
|
+
import { ConditionalScopedThemeProvider } from "@gooddata/sdk-ui-theme-provider";
|
|
7
|
+
import { accessibilityConfigToAttributes } from "../../typings/utilities.js";
|
|
8
|
+
import { bem } from "../@utils/bem.js";
|
|
9
|
+
import { makeGridKeyboardNavigation, makeMenuKeyboardNavigation } from "../@utils/keyboardNavigation.js";
|
|
10
|
+
import { useFloatingPosition } from "../UiFloatingElement/useFloatingPosition.js";
|
|
11
|
+
import { iconPaths } from "../UiIcon/icons.js";
|
|
12
|
+
import { UiIcon } from "../UiIcon/UiIcon.js";
|
|
13
|
+
import { hasSystemModifier } from "../UiToolbar/rovingFocusUtils.js";
|
|
14
|
+
import { UiTooltip } from "../UiTooltip/UiTooltip.js";
|
|
15
|
+
import { useOptionalUiResizableSidebar } from "./UiResizableSidebarContext.js";
|
|
16
|
+
const { b, e } = bem("gd-ui-kit-resizable-sidebar-navigation");
|
|
17
|
+
const ICON_SIZE = 18;
|
|
18
|
+
const CHEVRON_SIZE = 14;
|
|
19
|
+
const FLYOVER_OPEN_DELAY = 100;
|
|
20
|
+
function makeRow(item, parent) {
|
|
21
|
+
return { item, parent, key: JSON.stringify(parent ? [parent.id, item.id] : [item.id]) };
|
|
22
|
+
}
|
|
23
|
+
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
24
|
+
// A label can start with an emoji or a combined character that spans several UTF-16 code units.
|
|
25
|
+
function getFirstGrapheme(label) {
|
|
26
|
+
return graphemeSegmenter.segment(label)[Symbol.iterator]().next().value?.segment ?? "";
|
|
27
|
+
}
|
|
28
|
+
// Any supplied href, even an empty one, makes the item a link.
|
|
29
|
+
function isLink(item) {
|
|
30
|
+
return item.href !== undefined;
|
|
31
|
+
}
|
|
32
|
+
// A modified click on a link is left to the browser: a new tab, a window or a download.
|
|
33
|
+
function isBrowserLinkClick(item, event) {
|
|
34
|
+
return isLink(item) && (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey);
|
|
35
|
+
}
|
|
36
|
+
function isIconType(icon) {
|
|
37
|
+
return typeof icon === "string" && icon in iconPaths;
|
|
38
|
+
}
|
|
39
|
+
function isGroup(item) {
|
|
40
|
+
return (item.children?.length ?? 0) > 0;
|
|
41
|
+
}
|
|
42
|
+
function isActive(item) {
|
|
43
|
+
return !!item.isSelected || !!item.children?.some((child) => child.isSelected);
|
|
44
|
+
}
|
|
45
|
+
function hasGroupRow(items, rowKey) {
|
|
46
|
+
return items.some((item) => isGroup(item) && makeRow(item).key === rowKey);
|
|
47
|
+
}
|
|
48
|
+
function getSelectionKey(items) {
|
|
49
|
+
return items
|
|
50
|
+
.flatMap((item) => [makeRow(item), ...(item.children ?? []).map((child) => makeRow(child, item))])
|
|
51
|
+
.filter((row) => row.item.isSelected)
|
|
52
|
+
.map((row) => row.key)
|
|
53
|
+
.join();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Item list of a sidebar: top-level pages and expandable groups of sub-pages. A group expands by itself
|
|
57
|
+
* when it or one of its sub-items is selected, and the user can expand and collapse it with its chevron
|
|
58
|
+
* or the Left and Right arrow keys. The list is one tab stop: Up and Down move between the listed items,
|
|
59
|
+
* Home and End jump to the ends.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* Selection is driven by the `isSelected` flags of the items; the list does not keep a selection of its
|
|
63
|
+
* own. A group with a selected sub-item is highlighted together with the sub-item.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export function UiResizableSidebarNavigation({ items, onSelect, accessibilityConfig, isRail: isRailProp, flyoverClassName, dataTestId, }) {
|
|
68
|
+
const sidebar = useOptionalUiResizableSidebar();
|
|
69
|
+
const isRail = isRailProp ?? (!!sidebar && sidebar.isCollapsed && sidebar.hasRail);
|
|
70
|
+
const idPrefix = useId();
|
|
71
|
+
const selectionKey = getSelectionKey(items);
|
|
72
|
+
const [expansion, setExpansion] = useState({ selectionKey, toggles: new Map() });
|
|
73
|
+
const [flyoverState, setFlyoverState] = useState(null);
|
|
74
|
+
const flyover = isRail ? flyoverState : null;
|
|
75
|
+
const flyoverFocusRef = useRef(null);
|
|
76
|
+
// A flyover left open must not open again, and take focus, when the list returns to the rail or
|
|
77
|
+
// its group comes back.
|
|
78
|
+
if (flyoverState && (!isRail || !hasGroupRow(items, flyoverState.rowKey))) {
|
|
79
|
+
setFlyoverState(null);
|
|
80
|
+
}
|
|
81
|
+
// A change of selection forgets the manual toggles, so the group of the new page always opens.
|
|
82
|
+
if (expansion.selectionKey !== selectionKey) {
|
|
83
|
+
setExpansion({ selectionKey, toggles: new Map() });
|
|
84
|
+
}
|
|
85
|
+
const isExpanded = useCallback((item) => !isRail && isGroup(item) && (expansion.toggles.get(item.id) ?? isActive(item)), [expansion.toggles, isRail]);
|
|
86
|
+
const setExpanded = useCallback((id, expanded) => {
|
|
87
|
+
setExpansion((current) => ({
|
|
88
|
+
...current,
|
|
89
|
+
toggles: new Map(current.toggles).set(id, expanded),
|
|
90
|
+
}));
|
|
91
|
+
}, []);
|
|
92
|
+
const rows = useMemo(() => items.flatMap((item) => {
|
|
93
|
+
const own = makeRow(item);
|
|
94
|
+
return isExpanded(item)
|
|
95
|
+
? [own, ...(item.children ?? []).map((child) => makeRow(child, item))]
|
|
96
|
+
: [own];
|
|
97
|
+
}), [items, isExpanded]);
|
|
98
|
+
const [focusedKey, setFocusedKey] = useState(null);
|
|
99
|
+
const tabStopKey = useMemo(() => {
|
|
100
|
+
if (rows.some((row) => row.key === focusedKey)) {
|
|
101
|
+
return focusedKey;
|
|
102
|
+
}
|
|
103
|
+
const selected = rows.find((row) => row.item.isSelected) ?? rows.find((row) => isActive(row.item));
|
|
104
|
+
return (selected ?? rows[0])?.key ?? null;
|
|
105
|
+
}, [rows, focusedKey]);
|
|
106
|
+
const elementsRef = useRef(new Map());
|
|
107
|
+
const focusRow = useCallback((key) => {
|
|
108
|
+
if (key !== undefined) {
|
|
109
|
+
elementsRef.current.get(key)?.focus();
|
|
110
|
+
}
|
|
111
|
+
}, []);
|
|
112
|
+
const getRowIndex = useCallback((target) => {
|
|
113
|
+
const entry = [...elementsRef.current.entries()].find(([, element]) => element.contains(target));
|
|
114
|
+
return entry ? rows.findIndex((row) => row.key === entry[0]) : -1;
|
|
115
|
+
}, [rows]);
|
|
116
|
+
const onKeyDown = useMemo(() => {
|
|
117
|
+
// Enter and Space stay unhandled, so links and buttons keep their native activation.
|
|
118
|
+
const handleKey = makeGridKeyboardNavigation({
|
|
119
|
+
onFocusUp: (event) => {
|
|
120
|
+
const index = getRowIndex(event.target);
|
|
121
|
+
focusRow(rows[Math.max(0, index - 1)]?.key);
|
|
122
|
+
},
|
|
123
|
+
onFocusDown: (event) => {
|
|
124
|
+
const index = getRowIndex(event.target);
|
|
125
|
+
focusRow(rows[Math.min(rows.length - 1, index + 1)]?.key);
|
|
126
|
+
},
|
|
127
|
+
onFocusFirst: () => focusRow(rows[0]?.key),
|
|
128
|
+
onFocusLast: () => focusRow(rows[rows.length - 1]?.key),
|
|
129
|
+
onFocusRight: (event) => {
|
|
130
|
+
const row = rows[getRowIndex(event.target)];
|
|
131
|
+
const item = row?.item;
|
|
132
|
+
if (!item || row.parent || !isGroup(item)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (isRail) {
|
|
136
|
+
setFlyoverState({ rowKey: row.key, focusItems: true });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (isExpanded(item)) {
|
|
140
|
+
const firstChild = item.children?.[0];
|
|
141
|
+
focusRow(firstChild ? makeRow(firstChild, item).key : undefined);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
setExpanded(item.id, true);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
onFocusLeft: (event) => {
|
|
148
|
+
const row = rows[getRowIndex(event.target)];
|
|
149
|
+
if (!row) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (row.parent) {
|
|
153
|
+
focusRow(makeRow(row.parent).key);
|
|
154
|
+
}
|
|
155
|
+
else if (isExpanded(row.item)) {
|
|
156
|
+
setExpanded(row.item.id, false);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
// Modified keys stay with the browser, e.g. Alt+Left for history navigation. Keys from a flyover
|
|
161
|
+
// reach the list through the React tree only, because the flyover renders in a portal.
|
|
162
|
+
return (event) => {
|
|
163
|
+
const isFromList = event.currentTarget.contains(event.target);
|
|
164
|
+
if (isFromList && !hasSystemModifier(event)) {
|
|
165
|
+
handleKey(event);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}, [rows, getRowIndex, focusRow, isExpanded, setExpanded, isRail]);
|
|
169
|
+
// Leaving the rail, or removing the open group, unmounts the flyover with focus inside. Focus goes
|
|
170
|
+
// back to the group row, or to the tab stop of the list when the group is gone.
|
|
171
|
+
useLayoutEffect(() => {
|
|
172
|
+
const focus = flyoverFocusRef.current;
|
|
173
|
+
if (!focus) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const hasGroup = hasGroupRow(items, focus.rowKey);
|
|
177
|
+
if (isRail && hasGroup) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
flyoverFocusRef.current = null;
|
|
181
|
+
focusRow(hasGroup ? focus.rowKey : (tabStopKey ?? undefined));
|
|
182
|
+
}, [isRail, items, tabStopKey, focusRow]);
|
|
183
|
+
const registerElement = useCallback((key, element) => {
|
|
184
|
+
if (element) {
|
|
185
|
+
elementsRef.current.set(key, element);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
elementsRef.current.delete(key);
|
|
189
|
+
}
|
|
190
|
+
}, []);
|
|
191
|
+
const onActivate = useCallback((row, event) => {
|
|
192
|
+
const item = row.item;
|
|
193
|
+
if (isBrowserLinkClick(item, event)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (isRail && !row.parent && isGroup(item)) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
// A keyboard activation has no click count; it moves focus into the flyover.
|
|
199
|
+
setFlyoverState({ rowKey: row.key, focusItems: event.detail === 0 });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (row.parent || isRail || !isGroup(item)) {
|
|
203
|
+
onSelect?.(item, event);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (!isLink(item) || isActive(item)) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
setExpanded(item.id, !isExpanded(item));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
setExpanded(item.id, true);
|
|
212
|
+
onSelect?.(item, event);
|
|
213
|
+
}, [onSelect, isRail, isExpanded, setExpanded]);
|
|
214
|
+
const renderRow = (row) => {
|
|
215
|
+
const item = row.item;
|
|
216
|
+
const group = !row.parent && isGroup(item);
|
|
217
|
+
const expanded = isExpanded(item);
|
|
218
|
+
const childrenId = `${idPrefix}-${encodeURIComponent(item.id)}`;
|
|
219
|
+
// A collapsed group shows the marker of a sub-page, so the marker stays visible from outside.
|
|
220
|
+
const actionRequired = item.actionRequired ??
|
|
221
|
+
(group && !expanded
|
|
222
|
+
? item.children?.find((child) => child.actionRequired)?.actionRequired
|
|
223
|
+
: undefined);
|
|
224
|
+
const isFlyoverOpen = flyover?.rowKey === row.key;
|
|
225
|
+
const element = (_jsx(NavigationRow, { item: item, actionRequired: actionRequired, rowKey: row.key, isChild: !!row.parent, isRail: isRail, isActive: !row.parent && isActive(item), isExpanded: group && !isRail ? expanded : undefined, isFlyoverOpen: group && isRail ? isFlyoverOpen : undefined, childrenId: group ? childrenId : undefined, tabIndex: row.key === tabStopKey ? 0 : -1, onFocus: () => setFocusedKey(row.key), onActivate: (event) => onActivate(row, event), registerElement: registerElement }));
|
|
226
|
+
if (isRail && group) {
|
|
227
|
+
const closeFlyover = () => setFlyoverState((current) => (current?.rowKey === row.key ? null : current));
|
|
228
|
+
// The pointer must not take over from the keyboard in the flyover of another group.
|
|
229
|
+
const hoverOpenFlyover = () => {
|
|
230
|
+
const focus = flyoverFocusRef.current;
|
|
231
|
+
if (focus?.source === "keyboard" && focus.rowKey !== row.key) {
|
|
232
|
+
if (isFocusInFlyover()) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// The focused item was removed without a blur, so the record is stale.
|
|
236
|
+
flyoverFocusRef.current = null;
|
|
237
|
+
}
|
|
238
|
+
setFlyoverState({ rowKey: row.key, focusItems: false });
|
|
239
|
+
};
|
|
240
|
+
return (_jsx("li", { className: e("row", { rail: true }), children: _jsx(NavigationFlyover, { id: childrenId, className: flyoverClassName, label: item.label, anchor: _jsx(UiTooltip, { anchor: element, content: item.label, arrowPlacement: "left", triggerBy: ["focus"], disabled: isFlyoverOpen, accessibilityHidden: true }), isOpen: isFlyoverOpen, focusItems: isFlyoverOpen ? !!flyover?.focusItems : false, onOpenChange: (open) => (open ? hoverOpenFlyover() : closeFlyover()), onClose: closeFlyover, onReturnFocus: () => focusRow(row.key), onFocusChange: (source) => {
|
|
241
|
+
flyoverFocusRef.current = source ? { rowKey: row.key, source } : null;
|
|
242
|
+
}, children: item.children?.map((child) => {
|
|
243
|
+
const childRow = makeRow(child, item);
|
|
244
|
+
return (_jsx("li", { children: _jsx(NavigationRow, { item: child, actionRequired: child.actionRequired, rowKey: childRow.key, isChild: true, isFlyover: true, isRail: false, isActive: false, isExpanded: undefined, childrenId: undefined, tabIndex: -1, onActivate: (event) => {
|
|
245
|
+
onActivate(childRow, event);
|
|
246
|
+
// A new-tab click leaves the flyover open for more pages.
|
|
247
|
+
if (!isBrowserLinkClick(child, event)) {
|
|
248
|
+
closeFlyover();
|
|
249
|
+
}
|
|
250
|
+
} }) }, childRow.key));
|
|
251
|
+
}) }) }, row.key));
|
|
252
|
+
}
|
|
253
|
+
return (_jsxs("li", { className: e("row", { rail: isRail }), children: [isRail ? (_jsx(UiTooltip, { anchor: element, content: item.label, arrowPlacement: "left", triggerBy: ["hover", "focus"], accessibilityHidden: true, closeOnAnchorClick: true })) : (element), group && expanded ? (_jsx("ul", { id: childrenId, className: e("children"), children: item.children?.map((child) => renderRow(makeRow(child, item))) })) : null] }, row.key));
|
|
254
|
+
};
|
|
255
|
+
return (_jsx("nav", { className: b({ rail: isRail }), ...accessibilityConfigToAttributes(accessibilityConfig), "data-testid": dataTestId, onKeyDown: onKeyDown, children: _jsx("ul", { className: e("list"), children: items.map((item) => renderRow(makeRow(item))) }) }));
|
|
256
|
+
}
|
|
257
|
+
function NavigationRow({ item, actionRequired, rowKey, isChild, isFlyover = false, isRail, isActive, isExpanded, isFlyoverOpen, childrenId, tabIndex, onFocus, onActivate, registerElement, }) {
|
|
258
|
+
const showIcon = !isChild;
|
|
259
|
+
const showChevron = isExpanded !== undefined;
|
|
260
|
+
// A group whose current sub-page is not rendered (collapsed, or in a closed flyover) stands in for it.
|
|
261
|
+
const isSubPageShown = isExpanded === true || isFlyoverOpen === true;
|
|
262
|
+
const holdsHiddenCurrentPage = isActive && !item.isSelected && !isSubPageShown;
|
|
263
|
+
const ariaCurrent = item.isSelected
|
|
264
|
+
? "page"
|
|
265
|
+
: holdsHiddenCurrentPage
|
|
266
|
+
? "true"
|
|
267
|
+
: undefined;
|
|
268
|
+
const actionRequiredElement = actionRequired ? (_jsx("span", { className: e("action-required"), children: _jsx("span", { className: e("sr-only"), children: actionRequired.label }) })) : null;
|
|
269
|
+
const content = (_jsxs(_Fragment, { children: [showIcon ? (_jsx("span", { className: e("icon"), "aria-hidden": "true", children: isIconType(item.icon) ? (_jsx(UiIcon, { type: item.icon, size: ICON_SIZE, color: "currentColor", layout: "block" })) : ((item.icon ?? getFirstGrapheme(item.label))) })) : null, _jsx("span", { className: e(isRail ? "sr-only" : "label"), children: item.label }), actionRequiredElement, showChevron ? (_jsx("span", { className: e("chevron", { expanded: !!isExpanded }), "aria-hidden": "true", children: _jsx(UiIcon, { type: "chevronRight", size: CHEVRON_SIZE, color: "currentColor", layout: "block" }) })) : null] }));
|
|
270
|
+
const sharedProps = {
|
|
271
|
+
className: e("item", {
|
|
272
|
+
selected: !!item.isSelected,
|
|
273
|
+
active: isActive,
|
|
274
|
+
child: isChild,
|
|
275
|
+
flyover: isFlyover,
|
|
276
|
+
rail: isRail,
|
|
277
|
+
open: !!isFlyoverOpen,
|
|
278
|
+
}),
|
|
279
|
+
tabIndex,
|
|
280
|
+
"aria-current": ariaCurrent,
|
|
281
|
+
"aria-expanded": isExpanded ?? isFlyoverOpen,
|
|
282
|
+
"aria-controls": (isExpanded ?? isFlyoverOpen) ? childrenId : undefined,
|
|
283
|
+
"data-testid": item.dataTestId,
|
|
284
|
+
onFocus,
|
|
285
|
+
onClick: onActivate,
|
|
286
|
+
};
|
|
287
|
+
if (isLink(item)) {
|
|
288
|
+
return (_jsx("a", { ref: (element) => registerElement?.(rowKey, element), href: item.href, ...sharedProps, children: content }));
|
|
289
|
+
}
|
|
290
|
+
return (_jsx("button", { ref: (element) => registerElement?.(rowKey, element), type: "button", ...sharedProps, children: content }));
|
|
291
|
+
}
|
|
292
|
+
// The flyover starts at the edge of the sidebar, not at the edge of the narrower item in the rail.
|
|
293
|
+
const flyoverOffset = ({ elements }) => {
|
|
294
|
+
const sidebar = elements.reference instanceof Element
|
|
295
|
+
? elements.reference.closest(".gd-ui-kit-resizable-sidebar")
|
|
296
|
+
: null;
|
|
297
|
+
return sidebar
|
|
298
|
+
? sidebar.getBoundingClientRect().right - elements.reference.getBoundingClientRect().right
|
|
299
|
+
: 0;
|
|
300
|
+
};
|
|
301
|
+
function isFocusInFlyover() {
|
|
302
|
+
return !!document.activeElement?.closest(`.${e("flyover")}`);
|
|
303
|
+
}
|
|
304
|
+
// Scrolls only the container. Element.scrollIntoView would also scroll the page under the flyover.
|
|
305
|
+
function scrollIntoContainer(container, element) {
|
|
306
|
+
const box = container.getBoundingClientRect();
|
|
307
|
+
const target = element.getBoundingClientRect();
|
|
308
|
+
if (target.bottom > box.bottom) {
|
|
309
|
+
container.scrollTop += target.bottom - box.bottom;
|
|
310
|
+
}
|
|
311
|
+
else if (target.top < box.top) {
|
|
312
|
+
container.scrollTop -= box.top - target.top;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function getFlyoverItems(container) {
|
|
316
|
+
return container ? [...container.querySelectorAll("a, button")] : [];
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Lists the sub-items of a group in the rail. Hover opens it without moving focus; the Right arrow key
|
|
320
|
+
* on the group opens it with focus on the current page or the first sub-item.
|
|
321
|
+
*/
|
|
322
|
+
function NavigationFlyover({ id, className, label, anchor, isOpen, focusItems, onOpenChange, onClose, onReturnFocus, onFocusChange, children, }) {
|
|
323
|
+
const focusSourceRef = useRef(null);
|
|
324
|
+
const isPointerDownRef = useRef(false);
|
|
325
|
+
const setFocusSource = (source) => {
|
|
326
|
+
focusSourceRef.current = source;
|
|
327
|
+
onFocusChange(source);
|
|
328
|
+
};
|
|
329
|
+
const { refs, floatingStyles, zIndex, context } = useFloatingPosition({
|
|
330
|
+
isOpen,
|
|
331
|
+
// The pointer can leave while the keyboard works in the flyover; that must not close it.
|
|
332
|
+
onOpenChange: (open, _event, reason) => {
|
|
333
|
+
const isHoverClose = reason === "hover" || reason === "safe-polygon";
|
|
334
|
+
if (!open && isHoverClose && focusSourceRef.current === "keyboard") {
|
|
335
|
+
if (refs.floating.current?.contains(document.activeElement)) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
// The focused item was removed without a blur, so nothing holds the flyover open.
|
|
339
|
+
setFocusSource(null);
|
|
340
|
+
}
|
|
341
|
+
onOpenChange(open);
|
|
342
|
+
},
|
|
343
|
+
placement: "right-start",
|
|
344
|
+
offset: flyoverOffset,
|
|
345
|
+
autoFlip: false,
|
|
346
|
+
// Only the height is limited, to the viewport space below the group, so a long list scrolls.
|
|
347
|
+
maxWidth: "none",
|
|
348
|
+
});
|
|
349
|
+
const hover = useHover(context, {
|
|
350
|
+
delay: { open: FLYOVER_OPEN_DELAY },
|
|
351
|
+
handleClose: safePolygon(),
|
|
352
|
+
});
|
|
353
|
+
const dismiss = useDismiss(context);
|
|
354
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([hover, dismiss]);
|
|
355
|
+
// The portal mounts the flyover after the first commit, so focus waits for the element.
|
|
356
|
+
const [flyoverElement, setFlyoverElement] = useState(null);
|
|
357
|
+
const setFloating = useCallback((element) => {
|
|
358
|
+
refs.setFloating(element);
|
|
359
|
+
setFlyoverElement(element);
|
|
360
|
+
}, [refs]);
|
|
361
|
+
useLayoutEffect(() => {
|
|
362
|
+
if (!focusItems) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const items = getFlyoverItems(flyoverElement);
|
|
366
|
+
const current = items.find((item) => item.getAttribute("aria-current") === "page");
|
|
367
|
+
(current ?? items[0])?.focus({ preventScroll: true });
|
|
368
|
+
}, [focusItems, flyoverElement]);
|
|
369
|
+
// Removing the focused item, e.g. after a change of permissions, drops focus to the document. Focus
|
|
370
|
+
// goes back into the flyover, so its keys keep working.
|
|
371
|
+
useLayoutEffect(() => {
|
|
372
|
+
if (!focusSourceRef.current || !flyoverElement || document.activeElement !== document.body) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
// Focus from a press is not restored, or the flyover would count as keyboard focused.
|
|
376
|
+
if (focusSourceRef.current === "pointer") {
|
|
377
|
+
setFocusSource(null);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const items = getFlyoverItems(flyoverElement);
|
|
381
|
+
const current = items.find((item) => item.getAttribute("aria-current") === "page");
|
|
382
|
+
(current ?? items[0])?.focus({ preventScroll: true });
|
|
383
|
+
});
|
|
384
|
+
// The height limit applies once the flyover is positioned, so the focused item is revealed after it.
|
|
385
|
+
useLayoutEffect(() => {
|
|
386
|
+
const focused = document.activeElement;
|
|
387
|
+
if (focusItems && flyoverElement && focused && flyoverElement.contains(focused)) {
|
|
388
|
+
scrollIntoContainer(flyoverElement, focused);
|
|
389
|
+
}
|
|
390
|
+
}, [focusItems, flyoverElement, floatingStyles]);
|
|
391
|
+
// A flyover that closes with focus inside removes the focused item, so focus goes back to the group.
|
|
392
|
+
useLayoutEffect(() => {
|
|
393
|
+
if (!isOpen && focusSourceRef.current) {
|
|
394
|
+
// Focus from a press stays where the pointer goes, e.g. to the flyover of another group.
|
|
395
|
+
const isKeyboardFocus = focusSourceRef.current === "keyboard";
|
|
396
|
+
setFocusSource(null);
|
|
397
|
+
if (isKeyboardFocus) {
|
|
398
|
+
onReturnFocus();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
const moveFocus = (target, getIndex) => {
|
|
403
|
+
const items = getFlyoverItems(refs.floating.current);
|
|
404
|
+
const index = items.findIndex((item) => item.contains(target));
|
|
405
|
+
items[getIndex(index, items.length)]?.focus();
|
|
406
|
+
};
|
|
407
|
+
// Enter and Space stay unhandled, so links and buttons keep their native activation.
|
|
408
|
+
const handleKey = makeMenuKeyboardNavigation({
|
|
409
|
+
onFocusPrevious: (event) => moveFocus(event.target, (index) => Math.max(0, index - 1)),
|
|
410
|
+
onFocusNext: (event) => moveFocus(event.target, (index, count) => Math.min(count - 1, index + 1)),
|
|
411
|
+
onFocusFirst: (event) => moveFocus(event.target, () => 0),
|
|
412
|
+
onFocusLast: (event) => moveFocus(event.target, (_, count) => count - 1),
|
|
413
|
+
onLeaveLevel: onClose,
|
|
414
|
+
onClose,
|
|
415
|
+
});
|
|
416
|
+
// The navigation stops only the keys it handles, so page shortcuts such as Ctrl+K still work here.
|
|
417
|
+
const onKeyDown = (event) => {
|
|
418
|
+
isPointerDownRef.current = false;
|
|
419
|
+
if (!hasSystemModifier(event)) {
|
|
420
|
+
handleKey(event);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: e("flyover-anchor"), ref: refs.setReference, ...getReferenceProps(), children: anchor }), isOpen ? (_jsx(FloatingPortal, { children: _jsx(ConditionalScopedThemeProvider, { children: _jsx(FloatingFocusManager, { context: context, modal: false, initialFocus: -1, returnFocus: false, children: _jsx("div", { id: id, ref: setFloating, className: cx(e("flyover"), className), style: { ...floatingStyles, zIndex }, role: "group", "aria-label": label, ...getFloatingProps({
|
|
424
|
+
onKeyDown,
|
|
425
|
+
// A press focuses an item before the click, e.g. a right click for a
|
|
426
|
+
// new tab. That focus must not hold the flyover open like the keyboard.
|
|
427
|
+
onPointerDown: () => {
|
|
428
|
+
isPointerDownRef.current = true;
|
|
429
|
+
},
|
|
430
|
+
onPointerUp: () => {
|
|
431
|
+
isPointerDownRef.current = false;
|
|
432
|
+
},
|
|
433
|
+
onFocus: () => {
|
|
434
|
+
setFocusSource(isPointerDownRef.current ? "pointer" : "keyboard");
|
|
435
|
+
},
|
|
436
|
+
// A removed item can blur with no target; focus still has to go back.
|
|
437
|
+
onBlur: (event) => {
|
|
438
|
+
const target = event.relatedTarget;
|
|
439
|
+
if (target && !event.currentTarget.contains(target)) {
|
|
440
|
+
// Shift+Tab lands on the group, which keeps a non-modal flyover open.
|
|
441
|
+
const isKeyboardExit = focusSourceRef.current === "keyboard";
|
|
442
|
+
setFocusSource(null);
|
|
443
|
+
if (isKeyboardExit) {
|
|
444
|
+
onClose();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
}), children: _jsx("ul", { className: e("flyover-list"), children: children }) }) }) }) })) : null] }));
|
|
449
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type IAccessibilityConfigBase } from "../../typings/accessibility.js";
|
|
3
|
+
import { type IconType } from "../@types/icon.js";
|
|
1
4
|
/**
|
|
2
5
|
* Width state of a resizable, collapsible sidebar, shared between the sidebar and controls rendered
|
|
3
6
|
* elsewhere (for example a restore control in a header).
|
|
@@ -52,9 +55,14 @@ export interface IUiResizableSidebarStateOptions {
|
|
|
52
55
|
*/
|
|
53
56
|
hasRail?: boolean;
|
|
54
57
|
/**
|
|
55
|
-
* Width the sibling content must keep. Caps the maximum at the
|
|
58
|
+
* Width the sibling content must keep. Caps the maximum at the available width minus this value.
|
|
56
59
|
*/
|
|
57
60
|
minContentWidth?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Width the sidebar shares with its sibling content, e.g. their measured container when the host takes
|
|
63
|
+
* part of the window. Defaults to the viewport width.
|
|
64
|
+
*/
|
|
65
|
+
availableWidth?: number;
|
|
58
66
|
isResizable: boolean;
|
|
59
67
|
isCollapsible: boolean;
|
|
60
68
|
/**
|
|
@@ -77,4 +85,65 @@ export interface IUiResizableSidebarStateOptions {
|
|
|
77
85
|
*/
|
|
78
86
|
onUserChange?: (property: "collapsed" | "width") => void;
|
|
79
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Marks a page that needs an action from the user, e.g. a setting that is not complete.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
export interface IUiResizableSidebarNavigationActionRequired {
|
|
94
|
+
/**
|
|
95
|
+
* Accessible text of the marker, e.g. "Action required".
|
|
96
|
+
*/
|
|
97
|
+
label: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A page listed in a {@link UiResizableSidebarNavigation}: a sub-item of a group, or the base of a
|
|
101
|
+
* top-level item.
|
|
102
|
+
*
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export interface IUiResizableSidebarNavigationSubItem {
|
|
106
|
+
id: string;
|
|
107
|
+
label: string;
|
|
108
|
+
/**
|
|
109
|
+
* Renders the item as a link. An item without `href` renders as a button.
|
|
110
|
+
*/
|
|
111
|
+
href?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Marks the page the user is on; rendered as `aria-current="page"`.
|
|
114
|
+
*/
|
|
115
|
+
isSelected?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Shows a dot next to the label: the page needs an action from the user. A collapsed group, and a
|
|
118
|
+
* group in the rail, shows the dot when one of its sub-pages requires an action.
|
|
119
|
+
*/
|
|
120
|
+
actionRequired?: IUiResizableSidebarNavigationActionRequired;
|
|
121
|
+
dataTestId?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A top-level item of a {@link UiResizableSidebarNavigation}. With `children` it is an expandable group
|
|
125
|
+
* whose sub-items are listed while the group is expanded.
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export interface IUiResizableSidebarNavigationItem extends IUiResizableSidebarNavigationSubItem {
|
|
130
|
+
/**
|
|
131
|
+
* Icon shown before the label, and alone in rail mode: a kit icon name, or a custom node that
|
|
132
|
+
* paints itself in `currentColor`.
|
|
133
|
+
*/
|
|
134
|
+
icon?: IconType | ReactNode;
|
|
135
|
+
children?: IUiResizableSidebarNavigationSubItem[];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The navigation needs an accessible name.
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export type UiResizableSidebarNavigationNamingConfig = {
|
|
143
|
+
ariaLabel: NonNullable<IAccessibilityConfigBase["ariaLabel"]>;
|
|
144
|
+
ariaLabelledBy?: IAccessibilityConfigBase["ariaLabelledBy"];
|
|
145
|
+
} | {
|
|
146
|
+
ariaLabel?: IAccessibilityConfigBase["ariaLabel"];
|
|
147
|
+
ariaLabelledBy: NonNullable<IAccessibilityConfigBase["ariaLabelledBy"]>;
|
|
148
|
+
};
|
|
80
149
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiResizableSidebar/types.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC5C;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,KAAK,IAAI,CAAC;CAC5D"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiResizableSidebar/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACrC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,WAAW,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC5C;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,KAAK,IAAI,CAAC;CAC5D;AAED;;;;GAIG;AACH,MAAM,WAAW,2CAA2C;IACxD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oCAAoC;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,2CAA2C,CAAC;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iCAAkC,SAAQ,oCAAoC;IAC3F;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,EAAE,oCAAoC,EAAE,CAAC;CACrD;AAED;;;;GAIG;AACH,MAAM,MAAM,wCAAwC,GAC9C;IACI,SAAS,EAAE,WAAW,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAC,CAAC;IAC9D,cAAc,CAAC,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,CAAC;CAC/D,GACD;IACI,SAAS,CAAC,EAAE,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAClD,cAAc,EAAE,WAAW,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC,CAAC;CAC3E,CAAC"}
|
|
@@ -15,5 +15,5 @@ export declare const UI_RESIZABLE_SIDEBAR_RAIL_WIDTH = 48;
|
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
export declare function useUiResizableSidebarState({ widthStorageKey, collapsedStorageKey, minWidth, maxWidth, hasRail, minContentWidth, isResizable, isCollapsible, collapsedOverride, widthOverride, onUserChange, }: IUiResizableSidebarStateOptions): IUiResizableSidebarState;
|
|
18
|
+
export declare function useUiResizableSidebarState({ widthStorageKey, collapsedStorageKey, minWidth, maxWidth, hasRail, minContentWidth, availableWidth, isResizable, isCollapsible, collapsedOverride, widthOverride, onUserChange, }: IUiResizableSidebarStateOptions): IUiResizableSidebarState;
|
|
19
19
|
//# sourceMappingURL=useUiResizableSidebarState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUiResizableSidebarState.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiResizableSidebar/useUiResizableSidebarState.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,wBAAwB,EAAE,KAAK,+BAA+B,EAAE,MAAM,YAAY,CAAC;AAIjG;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAsBlD;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,EACvC,eAAe,EACf,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,OAAe,EACf,eAAe,EACf,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,GACf,EAAE,+BAA+B,GAAG,wBAAwB,
|
|
1
|
+
{"version":3,"file":"useUiResizableSidebarState.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiResizableSidebar/useUiResizableSidebarState.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,wBAAwB,EAAE,KAAK,+BAA+B,EAAE,MAAM,YAAY,CAAC;AAIjG;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAsBlD;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,EACvC,eAAe,EACf,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,OAAe,EACf,eAAe,EACf,cAAc,EACd,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,GACf,EAAE,+BAA+B,GAAG,wBAAwB,CAiG5D"}
|
|
@@ -33,8 +33,9 @@ function useWindowWidth(active) {
|
|
|
33
33
|
*
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
36
|
-
export function useUiResizableSidebarState({ widthStorageKey, collapsedStorageKey, minWidth, maxWidth, hasRail = false, minContentWidth, isResizable, isCollapsible, collapsedOverride, widthOverride, onUserChange, }) {
|
|
37
|
-
const viewportWidth = useWindowWidth(isResizable && minContentWidth !== undefined);
|
|
36
|
+
export function useUiResizableSidebarState({ widthStorageKey, collapsedStorageKey, minWidth, maxWidth, hasRail = false, minContentWidth, availableWidth, isResizable, isCollapsible, collapsedOverride, widthOverride, onUserChange, }) {
|
|
37
|
+
const viewportWidth = useWindowWidth(isResizable && minContentWidth !== undefined && availableWidth === undefined);
|
|
38
|
+
const sharedWidth = availableWidth ?? viewportWidth;
|
|
38
39
|
const [storedWidth, setPersistedWidth] = useLocalStorage(widthStorageKey, null);
|
|
39
40
|
const [storedCollapsed, setPersistedCollapsed] = useLocalStorage(collapsedStorageKey, false);
|
|
40
41
|
// Anything may have written these keys, so only well-formed values are trusted; the overrides
|
|
@@ -51,7 +52,7 @@ export function useUiResizableSidebarState({ widthStorageKey, collapsedStorageKe
|
|
|
51
52
|
const collapsedWidth = hasRail ? UI_RESIZABLE_SIDEBAR_RAIL_WIDTH : 0;
|
|
52
53
|
const max = minContentWidth === undefined
|
|
53
54
|
? maxWidth
|
|
54
|
-
: clamp(
|
|
55
|
+
: clamp(sharedWidth - minContentWidth, minWidth, maxWidth);
|
|
55
56
|
const expandedWidth = isResizable ? clamp(preferredWidth, minWidth, max) : minWidth;
|
|
56
57
|
// Live setters announce the user change first so the caller can release an override of the property.
|
|
57
58
|
const setCollapsed = isCollapsible ? announceAndSetCollapsed : noop;
|
|
@@ -113,6 +114,6 @@ export function useUiResizableSidebarState({ widthStorageKey, collapsedStorageKe
|
|
|
113
114
|
preferredCollapsed,
|
|
114
115
|
preferredWidth,
|
|
115
116
|
setPersistedWidth,
|
|
116
|
-
|
|
117
|
+
sharedWidth,
|
|
117
118
|
]);
|
|
118
119
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Ref } from "react";
|
|
2
|
+
import { type IconType } from "../@types/icon.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export interface IUiToolbarInputAccessibilityConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the value, for example "Width". Always the full name, never only the prefix letter.
|
|
9
|
+
*/
|
|
10
|
+
ariaLabel: string;
|
|
11
|
+
/**
|
|
12
|
+
* Spoken form of the unit, for example "pixels". Defaults to `unit`.
|
|
13
|
+
*/
|
|
14
|
+
unitLabel?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface IUiToolbarInputProps {
|
|
20
|
+
/**
|
|
21
|
+
* The committed value as text, for example "120".
|
|
22
|
+
*/
|
|
23
|
+
value: string;
|
|
24
|
+
/**
|
|
25
|
+
* Called with the typed text on Enter and on blur. Escape reverts the typed text instead.
|
|
26
|
+
* After a commit the field shows `value` again, so a parent that clamps or rejects the text
|
|
27
|
+
* only has to keep `value` as it wants it. While `isInvalid` is true, the typed text stays.
|
|
28
|
+
*/
|
|
29
|
+
onCommit: (value: string) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Called on ArrowUp and ArrowDown. `isLargeStep` is true while Shift is held.
|
|
32
|
+
*/
|
|
33
|
+
onStep?: (direction: 1 | -1, isLargeStep: boolean) => void;
|
|
34
|
+
/**
|
|
35
|
+
* A short text before the value that names it, for example "W". Use either `prefix` or
|
|
36
|
+
* `prefixIcon`, not both.
|
|
37
|
+
*/
|
|
38
|
+
prefix?: string;
|
|
39
|
+
/**
|
|
40
|
+
* A 14px icon before the value that names it. Never a generic icon such as search.
|
|
41
|
+
*/
|
|
42
|
+
prefixIcon?: IconType;
|
|
43
|
+
/**
|
|
44
|
+
* The unit after the value, for example "px", "%" or "°".
|
|
45
|
+
*/
|
|
46
|
+
unit?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Width of the field in pixels. Size it for the longest value in its range so the toolbar does
|
|
49
|
+
* not move while typing.
|
|
50
|
+
* @defaultValue 64
|
|
51
|
+
*/
|
|
52
|
+
width?: number;
|
|
53
|
+
isDisabled?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Marks the typed text as not acceptable.
|
|
56
|
+
* @defaultValue false
|
|
57
|
+
*/
|
|
58
|
+
isInvalid?: boolean;
|
|
59
|
+
placeholder?: string;
|
|
60
|
+
accessibilityConfig: IUiToolbarInputAccessibilityConfig;
|
|
61
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
62
|
+
dataTestId?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A typable number field with an optional prefix and unit. The prefix stays on the left; the value
|
|
66
|
+
* and the unit are aligned to the right.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare const UiToolbarInput: import("react").ForwardRefExoticComponent<IUiToolbarInputProps & import("react").RefAttributes<HTMLLabelElement>>;
|
|
71
|
+
//# sourceMappingURL=UiToolbarInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UiToolbarInput.d.ts","sourceRoot":"","sources":["../../../src/@ui/UiToolbarInput/UiToolbarInput.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAwC,KAAK,GAAG,EAA+B,MAAM,OAAO,CAAC;AAEpG,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAKlD;;GAEG;AACH,MAAM,WAAW,kCAAkC;IAC/C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,kCAAkC,CAAC;IACxD,QAAQ,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mHAiIzB,CAAC"}
|