@sybilion/uilib 1.4.37 → 1.4.40

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 (101) hide show
  1. package/dist/agent-glossary/workspace.generated.ts +1 -0
  2. package/dist/agent-glossary/workspace.index.md +1 -0
  3. package/dist/agent-glossary/workspace.md +1 -0
  4. package/dist/esm/src/components/ui/Banner/Banner.styl.js +1 -1
  5. package/dist/esm/src/components/ui/Chart/Chart.js +1 -2
  6. package/dist/esm/src/components/ui/Dialog/Dialog.styl.js +1 -1
  7. package/dist/esm/src/components/ui/Drawer/Drawer.styl.js +1 -1
  8. package/dist/esm/src/components/ui/DropdownMenu/DropdownMenu.styl.js +1 -1
  9. package/dist/esm/src/components/ui/MobileAdaptiveSelector/MobileAdaptiveSelector.styl.js +1 -1
  10. package/dist/esm/src/components/ui/Page/PageHeader/PageHeader.styl.js +1 -1
  11. package/dist/esm/src/components/ui/Select/Select.js +313 -5
  12. package/dist/esm/src/components/ui/Select/Select.styl.js +2 -2
  13. package/dist/esm/src/components/ui/Sheet/Sheet.styl.js +1 -1
  14. package/dist/esm/src/components/ui/SupplyChainMap/SupplyChainMap.js +384 -0
  15. package/dist/esm/src/components/ui/SupplyChainMap/SupplyChainMap.styl.js +7 -0
  16. package/dist/esm/src/components/ui/SupplyChainMap/map-colors.js +44 -0
  17. package/dist/esm/src/components/ui/SupplyChainMap/map-disclosure.js +142 -0
  18. package/dist/esm/src/components/ui/SupplyChainMap/map-labels.js +55 -0
  19. package/dist/esm/src/components/ui/SupplyChainMap/map-projection.js +186 -0
  20. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-clusters.js +96 -0
  21. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-draw.js +66 -0
  22. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-scene.js +59 -0
  23. package/dist/esm/src/components/ui/SupplyChainMap/supply-chain-map-types.js +10 -0
  24. package/dist/esm/src/components/ui/SupplyChainMap/use-map-base-renderer.js +122 -0
  25. package/dist/esm/src/components/ui/Table/Table.styl.js +1 -1
  26. package/dist/esm/src/components/ui/Tabs/Tabs.styl.js +1 -1
  27. package/dist/esm/src/components/ui/Tooltip/Tooltip.styl.js +1 -1
  28. package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +1 -2
  29. package/dist/esm/src/index.js +2 -0
  30. package/dist/esm/types/src/components/ui/Select/Select.d.ts +3 -3
  31. package/dist/esm/types/src/components/ui/Select/Select.types.d.ts +3 -1
  32. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.contract.test.d.ts +1 -0
  33. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.d.ts +2 -0
  34. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.example.d.ts +1 -0
  35. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.d.ts +15 -0
  36. package/dist/esm/types/src/components/ui/SupplyChainMap/SupplyChainMap.types.d.ts +10 -0
  37. package/dist/esm/types/src/components/ui/SupplyChainMap/index.d.ts +3 -0
  38. package/dist/esm/types/src/components/ui/SupplyChainMap/map-colors.d.ts +43 -0
  39. package/dist/esm/types/src/components/ui/SupplyChainMap/map-disclosure.d.ts +35 -0
  40. package/dist/esm/types/src/components/ui/SupplyChainMap/map-disclosure.test.d.ts +1 -0
  41. package/dist/esm/types/src/components/ui/SupplyChainMap/map-labels.d.ts +14 -0
  42. package/dist/esm/types/src/components/ui/SupplyChainMap/map-labels.test.d.ts +1 -0
  43. package/dist/esm/types/src/components/ui/SupplyChainMap/map-projection.d.ts +83 -0
  44. package/dist/esm/types/src/components/ui/SupplyChainMap/map-projection.test.d.ts +1 -0
  45. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-clusters.d.ts +25 -0
  46. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-clusters.test.d.ts +1 -0
  47. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-draw.d.ts +30 -0
  48. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-scene.d.ts +28 -0
  49. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-scene.test.d.ts +1 -0
  50. package/dist/esm/types/src/components/ui/SupplyChainMap/supply-chain-map-types.d.ts +31 -0
  51. package/dist/esm/types/src/components/ui/SupplyChainMap/use-map-base-renderer.d.ts +14 -0
  52. package/dist/esm/types/src/docs/pages/BannerPage.d.ts +1 -0
  53. package/dist/esm/types/src/docs/pages/SupplyChainMapPage.d.ts +1 -0
  54. package/dist/esm/types/src/index.d.ts +1 -0
  55. package/dist/esm/types/src/lib/logger.d.ts +1 -0
  56. package/package.json +7 -1
  57. package/src/components/ui/Banner/Banner.styl +1 -1
  58. package/src/components/ui/Dialog/Dialog.styl +2 -2
  59. package/src/components/ui/Drawer/Drawer.styl +2 -2
  60. package/src/components/ui/DropdownMenu/DropdownMenu.styl +2 -2
  61. package/src/components/ui/MobileAdaptiveSelector/MobileAdaptiveSelector.styl +1 -1
  62. package/src/components/ui/Page/PageHeader/PageHeader.styl +1 -1
  63. package/src/components/ui/Select/AGENT.md +3 -1
  64. package/src/components/ui/Select/Select.styl +31 -0
  65. package/src/components/ui/Select/Select.styl.d.ts +28 -25
  66. package/src/components/ui/Select/Select.tsx +506 -4
  67. package/src/components/ui/Select/Select.types.ts +3 -1
  68. package/src/components/ui/Sheet/Sheet.styl +2 -2
  69. package/src/components/ui/SupplyChainMap/AGENT.md +45 -0
  70. package/src/components/ui/SupplyChainMap/SupplyChainMap.contract.test.ts +45 -0
  71. package/src/components/ui/SupplyChainMap/SupplyChainMap.example.tsx +176 -0
  72. package/src/components/ui/SupplyChainMap/SupplyChainMap.render.worker.ts +63 -0
  73. package/src/components/ui/SupplyChainMap/SupplyChainMap.styl +221 -0
  74. package/src/components/ui/SupplyChainMap/SupplyChainMap.styl.d.ts +25 -0
  75. package/src/components/ui/SupplyChainMap/SupplyChainMap.tsx +720 -0
  76. package/src/components/ui/SupplyChainMap/SupplyChainMap.types.ts +15 -0
  77. package/src/components/ui/SupplyChainMap/index.ts +11 -0
  78. package/src/components/ui/SupplyChainMap/map-colors.ts +66 -0
  79. package/src/components/ui/SupplyChainMap/map-disclosure.test.ts +237 -0
  80. package/src/components/ui/SupplyChainMap/map-disclosure.ts +226 -0
  81. package/src/components/ui/SupplyChainMap/map-labels.test.ts +102 -0
  82. package/src/components/ui/SupplyChainMap/map-labels.ts +85 -0
  83. package/src/components/ui/SupplyChainMap/map-projection.test.ts +172 -0
  84. package/src/components/ui/SupplyChainMap/map-projection.ts +281 -0
  85. package/src/components/ui/SupplyChainMap/supply-chain-map-clusters.test.ts +182 -0
  86. package/src/components/ui/SupplyChainMap/supply-chain-map-clusters.ts +127 -0
  87. package/src/components/ui/SupplyChainMap/supply-chain-map-draw.ts +114 -0
  88. package/src/components/ui/SupplyChainMap/supply-chain-map-scene.test.ts +196 -0
  89. package/src/components/ui/SupplyChainMap/supply-chain-map-scene.ts +118 -0
  90. package/src/components/ui/SupplyChainMap/supply-chain-map-types.ts +45 -0
  91. package/src/components/ui/SupplyChainMap/use-map-base-renderer.ts +145 -0
  92. package/src/components/ui/Table/Table.styl +3 -3
  93. package/src/components/ui/Tabs/Tabs.styl +1 -0
  94. package/src/components/ui/Tooltip/Tooltip.styl +7 -2
  95. package/src/declarations.d.ts +4 -0
  96. package/src/docs/pages/BannerPage.tsx +83 -0
  97. package/src/docs/pages/FeedbackOverviewPage.tsx +7 -1
  98. package/src/docs/pages/SelectPage.tsx +30 -1
  99. package/src/docs/pages/SupplyChainMapPage.tsx +21 -0
  100. package/src/docs/registry.ts +12 -0
  101. package/src/index.ts +1 -0
@@ -1,31 +1,34 @@
1
1
  // This file is automatically generated.
2
2
  // Please do not change this file!
3
3
  interface CssExports {
4
- 'clear': string;
5
- 'darker': string;
6
- 'fadeIn': string;
7
- 'fadeOut': string;
8
- 'selectContent': string;
9
- 'selectContentPopper': string;
10
- 'selectIcon': string;
11
- 'selectItem': string;
12
- 'selectItemIndicator': string;
13
- 'selectItemIndicatorContainer': string;
14
- 'selectItemText': string;
15
- 'selectLabel': string;
16
- 'selectScrollButton': string;
17
- 'selectScrollIcon': string;
18
- 'selectSeparator': string;
19
- 'selectTrigger': string;
20
- 'selectViewport': string;
21
- 'selectViewportPopper': string;
22
- 'selected': string;
23
- 'slideInFromBottom': string;
24
- 'slideInFromLeft': string;
25
- 'slideInFromRight': string;
26
- 'slideInFromTop': string;
27
- 'zoomIn': string;
28
- 'zoomOut': string;
4
+ clear: string;
5
+ darker: string;
6
+ fadeIn: string;
7
+ fadeOut: string;
8
+ searchable: string;
9
+ selectContent: string;
10
+ selectContentPopper: string;
11
+ selectEmpty: string;
12
+ selectIcon: string;
13
+ selectItem: string;
14
+ selectItemIndicator: string;
15
+ selectItemIndicatorContainer: string;
16
+ selectItemText: string;
17
+ selectLabel: string;
18
+ selectScrollButton: string;
19
+ selectScrollIcon: string;
20
+ selectSeparator: string;
21
+ selectTrigger: string;
22
+ selectTriggerInput: string;
23
+ selectViewport: string;
24
+ selectViewportPopper: string;
25
+ selected: string;
26
+ slideInFromBottom: string;
27
+ slideInFromLeft: string;
28
+ slideInFromRight: string;
29
+ slideInFromTop: string;
30
+ zoomIn: string;
31
+ zoomOut: string;
29
32
  }
30
33
  export const cssExports: CssExports;
31
34
  export default cssExports;
@@ -1,14 +1,15 @@
1
1
  import cn from 'classnames';
2
+ import * as React from 'react';
3
+ import { createPortal } from 'react-dom';
2
4
 
3
5
  import * as SelectPrimitive from '@radix-ui/react-select';
4
- import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
6
+ import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react';
5
7
 
6
8
  import S from './Select.styl';
7
9
  import type {
8
10
  SelectContentProps,
9
11
  SelectGroupProps,
10
12
  SelectItemProps,
11
- SelectLabelProps,
12
13
  SelectProps,
13
14
  SelectScrollDownButtonProps,
14
15
  SelectScrollUpButtonProps,
@@ -17,10 +18,203 @@ import type {
17
18
  SelectValueProps,
18
19
  } from './Select.types';
19
20
 
21
+ type SearchableContextValue = {
22
+ open: boolean;
23
+ setOpen: (open: boolean) => void;
24
+ query: string;
25
+ setQuery: (query: string) => void;
26
+ dirty: boolean;
27
+ setDirty: (dirty: boolean) => void;
28
+ value?: string;
29
+ commitValue: (value: string) => void;
30
+ disabled?: boolean;
31
+ placeholder: string;
32
+ setPlaceholder: (placeholder: string) => void;
33
+ selectedLabel: string;
34
+ registerItem: (value: string, text: string) => void;
35
+ unregisterItem: (value: string) => void;
36
+ highlighted: string | null;
37
+ setHighlighted: (value: string | null) => void;
38
+ visibleValues: string[];
39
+ triggerRef: React.RefObject<HTMLDivElement | null>;
40
+ contentRef: React.RefObject<HTMLDivElement | null>;
41
+ listId: string;
42
+ };
43
+
44
+ const SearchableContext = React.createContext<SearchableContextValue | null>(
45
+ null,
46
+ );
47
+
48
+ function extractText(node: React.ReactNode): string {
49
+ if (node == null || typeof node === 'boolean') return '';
50
+ if (typeof node === 'string' || typeof node === 'number') return String(node);
51
+ if (Array.isArray(node)) return node.map(extractText).join('');
52
+ if (React.isValidElement<{ children?: React.ReactNode }>(node)) {
53
+ return extractText(node.props.children);
54
+ }
55
+ return '';
56
+ }
57
+
58
+ function SearchableSelectRoot({
59
+ value: valueProp,
60
+ defaultValue,
61
+ onValueChange,
62
+ open: openProp,
63
+ onOpenChange,
64
+ disabled,
65
+ children,
66
+ }: Pick<
67
+ SelectProps,
68
+ | 'value'
69
+ | 'defaultValue'
70
+ | 'onValueChange'
71
+ | 'open'
72
+ | 'onOpenChange'
73
+ | 'disabled'
74
+ | 'children'
75
+ >) {
76
+ const listId = React.useId();
77
+ const triggerRef = React.useRef<HTMLDivElement>(null);
78
+ const contentRef = React.useRef<HTMLDivElement>(null);
79
+ const [items, setItems] = React.useState<Record<string, string>>({});
80
+ const [placeholder, setPlaceholder] = React.useState('');
81
+ const [dirty, setDirty] = React.useState(false);
82
+ const [highlighted, setHighlighted] = React.useState<string | null>(null);
83
+
84
+ const [uncontrolledValue, setUncontrolledValue] = React.useState(
85
+ defaultValue ?? '',
86
+ );
87
+ const isValueControlled = valueProp !== undefined;
88
+ const value = isValueControlled ? valueProp : uncontrolledValue;
89
+
90
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
91
+ const isOpenControlled = openProp !== undefined;
92
+ const open = isOpenControlled ? Boolean(openProp) : uncontrolledOpen;
93
+
94
+ const setOpen = React.useCallback(
95
+ (next: boolean) => {
96
+ if (!isOpenControlled) setUncontrolledOpen(next);
97
+ onOpenChange?.(next);
98
+ },
99
+ [isOpenControlled, onOpenChange],
100
+ );
101
+
102
+ const commitValue = React.useCallback(
103
+ (next: string) => {
104
+ if (!isValueControlled) setUncontrolledValue(next);
105
+ onValueChange?.(next);
106
+ },
107
+ [isValueControlled, onValueChange],
108
+ );
109
+
110
+ const selectedLabel = (value && items[value]) || '';
111
+ const [query, setQuery] = React.useState(selectedLabel);
112
+
113
+ React.useEffect(() => {
114
+ if (!dirty) setQuery(selectedLabel);
115
+ }, [selectedLabel, dirty]);
116
+
117
+ const registerItem = React.useCallback((itemValue: string, text: string) => {
118
+ setItems(prev =>
119
+ prev[itemValue] === text ? prev : { ...prev, [itemValue]: text },
120
+ );
121
+ }, []);
122
+
123
+ const unregisterItem = React.useCallback((itemValue: string) => {
124
+ setItems(prev => {
125
+ if (!(itemValue in prev)) return prev;
126
+ const next = { ...prev };
127
+ delete next[itemValue];
128
+ return next;
129
+ });
130
+ }, []);
131
+
132
+ const filter = dirty ? query.trim().toLowerCase() : '';
133
+ const visibleValues = React.useMemo(() => {
134
+ const entries = Object.entries(items);
135
+ const matched = filter
136
+ ? entries.filter(([, text]) => text.toLowerCase().includes(filter))
137
+ : entries;
138
+ return matched.map(([itemValue]) => itemValue);
139
+ }, [items, filter]);
140
+
141
+ React.useEffect(() => {
142
+ if (!open) return;
143
+ setHighlighted(current =>
144
+ current && visibleValues.includes(current)
145
+ ? current
146
+ : (visibleValues[0] ?? null),
147
+ );
148
+ }, [open, visibleValues]);
149
+
150
+ const ctx = React.useMemo<SearchableContextValue>(
151
+ () => ({
152
+ open,
153
+ setOpen,
154
+ query,
155
+ setQuery,
156
+ dirty,
157
+ setDirty,
158
+ value,
159
+ commitValue,
160
+ disabled,
161
+ placeholder,
162
+ setPlaceholder,
163
+ selectedLabel,
164
+ registerItem,
165
+ unregisterItem,
166
+ highlighted,
167
+ setHighlighted,
168
+ visibleValues,
169
+ triggerRef,
170
+ contentRef,
171
+ listId,
172
+ }),
173
+ [
174
+ open,
175
+ setOpen,
176
+ query,
177
+ dirty,
178
+ value,
179
+ commitValue,
180
+ disabled,
181
+ placeholder,
182
+ selectedLabel,
183
+ registerItem,
184
+ unregisterItem,
185
+ highlighted,
186
+ visibleValues,
187
+ listId,
188
+ ],
189
+ );
190
+
191
+ return (
192
+ <SearchableContext.Provider value={ctx}>
193
+ {children}
194
+ </SearchableContext.Provider>
195
+ );
196
+ }
197
+
20
198
  function Select({
21
199
  variant = 'default',
200
+ searchable = false,
22
201
  ...props
23
202
  }: SelectProps & { variant?: 'default' | 'clear' }) {
203
+ if (searchable) {
204
+ return (
205
+ <SearchableSelectRoot
206
+ value={props.value}
207
+ defaultValue={props.defaultValue}
208
+ onValueChange={props.onValueChange}
209
+ open={props.open}
210
+ onOpenChange={props.onOpenChange}
211
+ disabled={props.disabled}
212
+ >
213
+ {props.children}
214
+ </SearchableSelectRoot>
215
+ );
216
+ }
217
+
24
218
  return (
25
219
  <SelectPrimitive.Root
26
220
  data-slot="select"
@@ -31,11 +225,164 @@ function Select({
31
225
  }
32
226
 
33
227
  function SelectGroup({ ...props }: SelectGroupProps) {
228
+ const searchable = React.useContext(SearchableContext);
229
+ if (searchable) {
230
+ return <div data-slot="select-group" {...props} />;
231
+ }
34
232
  return <SelectPrimitive.Group data-slot="select-group" {...props} />;
35
233
  }
36
234
 
37
- function SelectValue({ ...props }: SelectValueProps) {
38
- return <SelectPrimitive.Value data-slot="select-value" {...props} />;
235
+ function SelectValue({ placeholder, ...props }: SelectValueProps) {
236
+ const searchable = React.useContext(SearchableContext);
237
+ React.useEffect(() => {
238
+ if (!searchable) return;
239
+ searchable.setPlaceholder(
240
+ typeof placeholder === 'string' ? placeholder : extractText(placeholder),
241
+ );
242
+ }, [searchable, placeholder]);
243
+
244
+ if (searchable) return null;
245
+
246
+ return (
247
+ <SelectPrimitive.Value
248
+ data-slot="select-value"
249
+ placeholder={placeholder}
250
+ {...props}
251
+ />
252
+ );
253
+ }
254
+
255
+ function SearchableTrigger({
256
+ className,
257
+ size = 'md',
258
+ variant = 'default',
259
+ darker = false,
260
+ hideChevron = false,
261
+ disabled: disabledProp,
262
+ style,
263
+ id,
264
+ }: SelectTriggerProps) {
265
+ const ctx = React.useContext(SearchableContext);
266
+ const inputRef = React.useRef<HTMLInputElement>(null);
267
+ const selectAllOnFocus = React.useRef(false);
268
+ React.useLayoutEffect(() => {
269
+ if (!selectAllOnFocus.current) return;
270
+ inputRef.current?.select();
271
+ });
272
+ if (!ctx) return null;
273
+
274
+ const disabled = disabledProp ?? ctx.disabled;
275
+ const displayValue = ctx.open && ctx.dirty ? ctx.query : ctx.selectedLabel;
276
+
277
+ const closeAndReset = () => {
278
+ ctx.setOpen(false);
279
+ ctx.setDirty(false);
280
+ ctx.setQuery(ctx.selectedLabel);
281
+ };
282
+
283
+ const moveHighlight = (delta: number) => {
284
+ if (ctx.visibleValues.length === 0) return;
285
+ const current = ctx.highlighted
286
+ ? ctx.visibleValues.indexOf(ctx.highlighted)
287
+ : -1;
288
+ const nextIndex =
289
+ delta > 0
290
+ ? Math.min(ctx.visibleValues.length - 1, current + 1)
291
+ : Math.max(0, current < 0 ? ctx.visibleValues.length - 1 : current - 1);
292
+ ctx.setHighlighted(ctx.visibleValues[nextIndex] ?? null);
293
+ };
294
+
295
+ return (
296
+ <div
297
+ ref={ctx.triggerRef}
298
+ data-slot="select-trigger"
299
+ data-size={size}
300
+ data-variant={variant}
301
+ data-placeholder={!displayValue || undefined}
302
+ className={cn(
303
+ S.selectTrigger,
304
+ S.searchable,
305
+ darker && S.darker,
306
+ variant === 'clear' && S.clear,
307
+ className,
308
+ )}
309
+ style={style}
310
+ >
311
+ <input
312
+ ref={inputRef}
313
+ id={id}
314
+ className={S.selectTriggerInput}
315
+ role="combobox"
316
+ aria-expanded={ctx.open}
317
+ aria-controls={ctx.listId}
318
+ aria-autocomplete="list"
319
+ aria-activedescendant={
320
+ ctx.open && ctx.highlighted
321
+ ? `${ctx.listId}-${ctx.highlighted}`
322
+ : undefined
323
+ }
324
+ disabled={disabled}
325
+ placeholder={ctx.placeholder}
326
+ value={displayValue}
327
+ autoComplete="off"
328
+ onFocus={event => {
329
+ if (disabled) return;
330
+ ctx.setOpen(true);
331
+ selectAllOnFocus.current = true;
332
+ event.currentTarget.select();
333
+ window.setTimeout(() => {
334
+ selectAllOnFocus.current = false;
335
+ }, 0);
336
+ }}
337
+ onMouseUp={event => {
338
+ if (!selectAllOnFocus.current) return;
339
+ selectAllOnFocus.current = false;
340
+ event.currentTarget.select();
341
+ }}
342
+ onClick={() => {
343
+ if (disabled) return;
344
+ ctx.setOpen(true);
345
+ }}
346
+ onChange={event => {
347
+ selectAllOnFocus.current = false;
348
+ ctx.setDirty(true);
349
+ ctx.setQuery(event.target.value);
350
+ ctx.setOpen(true);
351
+ }}
352
+ onKeyDown={event => {
353
+ if (disabled) return;
354
+ if (event.key === 'ArrowDown') {
355
+ event.preventDefault();
356
+ if (!ctx.open) ctx.setOpen(true);
357
+ else moveHighlight(1);
358
+ } else if (event.key === 'ArrowUp') {
359
+ event.preventDefault();
360
+ if (!ctx.open) ctx.setOpen(true);
361
+ else moveHighlight(-1);
362
+ } else if (event.key === 'Enter') {
363
+ event.preventDefault();
364
+ if (ctx.highlighted) {
365
+ ctx.commitValue(ctx.highlighted);
366
+ ctx.setDirty(false);
367
+ ctx.setOpen(false);
368
+ }
369
+ } else if (event.key === 'Escape') {
370
+ event.preventDefault();
371
+ closeAndReset();
372
+ } else if (event.key === 'Home' && ctx.open) {
373
+ event.preventDefault();
374
+ ctx.setHighlighted(ctx.visibleValues[0] ?? null);
375
+ } else if (event.key === 'End' && ctx.open) {
376
+ event.preventDefault();
377
+ ctx.setHighlighted(
378
+ ctx.visibleValues[ctx.visibleValues.length - 1] ?? null,
379
+ );
380
+ }
381
+ }}
382
+ />
383
+ {!hideChevron && <ChevronDownIcon className={S.selectIcon} />}
384
+ </div>
385
+ );
39
386
  }
40
387
 
41
388
  function SelectTrigger({
@@ -48,6 +395,23 @@ function SelectTrigger({
48
395
  asChild = false,
49
396
  ...props
50
397
  }: SelectTriggerProps) {
398
+ const searchable = React.useContext(SearchableContext);
399
+ if (searchable) {
400
+ return (
401
+ <>
402
+ {children}
403
+ <SearchableTrigger
404
+ className={className}
405
+ size={size}
406
+ variant={variant}
407
+ darker={darker}
408
+ hideChevron={hideChevron}
409
+ {...props}
410
+ />
411
+ </>
412
+ );
413
+ }
414
+
51
415
  return (
52
416
  <SelectPrimitive.Trigger
53
417
  data-slot="select-trigger"
@@ -78,12 +442,92 @@ function SelectTrigger({
78
442
  );
79
443
  }
80
444
 
445
+ function SearchableContent({ className, children }: SelectContentProps) {
446
+ const ctx = React.useContext(SearchableContext);
447
+ const [coords, setCoords] = React.useState({ top: 0, left: 0, width: 0 });
448
+
449
+ const updateCoords = React.useCallback(() => {
450
+ const el = ctx?.triggerRef.current;
451
+ if (!el) return;
452
+ const rect = el.getBoundingClientRect();
453
+ setCoords({ top: rect.bottom + 4, left: rect.left, width: rect.width });
454
+ }, [ctx]);
455
+
456
+ React.useLayoutEffect(() => {
457
+ if (!ctx?.open) return;
458
+ updateCoords();
459
+ window.addEventListener('resize', updateCoords);
460
+ window.addEventListener('scroll', updateCoords, true);
461
+ return () => {
462
+ window.removeEventListener('resize', updateCoords);
463
+ window.removeEventListener('scroll', updateCoords, true);
464
+ };
465
+ }, [ctx?.open, updateCoords]);
466
+
467
+ React.useEffect(() => {
468
+ if (!ctx?.open) return;
469
+ const onPointerDown = (event: PointerEvent) => {
470
+ const target = event.target as Node;
471
+ if (ctx.triggerRef.current?.contains(target)) return;
472
+ if (ctx.contentRef.current?.contains(target)) return;
473
+ ctx.setOpen(false);
474
+ ctx.setDirty(false);
475
+ ctx.setQuery(ctx.selectedLabel);
476
+ };
477
+ document.addEventListener('pointerdown', onPointerDown);
478
+ return () => document.removeEventListener('pointerdown', onPointerDown);
479
+ }, [ctx]);
480
+
481
+ if (!ctx) return null;
482
+
483
+ return createPortal(
484
+ <div
485
+ ref={ctx.contentRef}
486
+ id={ctx.listId}
487
+ role="listbox"
488
+ data-slot="select-content"
489
+ data-state={ctx.open ? 'open' : 'closed'}
490
+ hidden={!ctx.open}
491
+ aria-hidden={!ctx.open}
492
+ className={cn(S.selectContent, S.selectContentPopper, className)}
493
+ style={
494
+ ctx.open
495
+ ? {
496
+ position: 'fixed',
497
+ top: coords.top,
498
+ left: coords.left,
499
+ minWidth: coords.width,
500
+ zIndex: 1100,
501
+ }
502
+ : { display: 'none' }
503
+ }
504
+ >
505
+ <div className={S.selectViewport}>
506
+ {children}
507
+ {ctx.visibleValues.length === 0 && (
508
+ <div className={S.selectEmpty}>No results</div>
509
+ )}
510
+ </div>
511
+ </div>,
512
+ document.body,
513
+ );
514
+ }
515
+
81
516
  function SelectContent({
82
517
  className,
83
518
  children,
84
519
  position = 'popper',
85
520
  ...props
86
521
  }: SelectContentProps) {
522
+ const searchable = React.useContext(SearchableContext);
523
+ if (searchable) {
524
+ return (
525
+ <SearchableContent className={className} {...props}>
526
+ {children}
527
+ </SearchableContent>
528
+ );
529
+ }
530
+
87
531
  return (
88
532
  <SelectPrimitive.Portal>
89
533
  <SelectPrimitive.Content
@@ -116,12 +560,60 @@ function SelectItem({
116
560
  className,
117
561
  children,
118
562
  selected,
563
+ value,
564
+ disabled,
565
+ textValue,
119
566
  ...props
120
567
  }: SelectItemProps) {
568
+ const searchable = React.useContext(SearchableContext);
569
+ const text = textValue || extractText(children);
570
+ const registerItem = searchable?.registerItem;
571
+ const unregisterItem = searchable?.unregisterItem;
572
+
573
+ React.useEffect(() => {
574
+ if (!registerItem || !unregisterItem) return;
575
+ registerItem(value, text);
576
+ return () => unregisterItem(value);
577
+ }, [registerItem, unregisterItem, value, text]);
578
+
579
+ if (searchable) {
580
+ const visible = searchable.visibleValues.includes(value);
581
+ if (!visible) return null;
582
+ const isHighlighted = searchable.highlighted === value;
583
+ const isSelected = selected || searchable.value === value;
584
+ return (
585
+ <div
586
+ {...props}
587
+ id={`${searchable.listId}-${value}`}
588
+ role="option"
589
+ data-slot="select-item"
590
+ data-highlighted={isHighlighted || undefined}
591
+ aria-selected={isSelected}
592
+ aria-disabled={disabled || undefined}
593
+ className={cn(S.selectItem, className, isSelected && S.selected)}
594
+ onPointerDown={event => {
595
+ event.preventDefault();
596
+ if (disabled) return;
597
+ searchable.commitValue(value);
598
+ searchable.setDirty(false);
599
+ searchable.setOpen(false);
600
+ }}
601
+ onMouseEnter={() => {
602
+ if (!disabled) searchable.setHighlighted(value);
603
+ }}
604
+ >
605
+ {children}
606
+ </div>
607
+ );
608
+ }
609
+
121
610
  return (
122
611
  <SelectPrimitive.Item
123
612
  data-slot="select-item"
124
613
  className={cn(S.selectItem, className, selected && S.selected)}
614
+ value={value}
615
+ disabled={disabled}
616
+ textValue={textValue}
125
617
  {...props}
126
618
  >
127
619
  <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
@@ -130,6 +622,16 @@ function SelectItem({
130
622
  }
131
623
 
132
624
  function SelectSeparator({ className, ...props }: SelectSeparatorProps) {
625
+ const searchable = React.useContext(SearchableContext);
626
+ if (searchable) {
627
+ return (
628
+ <div
629
+ data-slot="select-separator"
630
+ className={cn(S.selectSeparator, className)}
631
+ {...props}
632
+ />
633
+ );
634
+ }
133
635
  return (
134
636
  <SelectPrimitive.Separator
135
637
  data-slot="select-separator"
@@ -12,7 +12,9 @@ export interface SelectTriggerProps extends React.ComponentProps<
12
12
  asChild?: boolean;
13
13
  }
14
14
 
15
- export type SelectProps = React.ComponentProps<typeof SelectPrimitive.Root>;
15
+ export type SelectProps = React.ComponentProps<typeof SelectPrimitive.Root> & {
16
+ searchable?: boolean;
17
+ };
16
18
  export type SelectGroupProps = React.ComponentProps<
17
19
  typeof SelectPrimitive.Group
18
20
  >;
@@ -5,7 +5,7 @@ $animationDuration = 200ms
5
5
  .overlay
6
6
  position fixed
7
7
  inset 0
8
- z-index 50
8
+ z-index 1100
9
9
  background-color rgba(0, 0, 0, 0.5)
10
10
  backface-visibility hidden
11
11
 
@@ -17,7 +17,7 @@ $animationDuration = 200ms
17
17
 
18
18
  .content
19
19
  position fixed
20
- z-index 50
20
+ z-index 1100
21
21
  display flex
22
22
  flex-direction column
23
23
  // gap var(--p-4)