@dxos/react-ui-searchlist 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe
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/dist/lib/browser/index.mjs +246 -131
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +246 -131
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Combobox/Combobox.d.ts +44 -0
- package/dist/types/src/components/Combobox/Combobox.d.ts.map +1 -0
- package/dist/types/src/{composites/PopoverCombobox.stories.d.ts → components/Combobox/Combobox.stories.d.ts} +10 -2
- package/dist/types/src/components/Combobox/Combobox.stories.d.ts.map +1 -0
- package/dist/types/src/components/Combobox/index.d.ts +2 -0
- package/dist/types/src/components/Combobox/index.d.ts.map +1 -0
- package/dist/types/src/components/Listbox/Listbox.d.ts +31 -0
- package/dist/types/src/components/Listbox/Listbox.d.ts.map +1 -0
- package/dist/types/src/components/Listbox/Listbox.stories.d.ts +21 -0
- package/dist/types/src/components/Listbox/Listbox.stories.d.ts.map +1 -0
- package/dist/types/src/components/Listbox/index.d.ts +2 -0
- package/dist/types/src/components/Listbox/index.d.ts.map +1 -0
- package/dist/types/src/components/{SearchList.d.ts → SearchList/SearchList.d.ts} +7 -27
- package/dist/types/src/components/SearchList/SearchList.d.ts.map +1 -0
- package/dist/types/src/components/{SearchList.stories.d.ts → SearchList/SearchList.stories.d.ts} +9 -1
- package/dist/types/src/components/SearchList/SearchList.stories.d.ts.map +1 -0
- package/dist/types/src/components/SearchList/index.d.ts +2 -0
- package/dist/types/src/components/SearchList/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -14
- package/src/components/Combobox/Combobox.stories.tsx +57 -0
- package/src/components/Combobox/Combobox.tsx +335 -0
- package/src/components/Combobox/index.ts +5 -0
- package/src/components/Listbox/Listbox.stories.tsx +53 -0
- package/src/components/Listbox/Listbox.tsx +209 -0
- package/src/components/Listbox/index.ts +5 -0
- package/src/components/{SearchList.stories.tsx → SearchList/SearchList.stories.tsx} +17 -10
- package/src/components/SearchList/SearchList.tsx +163 -0
- package/src/components/SearchList/index.ts +5 -0
- package/src/components/index.ts +2 -0
- package/src/index.ts +0 -1
- package/src/translations.ts +3 -1
- package/dist/types/src/components/SearchList.d.ts.map +0 -1
- package/dist/types/src/components/SearchList.stories.d.ts.map +0 -1
- package/dist/types/src/composites/PopoverCombobox.d.ts +0 -32
- package/dist/types/src/composites/PopoverCombobox.d.ts.map +0 -1
- package/dist/types/src/composites/PopoverCombobox.stories.d.ts.map +0 -1
- package/dist/types/src/composites/index.d.ts +0 -2
- package/dist/types/src/composites/index.d.ts.map +0 -1
- package/src/components/SearchList.tsx +0 -253
- package/src/composites/PopoverCombobox.stories.tsx +0 -49
- package/src/composites/PopoverCombobox.tsx +0 -209
- package/src/composites/index.ts +0 -5
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
// src/components/
|
|
2
|
-
import { useSignals as
|
|
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
|
|
7
|
-
import {
|
|
8
|
-
import { mx
|
|
9
|
-
|
|
10
|
-
|
|
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(
|
|
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(({
|
|
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,
|
|
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
|
-
|
|
91
|
-
className: mx("p-1 pis-2 pie-2 rounded-sm 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/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
187
|
-
}, /* @__PURE__ */ React2.createElement(
|
|
142
|
+
modal
|
|
143
|
+
}, /* @__PURE__ */ React2.createElement(ComboboxProvider, {
|
|
144
|
+
isCombobox: true,
|
|
145
|
+
modalId,
|
|
146
|
+
placeholder,
|
|
188
147
|
open,
|
|
189
148
|
onOpenChange,
|
|
190
|
-
|
|
149
|
+
value,
|
|
150
|
+
onValueChange
|
|
191
151
|
}, children));
|
|
192
152
|
} finally {
|
|
193
153
|
_effect.f();
|
|
194
154
|
}
|
|
195
155
|
};
|
|
196
|
-
var
|
|
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 } =
|
|
159
|
+
const { modalId } = useComboboxContext(COMBOBOX_CONTENT_NAME);
|
|
201
160
|
return /* @__PURE__ */ React2.createElement(Popover.Content, {
|
|
202
161
|
side,
|
|
203
162
|
sideOffset,
|
|
@@ -217,7 +176,7 @@ var PopoverComboboxContent = /* @__PURE__ */ forwardRef2(({ side = "bottom", col
|
|
|
217
176
|
onInteractOutside,
|
|
218
177
|
forceMount,
|
|
219
178
|
classNames: [
|
|
220
|
-
"is-[--radix-popover-trigger-width] max-bs-[--radix-popover-content-available-height] grid grid-rows-[min-content_1fr]
|
|
179
|
+
"is-[--radix-popover-trigger-width] max-bs-[--radix-popover-content-available-height] grid grid-rows-[min-content_1fr]",
|
|
221
180
|
classNames
|
|
222
181
|
],
|
|
223
182
|
id: modalId,
|
|
@@ -231,22 +190,41 @@ var PopoverComboboxContent = /* @__PURE__ */ forwardRef2(({ side = "bottom", col
|
|
|
231
190
|
_effect.f();
|
|
232
191
|
}
|
|
233
192
|
});
|
|
234
|
-
|
|
235
|
-
var
|
|
193
|
+
ComboboxContent.displayName = COMBOBOX_CONTENT_NAME;
|
|
194
|
+
var ComboboxTrigger = /* @__PURE__ */ forwardRef2(({ children, onClick, ...props }, forwardedRef) => {
|
|
236
195
|
var _effect = _useSignals2();
|
|
237
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
|
+
]);
|
|
238
205
|
return /* @__PURE__ */ React2.createElement(Popover.Trigger, {
|
|
239
206
|
asChild: true
|
|
240
|
-
}, /* @__PURE__ */ React2.createElement(
|
|
207
|
+
}, /* @__PURE__ */ React2.createElement(Button, {
|
|
241
208
|
...props,
|
|
209
|
+
role: "combobox",
|
|
210
|
+
"aria-expanded": open,
|
|
211
|
+
"aria-controls": modalId,
|
|
212
|
+
"aria-haspopup": "dialog",
|
|
213
|
+
onClick: handleClick,
|
|
242
214
|
ref: forwardedRef
|
|
243
|
-
}
|
|
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
|
+
}))));
|
|
244
221
|
} finally {
|
|
245
222
|
_effect.f();
|
|
246
223
|
}
|
|
247
224
|
});
|
|
248
|
-
|
|
249
|
-
var
|
|
225
|
+
ComboboxTrigger.displayName = COMBOBOX_TRIGGER_NAME;
|
|
226
|
+
var ComboboxVirtualTrigger = Popover.VirtualTrigger;
|
|
227
|
+
var ComboboxInput = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
|
|
250
228
|
var _effect = _useSignals2();
|
|
251
229
|
try {
|
|
252
230
|
return /* @__PURE__ */ React2.createElement(SearchList.Input, {
|
|
@@ -261,7 +239,7 @@ var PopoverComboboxInput = /* @__PURE__ */ forwardRef2(({ classNames, ...props }
|
|
|
261
239
|
_effect.f();
|
|
262
240
|
}
|
|
263
241
|
});
|
|
264
|
-
var
|
|
242
|
+
var ComboboxList = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
|
|
265
243
|
var _effect = _useSignals2();
|
|
266
244
|
try {
|
|
267
245
|
return /* @__PURE__ */ React2.createElement(SearchList.Content, {
|
|
@@ -276,49 +254,186 @@ var PopoverComboboxList = /* @__PURE__ */ forwardRef2(({ classNames, ...props },
|
|
|
276
254
|
_effect.f();
|
|
277
255
|
}
|
|
278
256
|
});
|
|
279
|
-
var
|
|
257
|
+
var ComboboxItem = /* @__PURE__ */ forwardRef2(({ classNames, onSelect, ...props }, forwardedRef) => {
|
|
280
258
|
var _effect = _useSignals2();
|
|
281
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
|
+
]);
|
|
282
270
|
return /* @__PURE__ */ React2.createElement(SearchList.Item, {
|
|
283
271
|
...props,
|
|
284
272
|
classNames: [
|
|
285
273
|
"mli-cardSpacingChrome pli-cardSpacingChrome",
|
|
286
274
|
classNames
|
|
287
275
|
],
|
|
276
|
+
onSelect: handleSelect,
|
|
288
277
|
ref: forwardedRef
|
|
289
278
|
});
|
|
290
279
|
} finally {
|
|
291
280
|
_effect.f();
|
|
292
281
|
}
|
|
293
282
|
});
|
|
294
|
-
|
|
295
|
-
var
|
|
296
|
-
var
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
306
296
|
};
|
|
307
297
|
|
|
308
|
-
// src/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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();
|
|
315
352
|
}
|
|
316
|
-
|
|
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
|
+
};
|
|
317
428
|
export {
|
|
318
429
|
Combobox,
|
|
319
|
-
|
|
430
|
+
Listbox,
|
|
320
431
|
SearchList,
|
|
432
|
+
commandItem,
|
|
433
|
+
createListboxScope,
|
|
434
|
+
searchListItem,
|
|
321
435
|
translationKey,
|
|
322
|
-
translations
|
|
436
|
+
translations,
|
|
437
|
+
useListboxContext
|
|
323
438
|
};
|
|
324
439
|
//# sourceMappingURL=index.mjs.map
|