@primer/react 0.0.0-20260223174400 → 0.0.0-20260223174439
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/CHANGELOG.md +5 -3
- package/dist/Autocomplete/Autocomplete.js +76 -159
- package/dist/Autocomplete/AutocompleteMenu.js +128 -333
- package/dist/Autocomplete/AutocompleteOverlay.js +49 -130
- package/dist/Banner/Banner.js +64 -238
- package/dist/Checkbox/Checkbox.js +55 -163
- package/dist/Dialog/Dialog.js +105 -347
- package/dist/PageLayout/PageLayout.js +622 -1560
- package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +82 -32
- package/dist/TreeView/useRovingTabIndex.d.ts +0 -14
- package/dist/TreeView/useRovingTabIndex.d.ts.map +1 -1
- package/dist/TreeView/useRovingTabIndex.js +16 -94
- package/dist/UnderlineNav/UnderlineNavItem.js +56 -149
- package/dist/experimental/SelectPanel2/SelectPanel.js +209 -593
- package/dist/hooks/useScrollFlash.js +17 -27
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectPanel.d.ts","sourceRoot":"","sources":["../../src/SelectPanel/SelectPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAC1F,OAAO,KAAK,EAAE,EAA+E,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AACnH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAE5D,OAAO,KAAK,EAAC,iCAAiC,EAAC,MAAM,oCAAoC,CAAA;AACzF,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,uBAAuB,CAAA;AAGlE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAY,SAAS,EAAC,MAAM,IAAI,CAAA;AAiB5C,OAAO,KAAK,EAAC,WAAW,EAAE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L,aAAqB,EACrB,sBAAsB,EACtB,WAAW,EACX,GAAG,SAAS,EACb,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAiyBhC;AAED,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAM1C,CAAA;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,GAAG,WAAW,CAM1D,CAAA;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;CAItB,CAAA"}
|
|
@@ -133,8 +133,6 @@ function Panel({
|
|
|
133
133
|
wide: false
|
|
134
134
|
}, false);
|
|
135
135
|
const [selectedOnSort, setSelectedOnSort] = useState([]);
|
|
136
|
-
const [prevItems, setPrevItems] = useState([]);
|
|
137
|
-
const [prevOpen, setPrevOpen] = useState(open);
|
|
138
136
|
const initialHeightRef = useRef(0);
|
|
139
137
|
const initialScaleRef = useRef(1);
|
|
140
138
|
const noticeRef = useRef(null);
|
|
@@ -206,6 +204,19 @@ function Panel({
|
|
|
206
204
|
resetSort();
|
|
207
205
|
}
|
|
208
206
|
}, [loadingManagedInternally, externalOnFilterChange, setInternalFilterValue, dataLoadedOnce, safeSetTimeout, safeClearTimeout, items.length, resetSort]);
|
|
207
|
+
|
|
208
|
+
// Pre-compute a Set of item IDs in the current filtered view for O(1) lookups
|
|
209
|
+
const itemsInViewSet = useMemo(() => {
|
|
210
|
+
const set = new Set();
|
|
211
|
+
for (const item of items) {
|
|
212
|
+
if (item.id !== undefined) {
|
|
213
|
+
set.add(item.id);
|
|
214
|
+
} else {
|
|
215
|
+
set.add(item);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return set;
|
|
219
|
+
}, [items]);
|
|
209
220
|
const handleSelectAllChange = useCallback(checked => {
|
|
210
221
|
// Exit early if not in multi-select mode
|
|
211
222
|
if (!isMultiSelectVariant(selected)) {
|
|
@@ -213,13 +224,20 @@ function Panel({
|
|
|
213
224
|
}
|
|
214
225
|
const multiSelectOnChange = onSelectedChange;
|
|
215
226
|
const selectedArray = selected;
|
|
216
|
-
|
|
227
|
+
|
|
228
|
+
// Use Set for O(1) lookup instead of O(n) items.some()
|
|
229
|
+
const selectedItemsNotInFilteredView = selectedArray.filter(selectedItem => {
|
|
230
|
+
if (selectedItem.id !== undefined) {
|
|
231
|
+
return !itemsInViewSet.has(selectedItem.id);
|
|
232
|
+
}
|
|
233
|
+
return !itemsInViewSet.has(selectedItem);
|
|
234
|
+
});
|
|
217
235
|
if (checked) {
|
|
218
236
|
multiSelectOnChange([...selectedItemsNotInFilteredView, ...items]);
|
|
219
237
|
} else {
|
|
220
238
|
multiSelectOnChange(selectedItemsNotInFilteredView);
|
|
221
239
|
}
|
|
222
|
-
}, [items, onSelectedChange, selected]);
|
|
240
|
+
}, [items, itemsInViewSet, onSelectedChange, selected]);
|
|
223
241
|
|
|
224
242
|
// disable body scroll when the panel is open on narrow screens
|
|
225
243
|
useEffect(() => {
|
|
@@ -385,10 +403,29 @@ function Panel({
|
|
|
385
403
|
});
|
|
386
404
|
};
|
|
387
405
|
}, [placeholder, renderAnchor, selected]);
|
|
406
|
+
|
|
407
|
+
// Pre-compute a Set of selected item IDs/references for O(1) lookups
|
|
408
|
+
// This optimizes isItemCurrentlySelected from O(m) to O(1) per call
|
|
409
|
+
const selectedItemsSet = useMemo(() => {
|
|
410
|
+
const set = new Set();
|
|
411
|
+
if (isMultiSelectVariant(selected)) {
|
|
412
|
+
for (const item of selected) {
|
|
413
|
+
if (item.id !== undefined) {
|
|
414
|
+
set.add(item.id);
|
|
415
|
+
} else {
|
|
416
|
+
set.add(item);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return set;
|
|
421
|
+
}, [selected]);
|
|
388
422
|
const isItemCurrentlySelected = useCallback(item => {
|
|
389
|
-
// For multi-select,
|
|
423
|
+
// For multi-select, use the pre-computed Set for O(1) lookup
|
|
390
424
|
if (isMultiSelectVariant(selected)) {
|
|
391
|
-
|
|
425
|
+
if (item.id !== undefined) {
|
|
426
|
+
return selectedItemsSet.has(item.id);
|
|
427
|
+
}
|
|
428
|
+
return selectedItemsSet.has(item);
|
|
392
429
|
}
|
|
393
430
|
|
|
394
431
|
// For single-select modal, there is an intermediate state when the user has selected
|
|
@@ -399,8 +436,24 @@ function Panel({
|
|
|
399
436
|
|
|
400
437
|
// For single-select anchored, we just need to check if the item is the selected item
|
|
401
438
|
return (selected === null || selected === void 0 ? void 0 : selected.id) !== undefined ? selected.id === item.id : selected === item;
|
|
402
|
-
}, [selected, intermediateSelected, isSingleSelectModal]);
|
|
439
|
+
}, [selected, selectedItemsSet, intermediateSelected, isSingleSelectModal]);
|
|
403
440
|
const itemsToRender = useMemo(() => {
|
|
441
|
+
// Pre-compute a Set of selected item IDs/references for O(1) lookups during sorting
|
|
442
|
+
// This avoids O(m * k) work per comparison in the sort function
|
|
443
|
+
const selectedOnSortSet = new Set();
|
|
444
|
+
for (const item of selectedOnSort) {
|
|
445
|
+
if (item.id !== undefined) {
|
|
446
|
+
selectedOnSortSet.add(item.id);
|
|
447
|
+
} else {
|
|
448
|
+
selectedOnSortSet.add(item);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const isSelectedForSort = item => {
|
|
452
|
+
if (item.id !== undefined) {
|
|
453
|
+
return selectedOnSortSet.has(item.id);
|
|
454
|
+
}
|
|
455
|
+
return selectedOnSortSet.has(item);
|
|
456
|
+
};
|
|
404
457
|
return items.map(item => {
|
|
405
458
|
return {
|
|
406
459
|
...item,
|
|
@@ -437,42 +490,39 @@ function Panel({
|
|
|
437
490
|
};
|
|
438
491
|
}).sort((itemA, itemB) => {
|
|
439
492
|
if (shouldOrderSelectedFirst) {
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
if (key === 'selected') {
|
|
443
|
-
return true;
|
|
444
|
-
}
|
|
445
|
-
return itemA[key] === value;
|
|
446
|
-
}));
|
|
447
|
-
|
|
448
|
-
// itemB is selected (for sorting purposes) if an object in selectedOnSort matches every property of itemA, except for the selected property
|
|
449
|
-
const itemBSelected = selectedOnSort.some(item => Object.entries(item).every(([key, value]) => {
|
|
450
|
-
if (key === 'selected') {
|
|
451
|
-
return true;
|
|
452
|
-
}
|
|
453
|
-
return itemB[key] === value;
|
|
454
|
-
}));
|
|
493
|
+
const itemASelected = isSelectedForSort(itemA);
|
|
494
|
+
const itemBSelected = isSelectedForSort(itemB);
|
|
455
495
|
|
|
456
496
|
// order selected items first
|
|
457
|
-
if (itemASelected
|
|
497
|
+
if (itemASelected && !itemBSelected) {
|
|
458
498
|
return -1;
|
|
459
|
-
} else if (itemASelected
|
|
499
|
+
} else if (!itemASelected && itemBSelected) {
|
|
460
500
|
return 1;
|
|
461
501
|
}
|
|
462
502
|
}
|
|
463
503
|
return 0;
|
|
464
504
|
});
|
|
465
505
|
}, [onClose, onSelectedChange, items, selected, isItemCurrentlySelected, isSingleSelectModal, intermediateSelected, shouldOrderSelectedFirst, selectedOnSort]);
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
506
|
+
|
|
507
|
+
// Track previous items and reset sort when items first load
|
|
508
|
+
const prevItemsRef = useRef(items);
|
|
509
|
+
useEffect(() => {
|
|
510
|
+
if (prevItemsRef.current !== items) {
|
|
511
|
+
if (prevItemsRef.current.length === 0 && items.length > 0) {
|
|
512
|
+
resetSort();
|
|
513
|
+
}
|
|
514
|
+
prevItemsRef.current = items;
|
|
515
|
+
}
|
|
516
|
+
}, [items, resetSort]);
|
|
517
|
+
|
|
518
|
+
// Reset sort when panel opens
|
|
519
|
+
const prevOpenRef = useRef(open);
|
|
520
|
+
useEffect(() => {
|
|
521
|
+
if (prevOpenRef.current !== open) {
|
|
469
522
|
resetSort();
|
|
523
|
+
prevOpenRef.current = open;
|
|
470
524
|
}
|
|
471
|
-
}
|
|
472
|
-
if (open !== prevOpen) {
|
|
473
|
-
setPrevOpen(open);
|
|
474
|
-
resetSort();
|
|
475
|
-
}
|
|
525
|
+
}, [open, resetSort]);
|
|
476
526
|
const focusTrapSettings = {
|
|
477
527
|
initialFocusRef: inputRef || undefined
|
|
478
528
|
};
|
|
@@ -5,20 +5,6 @@ export declare function useRovingTabIndex({ containerRef, mouseDownRef, }: {
|
|
|
5
5
|
}): void;
|
|
6
6
|
export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
|
|
7
7
|
export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
|
|
8
|
-
/**
|
|
9
|
-
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
10
|
-
*
|
|
11
|
-
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
12
|
-
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
13
|
-
* that scans from the root to find the current element on every keystroke.
|
|
14
|
-
*
|
|
15
|
-
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
16
|
-
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
17
|
-
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
18
|
-
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
19
|
-
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
20
|
-
* for items inside collapsed parents.
|
|
21
|
-
*/
|
|
22
8
|
export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
|
|
23
9
|
export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
|
|
24
10
|
export declare function getParentElement(element: HTMLElement): HTMLElement | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IA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+123,25 @@ function getElementState(element) {
|
|
|
123
123
|
return 'end';
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Find the next or previous visible treeitem using direct DOM traversal.
|
|
129
|
-
*
|
|
130
|
-
* PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
|
|
131
|
-
* siblings and parent/child edges directly, rather than creating a TreeWalker
|
|
132
|
-
* that scans from the root to find the current element on every keystroke.
|
|
133
|
-
*
|
|
134
|
-
* NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
|
|
135
|
-
* (returning null when !isExpanded). Because collapsed subtree children are
|
|
136
|
-
* never in the DOM, we can safely skip them by only entering children of nodes
|
|
137
|
-
* with aria-expanded="true". If SubTree ever changes to keep collapsed children
|
|
138
|
-
* mounted (e.g. via CSS display:none), this logic would need to add filtering
|
|
139
|
-
* for items inside collapsed parents.
|
|
140
|
-
*/
|
|
141
126
|
function getVisibleElement(element, direction) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// Otherwise, walk up the tree looking for a next sibling
|
|
155
|
-
let current = element;
|
|
156
|
-
while (current) {
|
|
157
|
-
const next = getNextSiblingTreeItem(current);
|
|
158
|
-
if (next) return next;
|
|
159
|
-
|
|
160
|
-
// No next sibling at this level, try the parent's next sibling
|
|
161
|
-
current = getParentElement(current);
|
|
162
|
-
}
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
function getPreviousVisibleElement(element) {
|
|
166
|
-
const prev = getPreviousSiblingTreeItem(element);
|
|
167
|
-
if (prev) {
|
|
168
|
-
// Navigate to the deepest last visible descendant of the previous sibling
|
|
169
|
-
return getDeepestLastDescendant(prev);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// No previous sibling, the parent is the previous visible element
|
|
173
|
-
return getParentElement(element);
|
|
174
|
-
}
|
|
127
|
+
const root = element.closest('[role=tree]');
|
|
128
|
+
if (!root) return;
|
|
129
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, node => {
|
|
130
|
+
if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;
|
|
131
|
+
return node.getAttribute('role') === 'treeitem' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
132
|
+
});
|
|
133
|
+
let current = walker.firstChild();
|
|
134
|
+
while (current !== element) {
|
|
135
|
+
current = walker.nextNode();
|
|
136
|
+
}
|
|
137
|
+
let next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
175
138
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*/
|
|
181
|
-
function getDeepestLastDescendant(element) {
|
|
182
|
-
if (element.getAttribute('aria-expanded') === 'true') {
|
|
183
|
-
const lastChild = getLastChildTreeItem(element);
|
|
184
|
-
if (lastChild) {
|
|
185
|
-
return getDeepestLastDescendant(lastChild);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return element;
|
|
189
|
-
}
|
|
190
|
-
function getNextSiblingTreeItem(element) {
|
|
191
|
-
let sibling = element.nextElementSibling;
|
|
192
|
-
while (sibling) {
|
|
193
|
-
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
194
|
-
return sibling;
|
|
195
|
-
}
|
|
196
|
-
sibling = sibling.nextElementSibling;
|
|
197
|
-
}
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
function getPreviousSiblingTreeItem(element) {
|
|
201
|
-
let sibling = element.previousElementSibling;
|
|
202
|
-
while (sibling) {
|
|
203
|
-
if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
|
|
204
|
-
return sibling;
|
|
205
|
-
}
|
|
206
|
-
sibling = sibling.previousElementSibling;
|
|
207
|
-
}
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
function getLastChildTreeItem(element) {
|
|
211
|
-
// Find the [role=group] child (the subtree container), then get its last treeitem
|
|
212
|
-
for (let i = element.children.length - 1; i >= 0; i--) {
|
|
213
|
-
const child = element.children[i];
|
|
214
|
-
if (child instanceof HTMLElement && child.getAttribute('role') === 'group') {
|
|
215
|
-
let lastChild = child.lastElementChild;
|
|
216
|
-
while (lastChild && !(lastChild instanceof HTMLElement && lastChild.getAttribute('role') === 'treeitem')) {
|
|
217
|
-
lastChild = lastChild.previousElementSibling;
|
|
218
|
-
}
|
|
219
|
-
return lastChild instanceof HTMLElement ? lastChild : undefined;
|
|
220
|
-
}
|
|
139
|
+
// If next element is nested inside a collapsed subtree, continue iterating
|
|
140
|
+
while (next instanceof HTMLElement && (_next$parentElement = next.parentElement) !== null && _next$parentElement !== void 0 && _next$parentElement.closest('[role=treeitem][aria-expanded=false]')) {
|
|
141
|
+
var _next$parentElement;
|
|
142
|
+
next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
221
143
|
}
|
|
222
|
-
return undefined;
|
|
144
|
+
return next instanceof HTMLElement ? next : undefined;
|
|
223
145
|
}
|
|
224
146
|
function getFirstChildElement(element) {
|
|
225
147
|
const firstChild = element.querySelector('[role=treeitem]');
|
|
@@ -1,58 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef, useRef, useContext } from 'react';
|
|
1
|
+
import React, { forwardRef, useRef, useContext } from 'react';
|
|
3
2
|
import { UnderlineNavContext } from './UnderlineNavContext.js';
|
|
4
3
|
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
5
4
|
import { UnderlineItem } from '../internal/components/UnderlineTabbedInterface.js';
|
|
6
5
|
import classes from './UnderlineNavItem.module.css.js';
|
|
7
6
|
import { jsx } from 'react/jsx-runtime';
|
|
8
7
|
|
|
9
|
-
const UnderlineNavItem = /*#__PURE__*/forwardRef((
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let t2;
|
|
21
|
-
if ($[0] !== t0) {
|
|
22
|
-
({
|
|
23
|
-
as: t1,
|
|
24
|
-
href: t2,
|
|
25
|
-
children,
|
|
26
|
-
counter,
|
|
27
|
-
onSelect,
|
|
28
|
-
"aria-current": ariaCurrent,
|
|
29
|
-
icon: Icon,
|
|
30
|
-
leadingVisual,
|
|
31
|
-
...props
|
|
32
|
-
} = t0);
|
|
33
|
-
$[0] = t0;
|
|
34
|
-
$[1] = Icon;
|
|
35
|
-
$[2] = ariaCurrent;
|
|
36
|
-
$[3] = children;
|
|
37
|
-
$[4] = counter;
|
|
38
|
-
$[5] = leadingVisual;
|
|
39
|
-
$[6] = onSelect;
|
|
40
|
-
$[7] = props;
|
|
41
|
-
$[8] = t1;
|
|
42
|
-
$[9] = t2;
|
|
43
|
-
} else {
|
|
44
|
-
Icon = $[1];
|
|
45
|
-
ariaCurrent = $[2];
|
|
46
|
-
children = $[3];
|
|
47
|
-
counter = $[4];
|
|
48
|
-
leadingVisual = $[5];
|
|
49
|
-
onSelect = $[6];
|
|
50
|
-
props = $[7];
|
|
51
|
-
t1 = $[8];
|
|
52
|
-
t2 = $[9];
|
|
53
|
-
}
|
|
54
|
-
const Component = t1 === undefined ? "a" : t1;
|
|
55
|
-
const href = t2 === undefined ? "#" : t2;
|
|
8
|
+
const UnderlineNavItem = /*#__PURE__*/forwardRef(({
|
|
9
|
+
as: Component = 'a',
|
|
10
|
+
href = '#',
|
|
11
|
+
children,
|
|
12
|
+
counter,
|
|
13
|
+
onSelect,
|
|
14
|
+
'aria-current': ariaCurrent,
|
|
15
|
+
icon: Icon,
|
|
16
|
+
leadingVisual,
|
|
17
|
+
...props
|
|
18
|
+
}, forwardedRef) => {
|
|
56
19
|
const backupRef = useRef(null);
|
|
57
20
|
const ref = forwardedRef !== null && forwardedRef !== void 0 ? forwardedRef : backupRef;
|
|
58
21
|
const {
|
|
@@ -61,107 +24,51 @@ const UnderlineNavItem = /*#__PURE__*/forwardRef((t0, forwardedRef) => {
|
|
|
61
24
|
loadingCounters,
|
|
62
25
|
iconsVisible
|
|
63
26
|
} = useContext(UnderlineNavContext);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
let t6;
|
|
109
|
-
if ($[17] !== onSelect) {
|
|
110
|
-
t6 = event_0 => {
|
|
111
|
-
if (!event_0.defaultPrevented && typeof onSelect === "function") {
|
|
112
|
-
onSelect(event_0);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
$[17] = onSelect;
|
|
116
|
-
$[18] = t6;
|
|
117
|
-
} else {
|
|
118
|
-
t6 = $[18];
|
|
119
|
-
}
|
|
120
|
-
const clickHandler = t6;
|
|
121
|
-
const t7 = (_leadingVisual = leadingVisual) !== null && _leadingVisual !== void 0 ? _leadingVisual : Icon;
|
|
122
|
-
let t8;
|
|
123
|
-
if ($[19] !== Component || $[20] !== ariaCurrent || $[21] !== children || $[22] !== clickHandler || $[23] !== counter || $[24] !== href || $[25] !== iconsVisible || $[26] !== keyDownHandler || $[27] !== loadingCounters || $[28] !== props || $[29] !== ref || $[30] !== t7) {
|
|
124
|
-
t8 = /*#__PURE__*/jsx("li", {
|
|
125
|
-
className: classes.UnderlineNavItem,
|
|
126
|
-
children: /*#__PURE__*/jsx(UnderlineItem, {
|
|
127
|
-
ref: ref,
|
|
128
|
-
as: Component,
|
|
129
|
-
href: href,
|
|
130
|
-
"aria-current": ariaCurrent,
|
|
131
|
-
onKeyDown: keyDownHandler,
|
|
132
|
-
onClick: clickHandler,
|
|
133
|
-
counter: counter,
|
|
134
|
-
icon: t7,
|
|
135
|
-
loadingCounters: loadingCounters,
|
|
136
|
-
iconsVisible: iconsVisible,
|
|
137
|
-
...props,
|
|
138
|
-
children: children
|
|
139
|
-
})
|
|
140
|
-
});
|
|
141
|
-
$[19] = Component;
|
|
142
|
-
$[20] = ariaCurrent;
|
|
143
|
-
$[21] = children;
|
|
144
|
-
$[22] = clickHandler;
|
|
145
|
-
$[23] = counter;
|
|
146
|
-
$[24] = href;
|
|
147
|
-
$[25] = iconsVisible;
|
|
148
|
-
$[26] = keyDownHandler;
|
|
149
|
-
$[27] = loadingCounters;
|
|
150
|
-
$[28] = props;
|
|
151
|
-
$[29] = ref;
|
|
152
|
-
$[30] = t7;
|
|
153
|
-
$[31] = t8;
|
|
154
|
-
} else {
|
|
155
|
-
t8 = $[31];
|
|
156
|
-
}
|
|
157
|
-
return t8;
|
|
27
|
+
useIsomorphicLayoutEffect(() => {
|
|
28
|
+
if (ref.current) {
|
|
29
|
+
const domRect = ref.current.getBoundingClientRect();
|
|
30
|
+
const icon = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'icon');
|
|
31
|
+
const content = Array.from(ref.current.children).find(child => child.getAttribute('data-component') === 'text');
|
|
32
|
+
const text = content.textContent;
|
|
33
|
+
const iconWidthWithMargin = icon ? icon.getBoundingClientRect().width + Number(getComputedStyle(icon).marginRight.slice(0, -2)) + Number(getComputedStyle(icon).marginLeft.slice(0, -2)) : 0;
|
|
34
|
+
setChildrenWidth({
|
|
35
|
+
text,
|
|
36
|
+
width: domRect.width
|
|
37
|
+
});
|
|
38
|
+
setNoIconChildrenWidth({
|
|
39
|
+
text,
|
|
40
|
+
width: domRect.width - iconWidthWithMargin
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, [ref, setChildrenWidth, setNoIconChildrenWidth]);
|
|
44
|
+
const keyDownHandler = React.useCallback(event => {
|
|
45
|
+
if ((event.key === ' ' || event.key === 'Enter') && !event.defaultPrevented && typeof onSelect === 'function') {
|
|
46
|
+
onSelect(event);
|
|
47
|
+
}
|
|
48
|
+
}, [onSelect]);
|
|
49
|
+
const clickHandler = React.useCallback(event => {
|
|
50
|
+
if (!event.defaultPrevented && typeof onSelect === 'function') {
|
|
51
|
+
onSelect(event);
|
|
52
|
+
}
|
|
53
|
+
}, [onSelect]);
|
|
54
|
+
return /*#__PURE__*/jsx("li", {
|
|
55
|
+
className: classes.UnderlineNavItem,
|
|
56
|
+
children: /*#__PURE__*/jsx(UnderlineItem, {
|
|
57
|
+
ref: ref,
|
|
58
|
+
as: Component,
|
|
59
|
+
href: href,
|
|
60
|
+
"aria-current": ariaCurrent,
|
|
61
|
+
onKeyDown: keyDownHandler,
|
|
62
|
+
onClick: clickHandler,
|
|
63
|
+
counter: counter,
|
|
64
|
+
icon: leadingVisual !== null && leadingVisual !== void 0 ? leadingVisual : Icon,
|
|
65
|
+
loadingCounters: loadingCounters,
|
|
66
|
+
iconsVisible: iconsVisible,
|
|
67
|
+
...props,
|
|
68
|
+
children: children
|
|
69
|
+
})
|
|
70
|
+
});
|
|
158
71
|
});
|
|
159
72
|
UnderlineNavItem.displayName = 'UnderlineNavItem';
|
|
160
|
-
function _temp(child) {
|
|
161
|
-
return child.getAttribute("data-component") === "icon";
|
|
162
|
-
}
|
|
163
|
-
function _temp2(child_0) {
|
|
164
|
-
return child_0.getAttribute("data-component") === "text";
|
|
165
|
-
}
|
|
166
73
|
|
|
167
74
|
export { UnderlineNavItem };
|