@dxos/react-ui-searchlist 0.8.4-main.28f8d3d → 0.8.4-main.2c6827d

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 (58) hide show
  1. package/dist/lib/browser/index.mjs +258 -139
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +258 -139
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Combobox/Combobox.d.ts +44 -0
  8. package/dist/types/src/components/Combobox/Combobox.d.ts.map +1 -0
  9. package/dist/types/src/components/Combobox/Combobox.stories.d.ts +21 -0
  10. package/dist/types/src/components/Combobox/Combobox.stories.d.ts.map +1 -0
  11. package/dist/types/src/components/Combobox/index.d.ts +2 -0
  12. package/dist/types/src/components/Combobox/index.d.ts.map +1 -0
  13. package/dist/types/src/components/Listbox/Listbox.d.ts +31 -0
  14. package/dist/types/src/components/Listbox/Listbox.d.ts.map +1 -0
  15. package/dist/types/src/components/Listbox/Listbox.stories.d.ts +21 -0
  16. package/dist/types/src/components/Listbox/Listbox.stories.d.ts.map +1 -0
  17. package/dist/types/src/components/Listbox/index.d.ts +2 -0
  18. package/dist/types/src/components/Listbox/index.d.ts.map +1 -0
  19. package/dist/types/src/components/{SearchList.d.ts → SearchList/SearchList.d.ts} +7 -27
  20. package/dist/types/src/components/SearchList/SearchList.d.ts.map +1 -0
  21. package/dist/types/src/components/SearchList/SearchList.stories.d.ts +25 -0
  22. package/dist/types/src/components/SearchList/SearchList.stories.d.ts.map +1 -0
  23. package/dist/types/src/components/SearchList/index.d.ts +2 -0
  24. package/dist/types/src/components/SearchList/index.d.ts.map +1 -0
  25. package/dist/types/src/components/index.d.ts +2 -0
  26. package/dist/types/src/components/index.d.ts.map +1 -1
  27. package/dist/types/src/index.d.ts +0 -1
  28. package/dist/types/src/index.d.ts.map +1 -1
  29. package/dist/types/src/translations.d.ts +3 -1
  30. package/dist/types/src/translations.d.ts.map +1 -1
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +16 -14
  33. package/src/components/Combobox/Combobox.stories.tsx +57 -0
  34. package/src/components/Combobox/Combobox.tsx +335 -0
  35. package/src/components/Combobox/index.ts +5 -0
  36. package/src/components/Listbox/Listbox.stories.tsx +53 -0
  37. package/src/components/Listbox/Listbox.tsx +209 -0
  38. package/src/components/Listbox/index.ts +5 -0
  39. package/src/components/SearchList/SearchList.stories.tsx +64 -0
  40. package/src/components/SearchList/SearchList.tsx +163 -0
  41. package/src/components/SearchList/index.ts +5 -0
  42. package/src/components/index.ts +2 -0
  43. package/src/index.ts +0 -1
  44. package/src/translations.ts +3 -1
  45. package/dist/types/src/components/SearchList.d.ts.map +0 -1
  46. package/dist/types/src/components/SearchList.stories.d.ts +0 -15
  47. package/dist/types/src/components/SearchList.stories.d.ts.map +0 -1
  48. package/dist/types/src/composites/PopoverCombobox.d.ts +0 -32
  49. package/dist/types/src/composites/PopoverCombobox.d.ts.map +0 -1
  50. package/dist/types/src/composites/PopoverCombobox.stories.d.ts +0 -28
  51. package/dist/types/src/composites/PopoverCombobox.stories.d.ts.map +0 -1
  52. package/dist/types/src/composites/index.d.ts +0 -2
  53. package/dist/types/src/composites/index.d.ts.map +0 -1
  54. package/src/components/SearchList.stories.tsx +0 -47
  55. package/src/components/SearchList.tsx +0 -250
  56. package/src/composites/PopoverCombobox.stories.tsx +0 -44
  57. package/src/composites/PopoverCombobox.tsx +0 -208
  58. package/src/composites/index.ts +0 -5
@@ -1,22 +1,42 @@
1
- // src/components/SearchList.tsx
2
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
1
+ // src/components/Combobox/Combobox.tsx
2
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
3
3
  import { createContext } from "@radix-ui/react-context";
4
4
  import { useControllableState } from "@radix-ui/react-use-controllable-state";
5
+ import React2, { forwardRef as forwardRef2, useCallback } from "react";
6
+ import { Button, Icon, Popover } from "@dxos/react-ui";
7
+ import { useId } from "@dxos/react-ui";
8
+ import { mx as mx2, staticPlaceholderText } from "@dxos/react-ui-theme";
9
+
10
+ // src/components/SearchList/SearchList.tsx
11
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
5
12
  import { CommandEmpty, CommandInput, CommandItem, CommandList, CommandRoot } from "cmdk";
6
- import React, { forwardRef, useCallback } from "react";
7
- import { Button, Icon, useDensityContext, useElevationContext, useId, useThemeContext } from "@dxos/react-ui";
8
- import { mx, staticPlaceholderText } from "@dxos/react-ui-theme";
9
- var COMBOBOX_NAME = "Combobox";
10
- var COMBOBOX_TRIGGER_NAME = "ComboboxTrigger";
13
+ import React, { forwardRef } from "react";
14
+ import { useDensityContext, useElevationContext, useThemeContext, useTranslation } from "@dxos/react-ui";
15
+ import { mx } from "@dxos/react-ui-theme";
16
+
17
+ // src/translations.ts
18
+ var translationKey = "react-ui-searchlist";
19
+ var translations = [
20
+ {
21
+ "en-US": {
22
+ [translationKey]: {
23
+ "search.placeholder": "Search..."
24
+ }
25
+ }
26
+ }
27
+ ];
28
+
29
+ // src/components/SearchList/SearchList.tsx
30
+ var commandItem = "flex items-center overflow-hidden";
31
+ var searchListItem = "plb-1 pli-2 rounded-sm select-none cursor-pointer data-[selected]:bg-hoverOverlay hover:bg-hoverOverlay";
11
32
  var SEARCHLIST_NAME = "SearchList";
12
33
  var SEARCHLIST_ITEM_NAME = "SearchListItem";
13
- var [ComboboxProvider, useComboboxContext] = createContext(COMBOBOX_NAME, {});
14
34
  var SearchListRoot = /* @__PURE__ */ forwardRef(({ children, classNames, ...props }, forwardedRef) => {
15
35
  var _effect = _useSignals();
16
36
  try {
17
37
  return /* @__PURE__ */ React.createElement(CommandRoot, {
18
38
  ...props,
19
- className: mx("", classNames),
39
+ className: mx(classNames),
20
40
  ref: forwardedRef
21
41
  }, children);
22
42
  } finally {
@@ -24,15 +44,18 @@ var SearchListRoot = /* @__PURE__ */ forwardRef(({ children, classNames, ...prop
24
44
  }
25
45
  });
26
46
  SearchListRoot.displayName = SEARCHLIST_NAME;
27
- var SearchListInput = /* @__PURE__ */ forwardRef(({ children, classNames, density: propsDensity, elevation: propsElevation, variant, ...props }, forwardedRef) => {
47
+ var SearchListInput = /* @__PURE__ */ forwardRef(({ classNames, density: propsDensity, elevation: propsElevation, variant, ...props }, forwardedRef) => {
28
48
  var _effect = _useSignals();
29
49
  try {
50
+ const { t } = useTranslation(translationKey);
51
+ const placeholder = props.placeholder ?? t("search.placeholder");
30
52
  const { hasIosKeyboard } = useThemeContext();
31
53
  const { tx } = useThemeContext();
32
54
  const density = useDensityContext(propsDensity);
33
55
  const elevation = useElevationContext(propsElevation);
34
56
  return /* @__PURE__ */ React.createElement(CommandInput, {
35
57
  ...props,
58
+ placeholder,
36
59
  className: tx("input.input", "input", {
37
60
  variant,
38
61
  disabled: props.disabled,
@@ -72,23 +95,12 @@ var SearchListEmpty = /* @__PURE__ */ forwardRef(({ children, classNames, ...pro
72
95
  _effect.f();
73
96
  }
74
97
  });
75
- var SearchListItem = /* @__PURE__ */ forwardRef(({ children, classNames, onSelect, ...props }, forwardedRef) => {
98
+ var SearchListItem = /* @__PURE__ */ forwardRef(({ children, classNames, ...props }, forwardedRef) => {
76
99
  var _effect = _useSignals();
77
100
  try {
78
- const { onValueChange, onOpenChange } = useComboboxContext(SEARCHLIST_ITEM_NAME);
79
- const handleSelect = useCallback((nextValue) => {
80
- onValueChange?.(nextValue);
81
- onOpenChange?.(false);
82
- onSelect?.(nextValue);
83
- }, [
84
- onValueChange,
85
- onOpenChange,
86
- onSelect
87
- ]);
88
101
  return /* @__PURE__ */ React.createElement(CommandItem, {
89
102
  ...props,
90
- onSelect: handleSelect,
91
- className: mx("p-1 rounded select-none cursor-pointer data-[selected]:bg-hoverOverlay", classNames),
103
+ className: mx(searchListItem, classNames),
92
104
  ref: forwardedRef
93
105
  }, children);
94
106
  } finally {
@@ -96,64 +108,6 @@ var SearchListItem = /* @__PURE__ */ forwardRef(({ children, classNames, onSelec
96
108
  }
97
109
  });
98
110
  SearchListItem.displayName = SEARCHLIST_ITEM_NAME;
99
- var ComboboxRoot = ({ modalId: propsModalId, open: propsOpen, defaultOpen, onOpenChange: propsOnOpenChange, value: propsValue, defaultValue, onValueChange: propsOnValueChange, placeholder, children }) => {
100
- var _effect = _useSignals();
101
- try {
102
- const modalId = useId(COMBOBOX_NAME, propsModalId);
103
- const [open = false, onOpenChange] = useControllableState({
104
- prop: propsOpen,
105
- onChange: propsOnOpenChange,
106
- defaultProp: defaultOpen
107
- });
108
- const [value = "", onValueChange] = useControllableState({
109
- prop: propsValue,
110
- onChange: propsOnValueChange,
111
- defaultProp: defaultValue
112
- });
113
- return /* @__PURE__ */ React.createElement(ComboboxProvider, {
114
- isCombobox: true,
115
- modalId,
116
- open,
117
- onOpenChange,
118
- value,
119
- onValueChange,
120
- placeholder
121
- }, children);
122
- } finally {
123
- _effect.f();
124
- }
125
- };
126
- ComboboxRoot.displayName = COMBOBOX_NAME;
127
- var ComboboxTrigger = /* @__PURE__ */ forwardRef(({ children, onClick, ...props }, forwardedRef) => {
128
- var _effect = _useSignals();
129
- try {
130
- const { modalId, open, onOpenChange, placeholder, value } = useComboboxContext(COMBOBOX_TRIGGER_NAME);
131
- const handleClick = useCallback((event) => {
132
- onClick?.(event);
133
- onOpenChange?.(true);
134
- }, [
135
- onClick,
136
- onOpenChange
137
- ]);
138
- return /* @__PURE__ */ React.createElement(Button, {
139
- ...props,
140
- role: "combobox",
141
- "aria-expanded": open,
142
- "aria-controls": modalId,
143
- "aria-haspopup": "dialog",
144
- onClick: handleClick,
145
- ref: forwardedRef
146
- }, children ?? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
147
- className: mx("font-normal text-start flex-1 min-is-0 truncate mie-2", !value && staticPlaceholderText)
148
- }, value || placeholder), /* @__PURE__ */ React.createElement(Icon, {
149
- icon: "ph--caret-down--bold",
150
- size: 3
151
- })));
152
- } finally {
153
- _effect.f();
154
- }
155
- });
156
- ComboboxTrigger.displayName = COMBOBOX_TRIGGER_NAME;
157
111
  var SearchList = {
158
112
  Root: SearchListRoot,
159
113
  Input: SearchListInput,
@@ -161,43 +115,48 @@ var SearchList = {
161
115
  Empty: SearchListEmpty,
162
116
  Item: SearchListItem
163
117
  };
164
- var Combobox = {
165
- Root: ComboboxRoot,
166
- Trigger: ComboboxTrigger,
167
- useComboboxContext
168
- };
169
118
 
170
- // src/composites/PopoverCombobox.tsx
171
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
172
- import { useControllableState as useControllableState2 } from "@radix-ui/react-use-controllable-state";
173
- import React2, { forwardRef as forwardRef2 } from "react";
174
- import { Popover } from "@dxos/react-ui";
175
- var PopoverComboboxRoot = ({ modal, children, open: propsOpen, onOpenChange: propsOnOpenChange, defaultOpen, ...props }) => {
119
+ // src/components/Combobox/Combobox.tsx
120
+ var COMBOBOX_NAME = "Combobox";
121
+ var COMBOBOX_CONTENT_NAME = "ComboboxContent";
122
+ var COMBOBOX_ITEM_NAME = "ComboboxItem";
123
+ var COMBOBOX_TRIGGER_NAME = "ComboboxTrigger";
124
+ var [ComboboxProvider, useComboboxContext] = createContext(COMBOBOX_NAME, {});
125
+ var ComboboxRoot = ({ modal, modalId: propsModalId, open: propsOpen, defaultOpen, onOpenChange: propsOnOpenChange, value: propsValue, defaultValue, onValueChange: propsOnValueChange, placeholder, children }) => {
176
126
  var _effect = _useSignals2();
177
127
  try {
178
- const [open, onOpenChange] = useControllableState2({
128
+ const modalId = useId(COMBOBOX_NAME, propsModalId);
129
+ const [open = false, onOpenChange] = useControllableState({
179
130
  prop: propsOpen,
180
131
  onChange: propsOnOpenChange,
181
132
  defaultProp: defaultOpen
182
133
  });
183
- return /* @__PURE__ */ React2.createElement(Combobox.Root, {
134
+ const [value = "", onValueChange] = useControllableState({
135
+ prop: propsValue,
136
+ onChange: propsOnValueChange,
137
+ defaultProp: defaultValue
138
+ });
139
+ return /* @__PURE__ */ React2.createElement(Popover.Root, {
184
140
  open,
185
141
  onOpenChange,
186
- ...props
187
- }, /* @__PURE__ */ React2.createElement(Popover.Root, {
142
+ modal
143
+ }, /* @__PURE__ */ React2.createElement(ComboboxProvider, {
144
+ isCombobox: true,
145
+ modalId,
146
+ placeholder,
188
147
  open,
189
148
  onOpenChange,
190
- modal
149
+ value,
150
+ onValueChange
191
151
  }, children));
192
152
  } finally {
193
153
  _effect.f();
194
154
  }
195
155
  };
196
- var POPOVER_COMBOBOX_CONTENT_NAME = "PopoverComboboxContent";
197
- var PopoverComboboxContent = /* @__PURE__ */ forwardRef2(({ side = "bottom", collisionPadding = 48, sideOffset, align, alignOffset, avoidCollisions, collisionBoundary, arrowPadding, sticky, hideWhenDetached, onOpenAutoFocus, onCloseAutoFocus, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, forceMount, children, classNames, ...props }, forwardedRef) => {
156
+ var ComboboxContent = /* @__PURE__ */ forwardRef2(({ side = "bottom", collisionPadding = 48, sideOffset, align, alignOffset, avoidCollisions, collisionBoundary, arrowPadding, sticky, hideWhenDetached, onOpenAutoFocus, onCloseAutoFocus, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, forceMount, children, classNames, ...props }, forwardedRef) => {
198
157
  var _effect = _useSignals2();
199
158
  try {
200
- const { modalId } = Combobox.useComboboxContext(POPOVER_COMBOBOX_CONTENT_NAME);
159
+ const { modalId } = useComboboxContext(COMBOBOX_CONTENT_NAME);
201
160
  return /* @__PURE__ */ React2.createElement(Popover.Content, {
202
161
  side,
203
162
  sideOffset,
@@ -216,40 +175,62 @@ var PopoverComboboxContent = /* @__PURE__ */ forwardRef2(({ side = "bottom", col
216
175
  onFocusOutside,
217
176
  onInteractOutside,
218
177
  forceMount,
219
- classNames,
178
+ classNames: [
179
+ "is-[--radix-popover-trigger-width] max-bs-[--radix-popover-content-available-height] grid grid-rows-[min-content_1fr]",
180
+ classNames
181
+ ],
220
182
  id: modalId,
221
183
  ref: forwardedRef
222
- }, /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(SearchList.Root, {
184
+ }, /* @__PURE__ */ React2.createElement(SearchList.Root, {
223
185
  ...props,
224
186
  classNames: "contents density-fine",
225
187
  role: "none"
226
- }, children)));
188
+ }, children));
227
189
  } finally {
228
190
  _effect.f();
229
191
  }
230
192
  });
231
- PopoverComboboxContent.displayName = POPOVER_COMBOBOX_CONTENT_NAME;
232
- var PopoverComboboxTrigger = /* @__PURE__ */ forwardRef2((props, forwardedRef) => {
193
+ ComboboxContent.displayName = COMBOBOX_CONTENT_NAME;
194
+ var ComboboxTrigger = /* @__PURE__ */ forwardRef2(({ children, onClick, ...props }, forwardedRef) => {
233
195
  var _effect = _useSignals2();
234
196
  try {
197
+ const { modalId, open, onOpenChange, placeholder, value } = useComboboxContext(COMBOBOX_TRIGGER_NAME);
198
+ const handleClick = useCallback((event) => {
199
+ onClick?.(event);
200
+ onOpenChange?.(true);
201
+ }, [
202
+ onClick,
203
+ onOpenChange
204
+ ]);
235
205
  return /* @__PURE__ */ React2.createElement(Popover.Trigger, {
236
206
  asChild: true
237
- }, /* @__PURE__ */ React2.createElement(Combobox.Trigger, {
207
+ }, /* @__PURE__ */ React2.createElement(Button, {
238
208
  ...props,
209
+ role: "combobox",
210
+ "aria-expanded": open,
211
+ "aria-controls": modalId,
212
+ "aria-haspopup": "dialog",
213
+ onClick: handleClick,
239
214
  ref: forwardedRef
240
- }));
215
+ }, children ?? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("span", {
216
+ className: mx2("font-normal text-start flex-1 min-is-0 truncate mie-2", !value && staticPlaceholderText)
217
+ }, value || placeholder), /* @__PURE__ */ React2.createElement(Icon, {
218
+ icon: "ph--caret-down--bold",
219
+ size: 3
220
+ }))));
241
221
  } finally {
242
222
  _effect.f();
243
223
  }
244
224
  });
245
- var PopoverComboboxVirtualTrigger = Popover.VirtualTrigger;
246
- var PopoverComboboxInput = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
225
+ ComboboxTrigger.displayName = COMBOBOX_TRIGGER_NAME;
226
+ var ComboboxVirtualTrigger = Popover.VirtualTrigger;
227
+ var ComboboxInput = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
247
228
  var _effect = _useSignals2();
248
229
  try {
249
230
  return /* @__PURE__ */ React2.createElement(SearchList.Input, {
250
231
  ...props,
251
232
  classNames: [
252
- "mli-cardSpacingChrome mbs-cardSpacingChrome is-[calc(100%-2*var(--dx-cardSpacingChrome))]",
233
+ "mli-cardSpacingChrome mbs-cardSpacingChrome mbe-0 is-[calc(100%-2*var(--dx-cardSpacingChrome))]",
253
234
  classNames
254
235
  ],
255
236
  ref: forwardedRef
@@ -258,63 +239,201 @@ var PopoverComboboxInput = /* @__PURE__ */ forwardRef2(({ classNames, ...props }
258
239
  _effect.f();
259
240
  }
260
241
  });
261
- var PopoverComboboxList = /* @__PURE__ */ forwardRef2(({ constrainInline, constrainBlock, ...props }, forwardedRef) => {
242
+ var ComboboxList = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
262
243
  var _effect = _useSignals2();
263
244
  try {
264
- return /* @__PURE__ */ React2.createElement(Popover.Viewport, {
265
- constrainInline,
266
- constrainBlock
267
- }, /* @__PURE__ */ React2.createElement(SearchList.Content, {
245
+ return /* @__PURE__ */ React2.createElement(SearchList.Content, {
268
246
  ...props,
247
+ classNames: [
248
+ "min-bs-0 overflow-y-auto plb-cardSpacingChrome",
249
+ classNames
250
+ ],
269
251
  ref: forwardedRef
270
- }));
252
+ });
271
253
  } finally {
272
254
  _effect.f();
273
255
  }
274
256
  });
275
- var PopoverComboboxItem = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
257
+ var ComboboxItem = /* @__PURE__ */ forwardRef2(({ classNames, onSelect, ...props }, forwardedRef) => {
276
258
  var _effect = _useSignals2();
277
259
  try {
260
+ const { onValueChange, onOpenChange } = useComboboxContext(COMBOBOX_ITEM_NAME);
261
+ const handleSelect = useCallback((nextValue) => {
262
+ onSelect?.(nextValue);
263
+ onValueChange?.(nextValue);
264
+ onOpenChange?.(false);
265
+ }, [
266
+ onSelect,
267
+ onValueChange,
268
+ onOpenChange
269
+ ]);
278
270
  return /* @__PURE__ */ React2.createElement(SearchList.Item, {
279
271
  ...props,
280
272
  classNames: [
281
273
  "mli-cardSpacingChrome pli-cardSpacingChrome",
282
274
  classNames
283
275
  ],
276
+ onSelect: handleSelect,
284
277
  ref: forwardedRef
285
278
  });
286
279
  } finally {
287
280
  _effect.f();
288
281
  }
289
282
  });
290
- var PopoverComboboxArrow = Popover.Arrow;
291
- var PopoverComboboxEmpty = SearchList.Empty;
292
- var PopoverCombobox = {
293
- Root: PopoverComboboxRoot,
294
- Content: PopoverComboboxContent,
295
- Trigger: PopoverComboboxTrigger,
296
- VirtualTrigger: PopoverComboboxVirtualTrigger,
297
- Input: PopoverComboboxInput,
298
- List: PopoverComboboxList,
299
- Item: PopoverComboboxItem,
300
- Arrow: PopoverComboboxArrow,
301
- Empty: PopoverComboboxEmpty
283
+ ComboboxItem.displayName = COMBOBOX_ITEM_NAME;
284
+ var ComboboxArrow = Popover.Arrow;
285
+ var ComboboxEmpty = SearchList.Empty;
286
+ var Combobox = {
287
+ Root: ComboboxRoot,
288
+ Content: ComboboxContent,
289
+ Trigger: ComboboxTrigger,
290
+ VirtualTrigger: ComboboxVirtualTrigger,
291
+ Input: ComboboxInput,
292
+ List: ComboboxList,
293
+ Item: ComboboxItem,
294
+ Arrow: ComboboxArrow,
295
+ Empty: ComboboxEmpty
302
296
  };
303
297
 
304
- // src/translations.ts
305
- var translationKey = "react-ui-searchlist";
306
- var translations = [
307
- {
308
- "en-US": {
309
- [translationKey]: {}
310
- }
298
+ // src/components/Listbox/Listbox.tsx
299
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
300
+ import { useArrowNavigationGroup } from "@fluentui/react-tabster";
301
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
302
+ import { createContextScope } from "@radix-ui/react-context";
303
+ import { useControllableState as useControllableState2 } from "@radix-ui/react-use-controllable-state";
304
+ import React3, { forwardRef as forwardRef3, useCallback as useCallback2, useEffect, useRef } from "react";
305
+ import { Icon as Icon2 } from "@dxos/react-ui";
306
+ import { mx as mx3 } from "@dxos/react-ui-theme";
307
+ var LISTBOX_NAME = "Listbox";
308
+ var LISTBOX_OPTION_NAME = "ListboxOption";
309
+ var LISTBOX_OPTION_LABEL_NAME = "ListboxOptionLabel";
310
+ var LISTBOX_OPTION_INDICATOR_NAME = "ListboxOptionIndicator";
311
+ var [createListboxContext, createListboxScope] = createContextScope(LISTBOX_NAME, []);
312
+ var [createListboxOptionContext, createListboxOptionScope] = createContextScope(LISTBOX_OPTION_NAME, [
313
+ createListboxScope
314
+ ]);
315
+ var [ListboxProvider, useListboxContext] = createListboxContext(LISTBOX_NAME);
316
+ var [ListboxOptionProvider, useListboxOptionContext] = createListboxOptionContext(LISTBOX_OPTION_NAME);
317
+ var ListboxRoot = /* @__PURE__ */ forwardRef3((props, forwardedRef) => {
318
+ var _effect = _useSignals3();
319
+ try {
320
+ const { __listboxScope, children, classNames, value: propsValue, defaultValue, onValueChange, autoFocus, ...rootProps } = props;
321
+ const arrowGroup = useArrowNavigationGroup({
322
+ axis: "vertical"
323
+ });
324
+ const ref = useRef(null);
325
+ const rootRef = useComposedRefs(ref, forwardedRef);
326
+ const [selectedValue, setSelectedValue] = useControllableState2({
327
+ prop: propsValue,
328
+ defaultProp: defaultValue,
329
+ onChange: onValueChange
330
+ });
331
+ const handleValueChange = (value) => {
332
+ setSelectedValue(value);
333
+ };
334
+ useEffect(() => {
335
+ ref.current?.querySelector('[aria-selected="true"]')?.focus();
336
+ }, [
337
+ autoFocus
338
+ ]);
339
+ return /* @__PURE__ */ React3.createElement(ListboxProvider, {
340
+ scope: __listboxScope,
341
+ selectedValue,
342
+ onValueChange: handleValueChange
343
+ }, /* @__PURE__ */ React3.createElement("ul", {
344
+ role: "listbox",
345
+ ...rootProps,
346
+ className: mx3("is-full p-cardSpacingChrome", classNames),
347
+ ref: rootRef,
348
+ ...arrowGroup
349
+ }, children));
350
+ } finally {
351
+ _effect.f();
311
352
  }
312
- ];
353
+ });
354
+ ListboxRoot.displayName = LISTBOX_NAME;
355
+ var ListboxOption = /* @__PURE__ */ forwardRef3((props, forwardedRef) => {
356
+ var _effect = _useSignals3();
357
+ try {
358
+ const { __listboxScope, children, classNames, value, ...rootProps } = props;
359
+ const { selectedValue, onValueChange } = useListboxContext(LISTBOX_OPTION_NAME, __listboxScope);
360
+ const isSelected = selectedValue === value;
361
+ const handleSelect = useCallback2(() => {
362
+ onValueChange(value);
363
+ }, [
364
+ value,
365
+ onValueChange
366
+ ]);
367
+ return /* @__PURE__ */ React3.createElement(ListboxOptionProvider, {
368
+ scope: __listboxScope,
369
+ value,
370
+ isSelected
371
+ }, /* @__PURE__ */ React3.createElement("li", {
372
+ role: "option",
373
+ ...rootProps,
374
+ "aria-selected": isSelected,
375
+ tabIndex: 0,
376
+ className: mx3("dx-focus-ring", commandItem, searchListItem, classNames),
377
+ onClick: handleSelect,
378
+ onKeyDown: ({ key }) => {
379
+ if ([
380
+ "Enter",
381
+ " "
382
+ ].includes(key)) {
383
+ handleSelect();
384
+ }
385
+ },
386
+ ref: forwardedRef
387
+ }, children));
388
+ } finally {
389
+ _effect.f();
390
+ }
391
+ });
392
+ ListboxOption.displayName = LISTBOX_OPTION_NAME;
393
+ var ListboxOptionLabel = /* @__PURE__ */ forwardRef3(({ children, classNames, ...rootProps }, forwardedRef) => {
394
+ var _effect = _useSignals3();
395
+ try {
396
+ return /* @__PURE__ */ React3.createElement("span", {
397
+ ...rootProps,
398
+ className: mx3("grow truncate", classNames),
399
+ ref: forwardedRef
400
+ }, children);
401
+ } finally {
402
+ _effect.f();
403
+ }
404
+ });
405
+ ListboxOptionLabel.displayName = LISTBOX_OPTION_LABEL_NAME;
406
+ var ListboxOptionIndicator = /* @__PURE__ */ forwardRef3((props, forwardedRef) => {
407
+ var _effect = _useSignals3();
408
+ try {
409
+ const { __listboxOptionScope, classNames, ...rootProps } = props;
410
+ const { isSelected } = useListboxOptionContext(LISTBOX_OPTION_INDICATOR_NAME, __listboxOptionScope);
411
+ return /* @__PURE__ */ React3.createElement(Icon2, {
412
+ icon: "ph--check--regular",
413
+ ...rootProps,
414
+ classNames: mx3(!isSelected && "invisible", classNames),
415
+ ref: forwardedRef
416
+ });
417
+ } finally {
418
+ _effect.f();
419
+ }
420
+ });
421
+ ListboxOptionIndicator.displayName = LISTBOX_OPTION_INDICATOR_NAME;
422
+ var Listbox = {
423
+ Root: ListboxRoot,
424
+ Option: ListboxOption,
425
+ OptionLabel: ListboxOptionLabel,
426
+ OptionIndicator: ListboxOptionIndicator
427
+ };
313
428
  export {
314
429
  Combobox,
315
- PopoverCombobox,
430
+ Listbox,
316
431
  SearchList,
432
+ commandItem,
433
+ createListboxScope,
434
+ searchListItem,
317
435
  translationKey,
318
- translations
436
+ translations,
437
+ useListboxContext
319
438
  };
320
439
  //# sourceMappingURL=index.mjs.map