@primer/react 0.0.0-20260223024838 → 0.0.0-20260223110740
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 +1 -13
- package/dist/Autocomplete/Autocomplete.js +159 -76
- package/dist/Autocomplete/AutocompleteMenu.js +333 -128
- package/dist/Autocomplete/AutocompleteOverlay.js +130 -49
- package/dist/Banner/Banner.js +238 -64
- package/dist/Button/Button.js +34 -11
- package/dist/Button/IconButton.js +140 -51
- package/dist/Button/LinkButton.js +39 -11
- package/dist/Checkbox/Checkbox.js +163 -55
- package/dist/Dialog/Dialog.js +347 -105
- package/dist/FilteredActionList/FilteredActionList.d.ts +1 -16
- package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
- package/dist/FilteredActionList/FilteredActionList.js +42 -147
- package/dist/PageLayout/PageLayout.js +1560 -622
- package/dist/SelectPanel/SelectPanel.d.ts +1 -1
- package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +1 -3
- package/dist/Text/Text.d.ts +1 -1
- package/dist/Text/Text.d.ts.map +1 -1
- package/dist/Text/Text.js +13 -10
- package/dist/UnderlineNav/UnderlineNavItem.js +149 -56
- package/dist/experimental/SelectPanel2/SelectPanel.js +593 -209
- package/dist/hooks/useRefObjectAsForwardedRef.d.ts.map +1 -1
- package/dist/hooks/useRefObjectAsForwardedRef.js +2 -10
- package/dist/hooks/useScrollFlash.d.ts.map +1 -1
- package/dist/hooks/useScrollFlash.js +22 -14
- package/dist/hooks/useSlots.d.ts +6 -50
- package/dist/hooks/useSlots.d.ts.map +1 -1
- package/dist/hooks/useSlots.js +36 -114
- package/generated/components.json +3 -9
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c } from 'react-compiler-runtime';
|
|
2
2
|
import { scrollIntoView, FocusKeys } from '@primer/behaviors';
|
|
3
|
-
import { useCallback, useRef, useState, useEffect,
|
|
3
|
+
import { useCallback, useRef, useState, useEffect, forwardRef } from 'react';
|
|
4
4
|
import { ActionList } from '../ActionList/index.js';
|
|
5
5
|
import { useFocusZone } from '../hooks/useFocusZone.js';
|
|
6
6
|
import { useId } from '../hooks/useId.js';
|
|
@@ -13,7 +13,6 @@ import { ActionListContainerContext } from '../ActionList/ActionListContainerCon
|
|
|
13
13
|
import { isValidElementType } from 'react-is';
|
|
14
14
|
import { useAnnouncements } from './useAnnouncements.js';
|
|
15
15
|
import { clsx } from 'clsx';
|
|
16
|
-
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
17
16
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
18
17
|
import TextInput from '../TextInput/TextInput.js';
|
|
19
18
|
import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden.js';
|
|
@@ -52,19 +51,8 @@ function FilteredActionList({
|
|
|
52
51
|
setInitialFocus = false,
|
|
53
52
|
focusPrependedElements,
|
|
54
53
|
scrollBehavior,
|
|
55
|
-
virtualized = false,
|
|
56
54
|
...listProps
|
|
57
55
|
}) {
|
|
58
|
-
if (process.env.NODE_ENV !== "production") {
|
|
59
|
-
if (virtualized && groupMetadata !== null && groupMetadata !== void 0 && groupMetadata.length) {
|
|
60
|
-
// eslint-disable-next-line no-console
|
|
61
|
-
console.warn('FilteredActionList: `virtualized` has no effect when `groupMetadata` is provided. ' + 'Grouped lists are rendered without virtualization.');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Virtualization is disabled when groups are present — grouped lists render
|
|
66
|
-
// normally regardless of the `virtualized` prop.
|
|
67
|
-
const isVirtualized = virtualized && !(groupMetadata !== null && groupMetadata !== void 0 && groupMetadata.length);
|
|
68
56
|
const [filterValue, setInternalFilterValue] = useProvidedStateOrCreate(externalFilterValue, undefined, '');
|
|
69
57
|
const onInputChange = useCallback(e => {
|
|
70
58
|
const value = e.target.value;
|
|
@@ -142,61 +130,18 @@ function FilteredActionList({
|
|
|
142
130
|
useEffect(() => {
|
|
143
131
|
onInputRefChanged === null || onInputRefChanged === void 0 ? void 0 : onInputRefChanged(inputRef);
|
|
144
132
|
}, [inputRef, onInputRefChanged]);
|
|
145
|
-
|
|
146
|
-
// Matches the most common ActionList.Item height (single-line text + description).
|
|
147
|
-
// Items are measured dynamically via `measureElement`, so this only affects the
|
|
148
|
-
// initial total-height estimate before items scroll into view.
|
|
149
|
-
const DEFAULT_VIRTUAL_ITEM_HEIGHT = 32;
|
|
150
|
-
const virtualizer = useVirtualizer({
|
|
151
|
-
count: items.length,
|
|
152
|
-
getScrollElement: () => scrollContainerRef.current,
|
|
153
|
-
estimateSize: () => DEFAULT_VIRTUAL_ITEM_HEIGHT,
|
|
154
|
-
overscan: 10,
|
|
155
|
-
enabled: isVirtualized,
|
|
156
|
-
getItemKey: index => {
|
|
157
|
-
var _ref, _item_3$key, _item_3$id;
|
|
158
|
-
const item_3 = items[index];
|
|
159
|
-
return (_ref = (_item_3$key = item_3.key) !== null && _item_3$key !== void 0 ? _item_3$key : (_item_3$id = item_3.id) === null || _item_3$id === void 0 ? void 0 : _item_3$id.toString()) !== null && _ref !== void 0 ? _ref : index.toString();
|
|
160
|
-
},
|
|
161
|
-
measureElement: el => el.scrollHeight
|
|
162
|
-
});
|
|
163
|
-
const virtualItems = isVirtualized ? virtualizer.getVirtualItems() : undefined;
|
|
164
|
-
const virtualizedItemEntries = useMemo(() => {
|
|
165
|
-
if (!isVirtualized || !virtualItems) return undefined;
|
|
166
|
-
return virtualItems.map(virtualItem => {
|
|
167
|
-
const item_4 = items[virtualItem.index];
|
|
168
|
-
return {
|
|
169
|
-
virtualItem,
|
|
170
|
-
item: item_4,
|
|
171
|
-
index: virtualItem.index
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
}, [isVirtualized, virtualItems, items]);
|
|
175
133
|
useFocusZone(!usingRovingTabindex ? {
|
|
176
134
|
containerRef: {
|
|
177
135
|
current: listContainerElement
|
|
178
136
|
},
|
|
179
137
|
bindKeys: FocusKeys.ArrowVertical | FocusKeys.PageUpDown,
|
|
180
|
-
|
|
181
|
-
// 'wrap' would cycle focus within the visible window instead of reaching the
|
|
182
|
-
// true end of the list. 'stop' lets the virtualizer's scrollToIndex bring
|
|
183
|
-
// the correct items into view when navigating past the rendered boundaries.
|
|
184
|
-
focusOutBehavior: isVirtualized ? 'stop' : focusOutBehavior,
|
|
138
|
+
focusOutBehavior,
|
|
185
139
|
focusableElementFilter: element => {
|
|
186
140
|
return !(element instanceof HTMLInputElement);
|
|
187
141
|
},
|
|
188
142
|
activeDescendantFocus: inputRef,
|
|
189
143
|
onActiveDescendantChanged: (current, previous, directlyActivated) => {
|
|
190
144
|
activeDescendantRef.current = current;
|
|
191
|
-
if (isVirtualized && current) {
|
|
192
|
-
const index_0 = current.getAttribute('data-index');
|
|
193
|
-
const range = virtualizer.range;
|
|
194
|
-
if (index_0 !== null && range && (Number(index_0) < range.startIndex || Number(index_0) >= range.endIndex)) {
|
|
195
|
-
virtualizer.scrollToIndex(Number(index_0), {
|
|
196
|
-
align: 'auto'
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
145
|
if (current && scrollContainerRef.current && (directlyActivated || focusPrependedElements)) {
|
|
201
146
|
scrollIntoView(current, scrollContainerRef.current, {
|
|
202
147
|
...menuScrollMargins,
|
|
@@ -208,7 +153,7 @@ function FilteredActionList({
|
|
|
208
153
|
focusInStrategy: setInitialFocus ? 'initial' : 'previous',
|
|
209
154
|
ignoreHoverEvents: disableSelectOnHover,
|
|
210
155
|
focusPrependedElements
|
|
211
|
-
} : undefined, [listContainerElement, usingRovingTabindex, onActiveDescendantChanged, focusPrependedElements
|
|
156
|
+
} : undefined, [listContainerElement, usingRovingTabindex, onActiveDescendantChanged, focusPrependedElements]);
|
|
212
157
|
useEffect(() => {
|
|
213
158
|
if (activeDescendantRef.current && scrollContainerRef.current) {
|
|
214
159
|
scrollIntoView(activeDescendantRef.current, scrollContainerRef.current, {
|
|
@@ -262,82 +207,6 @@ function FilteredActionList({
|
|
|
262
207
|
return message;
|
|
263
208
|
}
|
|
264
209
|
let firstGroupIndex_0 = 0;
|
|
265
|
-
const renderListItems = () => {
|
|
266
|
-
if (groupMetadata !== null && groupMetadata !== void 0 && groupMetadata.length) {
|
|
267
|
-
return groupMetadata.map((group, index_1) => {
|
|
268
|
-
var _group$header, _group$header2;
|
|
269
|
-
if (index_1 === firstGroupIndex_0 && getItemListForEachGroup(group.groupId).length === 0) {
|
|
270
|
-
firstGroupIndex_0++;
|
|
271
|
-
}
|
|
272
|
-
return /*#__PURE__*/jsxs(ActionList.Group, {
|
|
273
|
-
children: [/*#__PURE__*/jsx(ActionList.GroupHeading, {
|
|
274
|
-
variant: (_group$header = group.header) !== null && _group$header !== void 0 && _group$header.variant ? group.header.variant : undefined,
|
|
275
|
-
children: (_group$header2 = group.header) !== null && _group$header2 !== void 0 && _group$header2.title ? group.header.title : `Group ${group.groupId}`
|
|
276
|
-
}), getItemListForEachGroup(group.groupId).map(({
|
|
277
|
-
key: itemKey,
|
|
278
|
-
...item_5
|
|
279
|
-
}, itemIndex) => {
|
|
280
|
-
var _ref2, _item_5$id;
|
|
281
|
-
const key = (_ref2 = itemKey !== null && itemKey !== void 0 ? itemKey : (_item_5$id = item_5.id) === null || _item_5$id === void 0 ? void 0 : _item_5$id.toString()) !== null && _ref2 !== void 0 ? _ref2 : itemIndex.toString();
|
|
282
|
-
return /*#__PURE__*/jsx(MappedActionListItem, {
|
|
283
|
-
className: clsx(classes.ActionListItem, 'className' in item_5 ? item_5.className : undefined),
|
|
284
|
-
"data-input-focused": isInputFocused ? '' : undefined,
|
|
285
|
-
"data-first-child": index_1 === firstGroupIndex_0 && itemIndex === 0 ? '' : undefined,
|
|
286
|
-
...item_5,
|
|
287
|
-
renderItem: listProps.renderItem
|
|
288
|
-
}, key);
|
|
289
|
-
})]
|
|
290
|
-
}, index_1);
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
if (isVirtualized && virtualizedItemEntries) {
|
|
294
|
-
return virtualizedItemEntries.map(({
|
|
295
|
-
virtualItem: virtualItem_0,
|
|
296
|
-
item: {
|
|
297
|
-
key: itemKey_0,
|
|
298
|
-
...item_6
|
|
299
|
-
},
|
|
300
|
-
index: index_2
|
|
301
|
-
}) => {
|
|
302
|
-
var _ref3, _item_6$id;
|
|
303
|
-
const key_0 = (_ref3 = itemKey_0 !== null && itemKey_0 !== void 0 ? itemKey_0 : (_item_6$id = item_6.id) === null || _item_6$id === void 0 ? void 0 : _item_6$id.toString()) !== null && _ref3 !== void 0 ? _ref3 : index_2.toString();
|
|
304
|
-
return /*#__PURE__*/jsx(MappedActionListItem, {
|
|
305
|
-
className: clsx(classes.ActionListItem, 'className' in item_6 ? item_6.className : undefined),
|
|
306
|
-
"data-input-focused": isInputFocused ? '' : undefined,
|
|
307
|
-
"data-first-child": index_2 === 0 ? '' : undefined,
|
|
308
|
-
"data-index": virtualItem_0.index,
|
|
309
|
-
ref: node_0 => {
|
|
310
|
-
if (node_0) {
|
|
311
|
-
virtualizer.measureElement(node_0);
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
style: {
|
|
315
|
-
position: 'absolute',
|
|
316
|
-
top: 0,
|
|
317
|
-
left: 0,
|
|
318
|
-
right: 0,
|
|
319
|
-
transform: `translateY(${virtualItem_0.start}px)`
|
|
320
|
-
},
|
|
321
|
-
...item_6,
|
|
322
|
-
renderItem: listProps.renderItem
|
|
323
|
-
}, key_0);
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
return items.map(({
|
|
327
|
-
key: itemKey_1,
|
|
328
|
-
...item_7
|
|
329
|
-
}, index_3) => {
|
|
330
|
-
var _ref4, _item_7$id;
|
|
331
|
-
const key_1 = (_ref4 = itemKey_1 !== null && itemKey_1 !== void 0 ? itemKey_1 : (_item_7$id = item_7.id) === null || _item_7$id === void 0 ? void 0 : _item_7$id.toString()) !== null && _ref4 !== void 0 ? _ref4 : index_3.toString();
|
|
332
|
-
return /*#__PURE__*/jsx(MappedActionListItem, {
|
|
333
|
-
className: clsx(classes.ActionListItem, 'className' in item_7 ? item_7.className : undefined),
|
|
334
|
-
"data-input-focused": isInputFocused ? '' : undefined,
|
|
335
|
-
"data-first-child": index_3 === 0 ? '' : undefined,
|
|
336
|
-
...item_7,
|
|
337
|
-
renderItem: listProps.renderItem
|
|
338
|
-
}, key_1);
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
210
|
const actionListContent = /*#__PURE__*/jsx(ActionList, {
|
|
342
211
|
ref: usingRovingTabindex ? listRef : listContainerRefCallback,
|
|
343
212
|
showDividers: showItemDividers,
|
|
@@ -346,19 +215,45 @@ function FilteredActionList({
|
|
|
346
215
|
...actionListProps,
|
|
347
216
|
role: "listbox",
|
|
348
217
|
id: listId,
|
|
349
|
-
className: clsx(classes.ActionList, actionListProps === null || actionListProps === void 0 ? void 0 : actionListProps.className)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
218
|
+
className: clsx(classes.ActionList, actionListProps === null || actionListProps === void 0 ? void 0 : actionListProps.className),
|
|
219
|
+
children: groupMetadata !== null && groupMetadata !== void 0 && groupMetadata.length ? groupMetadata.map((group, index) => {
|
|
220
|
+
var _group$header, _group$header2;
|
|
221
|
+
if (index === firstGroupIndex_0 && getItemListForEachGroup(group.groupId).length === 0) {
|
|
222
|
+
firstGroupIndex_0++; // Increment firstGroupIndex if the first group has no items
|
|
223
|
+
}
|
|
224
|
+
return /*#__PURE__*/jsxs(ActionList.Group, {
|
|
225
|
+
children: [/*#__PURE__*/jsx(ActionList.GroupHeading, {
|
|
226
|
+
variant: (_group$header = group.header) !== null && _group$header !== void 0 && _group$header.variant ? group.header.variant : undefined,
|
|
227
|
+
children: (_group$header2 = group.header) !== null && _group$header2 !== void 0 && _group$header2.title ? group.header.title : `Group ${group.groupId}`
|
|
228
|
+
}), getItemListForEachGroup(group.groupId).map(({
|
|
229
|
+
key: itemKey,
|
|
230
|
+
...item_3
|
|
231
|
+
}, itemIndex) => {
|
|
232
|
+
var _ref, _item_3$id;
|
|
233
|
+
const key = (_ref = itemKey !== null && itemKey !== void 0 ? itemKey : (_item_3$id = item_3.id) === null || _item_3$id === void 0 ? void 0 : _item_3$id.toString()) !== null && _ref !== void 0 ? _ref : itemIndex.toString();
|
|
234
|
+
return /*#__PURE__*/jsx(MappedActionListItem, {
|
|
235
|
+
className: clsx(classes.ActionListItem, 'className' in item_3 ? item_3.className : undefined),
|
|
236
|
+
"data-input-focused": isInputFocused ? '' : undefined,
|
|
237
|
+
"data-first-child": index === firstGroupIndex_0 && itemIndex === 0 ? '' : undefined,
|
|
238
|
+
...item_3,
|
|
239
|
+
renderItem: listProps.renderItem
|
|
240
|
+
}, key);
|
|
241
|
+
})]
|
|
242
|
+
}, index);
|
|
243
|
+
}) : items.map(({
|
|
244
|
+
key: itemKey_0,
|
|
245
|
+
...item_4
|
|
246
|
+
}, index_0) => {
|
|
247
|
+
var _ref2, _item_4$id;
|
|
248
|
+
const key_0 = (_ref2 = itemKey_0 !== null && itemKey_0 !== void 0 ? itemKey_0 : (_item_4$id = item_4.id) === null || _item_4$id === void 0 ? void 0 : _item_4$id.toString()) !== null && _ref2 !== void 0 ? _ref2 : index_0.toString();
|
|
249
|
+
return /*#__PURE__*/jsx(MappedActionListItem, {
|
|
250
|
+
className: clsx(classes.ActionListItem, 'className' in item_4 ? item_4.className : undefined),
|
|
251
|
+
"data-input-focused": isInputFocused ? '' : undefined,
|
|
252
|
+
"data-first-child": index_0 === 0 ? '' : undefined,
|
|
253
|
+
...item_4,
|
|
254
|
+
renderItem: listProps.renderItem
|
|
255
|
+
}, key_0);
|
|
256
|
+
})
|
|
362
257
|
});
|
|
363
258
|
|
|
364
259
|
// Use ActionListContainerContext.Provider only for the old behavior (when feature flag is disabled)
|