@sentry/scraps 0.6.0 → 0.7.0

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.
Files changed (88) hide show
  1. package/README.md +27 -0
  2. package/dist/alert/alert.js +10 -7
  3. package/dist/compactSelect/compactSelect.d.ts +2 -2
  4. package/dist/compactSelect/compactSelect.js +37 -23
  5. package/dist/compactSelect/control.js +12 -9
  6. package/dist/compactSelect/gridList/index.js +35 -36
  7. package/dist/compactSelect/gridList/option.d.ts +4 -1
  8. package/dist/compactSelect/gridList/option.js +4 -3
  9. package/dist/compactSelect/gridList/section.d.ts +10 -3
  10. package/dist/compactSelect/gridList/section.js +16 -33
  11. package/dist/compactSelect/listBox/index.d.ts +1 -1
  12. package/dist/compactSelect/listBox/index.js +46 -58
  13. package/dist/compactSelect/listBox/section.d.ts +10 -8
  14. package/dist/compactSelect/listBox/section.js +11 -30
  15. package/dist/compactSelect/styles.d.ts +6 -7
  16. package/dist/compactSelect/styles.js +1 -23
  17. package/dist/diagnostics/context.d.ts +12 -0
  18. package/dist/diagnostics/context.js +11 -0
  19. package/dist/diagnostics/index.d.ts +2 -0
  20. package/dist/diagnostics/index.js +1 -0
  21. package/dist/disclosure/disclosure.js +1 -1
  22. package/dist/dragHandle/dragHandle.js +3 -5
  23. package/dist/dropdownMenu/context.d.ts +10 -0
  24. package/dist/dropdownMenu/context.js +2 -1
  25. package/dist/dropdownMenu/item.d.ts +2 -7
  26. package/dist/dropdownMenu/item.js +13 -7
  27. package/dist/dropdownMenu/list.js +25 -23
  28. package/dist/dropdownMenu/useDropdownMenuRowLayout.js +6 -14
  29. package/dist/form/field/radioGroupField.d.ts +7 -0
  30. package/dist/form/field/radioGroupField.js +14 -0
  31. package/dist/form/field/selectField.d.ts +3 -4
  32. package/dist/form/field/selectField.js +16 -24
  33. package/dist/layout/container.d.ts +18 -7
  34. package/dist/layout/container.js +8 -11
  35. package/dist/layout/flex.js +1 -1
  36. package/dist/layout/grid.js +2 -2
  37. package/dist/layout/index.d.ts +1 -1
  38. package/dist/layout/index.js +1 -1
  39. package/dist/layout/stack.js +1 -1
  40. package/dist/layout/styles.d.ts +28 -8
  41. package/dist/layout/styles.js +67 -13
  42. package/dist/layout/surface.d.ts +2 -2
  43. package/dist/layout/surface.js +6 -3
  44. package/dist/menu/menu.js +4 -4
  45. package/dist/menu/selectValue.d.ts +2 -6
  46. package/dist/modal/components.js +2 -2
  47. package/dist/overlayArrow.js +2 -2
  48. package/dist/select/chips.d.ts +14 -0
  49. package/dist/select/chips.js +45 -0
  50. package/dist/select/filter.js +7 -11
  51. package/dist/select/index.d.ts +1 -1
  52. package/dist/select/indicators.d.ts +11 -0
  53. package/dist/select/indicators.js +61 -0
  54. package/dist/select/menu.d.ts +44 -0
  55. package/dist/select/menu.js +103 -0
  56. package/dist/select/option.d.ts +23 -15
  57. package/dist/select/option.js +66 -58
  58. package/dist/select/options.d.ts +31 -0
  59. package/dist/select/options.js +74 -0
  60. package/dist/select/select.d.ts +24 -11
  61. package/dist/select/select.js +527 -429
  62. package/dist/select/styles.d.ts +148 -2
  63. package/dist/select/styles.js +156 -1
  64. package/dist/select/types.d.ts +6 -7
  65. package/dist/select/types.js +4 -0
  66. package/dist/select/utils.d.ts +2 -0
  67. package/dist/select/utils.js +4 -0
  68. package/dist/separator/separator.d.ts +2 -2
  69. package/dist/separator/separator.js +4 -3
  70. package/dist/slot/slot.js +16 -12
  71. package/dist/tabs/tab.js +3 -1
  72. package/dist/theme/index.d.ts +2 -0
  73. package/dist/theme/index.js +2 -0
  74. package/dist/theme/types.d.ts +1 -0
  75. package/dist/theme/useResolvedTheme.d.ts +12 -0
  76. package/dist/theme/useResolvedTheme.js +20 -0
  77. package/dist/theme/variables.css +1116 -0
  78. package/dist/theme/variables.d.ts +985 -0
  79. package/dist/theme/variables.js +455 -0
  80. package/dist/useVirtualCollection.d.ts +14 -1
  81. package/dist/useVirtualCollection.js +59 -3
  82. package/package.json +12 -6
  83. package/dist/compactSelect/useVirtualizedItems.d.ts +0 -52
  84. package/dist/compactSelect/useVirtualizedItems.js +0 -74
  85. package/dist/select/reactSelectWrapper.d.ts +0 -8
  86. package/dist/select/reactSelectWrapper.js +0 -25
  87. package/dist/select/virtualizedMenuList.d.ts +0 -24
  88. package/dist/select/virtualizedMenuList.js +0 -123
package/README.md CHANGED
@@ -58,6 +58,33 @@ The stylesheet uses relative URLs to separate WOFF2 files. For direct asset impo
58
58
 
59
59
  To self-host without a bundler, copy `fonts.css` and the `fonts/` directory from the installed package into the same public directory, then link to `fonts.css` in your page. Keep `fonts/OFL.txt` with the font files.
60
60
 
61
+ ## Theme CSS variables
62
+
63
+ `@sentry/scraps/theme.css` declares the theme's semantic tokens as `--scraps-*`
64
+ custom properties in `@layer scraps.tokens`. It is generated from the
65
+ [design tokens](https://github.com/getsentry/design-engineering/tree/main/packages/tokens);
66
+ do not edit `src/theme/variables.css` or `src/theme/variables.tsx` by hand.
67
+
68
+ ```css
69
+ @import '@sentry/scraps/theme.css';
70
+
71
+ .panel {
72
+ padding: var(--scraps-space-md);
73
+ background: var(--scraps-background-primary);
74
+ }
75
+ ```
76
+
77
+ The nearest ancestor's `data-color-scheme` attribute picks the values: none or
78
+ `light` is light, `dark` is dark, and `system` follows `prefers-color-scheme`.
79
+ In dark mode, the nearest ancestor's `data-theme-dark` attribute (`ash` or
80
+ `midnight`) picks a dark theme; any other value or none keeps the default dark
81
+ theme. Scheme values live in `@layer colorScheme` and theme overrides in
82
+ `@layer themeVariant`, both inside `scraps.tokens`.
83
+ `themeVariables` from `@sentry/scraps/theme` has the same shape as the theme's
84
+ `tokens` and `shadow`, with `var(--scraps-*)` values. Components still read
85
+ literal values from the Emotion theme, so loading this file does not change
86
+ how they render yet.
87
+
61
88
  ## Date and duration formatting
62
89
 
63
90
  Components and plain formatters share the same presentation options:
@@ -119,11 +119,6 @@ const StyledTrailingItems = styled(Grid)`
119
119
  align-self: center;
120
120
  }
121
121
  `;
122
- const StyledMessage = styled('div')`
123
- line-height: ${(p)=>p.theme.font.lineHeight.comfortable};
124
- place-content: center;
125
- padding-block: ${(p)=>p.theme.space.xs};
126
- `;
127
122
  const StyledIconWrapper = styled('div')`
128
123
  position: absolute;
129
124
  top: ${(p)=>p.theme.space.lg};
@@ -169,8 +164,16 @@ function Alert({ icon, system, expand, trailingItems, className, children, varia
169
164
  variant: variant
170
165
  })
171
166
  }),
172
- /*#__PURE__*/ jsx(StyledMessage, {
173
- children: children
167
+ /*#__PURE__*/ jsx(Container, {
168
+ alignSelf: "center",
169
+ padding: "xs 0",
170
+ children: (containerProps)=>/*#__PURE__*/ jsx(Text, {
171
+ ...containerProps,
172
+ as: "div",
173
+ density: "comfortable",
174
+ variant: "inherit",
175
+ children: children
176
+ })
174
177
  }),
175
178
  !!trailingItems && /*#__PURE__*/ jsx(StyledTrailingItems, {
176
179
  flow: "column",
@@ -7,8 +7,8 @@ export type { SelectOption, SelectOptionOrSection, SelectSection, SelectKey };
7
7
  interface BaseSelectProps<Value extends SelectKey> extends Omit<ControlProps, 'onClear' | 'clearable'> {
8
8
  options: Array<SelectOptionOrSection<Value>>;
9
9
  /**
10
- * Number of options above which virtualization will be enabled.
11
- * Note that virtualization is always disabled if there are sections in the options.
10
+ * Number of options, including those inside sections, above which
11
+ * virtualization will be enabled.
12
12
  * @default 150
13
13
  */
14
14
  virtualizeThreshold?: number;
@@ -3,13 +3,15 @@ import { createElement } from "@emotion/react";
3
3
  import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
4
4
  import { Item, Section } from "@react-stately/collections";
5
5
  import { useTranslation } from "../translation/index.js";
6
+ import { DEFAULT_VIRTUALIZE_THRESHOLD } from "../useVirtualCollection.js";
7
+ import { useDiagnostics } from "../diagnostics/context.js";
6
8
  import { Control } from "./control.js";
7
9
  import { List } from "./list.js";
8
10
  import { EmptyMessage } from "./styles.js";
9
11
  import { getDuplicateOptionKeysInfo, getItemsWithKeys, shouldCloseOnSelect } from "./utils.js";
10
- import * as __rspack_external__sentry_react_f0cda475 from "@sentry/react";
11
12
  function CompactSelect({ options, value, onChange, multiple, clearable, isOptionDisabled, sizeLimit, sizeLimitMessage, virtualizeThreshold, mode, disabled, emptyMessage, size = 'md', closeOnSelect, menuWidth, ...controlProps }) {
12
13
  const { t } = useTranslation();
14
+ const diagnostics = useDiagnostics();
13
15
  const generatedTriggerId = useId();
14
16
  const triggerId = controlProps.triggerId ?? generatedTriggerId;
15
17
  const listProps = useMemo(()=>{
@@ -43,23 +45,7 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
43
45
  const allItemsWithKey = useMemo(()=>getItemsWithKeys(options), [
44
46
  options
45
47
  ]);
46
- const longestOptionItemsWithKey = useMemo(()=>{
47
- if (needsMeasuring) {
48
- let longestOption;
49
- let longestLength = -1;
50
- for (const option of options){
51
- const length = 'options' in option ? 0 : option.textValue ? option.textValue.length : 'string' == typeof option.label ? option.label.length : 0;
52
- if (length > longestLength) {
53
- longestOption = option;
54
- longestLength = length;
55
- }
56
- }
57
- return longestOption ? getItemsWithKeys([
58
- longestOption
59
- ]) : [];
60
- }
61
- return [];
62
- }, [
48
+ const longestOptionItemsWithKey = useMemo(()=>needsMeasuring ? getItemsWithKeys(getLongestOptionItems(options)) : [], [
63
49
  needsMeasuring,
64
50
  options
65
51
  ]);
@@ -77,7 +63,7 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
77
63
  const duplicateOptionKeySignature = duplicateOptionKeys.join(',');
78
64
  if (lastLoggedDuplicateKeySignatureRef.current === duplicateOptionKeySignature) return;
79
65
  lastLoggedDuplicateKeySignatureRef.current = duplicateOptionKeySignature;
80
- __rspack_external__sentry_react_f0cda475.logger.error('CompactSelect has duplicate option keys', {
66
+ diagnostics.logger.error('CompactSelect has duplicate option keys', {
81
67
  component_title: componentTitle,
82
68
  duplicate_option_key_count: duplicateOptionKeys.length,
83
69
  duplicate_option_key_signature: duplicateOptionKeySignature,
@@ -88,6 +74,7 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
88
74
  }, [
89
75
  allItemsWithKey,
90
76
  componentTitle,
77
+ diagnostics,
91
78
  virtualizeThreshold
92
79
  ]);
93
80
  return /*#__PURE__*/ jsxs(Control, {
@@ -142,9 +129,36 @@ function CompactSelect({ options, value, onChange, multiple, clearable, isOption
142
129
  ]
143
130
  });
144
131
  }
145
- function shouldVirtualize(items, virtualizeThreshold = 150) {
146
- const hasSections = items.some((item)=>'options' in item);
147
- if (hasSections) return false;
148
- return items.length > virtualizeThreshold;
132
+ function shouldVirtualize(items, virtualizeThreshold = DEFAULT_VIRTUALIZE_THRESHOLD) {
133
+ const optionCount = items.reduce((count, item)=>count + ('options' in item ? item.options.length : 1), 0);
134
+ return optionCount > virtualizeThreshold;
135
+ }
136
+ function getLabelLength(option) {
137
+ if (option.textValue) return option.textValue.length;
138
+ return 'string' == typeof option.label ? option.label.length : 0;
139
+ }
140
+ function getLongestOptionItems(items) {
141
+ let longest;
142
+ let longestLength = -1;
143
+ for (const item of items){
144
+ const options = 'options' in item ? item.options : [
145
+ item
146
+ ];
147
+ for (const option of options){
148
+ const length = getLabelLength(option);
149
+ if (length > longestLength) {
150
+ longestLength = length;
151
+ longest = 'options' in item ? {
152
+ ...item,
153
+ options: [
154
+ option
155
+ ]
156
+ } : option;
157
+ }
158
+ }
159
+ }
160
+ return longest ? [
161
+ longest
162
+ ] : [];
149
163
  }
150
164
  export { CompactSelect };
@@ -223,7 +223,7 @@ function Control({ autoFocus, trigger, triggerId, isOpen, onClose, isDismissable
223
223
  contain: true,
224
224
  children: [
225
225
  hasHeader && /*#__PURE__*/ jsx(Header, {
226
- borderBottom: searchEnabled ? 'none' : 'secondary',
226
+ borderBottomColor: searchEnabled ? 'none' : 'secondary',
227
227
  padding: searchEnabled ? 'xs lg 0 lg' : 'xs lg',
228
228
  children: /*#__PURE__*/ jsxs(Flex, {
229
229
  align: "center",
@@ -260,14 +260,17 @@ function Control({ autoFocus, trigger, triggerId, isOpen, onClose, isDismissable
260
260
  ]
261
261
  })
262
262
  }),
263
- searchEnabled && /*#__PURE__*/ jsx(Search, {
264
- ref: searchRef,
265
- placeholder: normalizedSearch?.placeholder ?? 'Search…',
266
- value: searchInputValue,
267
- onFocus: onSearchFocus,
268
- onBlur: onSearchBlur,
269
- onChange: (e)=>updateSearch(e.target.value),
270
- ...searchKeyboardProps
263
+ searchEnabled && /*#__PURE__*/ jsx(Container, {
264
+ borderBottomColor: "secondary",
265
+ children: /*#__PURE__*/ jsx(Search, {
266
+ ref: searchRef,
267
+ placeholder: normalizedSearch?.placeholder ?? 'Search…',
268
+ value: searchInputValue,
269
+ onFocus: onSearchFocus,
270
+ onBlur: onSearchBlur,
271
+ onChange: (e)=>updateSearch(e.target.value),
272
+ ...searchKeyboardProps
273
+ })
271
274
  }),
272
275
  'function' == typeof menuBody ? menuBody({
273
276
  closeOverlay: overlayState.close
@@ -1,20 +1,22 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { createElement } from "@emotion/react";
2
+ import { createElement, useTheme } from "@emotion/react";
3
3
  import { useContext, useId, useMemo, useRef } from "react";
4
4
  import { useGridList } from "@react-aria/gridlist";
5
5
  import { mergeProps } from "@react-aria/utils";
6
6
  import { SelectFilterContext } from "../selectFilterContext.js";
7
7
  import { ListLabel, ListSeparator, ListWrap, SizeLimitMessage } from "../styles.js";
8
- import { useVirtualizedItems } from "../useVirtualizedItems.js";
9
8
  import { hasVisibleLeadingItems } from "../utils.js";
10
9
  import { Container } from "../../layout/index.js";
11
10
  import { ControlContext, ReserveLeadingSlot } from "../../menu/index.js";
12
11
  import { useTranslation } from "../../translation/index.js";
12
+ import { VirtualRows, useVirtualCollection } from "../../useVirtualCollection.js";
13
13
  import { GridListOption } from "./option.js";
14
14
  import { GridListSection } from "./section.js";
15
15
  function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHandler, virtualized, ...props }) {
16
16
  const { t } = useTranslation();
17
+ const theme = useTheme();
17
18
  const ref = useRef(null);
19
+ const scrollElementRef = useRef(null);
18
20
  const labelId = useId();
19
21
  const { gridProps } = useGridList({
20
22
  ...props,
@@ -41,9 +43,13 @@ function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHand
41
43
  listItems,
42
44
  hiddenOptions
43
45
  ]);
44
- const virtualizer = useVirtualizedItems({
45
- listItems,
46
- virtualized,
46
+ const virtual = useVirtualCollection({
47
+ collection: listItems,
48
+ enabled: !!virtualized,
49
+ scrollRef: scrollElementRef,
50
+ focusedKey: listState.selectionManager.focusedKey,
51
+ hiddenKeys: hiddenOptions,
52
+ listPadding: parseFloat(theme.space.xs),
47
53
  size
48
54
  });
49
55
  const mergedProps = mergeProps(gridProps, props);
@@ -58,42 +64,35 @@ function GridList({ listState, size = 'md', label, sizeLimitMessage, keyDownHand
58
64
  children: label
59
65
  }),
60
66
  overlayIsOpen && /*#__PURE__*/ jsx(Container, {
61
- ref: virtualizer.scrollElementRef,
67
+ ref: scrollElementRef,
62
68
  height: "100%",
63
69
  overflowY: "auto",
64
- children: /*#__PURE__*/ jsx(Container, {
65
- ...virtualizer.wrapperProps,
66
- children: /*#__PURE__*/ jsxs(ListWrap, {
67
- ...mergedProps,
68
- style: {
69
- ...mergedProps.style,
70
- ...virtualizer.listWrapStyle
71
- },
72
- onKeyDown: onKeyDown,
73
- ref: ref,
74
- children: [
75
- virtualizer.items.map((row)=>{
76
- const item = listItems[row.index];
77
- if (!item) return null;
78
- if ('section' === item.type) return /*#__PURE__*/ createElement(GridListSection, {
79
- ...virtualizer.itemProps(row.index),
80
- key: item.key,
81
- node: item,
70
+ children: /*#__PURE__*/ jsxs(ListWrap, {
71
+ ...mergedProps,
72
+ onKeyDown: onKeyDown,
73
+ ref: ref,
74
+ children: [
75
+ /*#__PURE__*/ jsx(VirtualRows, {
76
+ virtual: virtual,
77
+ renderRow: ({ node, props: rowProps })=>/*#__PURE__*/ createElement(GridListOption, {
78
+ ...rowProps,
79
+ key: node.key,
80
+ node: node,
82
81
  listState: listState,
83
82
  size: size
84
- });
85
- return /*#__PURE__*/ jsx(GridListOption, {
86
- ...virtualizer.itemProps(row.index),
87
- node: item,
83
+ }),
84
+ renderSection: (section, rows)=>/*#__PURE__*/ jsx(GridListSection, {
85
+ node: section.node,
88
86
  listState: listState,
89
- size: size
90
- }, item.key);
91
- }),
92
- !searchable && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
93
- children: sizeLimitMessage ?? t('Use search to find more options…')
94
- })
95
- ]
96
- })
87
+ rowProps: section.props,
88
+ showSeparator: section.node !== listItems[0],
89
+ children: rows
90
+ })
91
+ }),
92
+ !searchable && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
93
+ children: sizeLimitMessage ?? t('Use search to find more options…')
94
+ })
95
+ ]
97
96
  })
98
97
  })
99
98
  ]
@@ -1,3 +1,4 @@
1
+ import type * as React from 'react';
1
2
  import type { AriaGridListItemOptions } from '@react-aria/gridlist';
2
3
  import type { ListState } from '@react-stately/list';
3
4
  import type { Node } from '@react-types/shared';
@@ -7,9 +8,11 @@ export interface GridListOptionProps<T extends ListItemBase> extends AriaGridLis
7
8
  listState: ListState<T>;
8
9
  node: Node<T>;
9
10
  size: FormSize;
11
+ 'data-index'?: number;
12
+ ref?: React.Ref<HTMLLIElement>;
10
13
  }
11
14
  /**
12
15
  * A <li /> element with accessibile behaviors & attributes.
13
16
  * https://react-spectrum.adobe.com/react-aria/useGridList.html
14
17
  */
15
- export declare function GridListOption<T extends ListItemBase>({ node, listState, size, }: GridListOptionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
18
+ export declare function GridListOption<T extends ListItemBase>({ node, listState, size, ref: refProp, 'data-index': dataIndex, }: GridListOptionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -2,13 +2,13 @@ import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { Fragment, useContext, useMemo, useRef, useState } from "react";
3
3
  import { useGridListItem, useGridListSelectionCheckbox } from "@react-aria/gridlist";
4
4
  import { useFocusWithin, useHover } from "@react-aria/interactions";
5
- import { mergeProps } from "@react-aria/utils";
5
+ import { mergeProps, mergeRefs } from "@react-aria/utils";
6
6
  import { IconCheckmark } from "@sentry/icons/checkmark";
7
7
  import { Checkbox } from "../../checkbox/index.js";
8
8
  import { HighlightText } from "../highlightText.js";
9
9
  import { LeadWrap, getOptionPaddingLeft } from "../styles.js";
10
10
  import { ControlContext, ListItem, useReserveLeadingSlot } from "../../menu/index.js";
11
- function GridListOption({ node, listState, size }) {
11
+ function GridListOption({ node, listState, size, ref: refProp, 'data-index': dataIndex }) {
12
12
  const ref = useRef(null);
13
13
  const { label, details, trailingItems, priority, hideCheck, tooltip, tooltipOptions, selectionMode } = node.props;
14
14
  const multiple = selectionMode ? 'multiple' === selectionMode : 'multiple' === listState.selectionManager.selectionMode;
@@ -84,7 +84,8 @@ function GridListOption({ node, listState, size }) {
84
84
  ]);
85
85
  return /*#__PURE__*/ jsx(ListItem, {
86
86
  ...rowPropsMerged,
87
- ref: ref,
87
+ "data-index": dataIndex,
88
+ ref: mergeRefs(ref, refProp),
88
89
  size: size,
89
90
  label: renderedLabel,
90
91
  details: details,
@@ -1,15 +1,22 @@
1
+ import type * as React from 'react';
1
2
  import type { ListState } from '@react-stately/list';
2
3
  import type { Node } from '@react-types/shared';
3
4
  import type { ListItemBase } from '../types.js';
4
- import { type GridListOptionProps } from './option.js';
5
+ import type { VirtualRowProps } from '../../useVirtualCollection.js';
5
6
  interface GridListSectionProps<T extends ListItemBase> {
7
+ children: React.ReactNode;
6
8
  listState: ListState<T>;
7
9
  node: Node<T>;
8
- size: GridListOptionProps<T>['size'];
10
+ showSeparator: boolean;
11
+ /**
12
+ * Measurement props for the section's own row when the list is virtualized.
13
+ * The row holds the separator and header above the section's options.
14
+ */
15
+ rowProps?: VirtualRowProps;
9
16
  }
10
17
  /**
11
18
  * A <li /> element that functions as a grid list section (renders a nested <ul />
12
19
  * inside). https://react-spectrum.adobe.com/react-aria/useGridList.html
13
20
  */
14
- export declare function GridListSection<T extends ListItemBase>({ node, listState, size, }: GridListSectionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
21
+ export declare function GridListSection<T extends ListItemBase>({ children, node, listState, showSeparator, rowProps, }: GridListSectionProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
15
22
  export {};
@@ -1,37 +1,23 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { Fragment, useContext, useId, useMemo } from "react";
3
- import { useSeparator } from "@react-aria/separator";
4
- import { SelectFilterContext } from "../selectFilterContext.js";
2
+ import { useId } from "react";
5
3
  import { SectionSeparator } from "../styles.js";
6
4
  import { SectionToggle } from "../utils.js";
7
5
  import { SectionGroup, SectionHeader, SectionLabel, SectionList } from "../../menu/index.js";
8
- import { GridListOption } from "./option.js";
9
- function GridListSection({ node, listState, size }) {
6
+ function GridListSection({ children, node, listState, showSeparator, rowProps }) {
10
7
  const titleId = useId();
11
- const { separatorProps } = useSeparator({
12
- elementType: 'li'
13
- });
14
8
  const showToggleAllButton = 'multiple' === listState.selectionManager.selectionMode && node.value?.showToggleAllButton;
15
- const hiddenOptions = useContext(SelectFilterContext);
16
- const childNodes = useMemo(()=>[
17
- ...node.childNodes
18
- ].filter((child)=>!hiddenOptions.has(child.key)), [
19
- node.childNodes,
20
- hiddenOptions
21
- ]);
22
- return /*#__PURE__*/ jsxs(Fragment, {
9
+ return /*#__PURE__*/ jsxs(SectionGroup, {
10
+ role: "rowgroup",
11
+ ...node['aria-label'] ? {
12
+ 'aria-label': node['aria-label']
13
+ } : {
14
+ 'aria-labelledby': titleId
15
+ },
23
16
  children: [
24
- /*#__PURE__*/ jsx(SectionSeparator, {
25
- ...separatorProps
26
- }),
27
- /*#__PURE__*/ jsxs(SectionGroup, {
28
- role: "rowgroup",
29
- ...node['aria-label'] ? {
30
- 'aria-label': node['aria-label']
31
- } : {
32
- 'aria-labelledby': titleId
33
- },
17
+ /*#__PURE__*/ jsxs("div", {
18
+ ...rowProps,
34
19
  children: [
20
+ showSeparator && /*#__PURE__*/ jsx(SectionSeparator, {}),
35
21
  (node.rendered || showToggleAllButton) && /*#__PURE__*/ jsx(SectionHeader, {
36
22
  trailingAction: showToggleAllButton ? /*#__PURE__*/ jsx(SectionToggle, {
37
23
  item: node,
@@ -39,18 +25,15 @@ function GridListSection({ node, listState, size }) {
39
25
  }) : null,
40
26
  children: node.rendered && /*#__PURE__*/ jsx(SectionLabel, {
41
27
  id: titleId,
28
+ size: "md",
42
29
  "aria-hidden": true,
43
30
  children: node.rendered
44
31
  })
45
- }),
46
- /*#__PURE__*/ jsx(SectionList, {
47
- children: childNodes.map((child)=>/*#__PURE__*/ jsx(GridListOption, {
48
- node: child,
49
- listState: listState,
50
- size: size
51
- }, child.key))
52
32
  })
53
33
  ]
34
+ }),
35
+ /*#__PURE__*/ jsx(SectionList, {
36
+ children: children
54
37
  })
55
38
  ]
56
39
  });
@@ -66,7 +66,7 @@ interface ListBoxProps<T extends ListItemBase> extends Omit<React.HTMLAttributes
66
66
  */
67
67
  virtualized?: boolean;
68
68
  /**
69
- * Vertical padding (in px) added to the virtualizer height. Defaults to 4 (theme.space.xs).
69
+ * Vertical padding (in px) added to the virtualizer height. Defaults to ListWrap's padding, theme.space.xs.
70
70
  */
71
71
  virtualizedListPadding?: number;
72
72
  }
@@ -1,15 +1,14 @@
1
1
  import { jsx, jsxs } from "@emotion/react/jsx-runtime";
2
- import { createElement } from "@emotion/react";
2
+ import { createElement, useTheme } from "@emotion/react";
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
- import { getInteractionModality } from "@react-aria/interactions";
5
4
  import { useListBox } from "@react-aria/listbox";
6
5
  import { mergeProps, mergeRefs } from "@react-aria/utils";
7
6
  import { ListLabel, ListSeparator, ListWrap, SizeLimitMessage } from "../styles.js";
8
- import { useVirtualizedItems } from "../useVirtualizedItems.js";
9
7
  import { hasVisibleLeadingItems } from "../utils.js";
10
8
  import { Container } from "../../layout/index.js";
11
9
  import { ReserveLeadingSlot } from "../../menu/index.js";
12
10
  import { useTranslation } from "../../translation/index.js";
11
+ import { VirtualRows, useVirtualCollection } from "../../useVirtualCollection.js";
13
12
  import { ListBoxDetailsHoverContext, ListBoxOption } from "./option.js";
14
13
  import { ListBoxSection } from "./section.js";
15
14
  const EMPTY_SET = new Set();
@@ -17,10 +16,11 @@ const DETAILS_CLOSE_DELAY = 150;
17
16
  const DEFAULT_KEY_DOWN_HANDLER = ()=>true;
18
17
  function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = true, shouldFocusOnHover = true, sizeLimitMessage, keyDownHandler = DEFAULT_KEY_DOWN_HANDLER, label, hiddenOptions = EMPTY_SET, hasSearch, searchable, overlayIsOpen, showSectionHeaders = true, showDetails = true, onAction, virtualized, virtualizedListPadding, scrollContainerRef, className, ...props }) {
19
18
  const { t } = useTranslation();
19
+ const theme = useTheme();
20
20
  const listElementRef = useRef(null);
21
21
  const scrollElementRef = useRef(null);
22
22
  const [hasEverOverflowed, setHasEverOverflowed] = useState(false);
23
- const { listBoxProps, labelProps } = useListBox({
23
+ const listBoxOptions = {
24
24
  ...props,
25
25
  scrollRef: scrollElementRef,
26
26
  autoFocus,
@@ -29,7 +29,8 @@ function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = tru
29
29
  shouldFocusOnHover,
30
30
  shouldSelectOnPressUp: true,
31
31
  onAction
32
- }, listState, listElementRef);
32
+ };
33
+ const { listBoxProps, labelProps } = useListBox(listBoxOptions, listState, listElementRef);
33
34
  const onKeyDown = (e)=>{
34
35
  const continueCallback = keyDownHandler?.(e);
35
36
  if (continueCallback && 'Escape' !== e.key) listBoxProps.onKeyDown?.(e);
@@ -79,31 +80,26 @@ function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = tru
79
80
  mergedProps.onMouseEnter?.(e);
80
81
  cancelFocusClear();
81
82
  };
82
- const virtualizer = useVirtualizedItems({
83
- listItems,
84
- virtualized,
85
- size,
86
- listPadding: virtualizedListPadding
83
+ const virtual = useVirtualCollection({
84
+ collection: listItems,
85
+ enabled: !!virtualized,
86
+ scrollRef: scrollElementRef,
87
+ focusedKey: listState.selectionManager.focusedKey,
88
+ hiddenKeys: hiddenOptions,
89
+ listPadding: virtualizedListPadding ?? parseFloat(theme.space.xs),
90
+ size
87
91
  });
88
- useEffect(()=>{
89
- if (!virtualized || null === listState.selectionManager.focusedKey || 'pointer' === getInteractionModality()) return;
90
- const focusedIndex = listItems.findIndex((item)=>item.key === listState.selectionManager.focusedKey);
91
- if (-1 !== focusedIndex) virtualizer.scrollToIndex(focusedIndex);
92
- }, [
93
- virtualized,
94
- listItems,
95
- listState.selectionManager.focusedKey,
96
- virtualizer
97
- ]);
98
92
  const refs = useMemo(()=>{
99
93
  const overflowTracker = (scrollContainer)=>{
100
94
  if (hasEverOverflowed || 0 === listItems.length || !scrollContainer) return;
101
- setHasEverOverflowed(scrollContainer.scrollHeight > scrollContainer.clientHeight);
95
+ requestAnimationFrame(()=>{
96
+ const overflowed = scrollContainer.scrollHeight - scrollContainer.clientHeight > 1;
97
+ setHasEverOverflowed((prev)=>prev || overflowed);
98
+ });
102
99
  };
103
- return mergeRefs(scrollElementRef, overflowTracker, virtualizer.scrollElementRef, scrollContainerRef);
100
+ return mergeRefs(scrollElementRef, overflowTracker, scrollContainerRef);
104
101
  }, [
105
102
  hasEverOverflowed,
106
- virtualizer.scrollElementRef,
107
103
  listItems,
108
104
  scrollContainerRef
109
105
  ]);
@@ -121,51 +117,43 @@ function ListBox({ ref, listState, autoFocus, size = 'md', shouldFocusWrap = tru
121
117
  }),
122
118
  /*#__PURE__*/ jsx(Container, {
123
119
  ref: refs,
120
+ "data-test-id": "compact-select-scroll-container",
124
121
  height: "100%",
125
122
  overflowY: "auto",
126
123
  className: className,
127
124
  style: hasEverOverflowed ? {
128
125
  scrollbarGutter: 'stable'
129
126
  } : void 0,
130
- children: /*#__PURE__*/ jsx(Container, {
131
- ...virtualizer.wrapperProps,
132
- children: /*#__PURE__*/ jsxs(ListWrap, {
133
- ...mergedProps,
134
- style: {
135
- ...mergedProps.style,
136
- ...virtualizer.listWrapStyle
137
- },
138
- onKeyDown: onKeyDown,
139
- onMouseEnter: onMouseEnter,
140
- onMouseLeave: onMouseLeave,
141
- ref: mergeRefs(listElementRef, ref),
142
- children: [
143
- overlayIsOpen && virtualizer.items.map((row)=>{
144
- const item = listItems[row.index];
145
- if (!item) return null;
146
- if ('section' === item.type) return /*#__PURE__*/ createElement(ListBoxSection, {
147
- ...virtualizer.itemProps(row.index),
148
- key: item.key,
149
- item: item,
127
+ children: /*#__PURE__*/ jsxs(ListWrap, {
128
+ ...mergedProps,
129
+ onKeyDown: onKeyDown,
130
+ onMouseEnter: onMouseEnter,
131
+ onMouseLeave: onMouseLeave,
132
+ ref: mergeRefs(listElementRef, ref),
133
+ children: [
134
+ overlayIsOpen && /*#__PURE__*/ jsx(VirtualRows, {
135
+ virtual: virtual,
136
+ renderRow: ({ node, props: rowProps })=>/*#__PURE__*/ createElement(ListBoxOption, {
137
+ ...rowProps,
138
+ key: node.key,
139
+ item: node,
150
140
  listState: listState,
151
- hiddenOptions: hiddenOptions,
152
141
  size: size,
153
- showSectionHeaders: showSectionHeaders,
154
142
  showDetails: showDetails
155
- });
156
- return /*#__PURE__*/ jsx(ListBoxOption, {
157
- ...virtualizer.itemProps(row.index),
158
- item: item,
143
+ }),
144
+ renderSection: (section, rows)=>/*#__PURE__*/ jsx(ListBoxSection, {
145
+ item: section.node,
159
146
  listState: listState,
160
- size: size,
161
- showDetails: showDetails
162
- }, item.key);
163
- }),
164
- !searchable && !hasSearch && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
165
- children: sizeLimitMessage ?? t('Use search to find more options…')
166
- })
167
- ]
168
- })
147
+ rowProps: section.props,
148
+ showSectionHeaders: showSectionHeaders,
149
+ showSeparator: section.node !== listItems[0],
150
+ children: rows
151
+ })
152
+ }),
153
+ !searchable && !hasSearch && hiddenOptions.size > 0 && /*#__PURE__*/ jsx(SizeLimitMessage, {
154
+ children: sizeLimitMessage ?? t('Use search to find more options…')
155
+ })
156
+ ]
169
157
  })
170
158
  })
171
159
  ]