@gridui/select 1.1.1 → 1.2.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.
- package/README.md +32 -7
- package/dist/autocomplete/autocomplete.d.ts +20 -0
- package/dist/combobox/combobox.d.ts +2 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +692 -473
- package/dist/index.js.map +4 -4
- package/dist/multi-select/multi-select.d.ts +2 -8
- package/dist/select/select-options.d.ts +2 -6
- package/dist/select/style.d.ts +0 -2
- package/dist/shared/{selection-actions.d.ts → popup/selection-actions.d.ts} +2 -2
- package/dist/shared/{selection-popup.d.ts → popup/selection-popup.d.ts} +1 -1
- package/dist/shared/{use-selection-popup.d.ts → popup/use-selection-popup.d.ts} +2 -2
- package/dist/shared/{combobox-options.d.ts → search/combobox-options.d.ts} +3 -5
- package/dist/shared/{scroll-option.d.ts → search/scroll-option.d.ts} +1 -1
- package/dist/shared/{use-search-options.d.ts → search/use-search-options.d.ts} +2 -2
- package/dist/shared/style.d.ts +0 -1
- package/dist/shared/types.d.ts +16 -4
- package/dist/styles.css +55 -81
- package/docs/catalog.json +21 -5
- package/docs/reference/README.md +7 -0
- package/docs/reference/autocomplete.md +127 -0
- package/docs/reference/combobox.md +149 -0
- package/docs/reference/multi-select.md +139 -0
- package/docs/reference/select.md +121 -0
- package/package.json +6 -7
package/dist/index.js
CHANGED
|
@@ -1,30 +1,151 @@
|
|
|
1
1
|
// src/shared/style.ts
|
|
2
|
-
import {
|
|
3
|
-
import { overlaySurfaceStyles } from "@gridui/overlay";
|
|
2
|
+
import { overlayListItemStyles, overlayListStyles } from "@gridui/overlay";
|
|
4
3
|
import { cn } from "@gridui/style-utils";
|
|
5
4
|
import { cva } from "class-variance-authority";
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var selectActionsStyles = cva("gridui-u-shrink-0 gridui-u-border-t gridui-u-border-border gridui-u-pt-gridui-4");
|
|
5
|
+
var selectIconStyles = cva("gridui-u-select--inline-flex gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--[&_svg]:size-gridui-16");
|
|
6
|
+
var selectOptionContentStyles = cva("gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere");
|
|
7
|
+
var selectOptionDescriptionStyles = cva("gridui-u-select--block gridui-u-select--text-muted gridui-u-select--type-caption gridui-u-select--mt-gridui-4");
|
|
8
|
+
var selectListStyles = cva("gridui-u-select--min-h-0 gridui-u-select--overflow-y-auto");
|
|
9
|
+
var selectEmptyStyles = cva("gridui-u-select--p-gridui-8 gridui-u-select--text-muted gridui-u-select--type-caption");
|
|
10
|
+
var selectActionsStyles = cva("gridui-u-select--shrink-0 gridui-u-select--border-t gridui-u-select--border-border");
|
|
13
11
|
var selectActionStyles = cva(cn(
|
|
14
|
-
|
|
15
|
-
"gridui-u-w-full gridui-u-text-start
|
|
12
|
+
overlayListItemStyles(),
|
|
13
|
+
"gridui-u-select--w-full gridui-u-select--text-start"
|
|
16
14
|
));
|
|
17
15
|
var comboboxContentStyles = cva(cn(
|
|
18
|
-
|
|
19
|
-
"gridui-u-
|
|
20
|
-
"gridui-combobox-content gridui-u-box-border gridui-u-flex gridui-u-flex-col gridui-u-overflow-hidden gridui-u-min-w-0 gridui-u-w-(--anchor-width) gridui-u-max-h-(--available-height) gridui-u-max-w-(--available-width)"
|
|
16
|
+
overlayListStyles(),
|
|
17
|
+
"gridui-combobox-content gridui-u-select--box-border gridui-u-select--flex gridui-u-select--flex-col gridui-u-select--overflow-hidden gridui-u-select--min-w-0 gridui-u-select--w-(--anchor-width) gridui-u-select--max-h-(--available-height) gridui-u-select--max-w-(--available-width)"
|
|
21
18
|
));
|
|
22
19
|
|
|
23
|
-
// src/shared/
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
20
|
+
// src/shared/popup/selection-popup.tsx
|
|
21
|
+
import { isComposingKeyEvent } from "@gridui/interaction";
|
|
22
|
+
import { interactionLayerProps } from "@gridui/overlay";
|
|
23
|
+
import * as Primitive from "@radix-ui/react-popover";
|
|
24
|
+
import { jsx } from "react/jsx-runtime";
|
|
25
|
+
var SelectionPopup = (props) => {
|
|
26
|
+
const { container, anchorRef, initialFocus, finalFocus, onEscape, onDismiss, ...restProps } = props;
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
Primitive.Portal,
|
|
29
|
+
{
|
|
30
|
+
container,
|
|
31
|
+
children: /* @__PURE__ */ jsx(
|
|
32
|
+
Primitive.Content,
|
|
33
|
+
{
|
|
34
|
+
...interactionLayerProps,
|
|
35
|
+
...restProps,
|
|
36
|
+
sideOffset: 8,
|
|
37
|
+
align: "start",
|
|
38
|
+
collisionPadding: 16,
|
|
39
|
+
className: comboboxContentStyles(),
|
|
40
|
+
onOpenAutoFocus: (event) => {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
initialFocus?.();
|
|
43
|
+
},
|
|
44
|
+
onCloseAutoFocus: (event) => {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
const target = finalFocus();
|
|
47
|
+
if (target) {
|
|
48
|
+
target.focus();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
onInteractOutside: (event) => {
|
|
52
|
+
if (anchorRef?.current?.contains(event.target)) {
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
} else {
|
|
55
|
+
onDismiss?.();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
onEscapeKeyDown: (event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
if (!isComposingKeyEvent(event)) {
|
|
62
|
+
onEscape();
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
onKeyDown: (event) => {
|
|
66
|
+
if (event.key === "Escape") {
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/shared/popup/use-selection-popup.ts
|
|
77
|
+
import { useEffect, useRef, useState } from "react";
|
|
78
|
+
import { flushSync } from "react-dom";
|
|
79
|
+
var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
|
|
80
|
+
const [
|
|
81
|
+
localOpen,
|
|
82
|
+
setLocalOpen
|
|
83
|
+
] = useState(false);
|
|
84
|
+
const popupRef = useRef(null);
|
|
85
|
+
const restoreFocus = useRef(true);
|
|
86
|
+
const unavailable = Boolean(disabled || readOnly);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (unavailable) {
|
|
89
|
+
setLocalOpen(false);
|
|
90
|
+
}
|
|
91
|
+
}, [unavailable]);
|
|
92
|
+
const available = () => {
|
|
93
|
+
return !unavailable && !controlRef.current?.matches(":disabled");
|
|
94
|
+
};
|
|
95
|
+
const changeOpen = (next) => {
|
|
96
|
+
if (next && !available()) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (next) {
|
|
100
|
+
restoreFocus.current = true;
|
|
101
|
+
}
|
|
102
|
+
setLocalOpen(next);
|
|
103
|
+
};
|
|
104
|
+
const close = () => {
|
|
105
|
+
restoreFocus.current = false;
|
|
106
|
+
setLocalOpen(false);
|
|
107
|
+
};
|
|
108
|
+
const focus = () => {
|
|
109
|
+
controlRef.current?.focus();
|
|
110
|
+
};
|
|
111
|
+
const finalFocus = () => {
|
|
112
|
+
const control = controlRef.current;
|
|
113
|
+
if (!restoreFocus.current || !control) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const active = control.ownerDocument.activeElement;
|
|
117
|
+
if (active && active !== control.ownerDocument.body && active !== control && !popupRef.current?.contains(active)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return control;
|
|
121
|
+
};
|
|
122
|
+
const runAction = (action) => {
|
|
123
|
+
if (action.disabled || !available()) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (action.closeOnAction !== false) {
|
|
127
|
+
flushSync(close);
|
|
128
|
+
focus();
|
|
129
|
+
}
|
|
130
|
+
action.onAction?.();
|
|
131
|
+
return true;
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
open: localOpen && !unavailable,
|
|
135
|
+
popupRef,
|
|
136
|
+
available,
|
|
137
|
+
changeOpen,
|
|
138
|
+
close,
|
|
139
|
+
focus,
|
|
140
|
+
finalFocus,
|
|
141
|
+
runAction
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/shared/search/combobox-options.tsx
|
|
146
|
+
import { overlayListIndicatorStyles, overlayListItemStyles as overlayListItemStyles2, overlayListLabelStyles, useInteractionOutline, useScrollbars } from "@gridui/overlay";
|
|
26
147
|
import { Check } from "lucide-react";
|
|
27
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
148
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
28
149
|
var ComboboxOptions = (props) => {
|
|
29
150
|
const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight } = props;
|
|
30
151
|
const scrollbarRef = useScrollbars();
|
|
@@ -46,7 +167,7 @@ var ComboboxOptions = (props) => {
|
|
|
46
167
|
"aria-describedby": option.description ? `${itemId}-description` : void 0,
|
|
47
168
|
"data-disabled": option.disabled ? "" : void 0,
|
|
48
169
|
"data-highlighted": active === option.value ? "" : void 0,
|
|
49
|
-
className:
|
|
170
|
+
className: overlayListItemStyles2(),
|
|
50
171
|
onPointerMove: () => {
|
|
51
172
|
onHighlight(option.value);
|
|
52
173
|
},
|
|
@@ -59,20 +180,7 @@ var ComboboxOptions = (props) => {
|
|
|
59
180
|
}
|
|
60
181
|
},
|
|
61
182
|
children: [
|
|
62
|
-
/* @__PURE__ */
|
|
63
|
-
"span",
|
|
64
|
-
{
|
|
65
|
-
className: dropdownIndicatorStyles(),
|
|
66
|
-
"aria-hidden": "true",
|
|
67
|
-
children: checked && /* @__PURE__ */ jsx(
|
|
68
|
-
Check,
|
|
69
|
-
{
|
|
70
|
-
size: 16
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
),
|
|
75
|
-
option.icon && /* @__PURE__ */ jsx(
|
|
183
|
+
option.icon && /* @__PURE__ */ jsx2(
|
|
76
184
|
"span",
|
|
77
185
|
{
|
|
78
186
|
className: selectIconStyles(),
|
|
@@ -85,14 +193,14 @@ var ComboboxOptions = (props) => {
|
|
|
85
193
|
{
|
|
86
194
|
className: selectOptionContentStyles(),
|
|
87
195
|
children: [
|
|
88
|
-
/* @__PURE__ */
|
|
196
|
+
/* @__PURE__ */ jsx2(
|
|
89
197
|
"span",
|
|
90
198
|
{
|
|
91
199
|
id: `${itemId}-label`,
|
|
92
200
|
children: option.label
|
|
93
201
|
}
|
|
94
202
|
),
|
|
95
|
-
option.description && /* @__PURE__ */
|
|
203
|
+
option.description && /* @__PURE__ */ jsx2(
|
|
96
204
|
"span",
|
|
97
205
|
{
|
|
98
206
|
id: `${itemId}-description`,
|
|
@@ -102,13 +210,26 @@ var ComboboxOptions = (props) => {
|
|
|
102
210
|
)
|
|
103
211
|
]
|
|
104
212
|
}
|
|
213
|
+
),
|
|
214
|
+
/* @__PURE__ */ jsx2(
|
|
215
|
+
"span",
|
|
216
|
+
{
|
|
217
|
+
className: overlayListIndicatorStyles(),
|
|
218
|
+
"aria-hidden": "true",
|
|
219
|
+
children: checked && /* @__PURE__ */ jsx2(
|
|
220
|
+
Check,
|
|
221
|
+
{
|
|
222
|
+
size: 16
|
|
223
|
+
}
|
|
224
|
+
)
|
|
225
|
+
}
|
|
105
226
|
)
|
|
106
227
|
]
|
|
107
228
|
},
|
|
108
229
|
option.value
|
|
109
230
|
);
|
|
110
231
|
};
|
|
111
|
-
return /* @__PURE__ */
|
|
232
|
+
return /* @__PURE__ */ jsx2(
|
|
112
233
|
"div",
|
|
113
234
|
{
|
|
114
235
|
ref,
|
|
@@ -124,11 +245,11 @@ var ComboboxOptions = (props) => {
|
|
|
124
245
|
role: "group",
|
|
125
246
|
"aria-labelledby": `${id}-group-${index}`,
|
|
126
247
|
children: [
|
|
127
|
-
/* @__PURE__ */
|
|
248
|
+
/* @__PURE__ */ jsx2(
|
|
128
249
|
"div",
|
|
129
250
|
{
|
|
130
251
|
id: `${id}-group-${index}`,
|
|
131
|
-
className:
|
|
252
|
+
className: overlayListLabelStyles(),
|
|
132
253
|
children: entry.label
|
|
133
254
|
}
|
|
134
255
|
),
|
|
@@ -142,214 +263,6 @@ var ComboboxOptions = (props) => {
|
|
|
142
263
|
);
|
|
143
264
|
};
|
|
144
265
|
|
|
145
|
-
// src/shared/selection-actions.tsx
|
|
146
|
-
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
147
|
-
var SelectionActions = (props) => {
|
|
148
|
-
const { actions, onAction } = props;
|
|
149
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx2(
|
|
150
|
-
"div",
|
|
151
|
-
{
|
|
152
|
-
className: selectActionsStyles(),
|
|
153
|
-
children: actions.map((action) => {
|
|
154
|
-
const content = /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
155
|
-
action.icon && /* @__PURE__ */ jsx2(
|
|
156
|
-
"span",
|
|
157
|
-
{
|
|
158
|
-
className: selectIconStyles(),
|
|
159
|
-
"aria-hidden": "true",
|
|
160
|
-
children: action.icon
|
|
161
|
-
}
|
|
162
|
-
),
|
|
163
|
-
action.label
|
|
164
|
-
] });
|
|
165
|
-
const actionClass = selectActionStyles();
|
|
166
|
-
if (action.href !== void 0) {
|
|
167
|
-
return /* @__PURE__ */ jsx2(
|
|
168
|
-
"a",
|
|
169
|
-
{
|
|
170
|
-
href: action.disabled ? void 0 : action.href,
|
|
171
|
-
target: action.target,
|
|
172
|
-
rel: action.rel,
|
|
173
|
-
"aria-disabled": action.disabled || void 0,
|
|
174
|
-
"data-disabled": action.disabled ? "" : void 0,
|
|
175
|
-
tabIndex: action.disabled ? -1 : void 0,
|
|
176
|
-
className: actionClass,
|
|
177
|
-
onClick: (event) => {
|
|
178
|
-
if (action.disabled) {
|
|
179
|
-
event.preventDefault();
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (!onAction(action)) {
|
|
183
|
-
event.preventDefault();
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
children: content
|
|
187
|
-
},
|
|
188
|
-
action.id
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
return /* @__PURE__ */ jsx2(
|
|
192
|
-
"button",
|
|
193
|
-
{
|
|
194
|
-
type: "button",
|
|
195
|
-
disabled: action.disabled,
|
|
196
|
-
"data-disabled": action.disabled ? "" : void 0,
|
|
197
|
-
className: actionClass,
|
|
198
|
-
onClick: () => {
|
|
199
|
-
onAction(action);
|
|
200
|
-
},
|
|
201
|
-
children: content
|
|
202
|
-
},
|
|
203
|
-
action.id
|
|
204
|
-
);
|
|
205
|
-
})
|
|
206
|
-
}
|
|
207
|
-
) });
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
// src/shared/selection-form.tsx
|
|
211
|
-
import { focusInvalidControl, useFormReset } from "@gridui/form";
|
|
212
|
-
import { useLayoutEffect, useRef } from "react";
|
|
213
|
-
import { flushSync } from "react-dom";
|
|
214
|
-
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
215
|
-
var SelectionForm = (props) => {
|
|
216
|
-
const {
|
|
217
|
-
name,
|
|
218
|
-
form,
|
|
219
|
-
required,
|
|
220
|
-
disabled,
|
|
221
|
-
selectedValue,
|
|
222
|
-
allOptions,
|
|
223
|
-
onValueChange,
|
|
224
|
-
onReset,
|
|
225
|
-
onInvalid
|
|
226
|
-
} = props;
|
|
227
|
-
const nativeRef = useRef(null);
|
|
228
|
-
const resetSelection = useRef(onReset);
|
|
229
|
-
const currentValue = useRef(selectedValue);
|
|
230
|
-
useLayoutEffect(() => {
|
|
231
|
-
resetSelection.current = onReset;
|
|
232
|
-
currentValue.current = selectedValue;
|
|
233
|
-
}, [
|
|
234
|
-
onReset,
|
|
235
|
-
selectedValue
|
|
236
|
-
]);
|
|
237
|
-
useFormReset(nativeRef, () => {
|
|
238
|
-
flushSync(() => {
|
|
239
|
-
resetSelection.current();
|
|
240
|
-
});
|
|
241
|
-
if (nativeRef.current) {
|
|
242
|
-
nativeRef.current.value = currentValue.current;
|
|
243
|
-
}
|
|
244
|
-
}, form);
|
|
245
|
-
return /* @__PURE__ */ jsxs3(
|
|
246
|
-
"select",
|
|
247
|
-
{
|
|
248
|
-
ref: nativeRef,
|
|
249
|
-
"aria-hidden": "true",
|
|
250
|
-
tabIndex: -1,
|
|
251
|
-
className: "gridui-u-sr-only",
|
|
252
|
-
name,
|
|
253
|
-
form,
|
|
254
|
-
required,
|
|
255
|
-
disabled,
|
|
256
|
-
value: selectedValue,
|
|
257
|
-
onChange: (event) => {
|
|
258
|
-
onValueChange(event.currentTarget.value);
|
|
259
|
-
},
|
|
260
|
-
onInvalid: (event) => {
|
|
261
|
-
focusInvalidControl(event, onInvalid);
|
|
262
|
-
},
|
|
263
|
-
children: [
|
|
264
|
-
!allOptions.some((option) => {
|
|
265
|
-
return option.value === "";
|
|
266
|
-
}) && /* @__PURE__ */ jsx3(
|
|
267
|
-
"option",
|
|
268
|
-
{
|
|
269
|
-
value: ""
|
|
270
|
-
}
|
|
271
|
-
),
|
|
272
|
-
selectedValue !== "" && !allOptions.some((option) => {
|
|
273
|
-
return option.value === selectedValue;
|
|
274
|
-
}) && /* @__PURE__ */ jsx3(
|
|
275
|
-
"option",
|
|
276
|
-
{
|
|
277
|
-
value: selectedValue,
|
|
278
|
-
children: selectedValue
|
|
279
|
-
}
|
|
280
|
-
),
|
|
281
|
-
allOptions.map((option) => {
|
|
282
|
-
return /* @__PURE__ */ jsx3(
|
|
283
|
-
"option",
|
|
284
|
-
{
|
|
285
|
-
value: option.value,
|
|
286
|
-
disabled: option.disabled,
|
|
287
|
-
children: option.label
|
|
288
|
-
},
|
|
289
|
-
option.value
|
|
290
|
-
);
|
|
291
|
-
})
|
|
292
|
-
]
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
// src/shared/selection-popup.tsx
|
|
298
|
-
import { isComposingKeyEvent } from "@gridui/interaction";
|
|
299
|
-
import { interactionLayerProps } from "@gridui/overlay";
|
|
300
|
-
import * as Primitive from "@radix-ui/react-popover";
|
|
301
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
302
|
-
var SelectionPopup = (props) => {
|
|
303
|
-
const { container, anchorRef, initialFocus, finalFocus, onEscape, onDismiss, ...restProps } = props;
|
|
304
|
-
return /* @__PURE__ */ jsx4(
|
|
305
|
-
Primitive.Portal,
|
|
306
|
-
{
|
|
307
|
-
container,
|
|
308
|
-
children: /* @__PURE__ */ jsx4(
|
|
309
|
-
Primitive.Content,
|
|
310
|
-
{
|
|
311
|
-
...interactionLayerProps,
|
|
312
|
-
...restProps,
|
|
313
|
-
sideOffset: 8,
|
|
314
|
-
align: "start",
|
|
315
|
-
collisionPadding: 16,
|
|
316
|
-
className: comboboxContentStyles(),
|
|
317
|
-
onOpenAutoFocus: (event) => {
|
|
318
|
-
event.preventDefault();
|
|
319
|
-
initialFocus?.();
|
|
320
|
-
},
|
|
321
|
-
onCloseAutoFocus: (event) => {
|
|
322
|
-
event.preventDefault();
|
|
323
|
-
const target = finalFocus();
|
|
324
|
-
if (target) {
|
|
325
|
-
target.focus();
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
onInteractOutside: (event) => {
|
|
329
|
-
if (anchorRef?.current?.contains(event.target)) {
|
|
330
|
-
event.preventDefault();
|
|
331
|
-
} else {
|
|
332
|
-
onDismiss?.();
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
onEscapeKeyDown: (event) => {
|
|
336
|
-
event.preventDefault();
|
|
337
|
-
event.stopPropagation();
|
|
338
|
-
if (!isComposingKeyEvent(event)) {
|
|
339
|
-
onEscape();
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
onKeyDown: (event) => {
|
|
343
|
-
if (event.key === "Escape") {
|
|
344
|
-
event.stopPropagation();
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
)
|
|
349
|
-
}
|
|
350
|
-
);
|
|
351
|
-
};
|
|
352
|
-
|
|
353
266
|
// src/shared/options.ts
|
|
354
267
|
var flattenOptions = (options) => {
|
|
355
268
|
return options.flatMap((entry) => {
|
|
@@ -378,7 +291,7 @@ var filterOptions = (options, query) => {
|
|
|
378
291
|
});
|
|
379
292
|
};
|
|
380
293
|
|
|
381
|
-
// src/shared/scroll-option.ts
|
|
294
|
+
// src/shared/search/scroll-option.ts
|
|
382
295
|
var scrollOption = (id) => {
|
|
383
296
|
const option = document.getElementById(id);
|
|
384
297
|
const list = option?.closest('[role="listbox"]');
|
|
@@ -394,8 +307,8 @@ var scrollOption = (id) => {
|
|
|
394
307
|
}
|
|
395
308
|
};
|
|
396
309
|
|
|
397
|
-
// src/shared/use-search-options.ts
|
|
398
|
-
import { useEffect, useRef as useRef2, useState } from "react";
|
|
310
|
+
// src/shared/search/use-search-options.ts
|
|
311
|
+
import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
399
312
|
var INITIAL_SEARCH = {
|
|
400
313
|
query: null,
|
|
401
314
|
highlighted: null
|
|
@@ -404,7 +317,7 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
404
317
|
const [
|
|
405
318
|
search,
|
|
406
319
|
setSearch
|
|
407
|
-
] =
|
|
320
|
+
] = useState2(INITIAL_SEARCH);
|
|
408
321
|
const { query: controlledQuery, onQueryChange, filterOptions: shouldFilter = true, loading, errorLabel } = searchProps;
|
|
409
322
|
const wasOpen = useRef2(open);
|
|
410
323
|
const query = open ? controlledQuery ?? search.query : null;
|
|
@@ -430,7 +343,7 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
430
343
|
return `${listId}-${optionIndices.get(value) ?? -1}`;
|
|
431
344
|
};
|
|
432
345
|
const activeOptionId = active ? optionId(active.value) : void 0;
|
|
433
|
-
|
|
346
|
+
useEffect2(() => {
|
|
434
347
|
if (!open && wasOpen.current) {
|
|
435
348
|
setSearch(INITIAL_SEARCH);
|
|
436
349
|
onQueryChange?.("");
|
|
@@ -440,7 +353,7 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
440
353
|
open,
|
|
441
354
|
onQueryChange
|
|
442
355
|
]);
|
|
443
|
-
|
|
356
|
+
useEffect2(() => {
|
|
444
357
|
if (open && activeOptionId !== void 0) {
|
|
445
358
|
scrollOption(activeOptionId);
|
|
446
359
|
}
|
|
@@ -482,88 +395,397 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
482
395
|
highlight(next.value);
|
|
483
396
|
}
|
|
484
397
|
}
|
|
485
|
-
};
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
// src/autocomplete/autocomplete.tsx
|
|
402
|
+
import { useFormReset } from "@gridui/form";
|
|
403
|
+
import { Input } from "@gridui/input";
|
|
404
|
+
import { isComposingKeyEvent as isComposingKeyEvent2 } from "@gridui/interaction";
|
|
405
|
+
import { cn as cn2 } from "@gridui/style-utils";
|
|
406
|
+
import * as Primitive2 from "@radix-ui/react-popover";
|
|
407
|
+
import { useEffect as useEffect3, useId, useImperativeHandle, useRef as useRef3, useState as useState3 } from "react";
|
|
408
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
409
|
+
var Autocomplete = (props) => {
|
|
410
|
+
const {
|
|
411
|
+
value,
|
|
412
|
+
defaultValue = "",
|
|
413
|
+
onValueChange,
|
|
414
|
+
options,
|
|
415
|
+
searchLabel,
|
|
416
|
+
emptyLabel,
|
|
417
|
+
filterOptions: filterOptions2,
|
|
418
|
+
loading,
|
|
419
|
+
loadingLabel,
|
|
420
|
+
errorLabel,
|
|
421
|
+
resultCountLabel,
|
|
422
|
+
portalContainer,
|
|
423
|
+
rootClassName,
|
|
424
|
+
onOptionSelect,
|
|
425
|
+
ref,
|
|
426
|
+
onChange,
|
|
427
|
+
onKeyDown,
|
|
428
|
+
onFocus,
|
|
429
|
+
onClick,
|
|
430
|
+
...restProps
|
|
431
|
+
} = props;
|
|
432
|
+
const [
|
|
433
|
+
local,
|
|
434
|
+
setLocal
|
|
435
|
+
] = useState3(defaultValue);
|
|
436
|
+
const [
|
|
437
|
+
navigating,
|
|
438
|
+
setNavigating
|
|
439
|
+
] = useState3(false);
|
|
440
|
+
const text = value ?? local;
|
|
441
|
+
const input = useRef3(null);
|
|
442
|
+
const anchor = useRef3(null);
|
|
443
|
+
const initial = useRef3(defaultValue);
|
|
444
|
+
useImperativeHandle(ref, () => {
|
|
445
|
+
return input.current;
|
|
446
|
+
});
|
|
447
|
+
const popup = useSelectionPopup({
|
|
448
|
+
disabled: restProps.disabled,
|
|
449
|
+
readOnly: restProps.readOnly,
|
|
450
|
+
controlRef: input
|
|
451
|
+
});
|
|
452
|
+
useEffect3(() => {
|
|
453
|
+
if (!popup.open) {
|
|
454
|
+
setNavigating(false);
|
|
455
|
+
}
|
|
456
|
+
}, [popup.open]);
|
|
457
|
+
const generatedId = useId();
|
|
458
|
+
const listId = `${generatedId}-list`;
|
|
459
|
+
const search = useSearchOptions(options, [], listId, popup.open, {
|
|
460
|
+
query: text,
|
|
461
|
+
filterOptions: filterOptions2,
|
|
462
|
+
loading,
|
|
463
|
+
errorLabel
|
|
464
|
+
});
|
|
465
|
+
const close = () => {
|
|
466
|
+
popup.close();
|
|
467
|
+
setNavigating(false);
|
|
468
|
+
};
|
|
469
|
+
const change = (next) => {
|
|
470
|
+
if (!popup.available()) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (value === void 0) {
|
|
474
|
+
setLocal(next);
|
|
475
|
+
}
|
|
476
|
+
onValueChange?.(next);
|
|
477
|
+
};
|
|
478
|
+
useFormReset(input, () => {
|
|
479
|
+
if (value === void 0) {
|
|
480
|
+
setLocal(initial.current);
|
|
481
|
+
}
|
|
482
|
+
close();
|
|
483
|
+
}, restProps.form);
|
|
484
|
+
const choose = (option) => {
|
|
485
|
+
if (!popup.available() || option.disabled || loading || errorLabel) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
change(option.label);
|
|
489
|
+
close();
|
|
490
|
+
popup.focus();
|
|
491
|
+
onOptionSelect?.(option);
|
|
492
|
+
};
|
|
493
|
+
return /* @__PURE__ */ jsxs2(
|
|
494
|
+
Primitive2.Root,
|
|
495
|
+
{
|
|
496
|
+
open: popup.open,
|
|
497
|
+
onOpenChange: popup.changeOpen,
|
|
498
|
+
children: [
|
|
499
|
+
/* @__PURE__ */ jsx3(
|
|
500
|
+
Primitive2.Anchor,
|
|
501
|
+
{
|
|
502
|
+
asChild: true,
|
|
503
|
+
children: /* @__PURE__ */ jsx3(
|
|
504
|
+
"div",
|
|
505
|
+
{
|
|
506
|
+
ref: anchor,
|
|
507
|
+
dir: restProps.dir,
|
|
508
|
+
className: cn2("gridui-autocomplete gridui-u-select--min-w-0 gridui-u-select--w-full", rootClassName),
|
|
509
|
+
children: /* @__PURE__ */ jsx3(
|
|
510
|
+
Input,
|
|
511
|
+
{
|
|
512
|
+
...restProps,
|
|
513
|
+
id: restProps.id ?? generatedId,
|
|
514
|
+
ref: input,
|
|
515
|
+
type: "text",
|
|
516
|
+
role: "combobox",
|
|
517
|
+
"aria-label": restProps["aria-label"] ?? (restProps.id || restProps["aria-labelledby"] ? void 0 : searchLabel),
|
|
518
|
+
autoComplete: restProps.autoComplete ?? "off",
|
|
519
|
+
value: text,
|
|
520
|
+
"aria-autocomplete": "list",
|
|
521
|
+
"aria-expanded": popup.open,
|
|
522
|
+
"aria-busy": loading || void 0,
|
|
523
|
+
"aria-controls": popup.open ? listId : void 0,
|
|
524
|
+
"aria-activedescendant": popup.open && navigating ? search.activeOptionId : void 0,
|
|
525
|
+
onChange: (event) => {
|
|
526
|
+
onChange?.(event);
|
|
527
|
+
change(event.currentTarget.value);
|
|
528
|
+
search.changeQuery(event.currentTarget.value);
|
|
529
|
+
setNavigating(false);
|
|
530
|
+
popup.changeOpen(true);
|
|
531
|
+
},
|
|
532
|
+
onFocus: (event) => {
|
|
533
|
+
onFocus?.(event);
|
|
534
|
+
if (!event.defaultPrevented) {
|
|
535
|
+
popup.changeOpen(true);
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
onClick: (event) => {
|
|
539
|
+
onClick?.(event);
|
|
540
|
+
if (!event.defaultPrevented) {
|
|
541
|
+
popup.changeOpen(true);
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
onKeyDown: (event) => {
|
|
545
|
+
onKeyDown?.(event);
|
|
546
|
+
if (event.defaultPrevented || !popup.available()) {
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (isComposingKeyEvent2(event.nativeEvent)) {
|
|
550
|
+
if (event.key === "Enter" || event.key === "Escape") {
|
|
551
|
+
event.stopPropagation();
|
|
552
|
+
}
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
556
|
+
event.preventDefault();
|
|
557
|
+
popup.changeOpen(true);
|
|
558
|
+
if (navigating && popup.open) {
|
|
559
|
+
search.moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
560
|
+
}
|
|
561
|
+
setNavigating(true);
|
|
562
|
+
} else if (event.key === "Enter" && popup.open && navigating && search.activeOption) {
|
|
563
|
+
event.preventDefault();
|
|
564
|
+
choose(search.activeOption);
|
|
565
|
+
} else if (event.key === "Escape" && popup.open) {
|
|
566
|
+
event.preventDefault();
|
|
567
|
+
event.stopPropagation();
|
|
568
|
+
close();
|
|
569
|
+
} else if (event.key === "Tab") {
|
|
570
|
+
close();
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
)
|
|
575
|
+
}
|
|
576
|
+
)
|
|
577
|
+
}
|
|
578
|
+
),
|
|
579
|
+
/* @__PURE__ */ jsxs2(
|
|
580
|
+
SelectionPopup,
|
|
581
|
+
{
|
|
582
|
+
ref: popup.popupRef,
|
|
583
|
+
container: portalContainer,
|
|
584
|
+
anchorRef: anchor,
|
|
585
|
+
dir: restProps.dir,
|
|
586
|
+
role: "presentation",
|
|
587
|
+
finalFocus: popup.finalFocus,
|
|
588
|
+
onDismiss: close,
|
|
589
|
+
onEscape: () => {
|
|
590
|
+
close();
|
|
591
|
+
popup.focus();
|
|
592
|
+
},
|
|
593
|
+
children: [
|
|
594
|
+
/* @__PURE__ */ jsx3(
|
|
595
|
+
"div",
|
|
596
|
+
{
|
|
597
|
+
role: "status",
|
|
598
|
+
"aria-atomic": "true",
|
|
599
|
+
className: cn2(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
600
|
+
children: loading ? loadingLabel : errorLabel ?? (search.visible.length ? resultCountLabel?.(search.visible.length) : emptyLabel)
|
|
601
|
+
}
|
|
602
|
+
),
|
|
603
|
+
/* @__PURE__ */ jsx3(
|
|
604
|
+
ComboboxOptions,
|
|
605
|
+
{
|
|
606
|
+
id: listId,
|
|
607
|
+
label: searchLabel,
|
|
608
|
+
options: search.filtered,
|
|
609
|
+
selected: [],
|
|
610
|
+
active: navigating ? search.active : null,
|
|
611
|
+
optionId: search.optionId,
|
|
612
|
+
onSelect: choose,
|
|
613
|
+
onHighlight: (next) => {
|
|
614
|
+
setNavigating(true);
|
|
615
|
+
search.highlight(next);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
)
|
|
619
|
+
]
|
|
620
|
+
}
|
|
621
|
+
)
|
|
622
|
+
]
|
|
623
|
+
}
|
|
624
|
+
);
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
// src/shared/popup/selection-actions.tsx
|
|
628
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
629
|
+
var SelectionActions = (props) => {
|
|
630
|
+
const { actions, onAction } = props;
|
|
631
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx4(
|
|
632
|
+
"div",
|
|
633
|
+
{
|
|
634
|
+
className: selectActionsStyles(),
|
|
635
|
+
children: actions.map((action) => {
|
|
636
|
+
const content = /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
637
|
+
action.icon && /* @__PURE__ */ jsx4(
|
|
638
|
+
"span",
|
|
639
|
+
{
|
|
640
|
+
className: selectIconStyles(),
|
|
641
|
+
"aria-hidden": "true",
|
|
642
|
+
children: action.icon
|
|
643
|
+
}
|
|
644
|
+
),
|
|
645
|
+
action.label
|
|
646
|
+
] });
|
|
647
|
+
const actionClass = selectActionStyles();
|
|
648
|
+
if (action.href !== void 0) {
|
|
649
|
+
return /* @__PURE__ */ jsx4(
|
|
650
|
+
"a",
|
|
651
|
+
{
|
|
652
|
+
href: action.disabled ? void 0 : action.href,
|
|
653
|
+
target: action.target,
|
|
654
|
+
rel: action.rel,
|
|
655
|
+
"aria-disabled": action.disabled || void 0,
|
|
656
|
+
"data-disabled": action.disabled ? "" : void 0,
|
|
657
|
+
tabIndex: action.disabled ? -1 : void 0,
|
|
658
|
+
className: actionClass,
|
|
659
|
+
onClick: (event) => {
|
|
660
|
+
if (action.disabled) {
|
|
661
|
+
event.preventDefault();
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
if (!onAction(action)) {
|
|
665
|
+
event.preventDefault();
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
children: content
|
|
669
|
+
},
|
|
670
|
+
action.id
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
return /* @__PURE__ */ jsx4(
|
|
674
|
+
"button",
|
|
675
|
+
{
|
|
676
|
+
type: "button",
|
|
677
|
+
disabled: action.disabled,
|
|
678
|
+
"data-disabled": action.disabled ? "" : void 0,
|
|
679
|
+
className: actionClass,
|
|
680
|
+
onClick: () => {
|
|
681
|
+
onAction(action);
|
|
682
|
+
},
|
|
683
|
+
children: content
|
|
684
|
+
},
|
|
685
|
+
action.id
|
|
686
|
+
);
|
|
687
|
+
})
|
|
688
|
+
}
|
|
689
|
+
) });
|
|
486
690
|
};
|
|
487
691
|
|
|
488
|
-
// src/shared/
|
|
489
|
-
import {
|
|
692
|
+
// src/shared/selection-form.tsx
|
|
693
|
+
import { focusInvalidControl, useFormReset as useFormReset2 } from "@gridui/form";
|
|
694
|
+
import { useLayoutEffect, useRef as useRef4 } from "react";
|
|
490
695
|
import { flushSync as flushSync2 } from "react-dom";
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const focus = () => {
|
|
521
|
-
controlRef.current?.focus();
|
|
522
|
-
};
|
|
523
|
-
const finalFocus = () => {
|
|
524
|
-
const control = controlRef.current;
|
|
525
|
-
if (!restoreFocus.current || !control) {
|
|
526
|
-
return false;
|
|
527
|
-
}
|
|
528
|
-
const active = control.ownerDocument.activeElement;
|
|
529
|
-
if (active && active !== control.ownerDocument.body && active !== control && !popupRef.current?.contains(active)) {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
return control;
|
|
533
|
-
};
|
|
534
|
-
const runAction = (action) => {
|
|
535
|
-
if (action.disabled || !available()) {
|
|
536
|
-
return false;
|
|
696
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
697
|
+
var SelectionForm = (props) => {
|
|
698
|
+
const {
|
|
699
|
+
name,
|
|
700
|
+
form,
|
|
701
|
+
required,
|
|
702
|
+
disabled,
|
|
703
|
+
selectedValue,
|
|
704
|
+
allOptions,
|
|
705
|
+
onValueChange,
|
|
706
|
+
onReset,
|
|
707
|
+
onInvalid
|
|
708
|
+
} = props;
|
|
709
|
+
const nativeRef = useRef4(null);
|
|
710
|
+
const resetSelection = useRef4(onReset);
|
|
711
|
+
const currentValue = useRef4(selectedValue);
|
|
712
|
+
useLayoutEffect(() => {
|
|
713
|
+
resetSelection.current = onReset;
|
|
714
|
+
currentValue.current = selectedValue;
|
|
715
|
+
}, [
|
|
716
|
+
onReset,
|
|
717
|
+
selectedValue
|
|
718
|
+
]);
|
|
719
|
+
useFormReset2(nativeRef, () => {
|
|
720
|
+
flushSync2(() => {
|
|
721
|
+
resetSelection.current();
|
|
722
|
+
});
|
|
723
|
+
if (nativeRef.current) {
|
|
724
|
+
nativeRef.current.value = currentValue.current;
|
|
537
725
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
726
|
+
}, form);
|
|
727
|
+
return /* @__PURE__ */ jsxs4(
|
|
728
|
+
"select",
|
|
729
|
+
{
|
|
730
|
+
ref: nativeRef,
|
|
731
|
+
"aria-hidden": "true",
|
|
732
|
+
tabIndex: -1,
|
|
733
|
+
className: "gridui-u-select--sr-only",
|
|
734
|
+
name,
|
|
735
|
+
form,
|
|
736
|
+
required,
|
|
737
|
+
disabled,
|
|
738
|
+
value: selectedValue,
|
|
739
|
+
onChange: (event) => {
|
|
740
|
+
onValueChange(event.currentTarget.value);
|
|
741
|
+
},
|
|
742
|
+
onInvalid: (event) => {
|
|
743
|
+
focusInvalidControl(event, onInvalid);
|
|
744
|
+
},
|
|
745
|
+
children: [
|
|
746
|
+
!allOptions.some((option) => {
|
|
747
|
+
return option.value === "";
|
|
748
|
+
}) && /* @__PURE__ */ jsx5(
|
|
749
|
+
"option",
|
|
750
|
+
{
|
|
751
|
+
value: ""
|
|
752
|
+
}
|
|
753
|
+
),
|
|
754
|
+
selectedValue !== "" && !allOptions.some((option) => {
|
|
755
|
+
return option.value === selectedValue;
|
|
756
|
+
}) && /* @__PURE__ */ jsx5(
|
|
757
|
+
"option",
|
|
758
|
+
{
|
|
759
|
+
value: selectedValue,
|
|
760
|
+
children: selectedValue
|
|
761
|
+
}
|
|
762
|
+
),
|
|
763
|
+
allOptions.map((option) => {
|
|
764
|
+
return /* @__PURE__ */ jsx5(
|
|
765
|
+
"option",
|
|
766
|
+
{
|
|
767
|
+
value: option.value,
|
|
768
|
+
disabled: option.disabled,
|
|
769
|
+
children: option.label
|
|
770
|
+
},
|
|
771
|
+
option.value
|
|
772
|
+
);
|
|
773
|
+
})
|
|
774
|
+
]
|
|
541
775
|
}
|
|
542
|
-
|
|
543
|
-
return true;
|
|
544
|
-
};
|
|
545
|
-
return {
|
|
546
|
-
open: localOpen && !unavailable,
|
|
547
|
-
popupRef,
|
|
548
|
-
available,
|
|
549
|
-
changeOpen,
|
|
550
|
-
close,
|
|
551
|
-
focus,
|
|
552
|
-
finalFocus,
|
|
553
|
-
runAction
|
|
554
|
-
};
|
|
776
|
+
);
|
|
555
777
|
};
|
|
556
778
|
|
|
557
779
|
// src/shared/use-selection-value.ts
|
|
558
|
-
import { useRef as
|
|
780
|
+
import { useRef as useRef5, useState as useState4 } from "react";
|
|
559
781
|
var useSelectionValue = (props, available) => {
|
|
560
782
|
const { value, defaultValue = "", onValueChange } = props;
|
|
561
783
|
const [
|
|
562
784
|
localValue,
|
|
563
785
|
setLocalValue
|
|
564
|
-
] =
|
|
786
|
+
] = useState4(defaultValue);
|
|
565
787
|
const selectedValue = value ?? localValue;
|
|
566
|
-
const initialValue =
|
|
788
|
+
const initialValue = useRef5(selectedValue);
|
|
567
789
|
const update = (next) => {
|
|
568
790
|
if (next === selectedValue) {
|
|
569
791
|
return;
|
|
@@ -588,17 +810,17 @@ var useSelectionValue = (props, available) => {
|
|
|
588
810
|
|
|
589
811
|
// src/combobox/style.ts
|
|
590
812
|
import { cva as cva2 } from "class-variance-authority";
|
|
591
|
-
var comboboxInputStyles = cva2("gridui-u-pr-11 gridui-u-text-ellipsis");
|
|
592
|
-
var comboboxTriggerStyles = cva2("gridui-u-absolute gridui-u-inset-y-0 gridui-u-right-0 gridui-u-flex gridui-u-w-9 gridui-u-items-center gridui-u-justify-center gridui-u-rounded-control gridui-u-text-foreground gridui-u-cursor-pointer gridui-u-disabled:cursor-not-allowed gridui-u-disabled:opacity-50");
|
|
813
|
+
var comboboxInputStyles = cva2("gridui-u-select--pr-11 gridui-u-select--text-ellipsis");
|
|
814
|
+
var comboboxTriggerStyles = cva2("gridui-u-select--absolute gridui-u-select--inset-y-0 gridui-u-select--right-0 gridui-u-select--flex gridui-u-select--w-9 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--rounded-control gridui-u-select--text-foreground gridui-u-select--cursor-pointer gridui-u-select--disabled:cursor-not-allowed gridui-u-select--disabled:opacity-50");
|
|
593
815
|
|
|
594
816
|
// src/combobox/combobox.tsx
|
|
595
817
|
import { controlVariants } from "@gridui/input";
|
|
596
|
-
import { isComposingKeyEvent as
|
|
597
|
-
import { cn as
|
|
598
|
-
import * as
|
|
818
|
+
import { isComposingKeyEvent as isComposingKeyEvent3 } from "@gridui/interaction";
|
|
819
|
+
import { cn as cn3 } from "@gridui/style-utils";
|
|
820
|
+
import * as Primitive3 from "@radix-ui/react-popover";
|
|
599
821
|
import { ChevronDown, X } from "lucide-react";
|
|
600
|
-
import { useId, useRef as
|
|
601
|
-
import { jsx as
|
|
822
|
+
import { useId as useId2, useRef as useRef6 } from "react";
|
|
823
|
+
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
602
824
|
var Combobox = (props) => {
|
|
603
825
|
const {
|
|
604
826
|
options,
|
|
@@ -631,8 +853,8 @@ var Combobox = (props) => {
|
|
|
631
853
|
resultCountLabel,
|
|
632
854
|
...restProps
|
|
633
855
|
} = props;
|
|
634
|
-
const controlRef =
|
|
635
|
-
const anchorRef =
|
|
856
|
+
const controlRef = useRef6(null);
|
|
857
|
+
const anchorRef = useRef6(null);
|
|
636
858
|
const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
|
|
637
859
|
disabled,
|
|
638
860
|
readOnly,
|
|
@@ -643,7 +865,7 @@ var Combobox = (props) => {
|
|
|
643
865
|
defaultValue,
|
|
644
866
|
onValueChange
|
|
645
867
|
}, available);
|
|
646
|
-
const inputId =
|
|
868
|
+
const inputId = useId2();
|
|
647
869
|
const listId = `${inputId}-list`;
|
|
648
870
|
const search = useSearchOptions(options, [selectedValue], listId, open, {
|
|
649
871
|
query: controlledQuery,
|
|
@@ -668,29 +890,29 @@ var Combobox = (props) => {
|
|
|
668
890
|
close();
|
|
669
891
|
focus();
|
|
670
892
|
};
|
|
671
|
-
return /* @__PURE__ */
|
|
672
|
-
|
|
893
|
+
return /* @__PURE__ */ jsxs5(
|
|
894
|
+
Primitive3.Root,
|
|
673
895
|
{
|
|
674
896
|
open,
|
|
675
897
|
onOpenChange: changeOpen,
|
|
676
898
|
children: [
|
|
677
|
-
/* @__PURE__ */
|
|
899
|
+
/* @__PURE__ */ jsxs5(
|
|
678
900
|
"div",
|
|
679
901
|
{
|
|
680
|
-
className: "gridui-u-relative gridui-u-flex gridui-u-min-w-0 gridui-u-w-full gridui-u-items-stretch gridui-u-gap-gridui-4",
|
|
902
|
+
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--w-full gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
|
|
681
903
|
dir,
|
|
682
904
|
children: [
|
|
683
|
-
/* @__PURE__ */
|
|
684
|
-
|
|
905
|
+
/* @__PURE__ */ jsx6(
|
|
906
|
+
Primitive3.Anchor,
|
|
685
907
|
{
|
|
686
908
|
asChild: true,
|
|
687
|
-
children: /* @__PURE__ */
|
|
909
|
+
children: /* @__PURE__ */ jsxs5(
|
|
688
910
|
"div",
|
|
689
911
|
{
|
|
690
912
|
ref: anchorRef,
|
|
691
|
-
className: "gridui-u-relative gridui-u-flex gridui-u-min-w-0 gridui-u-flex-1 gridui-u-items-stretch",
|
|
913
|
+
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--items-stretch",
|
|
692
914
|
children: [
|
|
693
|
-
/* @__PURE__ */
|
|
915
|
+
/* @__PURE__ */ jsx6(
|
|
694
916
|
"input",
|
|
695
917
|
{
|
|
696
918
|
...restProps,
|
|
@@ -718,7 +940,7 @@ var Combobox = (props) => {
|
|
|
718
940
|
form,
|
|
719
941
|
disabled,
|
|
720
942
|
readOnly,
|
|
721
|
-
className:
|
|
943
|
+
className: cn3(controlVariants({ size: controlSize }), comboboxInputStyles(), className),
|
|
722
944
|
value: text,
|
|
723
945
|
onClick: (event) => {
|
|
724
946
|
onClick?.(event);
|
|
@@ -738,7 +960,7 @@ var Combobox = (props) => {
|
|
|
738
960
|
if (event.defaultPrevented || readOnly) {
|
|
739
961
|
return;
|
|
740
962
|
}
|
|
741
|
-
if (
|
|
963
|
+
if (isComposingKeyEvent3(event.nativeEvent)) {
|
|
742
964
|
if (event.key === "Enter" || event.key === "Escape") {
|
|
743
965
|
event.stopPropagation();
|
|
744
966
|
}
|
|
@@ -776,7 +998,7 @@ var Combobox = (props) => {
|
|
|
776
998
|
}
|
|
777
999
|
}
|
|
778
1000
|
),
|
|
779
|
-
/* @__PURE__ */
|
|
1001
|
+
/* @__PURE__ */ jsx6(
|
|
780
1002
|
"button",
|
|
781
1003
|
{
|
|
782
1004
|
type: "button",
|
|
@@ -791,7 +1013,7 @@ var Combobox = (props) => {
|
|
|
791
1013
|
}
|
|
792
1014
|
focus();
|
|
793
1015
|
},
|
|
794
|
-
children: /* @__PURE__ */
|
|
1016
|
+
children: /* @__PURE__ */ jsx6(
|
|
795
1017
|
ChevronDown,
|
|
796
1018
|
{
|
|
797
1019
|
size: 16,
|
|
@@ -805,7 +1027,7 @@ var Combobox = (props) => {
|
|
|
805
1027
|
)
|
|
806
1028
|
}
|
|
807
1029
|
),
|
|
808
|
-
clearLabel && /* @__PURE__ */
|
|
1030
|
+
clearLabel && /* @__PURE__ */ jsx6(
|
|
809
1031
|
"button",
|
|
810
1032
|
{
|
|
811
1033
|
type: "button",
|
|
@@ -816,8 +1038,8 @@ var Combobox = (props) => {
|
|
|
816
1038
|
close();
|
|
817
1039
|
focus();
|
|
818
1040
|
},
|
|
819
|
-
className:
|
|
820
|
-
children: /* @__PURE__ */
|
|
1041
|
+
className: cn3(controlVariants({ size: controlSize }), "gridui-u-select--flex gridui-u-select--w-auto gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--min-w-11 gridui-u-select--cursor-pointer"),
|
|
1042
|
+
children: /* @__PURE__ */ jsx6(
|
|
821
1043
|
X,
|
|
822
1044
|
{
|
|
823
1045
|
size: 16,
|
|
@@ -826,7 +1048,7 @@ var Combobox = (props) => {
|
|
|
826
1048
|
)
|
|
827
1049
|
}
|
|
828
1050
|
),
|
|
829
|
-
/* @__PURE__ */
|
|
1051
|
+
/* @__PURE__ */ jsx6(
|
|
830
1052
|
SelectionForm,
|
|
831
1053
|
{
|
|
832
1054
|
name,
|
|
@@ -846,7 +1068,7 @@ var Combobox = (props) => {
|
|
|
846
1068
|
]
|
|
847
1069
|
}
|
|
848
1070
|
),
|
|
849
|
-
/* @__PURE__ */
|
|
1071
|
+
/* @__PURE__ */ jsxs5(
|
|
850
1072
|
SelectionPopup,
|
|
851
1073
|
{
|
|
852
1074
|
container: portalContainer,
|
|
@@ -861,16 +1083,16 @@ var Combobox = (props) => {
|
|
|
861
1083
|
focus();
|
|
862
1084
|
},
|
|
863
1085
|
children: [
|
|
864
|
-
/* @__PURE__ */
|
|
1086
|
+
/* @__PURE__ */ jsx6(
|
|
865
1087
|
"div",
|
|
866
1088
|
{
|
|
867
1089
|
role: "status",
|
|
868
1090
|
"aria-atomic": "true",
|
|
869
|
-
className:
|
|
1091
|
+
className: cn3(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
870
1092
|
children: loading ? loadingLabel : errorLabel ?? (visible.length ? resultCountLabel?.(visible.length) : emptyLabel)
|
|
871
1093
|
}
|
|
872
1094
|
),
|
|
873
|
-
/* @__PURE__ */
|
|
1095
|
+
/* @__PURE__ */ jsx6(
|
|
874
1096
|
ComboboxOptions,
|
|
875
1097
|
{
|
|
876
1098
|
id: listId,
|
|
@@ -883,7 +1105,7 @@ var Combobox = (props) => {
|
|
|
883
1105
|
onHighlight: search.highlight
|
|
884
1106
|
}
|
|
885
1107
|
),
|
|
886
|
-
/* @__PURE__ */
|
|
1108
|
+
/* @__PURE__ */ jsx6(
|
|
887
1109
|
SelectionActions,
|
|
888
1110
|
{
|
|
889
1111
|
actions,
|
|
@@ -901,12 +1123,12 @@ var Combobox = (props) => {
|
|
|
901
1123
|
// src/multi-select/multi-select.tsx
|
|
902
1124
|
import { ListFieldControl, useListField } from "@gridui/form";
|
|
903
1125
|
import { controlVariants as controlVariants2 } from "@gridui/input";
|
|
904
|
-
import { isComposingKeyEvent as
|
|
905
|
-
import { cn as
|
|
906
|
-
import * as
|
|
1126
|
+
import { isComposingKeyEvent as isComposingKeyEvent4 } from "@gridui/interaction";
|
|
1127
|
+
import { cn as cn4 } from "@gridui/style-utils";
|
|
1128
|
+
import * as Primitive4 from "@radix-ui/react-popover";
|
|
907
1129
|
import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
|
|
908
|
-
import { useId as
|
|
909
|
-
import { jsx as
|
|
1130
|
+
import { useId as useId3, useRef as useRef7 } from "react";
|
|
1131
|
+
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
910
1132
|
var MultiSelect = (props) => {
|
|
911
1133
|
const {
|
|
912
1134
|
value,
|
|
@@ -935,8 +1157,8 @@ var MultiSelect = (props) => {
|
|
|
935
1157
|
resultCountLabel,
|
|
936
1158
|
...restProps
|
|
937
1159
|
} = props;
|
|
938
|
-
const search =
|
|
939
|
-
const id =
|
|
1160
|
+
const search = useRef7(null);
|
|
1161
|
+
const id = useId3();
|
|
940
1162
|
const { selected, native, control, change } = useListField({
|
|
941
1163
|
value,
|
|
942
1164
|
defaultValue,
|
|
@@ -972,23 +1194,23 @@ var MultiSelect = (props) => {
|
|
|
972
1194
|
]);
|
|
973
1195
|
search.current?.focus({ preventScroll: true });
|
|
974
1196
|
};
|
|
975
|
-
return /* @__PURE__ */
|
|
976
|
-
|
|
1197
|
+
return /* @__PURE__ */ jsxs6(
|
|
1198
|
+
Primitive4.Root,
|
|
977
1199
|
{
|
|
978
1200
|
open,
|
|
979
1201
|
onOpenChange: changeOpen,
|
|
980
1202
|
children: [
|
|
981
|
-
/* @__PURE__ */
|
|
1203
|
+
/* @__PURE__ */ jsxs6(
|
|
982
1204
|
"div",
|
|
983
1205
|
{
|
|
984
|
-
className: "gridui-u-flex gridui-u-min-w-0 gridui-u-items-stretch gridui-u-gap-gridui-4",
|
|
1206
|
+
className: "gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
|
|
985
1207
|
dir: restProps.dir,
|
|
986
1208
|
children: [
|
|
987
|
-
/* @__PURE__ */
|
|
988
|
-
|
|
1209
|
+
/* @__PURE__ */ jsx7(
|
|
1210
|
+
Primitive4.Trigger,
|
|
989
1211
|
{
|
|
990
1212
|
asChild: true,
|
|
991
|
-
children: /* @__PURE__ */
|
|
1213
|
+
children: /* @__PURE__ */ jsxs6(
|
|
992
1214
|
"button",
|
|
993
1215
|
{
|
|
994
1216
|
...restProps,
|
|
@@ -1006,7 +1228,7 @@ var MultiSelect = (props) => {
|
|
|
1006
1228
|
ref.current = element;
|
|
1007
1229
|
}
|
|
1008
1230
|
},
|
|
1009
|
-
className:
|
|
1231
|
+
className: cn4(controlVariants2(), "gridui-u-select--flex gridui-u-select--flex-1 gridui-u-select--items-center gridui-u-select--gap-gridui-8 gridui-u-select--text-start", className),
|
|
1010
1232
|
onKeyDown: (event) => {
|
|
1011
1233
|
onKeyDown?.(event);
|
|
1012
1234
|
if (!event.defaultPrevented && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
@@ -1015,10 +1237,10 @@ var MultiSelect = (props) => {
|
|
|
1015
1237
|
}
|
|
1016
1238
|
},
|
|
1017
1239
|
children: [
|
|
1018
|
-
/* @__PURE__ */
|
|
1240
|
+
/* @__PURE__ */ jsx7(
|
|
1019
1241
|
"span",
|
|
1020
1242
|
{
|
|
1021
|
-
className: "gridui-u-min-w-0 gridui-u-flex-1 gridui-u-wrap-anywhere",
|
|
1243
|
+
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--wrap-anywhere",
|
|
1022
1244
|
children: selected.length ? selected.map((entry) => {
|
|
1023
1245
|
return all.find((option) => {
|
|
1024
1246
|
return option.value === entry;
|
|
@@ -1026,7 +1248,7 @@ var MultiSelect = (props) => {
|
|
|
1026
1248
|
}).join(", ") : placeholder
|
|
1027
1249
|
}
|
|
1028
1250
|
),
|
|
1029
|
-
/* @__PURE__ */
|
|
1251
|
+
/* @__PURE__ */ jsx7(
|
|
1030
1252
|
ChevronDown2,
|
|
1031
1253
|
{
|
|
1032
1254
|
size: 16,
|
|
@@ -1038,18 +1260,18 @@ var MultiSelect = (props) => {
|
|
|
1038
1260
|
)
|
|
1039
1261
|
}
|
|
1040
1262
|
),
|
|
1041
|
-
clearLabel && /* @__PURE__ */
|
|
1263
|
+
clearLabel && /* @__PURE__ */ jsx7(
|
|
1042
1264
|
"button",
|
|
1043
1265
|
{
|
|
1044
1266
|
type: "button",
|
|
1045
1267
|
"aria-label": clearLabel,
|
|
1046
1268
|
disabled: disabled || readOnly || required || !selected.length,
|
|
1047
|
-
className:
|
|
1269
|
+
className: cn4(controlVariants2(), "gridui-u-select--flex gridui-u-select--w-auto gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--min-w-11 gridui-u-select--cursor-pointer"),
|
|
1048
1270
|
onClick: () => {
|
|
1049
1271
|
change([]);
|
|
1050
1272
|
control.current?.focus();
|
|
1051
1273
|
},
|
|
1052
|
-
children: /* @__PURE__ */
|
|
1274
|
+
children: /* @__PURE__ */ jsx7(
|
|
1053
1275
|
X2,
|
|
1054
1276
|
{
|
|
1055
1277
|
size: 16,
|
|
@@ -1058,7 +1280,7 @@ var MultiSelect = (props) => {
|
|
|
1058
1280
|
)
|
|
1059
1281
|
}
|
|
1060
1282
|
),
|
|
1061
|
-
/* @__PURE__ */
|
|
1283
|
+
/* @__PURE__ */ jsxs6(
|
|
1062
1284
|
ListFieldControl,
|
|
1063
1285
|
{
|
|
1064
1286
|
ref: native,
|
|
@@ -1073,7 +1295,7 @@ var MultiSelect = (props) => {
|
|
|
1073
1295
|
},
|
|
1074
1296
|
children: [
|
|
1075
1297
|
all.map((option) => {
|
|
1076
|
-
return /* @__PURE__ */
|
|
1298
|
+
return /* @__PURE__ */ jsx7(
|
|
1077
1299
|
"option",
|
|
1078
1300
|
{
|
|
1079
1301
|
value: option.value,
|
|
@@ -1088,7 +1310,7 @@ var MultiSelect = (props) => {
|
|
|
1088
1310
|
return option.value === entry;
|
|
1089
1311
|
});
|
|
1090
1312
|
}).map((entry) => {
|
|
1091
|
-
return /* @__PURE__ */
|
|
1313
|
+
return /* @__PURE__ */ jsx7(
|
|
1092
1314
|
"option",
|
|
1093
1315
|
{
|
|
1094
1316
|
value: entry,
|
|
@@ -1103,7 +1325,7 @@ var MultiSelect = (props) => {
|
|
|
1103
1325
|
]
|
|
1104
1326
|
}
|
|
1105
1327
|
),
|
|
1106
|
-
/* @__PURE__ */
|
|
1328
|
+
/* @__PURE__ */ jsxs6(
|
|
1107
1329
|
SelectionPopup,
|
|
1108
1330
|
{
|
|
1109
1331
|
container: portalContainer,
|
|
@@ -1119,7 +1341,7 @@ var MultiSelect = (props) => {
|
|
|
1119
1341
|
focus();
|
|
1120
1342
|
},
|
|
1121
1343
|
children: [
|
|
1122
|
-
/* @__PURE__ */
|
|
1344
|
+
/* @__PURE__ */ jsx7(
|
|
1123
1345
|
"input",
|
|
1124
1346
|
{
|
|
1125
1347
|
ref: search,
|
|
@@ -1132,12 +1354,12 @@ var MultiSelect = (props) => {
|
|
|
1132
1354
|
"aria-controls": `${id}-list`,
|
|
1133
1355
|
"aria-activedescendant": activeOptionId,
|
|
1134
1356
|
value: query ?? "",
|
|
1135
|
-
className:
|
|
1357
|
+
className: cn4(controlVariants2({ size: "small" }), "gridui-u-select--m-gridui-8 gridui-u-select--w-auto gridui-u-select--shrink-0"),
|
|
1136
1358
|
onChange: (event) => {
|
|
1137
1359
|
searchOptions.changeQuery(event.target.value);
|
|
1138
1360
|
},
|
|
1139
1361
|
onKeyDown: (event) => {
|
|
1140
|
-
if (
|
|
1362
|
+
if (isComposingKeyEvent4(event.nativeEvent)) {
|
|
1141
1363
|
event.stopPropagation();
|
|
1142
1364
|
return;
|
|
1143
1365
|
}
|
|
@@ -1155,7 +1377,7 @@ var MultiSelect = (props) => {
|
|
|
1155
1377
|
}
|
|
1156
1378
|
}
|
|
1157
1379
|
),
|
|
1158
|
-
/* @__PURE__ */
|
|
1380
|
+
/* @__PURE__ */ jsx7(
|
|
1159
1381
|
ComboboxOptions,
|
|
1160
1382
|
{
|
|
1161
1383
|
id: `${id}-list`,
|
|
@@ -1169,12 +1391,12 @@ var MultiSelect = (props) => {
|
|
|
1169
1391
|
onHighlight: searchOptions.highlight
|
|
1170
1392
|
}
|
|
1171
1393
|
),
|
|
1172
|
-
/* @__PURE__ */
|
|
1394
|
+
/* @__PURE__ */ jsx7(
|
|
1173
1395
|
"div",
|
|
1174
1396
|
{
|
|
1175
1397
|
role: "status",
|
|
1176
1398
|
"aria-atomic": "true",
|
|
1177
|
-
className:
|
|
1399
|
+
className: cn4(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
1178
1400
|
children: loading ? loadingLabel : errorLabel ?? (visible.length ? resultCountLabel?.(visible.length) : emptyLabel)
|
|
1179
1401
|
}
|
|
1180
1402
|
)
|
|
@@ -1186,33 +1408,12 @@ var MultiSelect = (props) => {
|
|
|
1186
1408
|
);
|
|
1187
1409
|
};
|
|
1188
1410
|
|
|
1189
|
-
// src/select/style.ts
|
|
1190
|
-
import { overlaySurfaceStyles as overlaySurfaceStyles2 } from "@gridui/overlay";
|
|
1191
|
-
import { cn as cn4 } from "@gridui/style-utils";
|
|
1192
|
-
import { cva as cva3 } from "class-variance-authority";
|
|
1193
|
-
var selectContentStyles = cva3(cn4(
|
|
1194
|
-
overlaySurfaceStyles2(),
|
|
1195
|
-
"gridui-u-z-(--gridui-z-popover) gridui-u-p-gridui-4 gridui-u-type-data",
|
|
1196
|
-
"gridui-select-content gridui-u-box-border gridui-u-relative gridui-u-flex gridui-u-flex-col gridui-u-overflow-hidden gridui-u-min-w-0 gridui-u-w-(--anchor-width) gridui-u-max-w-(--available-width) gridui-u-max-h-(--available-height)"
|
|
1197
|
-
));
|
|
1198
|
-
var selectMenuItemStyles = cva3(cn4(selectItemStyles(), "gridui-u-relative gridui-u-px-gridui-4 gridui-u-pr-9"));
|
|
1199
|
-
var selectIndicatorStyles = cva3("gridui-u-absolute gridui-u-inset-y-0 gridui-u-right-gridui-4 gridui-u-flex gridui-u-w-gridui-16 gridui-u-items-center gridui-u-justify-center gridui-u-text-foreground");
|
|
1200
|
-
var selectScrollArrowStyles = cva3("gridui-u-absolute gridui-u-inset-x-0 gridui-u-z-(--gridui-z-content) gridui-u-flex gridui-u-h-gridui-24 gridui-u-items-center gridui-u-justify-center gridui-u-bg-background gridui-u-text-foreground", {
|
|
1201
|
-
variants: {
|
|
1202
|
-
direction: {
|
|
1203
|
-
up: "gridui-u-top-0",
|
|
1204
|
-
down: "gridui-u-bottom-0"
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
});
|
|
1208
|
-
|
|
1209
1411
|
// src/select/select-options.tsx
|
|
1210
|
-
import {
|
|
1211
|
-
import
|
|
1212
|
-
import * as Primitive4 from "@radix-ui/react-select";
|
|
1412
|
+
import { overlayListIndicatorStyles as overlayListIndicatorStyles2, overlayListItemStyles as overlayListItemStyles3, overlayListLabelStyles as overlayListLabelStyles2, useInteractionOutline as useInteractionOutline2, useScrollbars as useScrollbars2 } from "@gridui/overlay";
|
|
1413
|
+
import * as Primitive5 from "@radix-ui/react-select";
|
|
1213
1414
|
import { Check as Check2 } from "lucide-react";
|
|
1214
|
-
import { useId as
|
|
1215
|
-
import { jsx as
|
|
1415
|
+
import { useId as useId4 } from "react";
|
|
1416
|
+
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1216
1417
|
var SelectOptions = (props) => {
|
|
1217
1418
|
const { options, id, label } = props;
|
|
1218
1419
|
const scrollbarRef = useScrollbars2();
|
|
@@ -1220,8 +1421,8 @@ var SelectOptions = (props) => {
|
|
|
1220
1421
|
ref: scrollbarRef,
|
|
1221
1422
|
selector: '[role="option"]'
|
|
1222
1423
|
});
|
|
1223
|
-
return /* @__PURE__ */
|
|
1224
|
-
|
|
1424
|
+
return /* @__PURE__ */ jsx8(
|
|
1425
|
+
Primitive5.Viewport,
|
|
1225
1426
|
{
|
|
1226
1427
|
ref,
|
|
1227
1428
|
className: selectListStyles(),
|
|
@@ -1230,7 +1431,7 @@ var SelectOptions = (props) => {
|
|
|
1230
1431
|
"aria-label": label,
|
|
1231
1432
|
children: options.map((entry) => {
|
|
1232
1433
|
if (!("options" in entry)) {
|
|
1233
|
-
return /* @__PURE__ */
|
|
1434
|
+
return /* @__PURE__ */ jsx8(
|
|
1234
1435
|
SelectOptionItem,
|
|
1235
1436
|
{
|
|
1236
1437
|
option: entry
|
|
@@ -1238,19 +1439,19 @@ var SelectOptions = (props) => {
|
|
|
1238
1439
|
entry.value
|
|
1239
1440
|
);
|
|
1240
1441
|
}
|
|
1241
|
-
return /* @__PURE__ */
|
|
1242
|
-
|
|
1442
|
+
return /* @__PURE__ */ jsxs7(
|
|
1443
|
+
Primitive5.Group,
|
|
1243
1444
|
{
|
|
1244
1445
|
children: [
|
|
1245
|
-
/* @__PURE__ */
|
|
1246
|
-
|
|
1446
|
+
/* @__PURE__ */ jsx8(
|
|
1447
|
+
Primitive5.Label,
|
|
1247
1448
|
{
|
|
1248
|
-
className:
|
|
1449
|
+
className: overlayListLabelStyles2(),
|
|
1249
1450
|
children: entry.label
|
|
1250
1451
|
}
|
|
1251
1452
|
),
|
|
1252
1453
|
entry.options.map((option) => {
|
|
1253
|
-
return /* @__PURE__ */
|
|
1454
|
+
return /* @__PURE__ */ jsx8(
|
|
1254
1455
|
SelectOptionItem,
|
|
1255
1456
|
{
|
|
1256
1457
|
option
|
|
@@ -1268,19 +1469,19 @@ var SelectOptions = (props) => {
|
|
|
1268
1469
|
};
|
|
1269
1470
|
var SelectOptionItem = (props) => {
|
|
1270
1471
|
const { option } = props;
|
|
1271
|
-
const labelId =
|
|
1472
|
+
const labelId = useId4();
|
|
1272
1473
|
const descriptionId = `${labelId}-description`;
|
|
1273
|
-
return /* @__PURE__ */
|
|
1274
|
-
|
|
1474
|
+
return /* @__PURE__ */ jsxs7(
|
|
1475
|
+
Primitive5.Item,
|
|
1275
1476
|
{
|
|
1276
1477
|
value: `gridui:${option.value}`,
|
|
1277
1478
|
"aria-labelledby": labelId,
|
|
1278
1479
|
"aria-describedby": option.description ? descriptionId : void 0,
|
|
1279
1480
|
textValue: option.label,
|
|
1280
1481
|
disabled: option.disabled,
|
|
1281
|
-
className:
|
|
1482
|
+
className: overlayListItemStyles3(),
|
|
1282
1483
|
children: [
|
|
1283
|
-
option.icon && /* @__PURE__ */
|
|
1484
|
+
option.icon && /* @__PURE__ */ jsx8(
|
|
1284
1485
|
"span",
|
|
1285
1486
|
{
|
|
1286
1487
|
className: selectIconStyles(),
|
|
@@ -1288,19 +1489,19 @@ var SelectOptionItem = (props) => {
|
|
|
1288
1489
|
children: option.icon
|
|
1289
1490
|
}
|
|
1290
1491
|
),
|
|
1291
|
-
/* @__PURE__ */
|
|
1492
|
+
/* @__PURE__ */ jsxs7(
|
|
1292
1493
|
"span",
|
|
1293
1494
|
{
|
|
1294
1495
|
className: selectOptionContentStyles(),
|
|
1295
1496
|
children: [
|
|
1296
|
-
/* @__PURE__ */
|
|
1297
|
-
|
|
1497
|
+
/* @__PURE__ */ jsx8(
|
|
1498
|
+
Primitive5.ItemText,
|
|
1298
1499
|
{
|
|
1299
1500
|
id: labelId,
|
|
1300
1501
|
children: option.label
|
|
1301
1502
|
}
|
|
1302
1503
|
),
|
|
1303
|
-
option.description && /* @__PURE__ */
|
|
1504
|
+
option.description && /* @__PURE__ */ jsx8(
|
|
1304
1505
|
"span",
|
|
1305
1506
|
{
|
|
1306
1507
|
id: descriptionId,
|
|
@@ -1311,17 +1512,17 @@ var SelectOptionItem = (props) => {
|
|
|
1311
1512
|
]
|
|
1312
1513
|
}
|
|
1313
1514
|
),
|
|
1314
|
-
/* @__PURE__ */
|
|
1315
|
-
|
|
1515
|
+
/* @__PURE__ */ jsx8(
|
|
1516
|
+
"span",
|
|
1316
1517
|
{
|
|
1317
|
-
className:
|
|
1518
|
+
className: overlayListIndicatorStyles2(),
|
|
1318
1519
|
"aria-hidden": "true",
|
|
1319
|
-
children: /* @__PURE__ */
|
|
1520
|
+
children: /* @__PURE__ */ jsx8(Primitive5.ItemIndicator, { children: /* @__PURE__ */ jsx8(
|
|
1320
1521
|
Check2,
|
|
1321
1522
|
{
|
|
1322
1523
|
size: 16
|
|
1323
1524
|
}
|
|
1324
|
-
)
|
|
1525
|
+
) })
|
|
1325
1526
|
}
|
|
1326
1527
|
)
|
|
1327
1528
|
]
|
|
@@ -1329,14 +1530,31 @@ var SelectOptionItem = (props) => {
|
|
|
1329
1530
|
);
|
|
1330
1531
|
};
|
|
1331
1532
|
|
|
1533
|
+
// src/select/style.ts
|
|
1534
|
+
import { overlayListStyles as overlayListStyles2 } from "@gridui/overlay";
|
|
1535
|
+
import { cn as cn5 } from "@gridui/style-utils";
|
|
1536
|
+
import { cva as cva3 } from "class-variance-authority";
|
|
1537
|
+
var selectContentStyles = cva3(cn5(
|
|
1538
|
+
overlayListStyles2(),
|
|
1539
|
+
"gridui-select-content gridui-u-select--box-border gridui-u-select--relative gridui-u-select--flex gridui-u-select--flex-col gridui-u-select--overflow-hidden gridui-u-select--min-w-0 gridui-u-select--w-(--anchor-width) gridui-u-select--max-w-(--available-width) gridui-u-select--max-h-(--available-height)"
|
|
1540
|
+
));
|
|
1541
|
+
var selectScrollArrowStyles = cva3("gridui-u-select--absolute gridui-u-select--inset-x-0 gridui-u-select--z-(--gridui-z-content) gridui-u-select--flex gridui-u-select--h-gridui-24 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--bg-background gridui-u-select--text-foreground", {
|
|
1542
|
+
variants: {
|
|
1543
|
+
direction: {
|
|
1544
|
+
up: "gridui-u-select--top-0",
|
|
1545
|
+
down: "gridui-u-select--bottom-0"
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
});
|
|
1549
|
+
|
|
1332
1550
|
// src/select/select.tsx
|
|
1333
1551
|
import { controlVariants as controlVariants3 } from "@gridui/input";
|
|
1334
1552
|
import { interactionLayerProps as interactionLayerProps2 } from "@gridui/overlay";
|
|
1335
|
-
import { cn as
|
|
1336
|
-
import * as
|
|
1553
|
+
import { cn as cn6 } from "@gridui/style-utils";
|
|
1554
|
+
import * as Primitive6 from "@radix-ui/react-select";
|
|
1337
1555
|
import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
|
|
1338
|
-
import { useId as
|
|
1339
|
-
import { jsx as
|
|
1556
|
+
import { useId as useId5, useRef as useRef8, useState as useState5 } from "react";
|
|
1557
|
+
import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1340
1558
|
var Select = (props) => {
|
|
1341
1559
|
const {
|
|
1342
1560
|
options,
|
|
@@ -1358,7 +1576,7 @@ var Select = (props) => {
|
|
|
1358
1576
|
ref,
|
|
1359
1577
|
...restProps
|
|
1360
1578
|
} = props;
|
|
1361
|
-
const controlRef =
|
|
1579
|
+
const controlRef = useRef8(null);
|
|
1362
1580
|
const {
|
|
1363
1581
|
open,
|
|
1364
1582
|
popupRef,
|
|
@@ -1377,19 +1595,19 @@ var Select = (props) => {
|
|
|
1377
1595
|
defaultValue,
|
|
1378
1596
|
onValueChange
|
|
1379
1597
|
}, available);
|
|
1380
|
-
const listId =
|
|
1598
|
+
const listId = useId5();
|
|
1381
1599
|
const [
|
|
1382
1600
|
triggerWidth,
|
|
1383
1601
|
setTriggerWidth
|
|
1384
|
-
] =
|
|
1602
|
+
] = useState5();
|
|
1385
1603
|
const allOptions = flattenOptions(options);
|
|
1386
1604
|
const selected = allOptions.find((option) => {
|
|
1387
1605
|
return option.value === selectedValue;
|
|
1388
1606
|
});
|
|
1389
1607
|
const fallback = selectedValue === "" ? placeholder ?? "" : selectedValue;
|
|
1390
1608
|
const display = selected?.label ?? fallback;
|
|
1391
|
-
return /* @__PURE__ */
|
|
1392
|
-
|
|
1609
|
+
return /* @__PURE__ */ jsxs8(
|
|
1610
|
+
Primitive6.Root,
|
|
1393
1611
|
{
|
|
1394
1612
|
form: `${listId}-detached`,
|
|
1395
1613
|
value: selected ? `gridui:${selectedValue}` : "",
|
|
@@ -1406,14 +1624,14 @@ var Select = (props) => {
|
|
|
1406
1624
|
},
|
|
1407
1625
|
dir: dir === "rtl" ? "rtl" : "ltr",
|
|
1408
1626
|
children: [
|
|
1409
|
-
/* @__PURE__ */
|
|
1627
|
+
/* @__PURE__ */ jsxs8(
|
|
1410
1628
|
"div",
|
|
1411
1629
|
{
|
|
1412
|
-
className: "gridui-u-relative gridui-u-flex gridui-u-min-w-0 gridui-u-w-full gridui-u-items-stretch gridui-u-gap-gridui-4",
|
|
1630
|
+
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--w-full gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
|
|
1413
1631
|
dir,
|
|
1414
1632
|
children: [
|
|
1415
|
-
/* @__PURE__ */
|
|
1416
|
-
|
|
1633
|
+
/* @__PURE__ */ jsxs8(
|
|
1634
|
+
Primitive6.Trigger,
|
|
1417
1635
|
{
|
|
1418
1636
|
...restProps,
|
|
1419
1637
|
form,
|
|
@@ -1428,9 +1646,9 @@ var Select = (props) => {
|
|
|
1428
1646
|
ref.current = element;
|
|
1429
1647
|
}
|
|
1430
1648
|
},
|
|
1431
|
-
className:
|
|
1649
|
+
className: cn6(controlVariants3({ size: controlSize }), "gridui-u-select--flex gridui-u-select--flex-1 gridui-u-select--items-center gridui-u-select--gap-gridui-8 gridui-u-select--text-start", className),
|
|
1432
1650
|
children: [
|
|
1433
|
-
selected?.icon && /* @__PURE__ */
|
|
1651
|
+
selected?.icon && /* @__PURE__ */ jsx9(
|
|
1434
1652
|
"span",
|
|
1435
1653
|
{
|
|
1436
1654
|
className: selectIconStyles(),
|
|
@@ -1438,12 +1656,12 @@ var Select = (props) => {
|
|
|
1438
1656
|
children: selected.icon
|
|
1439
1657
|
}
|
|
1440
1658
|
),
|
|
1441
|
-
/* @__PURE__ */
|
|
1659
|
+
/* @__PURE__ */ jsx9(
|
|
1442
1660
|
"span",
|
|
1443
1661
|
{
|
|
1444
|
-
className: "gridui-u-min-w-0 gridui-u-flex-1 gridui-u-whitespace-normal gridui-u-wrap-anywhere",
|
|
1445
|
-
children: /* @__PURE__ */
|
|
1446
|
-
|
|
1662
|
+
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere",
|
|
1663
|
+
children: /* @__PURE__ */ jsx9(
|
|
1664
|
+
Primitive6.Value,
|
|
1447
1665
|
{
|
|
1448
1666
|
placeholder: display,
|
|
1449
1667
|
children: display
|
|
@@ -1451,18 +1669,18 @@ var Select = (props) => {
|
|
|
1451
1669
|
)
|
|
1452
1670
|
}
|
|
1453
1671
|
),
|
|
1454
|
-
/* @__PURE__ */
|
|
1672
|
+
/* @__PURE__ */ jsx9(Primitive6.Icon, { children: /* @__PURE__ */ jsx9(
|
|
1455
1673
|
ChevronDown3,
|
|
1456
1674
|
{
|
|
1457
1675
|
size: 16,
|
|
1458
|
-
className: "gridui-u-shrink-0",
|
|
1676
|
+
className: "gridui-u-select--shrink-0",
|
|
1459
1677
|
"aria-hidden": "true"
|
|
1460
1678
|
}
|
|
1461
1679
|
) })
|
|
1462
1680
|
]
|
|
1463
1681
|
}
|
|
1464
1682
|
),
|
|
1465
|
-
clearLabel && /* @__PURE__ */
|
|
1683
|
+
clearLabel && /* @__PURE__ */ jsx9(
|
|
1466
1684
|
"button",
|
|
1467
1685
|
{
|
|
1468
1686
|
type: "button",
|
|
@@ -1472,8 +1690,8 @@ var Select = (props) => {
|
|
|
1472
1690
|
change("");
|
|
1473
1691
|
controlRef.current?.focus();
|
|
1474
1692
|
},
|
|
1475
|
-
className:
|
|
1476
|
-
children: /* @__PURE__ */
|
|
1693
|
+
className: cn6(controlVariants3({ size: controlSize }), "gridui-u-select--flex gridui-u-select--w-auto gridui-u-select--shrink-0 gridui-u-select--items-center gridui-u-select--justify-center gridui-u-select--min-w-11 gridui-u-select--cursor-pointer"),
|
|
1694
|
+
children: /* @__PURE__ */ jsx9(
|
|
1477
1695
|
X3,
|
|
1478
1696
|
{
|
|
1479
1697
|
size: 16,
|
|
@@ -1482,7 +1700,7 @@ var Select = (props) => {
|
|
|
1482
1700
|
)
|
|
1483
1701
|
}
|
|
1484
1702
|
),
|
|
1485
|
-
/* @__PURE__ */
|
|
1703
|
+
/* @__PURE__ */ jsx9(
|
|
1486
1704
|
SelectionForm,
|
|
1487
1705
|
{
|
|
1488
1706
|
name,
|
|
@@ -1502,12 +1720,12 @@ var Select = (props) => {
|
|
|
1502
1720
|
]
|
|
1503
1721
|
}
|
|
1504
1722
|
),
|
|
1505
|
-
/* @__PURE__ */
|
|
1506
|
-
|
|
1723
|
+
/* @__PURE__ */ jsx9(
|
|
1724
|
+
Primitive6.Portal,
|
|
1507
1725
|
{
|
|
1508
1726
|
container: portalContainer,
|
|
1509
|
-
children: /* @__PURE__ */
|
|
1510
|
-
|
|
1727
|
+
children: /* @__PURE__ */ jsxs8(
|
|
1728
|
+
Primitive6.Content,
|
|
1511
1729
|
{
|
|
1512
1730
|
...interactionLayerProps2,
|
|
1513
1731
|
position,
|
|
@@ -1557,16 +1775,16 @@ var Select = (props) => {
|
|
|
1557
1775
|
}
|
|
1558
1776
|
},
|
|
1559
1777
|
children: [
|
|
1560
|
-
/* @__PURE__ */
|
|
1778
|
+
/* @__PURE__ */ jsxs8(
|
|
1561
1779
|
"div",
|
|
1562
1780
|
{
|
|
1563
|
-
className: "gridui-u-relative gridui-u-flex gridui-u-min-h-0 gridui-u-flex-col",
|
|
1781
|
+
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-h-0 gridui-u-select--flex-col",
|
|
1564
1782
|
children: [
|
|
1565
|
-
/* @__PURE__ */
|
|
1566
|
-
|
|
1783
|
+
/* @__PURE__ */ jsx9(
|
|
1784
|
+
Primitive6.ScrollUpButton,
|
|
1567
1785
|
{
|
|
1568
1786
|
className: selectScrollArrowStyles({ direction: "up" }),
|
|
1569
|
-
children: /* @__PURE__ */
|
|
1787
|
+
children: /* @__PURE__ */ jsx9(
|
|
1570
1788
|
ChevronUp,
|
|
1571
1789
|
{
|
|
1572
1790
|
size: 16,
|
|
@@ -1575,7 +1793,7 @@ var Select = (props) => {
|
|
|
1575
1793
|
)
|
|
1576
1794
|
}
|
|
1577
1795
|
),
|
|
1578
|
-
/* @__PURE__ */
|
|
1796
|
+
/* @__PURE__ */ jsx9(
|
|
1579
1797
|
SelectOptions,
|
|
1580
1798
|
{
|
|
1581
1799
|
options,
|
|
@@ -1583,11 +1801,11 @@ var Select = (props) => {
|
|
|
1583
1801
|
label: restProps["aria-label"]
|
|
1584
1802
|
}
|
|
1585
1803
|
),
|
|
1586
|
-
/* @__PURE__ */
|
|
1587
|
-
|
|
1804
|
+
/* @__PURE__ */ jsx9(
|
|
1805
|
+
Primitive6.ScrollDownButton,
|
|
1588
1806
|
{
|
|
1589
1807
|
className: selectScrollArrowStyles({ direction: "down" }),
|
|
1590
|
-
children: /* @__PURE__ */
|
|
1808
|
+
children: /* @__PURE__ */ jsx9(
|
|
1591
1809
|
ChevronDown3,
|
|
1592
1810
|
{
|
|
1593
1811
|
size: 16,
|
|
@@ -1599,7 +1817,7 @@ var Select = (props) => {
|
|
|
1599
1817
|
]
|
|
1600
1818
|
}
|
|
1601
1819
|
),
|
|
1602
|
-
/* @__PURE__ */
|
|
1820
|
+
/* @__PURE__ */ jsx9(
|
|
1603
1821
|
SelectionActions,
|
|
1604
1822
|
{
|
|
1605
1823
|
actions,
|
|
@@ -1661,7 +1879,7 @@ var createOptionsRequest = (loadOptions, onState) => {
|
|
|
1661
1879
|
};
|
|
1662
1880
|
|
|
1663
1881
|
// src/use-async-options/use-async-options.ts
|
|
1664
|
-
import { useEffect as
|
|
1882
|
+
import { useEffect as useEffect4, useState as useState6 } from "react";
|
|
1665
1883
|
var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true }) => {
|
|
1666
1884
|
if (!Number.isFinite(debounceMs) || debounceMs < 0) {
|
|
1667
1885
|
throw new RangeError("Option search debounce must be finite and nonnegative.");
|
|
@@ -1669,7 +1887,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1669
1887
|
const [
|
|
1670
1888
|
state,
|
|
1671
1889
|
setState
|
|
1672
|
-
] =
|
|
1890
|
+
] = useState6({
|
|
1673
1891
|
loader: loadOptions,
|
|
1674
1892
|
result: {
|
|
1675
1893
|
query,
|
|
@@ -1678,7 +1896,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1678
1896
|
error: null
|
|
1679
1897
|
}
|
|
1680
1898
|
});
|
|
1681
|
-
|
|
1899
|
+
useEffect4(() => {
|
|
1682
1900
|
const publish = (result) => {
|
|
1683
1901
|
setState({
|
|
1684
1902
|
loader: loadOptions,
|
|
@@ -1716,6 +1934,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1716
1934
|
};
|
|
1717
1935
|
};
|
|
1718
1936
|
export {
|
|
1937
|
+
Autocomplete,
|
|
1719
1938
|
Combobox,
|
|
1720
1939
|
MultiSelect,
|
|
1721
1940
|
Select,
|