@gridui/select 1.1.2 → 1.2.1
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 +25 -1
- package/dist/autocomplete/autocomplete.d.ts +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +438 -211
- package/dist/index.js.map +4 -4
- package/docs/catalog.json +25 -3
- 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 +4 -4
package/dist/index.js
CHANGED
|
@@ -17,83 +17,18 @@ var comboboxContentStyles = cva(cn(
|
|
|
17
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)"
|
|
18
18
|
));
|
|
19
19
|
|
|
20
|
-
// src/shared/popup/selection-actions.tsx
|
|
21
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
|
-
var SelectionActions = (props) => {
|
|
23
|
-
const { actions, onAction } = props;
|
|
24
|
-
return /* @__PURE__ */ jsx(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx(
|
|
25
|
-
"div",
|
|
26
|
-
{
|
|
27
|
-
className: selectActionsStyles(),
|
|
28
|
-
children: actions.map((action) => {
|
|
29
|
-
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
30
|
-
action.icon && /* @__PURE__ */ jsx(
|
|
31
|
-
"span",
|
|
32
|
-
{
|
|
33
|
-
className: selectIconStyles(),
|
|
34
|
-
"aria-hidden": "true",
|
|
35
|
-
children: action.icon
|
|
36
|
-
}
|
|
37
|
-
),
|
|
38
|
-
action.label
|
|
39
|
-
] });
|
|
40
|
-
const actionClass = selectActionStyles();
|
|
41
|
-
if (action.href !== void 0) {
|
|
42
|
-
return /* @__PURE__ */ jsx(
|
|
43
|
-
"a",
|
|
44
|
-
{
|
|
45
|
-
href: action.disabled ? void 0 : action.href,
|
|
46
|
-
target: action.target,
|
|
47
|
-
rel: action.rel,
|
|
48
|
-
"aria-disabled": action.disabled || void 0,
|
|
49
|
-
"data-disabled": action.disabled ? "" : void 0,
|
|
50
|
-
tabIndex: action.disabled ? -1 : void 0,
|
|
51
|
-
className: actionClass,
|
|
52
|
-
onClick: (event) => {
|
|
53
|
-
if (action.disabled) {
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (!onAction(action)) {
|
|
58
|
-
event.preventDefault();
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
children: content
|
|
62
|
-
},
|
|
63
|
-
action.id
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return /* @__PURE__ */ jsx(
|
|
67
|
-
"button",
|
|
68
|
-
{
|
|
69
|
-
type: "button",
|
|
70
|
-
disabled: action.disabled,
|
|
71
|
-
"data-disabled": action.disabled ? "" : void 0,
|
|
72
|
-
className: actionClass,
|
|
73
|
-
onClick: () => {
|
|
74
|
-
onAction(action);
|
|
75
|
-
},
|
|
76
|
-
children: content
|
|
77
|
-
},
|
|
78
|
-
action.id
|
|
79
|
-
);
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
) });
|
|
83
|
-
};
|
|
84
|
-
|
|
85
20
|
// src/shared/popup/selection-popup.tsx
|
|
86
21
|
import { isComposingKeyEvent } from "@gridui/interaction";
|
|
87
22
|
import { interactionLayerProps } from "@gridui/overlay";
|
|
88
23
|
import * as Primitive from "@radix-ui/react-popover";
|
|
89
|
-
import { jsx
|
|
24
|
+
import { jsx } from "react/jsx-runtime";
|
|
90
25
|
var SelectionPopup = (props) => {
|
|
91
26
|
const { container, anchorRef, initialFocus, finalFocus, onEscape, onDismiss, ...restProps } = props;
|
|
92
|
-
return /* @__PURE__ */
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
93
28
|
Primitive.Portal,
|
|
94
29
|
{
|
|
95
30
|
container,
|
|
96
|
-
children: /* @__PURE__ */
|
|
31
|
+
children: /* @__PURE__ */ jsx(
|
|
97
32
|
Primitive.Content,
|
|
98
33
|
{
|
|
99
34
|
...interactionLayerProps,
|
|
@@ -210,7 +145,7 @@ var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
|
|
|
210
145
|
// src/shared/search/combobox-options.tsx
|
|
211
146
|
import { overlayListIndicatorStyles, overlayListItemStyles as overlayListItemStyles2, overlayListLabelStyles, useInteractionOutline, useScrollbars } from "@gridui/overlay";
|
|
212
147
|
import { Check } from "lucide-react";
|
|
213
|
-
import { jsx as
|
|
148
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
214
149
|
var ComboboxOptions = (props) => {
|
|
215
150
|
const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight } = props;
|
|
216
151
|
const scrollbarRef = useScrollbars();
|
|
@@ -221,7 +156,7 @@ var ComboboxOptions = (props) => {
|
|
|
221
156
|
const renderOption = (option) => {
|
|
222
157
|
const itemId = optionId(option.value);
|
|
223
158
|
const checked = typeof selected === "string" ? selected === option.value : selected.includes(option.value);
|
|
224
|
-
return /* @__PURE__ */
|
|
159
|
+
return /* @__PURE__ */ jsxs(
|
|
225
160
|
"div",
|
|
226
161
|
{
|
|
227
162
|
id: itemId,
|
|
@@ -245,7 +180,7 @@ var ComboboxOptions = (props) => {
|
|
|
245
180
|
}
|
|
246
181
|
},
|
|
247
182
|
children: [
|
|
248
|
-
option.icon && /* @__PURE__ */
|
|
183
|
+
option.icon && /* @__PURE__ */ jsx2(
|
|
249
184
|
"span",
|
|
250
185
|
{
|
|
251
186
|
className: selectIconStyles(),
|
|
@@ -253,19 +188,19 @@ var ComboboxOptions = (props) => {
|
|
|
253
188
|
children: option.icon
|
|
254
189
|
}
|
|
255
190
|
),
|
|
256
|
-
/* @__PURE__ */
|
|
191
|
+
/* @__PURE__ */ jsxs(
|
|
257
192
|
"span",
|
|
258
193
|
{
|
|
259
194
|
className: selectOptionContentStyles(),
|
|
260
195
|
children: [
|
|
261
|
-
/* @__PURE__ */
|
|
196
|
+
/* @__PURE__ */ jsx2(
|
|
262
197
|
"span",
|
|
263
198
|
{
|
|
264
199
|
id: `${itemId}-label`,
|
|
265
200
|
children: option.label
|
|
266
201
|
}
|
|
267
202
|
),
|
|
268
|
-
option.description && /* @__PURE__ */
|
|
203
|
+
option.description && /* @__PURE__ */ jsx2(
|
|
269
204
|
"span",
|
|
270
205
|
{
|
|
271
206
|
id: `${itemId}-description`,
|
|
@@ -276,12 +211,12 @@ var ComboboxOptions = (props) => {
|
|
|
276
211
|
]
|
|
277
212
|
}
|
|
278
213
|
),
|
|
279
|
-
/* @__PURE__ */
|
|
214
|
+
/* @__PURE__ */ jsx2(
|
|
280
215
|
"span",
|
|
281
216
|
{
|
|
282
217
|
className: overlayListIndicatorStyles(),
|
|
283
218
|
"aria-hidden": "true",
|
|
284
|
-
children: checked && /* @__PURE__ */
|
|
219
|
+
children: checked && /* @__PURE__ */ jsx2(
|
|
285
220
|
Check,
|
|
286
221
|
{
|
|
287
222
|
size: 16
|
|
@@ -294,7 +229,7 @@ var ComboboxOptions = (props) => {
|
|
|
294
229
|
option.value
|
|
295
230
|
);
|
|
296
231
|
};
|
|
297
|
-
return /* @__PURE__ */
|
|
232
|
+
return /* @__PURE__ */ jsx2(
|
|
298
233
|
"div",
|
|
299
234
|
{
|
|
300
235
|
ref,
|
|
@@ -304,13 +239,13 @@ var ComboboxOptions = (props) => {
|
|
|
304
239
|
"aria-label": label,
|
|
305
240
|
className: selectListStyles(),
|
|
306
241
|
children: options.map((entry, index) => {
|
|
307
|
-
return "options" in entry ? /* @__PURE__ */
|
|
242
|
+
return "options" in entry ? /* @__PURE__ */ jsxs(
|
|
308
243
|
"div",
|
|
309
244
|
{
|
|
310
245
|
role: "group",
|
|
311
246
|
"aria-labelledby": `${id}-group-${index}`,
|
|
312
247
|
children: [
|
|
313
|
-
/* @__PURE__ */
|
|
248
|
+
/* @__PURE__ */ jsx2(
|
|
314
249
|
"div",
|
|
315
250
|
{
|
|
316
251
|
id: `${id}-group-${index}`,
|
|
@@ -463,11 +398,302 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
463
398
|
};
|
|
464
399
|
};
|
|
465
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
|
+
) });
|
|
690
|
+
};
|
|
691
|
+
|
|
466
692
|
// src/shared/selection-form.tsx
|
|
467
|
-
import { focusInvalidControl, useFormReset } from "@gridui/form";
|
|
468
|
-
import { useLayoutEffect, useRef as
|
|
693
|
+
import { focusInvalidControl, useFormReset as useFormReset2 } from "@gridui/form";
|
|
694
|
+
import { useLayoutEffect, useRef as useRef4 } from "react";
|
|
469
695
|
import { flushSync as flushSync2 } from "react-dom";
|
|
470
|
-
import { jsx as
|
|
696
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
471
697
|
var SelectionForm = (props) => {
|
|
472
698
|
const {
|
|
473
699
|
name,
|
|
@@ -480,9 +706,9 @@ var SelectionForm = (props) => {
|
|
|
480
706
|
onReset,
|
|
481
707
|
onInvalid
|
|
482
708
|
} = props;
|
|
483
|
-
const nativeRef =
|
|
484
|
-
const resetSelection =
|
|
485
|
-
const currentValue =
|
|
709
|
+
const nativeRef = useRef4(null);
|
|
710
|
+
const resetSelection = useRef4(onReset);
|
|
711
|
+
const currentValue = useRef4(selectedValue);
|
|
486
712
|
useLayoutEffect(() => {
|
|
487
713
|
resetSelection.current = onReset;
|
|
488
714
|
currentValue.current = selectedValue;
|
|
@@ -490,7 +716,7 @@ var SelectionForm = (props) => {
|
|
|
490
716
|
onReset,
|
|
491
717
|
selectedValue
|
|
492
718
|
]);
|
|
493
|
-
|
|
719
|
+
useFormReset2(nativeRef, () => {
|
|
494
720
|
flushSync2(() => {
|
|
495
721
|
resetSelection.current();
|
|
496
722
|
});
|
|
@@ -498,7 +724,7 @@ var SelectionForm = (props) => {
|
|
|
498
724
|
nativeRef.current.value = currentValue.current;
|
|
499
725
|
}
|
|
500
726
|
}, form);
|
|
501
|
-
return /* @__PURE__ */
|
|
727
|
+
return /* @__PURE__ */ jsxs4(
|
|
502
728
|
"select",
|
|
503
729
|
{
|
|
504
730
|
ref: nativeRef,
|
|
@@ -519,7 +745,7 @@ var SelectionForm = (props) => {
|
|
|
519
745
|
children: [
|
|
520
746
|
!allOptions.some((option) => {
|
|
521
747
|
return option.value === "";
|
|
522
|
-
}) && /* @__PURE__ */
|
|
748
|
+
}) && /* @__PURE__ */ jsx5(
|
|
523
749
|
"option",
|
|
524
750
|
{
|
|
525
751
|
value: ""
|
|
@@ -527,7 +753,7 @@ var SelectionForm = (props) => {
|
|
|
527
753
|
),
|
|
528
754
|
selectedValue !== "" && !allOptions.some((option) => {
|
|
529
755
|
return option.value === selectedValue;
|
|
530
|
-
}) && /* @__PURE__ */
|
|
756
|
+
}) && /* @__PURE__ */ jsx5(
|
|
531
757
|
"option",
|
|
532
758
|
{
|
|
533
759
|
value: selectedValue,
|
|
@@ -535,7 +761,7 @@ var SelectionForm = (props) => {
|
|
|
535
761
|
}
|
|
536
762
|
),
|
|
537
763
|
allOptions.map((option) => {
|
|
538
|
-
return /* @__PURE__ */
|
|
764
|
+
return /* @__PURE__ */ jsx5(
|
|
539
765
|
"option",
|
|
540
766
|
{
|
|
541
767
|
value: option.value,
|
|
@@ -551,15 +777,15 @@ var SelectionForm = (props) => {
|
|
|
551
777
|
};
|
|
552
778
|
|
|
553
779
|
// src/shared/use-selection-value.ts
|
|
554
|
-
import { useRef as
|
|
780
|
+
import { useRef as useRef5, useState as useState4 } from "react";
|
|
555
781
|
var useSelectionValue = (props, available) => {
|
|
556
782
|
const { value, defaultValue = "", onValueChange } = props;
|
|
557
783
|
const [
|
|
558
784
|
localValue,
|
|
559
785
|
setLocalValue
|
|
560
|
-
] =
|
|
786
|
+
] = useState4(defaultValue);
|
|
561
787
|
const selectedValue = value ?? localValue;
|
|
562
|
-
const initialValue =
|
|
788
|
+
const initialValue = useRef5(selectedValue);
|
|
563
789
|
const update = (next) => {
|
|
564
790
|
if (next === selectedValue) {
|
|
565
791
|
return;
|
|
@@ -589,12 +815,12 @@ var comboboxTriggerStyles = cva2("gridui-u-select--absolute gridui-u-select--ins
|
|
|
589
815
|
|
|
590
816
|
// src/combobox/combobox.tsx
|
|
591
817
|
import { controlVariants } from "@gridui/input";
|
|
592
|
-
import { isComposingKeyEvent as
|
|
593
|
-
import { cn as
|
|
594
|
-
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";
|
|
595
821
|
import { ChevronDown, X } from "lucide-react";
|
|
596
|
-
import { useId, useRef as
|
|
597
|
-
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";
|
|
598
824
|
var Combobox = (props) => {
|
|
599
825
|
const {
|
|
600
826
|
options,
|
|
@@ -627,8 +853,8 @@ var Combobox = (props) => {
|
|
|
627
853
|
resultCountLabel,
|
|
628
854
|
...restProps
|
|
629
855
|
} = props;
|
|
630
|
-
const controlRef =
|
|
631
|
-
const anchorRef =
|
|
856
|
+
const controlRef = useRef6(null);
|
|
857
|
+
const anchorRef = useRef6(null);
|
|
632
858
|
const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
|
|
633
859
|
disabled,
|
|
634
860
|
readOnly,
|
|
@@ -639,7 +865,7 @@ var Combobox = (props) => {
|
|
|
639
865
|
defaultValue,
|
|
640
866
|
onValueChange
|
|
641
867
|
}, available);
|
|
642
|
-
const inputId =
|
|
868
|
+
const inputId = useId2();
|
|
643
869
|
const listId = `${inputId}-list`;
|
|
644
870
|
const search = useSearchOptions(options, [selectedValue], listId, open, {
|
|
645
871
|
query: controlledQuery,
|
|
@@ -664,29 +890,29 @@ var Combobox = (props) => {
|
|
|
664
890
|
close();
|
|
665
891
|
focus();
|
|
666
892
|
};
|
|
667
|
-
return /* @__PURE__ */
|
|
668
|
-
|
|
893
|
+
return /* @__PURE__ */ jsxs5(
|
|
894
|
+
Primitive3.Root,
|
|
669
895
|
{
|
|
670
896
|
open,
|
|
671
897
|
onOpenChange: changeOpen,
|
|
672
898
|
children: [
|
|
673
|
-
/* @__PURE__ */
|
|
899
|
+
/* @__PURE__ */ jsxs5(
|
|
674
900
|
"div",
|
|
675
901
|
{
|
|
676
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",
|
|
677
903
|
dir,
|
|
678
904
|
children: [
|
|
679
|
-
/* @__PURE__ */
|
|
680
|
-
|
|
905
|
+
/* @__PURE__ */ jsx6(
|
|
906
|
+
Primitive3.Anchor,
|
|
681
907
|
{
|
|
682
908
|
asChild: true,
|
|
683
|
-
children: /* @__PURE__ */
|
|
909
|
+
children: /* @__PURE__ */ jsxs5(
|
|
684
910
|
"div",
|
|
685
911
|
{
|
|
686
912
|
ref: anchorRef,
|
|
687
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",
|
|
688
914
|
children: [
|
|
689
|
-
/* @__PURE__ */
|
|
915
|
+
/* @__PURE__ */ jsx6(
|
|
690
916
|
"input",
|
|
691
917
|
{
|
|
692
918
|
...restProps,
|
|
@@ -714,7 +940,7 @@ var Combobox = (props) => {
|
|
|
714
940
|
form,
|
|
715
941
|
disabled,
|
|
716
942
|
readOnly,
|
|
717
|
-
className:
|
|
943
|
+
className: cn3(controlVariants({ size: controlSize }), comboboxInputStyles(), className),
|
|
718
944
|
value: text,
|
|
719
945
|
onClick: (event) => {
|
|
720
946
|
onClick?.(event);
|
|
@@ -734,7 +960,7 @@ var Combobox = (props) => {
|
|
|
734
960
|
if (event.defaultPrevented || readOnly) {
|
|
735
961
|
return;
|
|
736
962
|
}
|
|
737
|
-
if (
|
|
963
|
+
if (isComposingKeyEvent3(event.nativeEvent)) {
|
|
738
964
|
if (event.key === "Enter" || event.key === "Escape") {
|
|
739
965
|
event.stopPropagation();
|
|
740
966
|
}
|
|
@@ -772,7 +998,7 @@ var Combobox = (props) => {
|
|
|
772
998
|
}
|
|
773
999
|
}
|
|
774
1000
|
),
|
|
775
|
-
/* @__PURE__ */
|
|
1001
|
+
/* @__PURE__ */ jsx6(
|
|
776
1002
|
"button",
|
|
777
1003
|
{
|
|
778
1004
|
type: "button",
|
|
@@ -787,7 +1013,7 @@ var Combobox = (props) => {
|
|
|
787
1013
|
}
|
|
788
1014
|
focus();
|
|
789
1015
|
},
|
|
790
|
-
children: /* @__PURE__ */
|
|
1016
|
+
children: /* @__PURE__ */ jsx6(
|
|
791
1017
|
ChevronDown,
|
|
792
1018
|
{
|
|
793
1019
|
size: 16,
|
|
@@ -801,7 +1027,7 @@ var Combobox = (props) => {
|
|
|
801
1027
|
)
|
|
802
1028
|
}
|
|
803
1029
|
),
|
|
804
|
-
clearLabel && /* @__PURE__ */
|
|
1030
|
+
clearLabel && /* @__PURE__ */ jsx6(
|
|
805
1031
|
"button",
|
|
806
1032
|
{
|
|
807
1033
|
type: "button",
|
|
@@ -812,8 +1038,8 @@ var Combobox = (props) => {
|
|
|
812
1038
|
close();
|
|
813
1039
|
focus();
|
|
814
1040
|
},
|
|
815
|
-
className:
|
|
816
|
-
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(
|
|
817
1043
|
X,
|
|
818
1044
|
{
|
|
819
1045
|
size: 16,
|
|
@@ -822,7 +1048,7 @@ var Combobox = (props) => {
|
|
|
822
1048
|
)
|
|
823
1049
|
}
|
|
824
1050
|
),
|
|
825
|
-
/* @__PURE__ */
|
|
1051
|
+
/* @__PURE__ */ jsx6(
|
|
826
1052
|
SelectionForm,
|
|
827
1053
|
{
|
|
828
1054
|
name,
|
|
@@ -842,7 +1068,7 @@ var Combobox = (props) => {
|
|
|
842
1068
|
]
|
|
843
1069
|
}
|
|
844
1070
|
),
|
|
845
|
-
/* @__PURE__ */
|
|
1071
|
+
/* @__PURE__ */ jsxs5(
|
|
846
1072
|
SelectionPopup,
|
|
847
1073
|
{
|
|
848
1074
|
container: portalContainer,
|
|
@@ -857,16 +1083,16 @@ var Combobox = (props) => {
|
|
|
857
1083
|
focus();
|
|
858
1084
|
},
|
|
859
1085
|
children: [
|
|
860
|
-
/* @__PURE__ */
|
|
1086
|
+
/* @__PURE__ */ jsx6(
|
|
861
1087
|
"div",
|
|
862
1088
|
{
|
|
863
1089
|
role: "status",
|
|
864
1090
|
"aria-atomic": "true",
|
|
865
|
-
className:
|
|
1091
|
+
className: cn3(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
866
1092
|
children: loading ? loadingLabel : errorLabel ?? (visible.length ? resultCountLabel?.(visible.length) : emptyLabel)
|
|
867
1093
|
}
|
|
868
1094
|
),
|
|
869
|
-
/* @__PURE__ */
|
|
1095
|
+
/* @__PURE__ */ jsx6(
|
|
870
1096
|
ComboboxOptions,
|
|
871
1097
|
{
|
|
872
1098
|
id: listId,
|
|
@@ -879,7 +1105,7 @@ var Combobox = (props) => {
|
|
|
879
1105
|
onHighlight: search.highlight
|
|
880
1106
|
}
|
|
881
1107
|
),
|
|
882
|
-
/* @__PURE__ */
|
|
1108
|
+
/* @__PURE__ */ jsx6(
|
|
883
1109
|
SelectionActions,
|
|
884
1110
|
{
|
|
885
1111
|
actions,
|
|
@@ -897,12 +1123,12 @@ var Combobox = (props) => {
|
|
|
897
1123
|
// src/multi-select/multi-select.tsx
|
|
898
1124
|
import { ListFieldControl, useListField } from "@gridui/form";
|
|
899
1125
|
import { controlVariants as controlVariants2 } from "@gridui/input";
|
|
900
|
-
import { isComposingKeyEvent as
|
|
901
|
-
import { cn as
|
|
902
|
-
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";
|
|
903
1129
|
import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
|
|
904
|
-
import { useId as
|
|
905
|
-
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";
|
|
906
1132
|
var MultiSelect = (props) => {
|
|
907
1133
|
const {
|
|
908
1134
|
value,
|
|
@@ -931,8 +1157,8 @@ var MultiSelect = (props) => {
|
|
|
931
1157
|
resultCountLabel,
|
|
932
1158
|
...restProps
|
|
933
1159
|
} = props;
|
|
934
|
-
const search =
|
|
935
|
-
const id =
|
|
1160
|
+
const search = useRef7(null);
|
|
1161
|
+
const id = useId3();
|
|
936
1162
|
const { selected, native, control, change } = useListField({
|
|
937
1163
|
value,
|
|
938
1164
|
defaultValue,
|
|
@@ -968,23 +1194,23 @@ var MultiSelect = (props) => {
|
|
|
968
1194
|
]);
|
|
969
1195
|
search.current?.focus({ preventScroll: true });
|
|
970
1196
|
};
|
|
971
|
-
return /* @__PURE__ */
|
|
972
|
-
|
|
1197
|
+
return /* @__PURE__ */ jsxs6(
|
|
1198
|
+
Primitive4.Root,
|
|
973
1199
|
{
|
|
974
1200
|
open,
|
|
975
1201
|
onOpenChange: changeOpen,
|
|
976
1202
|
children: [
|
|
977
|
-
/* @__PURE__ */
|
|
1203
|
+
/* @__PURE__ */ jsxs6(
|
|
978
1204
|
"div",
|
|
979
1205
|
{
|
|
980
1206
|
className: "gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
|
|
981
1207
|
dir: restProps.dir,
|
|
982
1208
|
children: [
|
|
983
|
-
/* @__PURE__ */
|
|
984
|
-
|
|
1209
|
+
/* @__PURE__ */ jsx7(
|
|
1210
|
+
Primitive4.Trigger,
|
|
985
1211
|
{
|
|
986
1212
|
asChild: true,
|
|
987
|
-
children: /* @__PURE__ */
|
|
1213
|
+
children: /* @__PURE__ */ jsxs6(
|
|
988
1214
|
"button",
|
|
989
1215
|
{
|
|
990
1216
|
...restProps,
|
|
@@ -1002,7 +1228,7 @@ var MultiSelect = (props) => {
|
|
|
1002
1228
|
ref.current = element;
|
|
1003
1229
|
}
|
|
1004
1230
|
},
|
|
1005
|
-
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),
|
|
1006
1232
|
onKeyDown: (event) => {
|
|
1007
1233
|
onKeyDown?.(event);
|
|
1008
1234
|
if (!event.defaultPrevented && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
|
|
@@ -1011,7 +1237,7 @@ var MultiSelect = (props) => {
|
|
|
1011
1237
|
}
|
|
1012
1238
|
},
|
|
1013
1239
|
children: [
|
|
1014
|
-
/* @__PURE__ */
|
|
1240
|
+
/* @__PURE__ */ jsx7(
|
|
1015
1241
|
"span",
|
|
1016
1242
|
{
|
|
1017
1243
|
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--wrap-anywhere",
|
|
@@ -1022,7 +1248,7 @@ var MultiSelect = (props) => {
|
|
|
1022
1248
|
}).join(", ") : placeholder
|
|
1023
1249
|
}
|
|
1024
1250
|
),
|
|
1025
|
-
/* @__PURE__ */
|
|
1251
|
+
/* @__PURE__ */ jsx7(
|
|
1026
1252
|
ChevronDown2,
|
|
1027
1253
|
{
|
|
1028
1254
|
size: 16,
|
|
@@ -1034,18 +1260,18 @@ var MultiSelect = (props) => {
|
|
|
1034
1260
|
)
|
|
1035
1261
|
}
|
|
1036
1262
|
),
|
|
1037
|
-
clearLabel && /* @__PURE__ */
|
|
1263
|
+
clearLabel && /* @__PURE__ */ jsx7(
|
|
1038
1264
|
"button",
|
|
1039
1265
|
{
|
|
1040
1266
|
type: "button",
|
|
1041
1267
|
"aria-label": clearLabel,
|
|
1042
1268
|
disabled: disabled || readOnly || required || !selected.length,
|
|
1043
|
-
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"),
|
|
1044
1270
|
onClick: () => {
|
|
1045
1271
|
change([]);
|
|
1046
1272
|
control.current?.focus();
|
|
1047
1273
|
},
|
|
1048
|
-
children: /* @__PURE__ */
|
|
1274
|
+
children: /* @__PURE__ */ jsx7(
|
|
1049
1275
|
X2,
|
|
1050
1276
|
{
|
|
1051
1277
|
size: 16,
|
|
@@ -1054,7 +1280,7 @@ var MultiSelect = (props) => {
|
|
|
1054
1280
|
)
|
|
1055
1281
|
}
|
|
1056
1282
|
),
|
|
1057
|
-
/* @__PURE__ */
|
|
1283
|
+
/* @__PURE__ */ jsxs6(
|
|
1058
1284
|
ListFieldControl,
|
|
1059
1285
|
{
|
|
1060
1286
|
ref: native,
|
|
@@ -1069,7 +1295,7 @@ var MultiSelect = (props) => {
|
|
|
1069
1295
|
},
|
|
1070
1296
|
children: [
|
|
1071
1297
|
all.map((option) => {
|
|
1072
|
-
return /* @__PURE__ */
|
|
1298
|
+
return /* @__PURE__ */ jsx7(
|
|
1073
1299
|
"option",
|
|
1074
1300
|
{
|
|
1075
1301
|
value: option.value,
|
|
@@ -1084,7 +1310,7 @@ var MultiSelect = (props) => {
|
|
|
1084
1310
|
return option.value === entry;
|
|
1085
1311
|
});
|
|
1086
1312
|
}).map((entry) => {
|
|
1087
|
-
return /* @__PURE__ */
|
|
1313
|
+
return /* @__PURE__ */ jsx7(
|
|
1088
1314
|
"option",
|
|
1089
1315
|
{
|
|
1090
1316
|
value: entry,
|
|
@@ -1099,7 +1325,7 @@ var MultiSelect = (props) => {
|
|
|
1099
1325
|
]
|
|
1100
1326
|
}
|
|
1101
1327
|
),
|
|
1102
|
-
/* @__PURE__ */
|
|
1328
|
+
/* @__PURE__ */ jsxs6(
|
|
1103
1329
|
SelectionPopup,
|
|
1104
1330
|
{
|
|
1105
1331
|
container: portalContainer,
|
|
@@ -1115,7 +1341,7 @@ var MultiSelect = (props) => {
|
|
|
1115
1341
|
focus();
|
|
1116
1342
|
},
|
|
1117
1343
|
children: [
|
|
1118
|
-
/* @__PURE__ */
|
|
1344
|
+
/* @__PURE__ */ jsx7(
|
|
1119
1345
|
"input",
|
|
1120
1346
|
{
|
|
1121
1347
|
ref: search,
|
|
@@ -1128,12 +1354,12 @@ var MultiSelect = (props) => {
|
|
|
1128
1354
|
"aria-controls": `${id}-list`,
|
|
1129
1355
|
"aria-activedescendant": activeOptionId,
|
|
1130
1356
|
value: query ?? "",
|
|
1131
|
-
className:
|
|
1357
|
+
className: cn4(controlVariants2({ size: "small" }), "gridui-u-select--m-gridui-8 gridui-u-select--w-auto gridui-u-select--shrink-0"),
|
|
1132
1358
|
onChange: (event) => {
|
|
1133
1359
|
searchOptions.changeQuery(event.target.value);
|
|
1134
1360
|
},
|
|
1135
1361
|
onKeyDown: (event) => {
|
|
1136
|
-
if (
|
|
1362
|
+
if (isComposingKeyEvent4(event.nativeEvent)) {
|
|
1137
1363
|
event.stopPropagation();
|
|
1138
1364
|
return;
|
|
1139
1365
|
}
|
|
@@ -1151,7 +1377,7 @@ var MultiSelect = (props) => {
|
|
|
1151
1377
|
}
|
|
1152
1378
|
}
|
|
1153
1379
|
),
|
|
1154
|
-
/* @__PURE__ */
|
|
1380
|
+
/* @__PURE__ */ jsx7(
|
|
1155
1381
|
ComboboxOptions,
|
|
1156
1382
|
{
|
|
1157
1383
|
id: `${id}-list`,
|
|
@@ -1165,12 +1391,12 @@ var MultiSelect = (props) => {
|
|
|
1165
1391
|
onHighlight: searchOptions.highlight
|
|
1166
1392
|
}
|
|
1167
1393
|
),
|
|
1168
|
-
/* @__PURE__ */
|
|
1394
|
+
/* @__PURE__ */ jsx7(
|
|
1169
1395
|
"div",
|
|
1170
1396
|
{
|
|
1171
1397
|
role: "status",
|
|
1172
1398
|
"aria-atomic": "true",
|
|
1173
|
-
className:
|
|
1399
|
+
className: cn4(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
1174
1400
|
children: loading ? loadingLabel : errorLabel ?? (visible.length ? resultCountLabel?.(visible.length) : emptyLabel)
|
|
1175
1401
|
}
|
|
1176
1402
|
)
|
|
@@ -1184,10 +1410,10 @@ var MultiSelect = (props) => {
|
|
|
1184
1410
|
|
|
1185
1411
|
// src/select/select-options.tsx
|
|
1186
1412
|
import { overlayListIndicatorStyles as overlayListIndicatorStyles2, overlayListItemStyles as overlayListItemStyles3, overlayListLabelStyles as overlayListLabelStyles2, useInteractionOutline as useInteractionOutline2, useScrollbars as useScrollbars2 } from "@gridui/overlay";
|
|
1187
|
-
import * as
|
|
1413
|
+
import * as Primitive5 from "@radix-ui/react-select";
|
|
1188
1414
|
import { Check as Check2 } from "lucide-react";
|
|
1189
|
-
import { useId as
|
|
1190
|
-
import { jsx as
|
|
1415
|
+
import { useId as useId4 } from "react";
|
|
1416
|
+
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1191
1417
|
var SelectOptions = (props) => {
|
|
1192
1418
|
const { options, id, label } = props;
|
|
1193
1419
|
const scrollbarRef = useScrollbars2();
|
|
@@ -1195,8 +1421,8 @@ var SelectOptions = (props) => {
|
|
|
1195
1421
|
ref: scrollbarRef,
|
|
1196
1422
|
selector: '[role="option"]'
|
|
1197
1423
|
});
|
|
1198
|
-
return /* @__PURE__ */
|
|
1199
|
-
|
|
1424
|
+
return /* @__PURE__ */ jsx8(
|
|
1425
|
+
Primitive5.Viewport,
|
|
1200
1426
|
{
|
|
1201
1427
|
ref,
|
|
1202
1428
|
className: selectListStyles(),
|
|
@@ -1205,7 +1431,7 @@ var SelectOptions = (props) => {
|
|
|
1205
1431
|
"aria-label": label,
|
|
1206
1432
|
children: options.map((entry) => {
|
|
1207
1433
|
if (!("options" in entry)) {
|
|
1208
|
-
return /* @__PURE__ */
|
|
1434
|
+
return /* @__PURE__ */ jsx8(
|
|
1209
1435
|
SelectOptionItem,
|
|
1210
1436
|
{
|
|
1211
1437
|
option: entry
|
|
@@ -1213,19 +1439,19 @@ var SelectOptions = (props) => {
|
|
|
1213
1439
|
entry.value
|
|
1214
1440
|
);
|
|
1215
1441
|
}
|
|
1216
|
-
return /* @__PURE__ */
|
|
1217
|
-
|
|
1442
|
+
return /* @__PURE__ */ jsxs7(
|
|
1443
|
+
Primitive5.Group,
|
|
1218
1444
|
{
|
|
1219
1445
|
children: [
|
|
1220
|
-
/* @__PURE__ */
|
|
1221
|
-
|
|
1446
|
+
/* @__PURE__ */ jsx8(
|
|
1447
|
+
Primitive5.Label,
|
|
1222
1448
|
{
|
|
1223
1449
|
className: overlayListLabelStyles2(),
|
|
1224
1450
|
children: entry.label
|
|
1225
1451
|
}
|
|
1226
1452
|
),
|
|
1227
1453
|
entry.options.map((option) => {
|
|
1228
|
-
return /* @__PURE__ */
|
|
1454
|
+
return /* @__PURE__ */ jsx8(
|
|
1229
1455
|
SelectOptionItem,
|
|
1230
1456
|
{
|
|
1231
1457
|
option
|
|
@@ -1243,10 +1469,10 @@ var SelectOptions = (props) => {
|
|
|
1243
1469
|
};
|
|
1244
1470
|
var SelectOptionItem = (props) => {
|
|
1245
1471
|
const { option } = props;
|
|
1246
|
-
const labelId =
|
|
1472
|
+
const labelId = useId4();
|
|
1247
1473
|
const descriptionId = `${labelId}-description`;
|
|
1248
|
-
return /* @__PURE__ */
|
|
1249
|
-
|
|
1474
|
+
return /* @__PURE__ */ jsxs7(
|
|
1475
|
+
Primitive5.Item,
|
|
1250
1476
|
{
|
|
1251
1477
|
value: `gridui:${option.value}`,
|
|
1252
1478
|
"aria-labelledby": labelId,
|
|
@@ -1255,7 +1481,7 @@ var SelectOptionItem = (props) => {
|
|
|
1255
1481
|
disabled: option.disabled,
|
|
1256
1482
|
className: overlayListItemStyles3(),
|
|
1257
1483
|
children: [
|
|
1258
|
-
option.icon && /* @__PURE__ */
|
|
1484
|
+
option.icon && /* @__PURE__ */ jsx8(
|
|
1259
1485
|
"span",
|
|
1260
1486
|
{
|
|
1261
1487
|
className: selectIconStyles(),
|
|
@@ -1263,19 +1489,19 @@ var SelectOptionItem = (props) => {
|
|
|
1263
1489
|
children: option.icon
|
|
1264
1490
|
}
|
|
1265
1491
|
),
|
|
1266
|
-
/* @__PURE__ */
|
|
1492
|
+
/* @__PURE__ */ jsxs7(
|
|
1267
1493
|
"span",
|
|
1268
1494
|
{
|
|
1269
1495
|
className: selectOptionContentStyles(),
|
|
1270
1496
|
children: [
|
|
1271
|
-
/* @__PURE__ */
|
|
1272
|
-
|
|
1497
|
+
/* @__PURE__ */ jsx8(
|
|
1498
|
+
Primitive5.ItemText,
|
|
1273
1499
|
{
|
|
1274
1500
|
id: labelId,
|
|
1275
1501
|
children: option.label
|
|
1276
1502
|
}
|
|
1277
1503
|
),
|
|
1278
|
-
option.description && /* @__PURE__ */
|
|
1504
|
+
option.description && /* @__PURE__ */ jsx8(
|
|
1279
1505
|
"span",
|
|
1280
1506
|
{
|
|
1281
1507
|
id: descriptionId,
|
|
@@ -1286,12 +1512,12 @@ var SelectOptionItem = (props) => {
|
|
|
1286
1512
|
]
|
|
1287
1513
|
}
|
|
1288
1514
|
),
|
|
1289
|
-
/* @__PURE__ */
|
|
1515
|
+
/* @__PURE__ */ jsx8(
|
|
1290
1516
|
"span",
|
|
1291
1517
|
{
|
|
1292
1518
|
className: overlayListIndicatorStyles2(),
|
|
1293
1519
|
"aria-hidden": "true",
|
|
1294
|
-
children: /* @__PURE__ */
|
|
1520
|
+
children: /* @__PURE__ */ jsx8(Primitive5.ItemIndicator, { children: /* @__PURE__ */ jsx8(
|
|
1295
1521
|
Check2,
|
|
1296
1522
|
{
|
|
1297
1523
|
size: 16
|
|
@@ -1306,9 +1532,9 @@ var SelectOptionItem = (props) => {
|
|
|
1306
1532
|
|
|
1307
1533
|
// src/select/style.ts
|
|
1308
1534
|
import { overlayListStyles as overlayListStyles2 } from "@gridui/overlay";
|
|
1309
|
-
import { cn as
|
|
1535
|
+
import { cn as cn5 } from "@gridui/style-utils";
|
|
1310
1536
|
import { cva as cva3 } from "class-variance-authority";
|
|
1311
|
-
var selectContentStyles = cva3(
|
|
1537
|
+
var selectContentStyles = cva3(cn5(
|
|
1312
1538
|
overlayListStyles2(),
|
|
1313
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)"
|
|
1314
1540
|
));
|
|
@@ -1324,11 +1550,11 @@ var selectScrollArrowStyles = cva3("gridui-u-select--absolute gridui-u-select--i
|
|
|
1324
1550
|
// src/select/select.tsx
|
|
1325
1551
|
import { controlVariants as controlVariants3 } from "@gridui/input";
|
|
1326
1552
|
import { interactionLayerProps as interactionLayerProps2 } from "@gridui/overlay";
|
|
1327
|
-
import { cn as
|
|
1328
|
-
import * as
|
|
1553
|
+
import { cn as cn6 } from "@gridui/style-utils";
|
|
1554
|
+
import * as Primitive6 from "@radix-ui/react-select";
|
|
1329
1555
|
import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
|
|
1330
|
-
import { useId as
|
|
1331
|
-
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";
|
|
1332
1558
|
var Select = (props) => {
|
|
1333
1559
|
const {
|
|
1334
1560
|
options,
|
|
@@ -1350,7 +1576,7 @@ var Select = (props) => {
|
|
|
1350
1576
|
ref,
|
|
1351
1577
|
...restProps
|
|
1352
1578
|
} = props;
|
|
1353
|
-
const controlRef =
|
|
1579
|
+
const controlRef = useRef8(null);
|
|
1354
1580
|
const {
|
|
1355
1581
|
open,
|
|
1356
1582
|
popupRef,
|
|
@@ -1369,19 +1595,19 @@ var Select = (props) => {
|
|
|
1369
1595
|
defaultValue,
|
|
1370
1596
|
onValueChange
|
|
1371
1597
|
}, available);
|
|
1372
|
-
const listId =
|
|
1598
|
+
const listId = useId5();
|
|
1373
1599
|
const [
|
|
1374
1600
|
triggerWidth,
|
|
1375
1601
|
setTriggerWidth
|
|
1376
|
-
] =
|
|
1602
|
+
] = useState5();
|
|
1377
1603
|
const allOptions = flattenOptions(options);
|
|
1378
1604
|
const selected = allOptions.find((option) => {
|
|
1379
1605
|
return option.value === selectedValue;
|
|
1380
1606
|
});
|
|
1381
1607
|
const fallback = selectedValue === "" ? placeholder ?? "" : selectedValue;
|
|
1382
1608
|
const display = selected?.label ?? fallback;
|
|
1383
|
-
return /* @__PURE__ */
|
|
1384
|
-
|
|
1609
|
+
return /* @__PURE__ */ jsxs8(
|
|
1610
|
+
Primitive6.Root,
|
|
1385
1611
|
{
|
|
1386
1612
|
form: `${listId}-detached`,
|
|
1387
1613
|
value: selected ? `gridui:${selectedValue}` : "",
|
|
@@ -1398,14 +1624,14 @@ var Select = (props) => {
|
|
|
1398
1624
|
},
|
|
1399
1625
|
dir: dir === "rtl" ? "rtl" : "ltr",
|
|
1400
1626
|
children: [
|
|
1401
|
-
/* @__PURE__ */
|
|
1627
|
+
/* @__PURE__ */ jsxs8(
|
|
1402
1628
|
"div",
|
|
1403
1629
|
{
|
|
1404
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",
|
|
1405
1631
|
dir,
|
|
1406
1632
|
children: [
|
|
1407
|
-
/* @__PURE__ */
|
|
1408
|
-
|
|
1633
|
+
/* @__PURE__ */ jsxs8(
|
|
1634
|
+
Primitive6.Trigger,
|
|
1409
1635
|
{
|
|
1410
1636
|
...restProps,
|
|
1411
1637
|
form,
|
|
@@ -1420,9 +1646,9 @@ var Select = (props) => {
|
|
|
1420
1646
|
ref.current = element;
|
|
1421
1647
|
}
|
|
1422
1648
|
},
|
|
1423
|
-
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),
|
|
1424
1650
|
children: [
|
|
1425
|
-
selected?.icon && /* @__PURE__ */
|
|
1651
|
+
selected?.icon && /* @__PURE__ */ jsx9(
|
|
1426
1652
|
"span",
|
|
1427
1653
|
{
|
|
1428
1654
|
className: selectIconStyles(),
|
|
@@ -1430,12 +1656,12 @@ var Select = (props) => {
|
|
|
1430
1656
|
children: selected.icon
|
|
1431
1657
|
}
|
|
1432
1658
|
),
|
|
1433
|
-
/* @__PURE__ */
|
|
1659
|
+
/* @__PURE__ */ jsx9(
|
|
1434
1660
|
"span",
|
|
1435
1661
|
{
|
|
1436
1662
|
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere",
|
|
1437
|
-
children: /* @__PURE__ */
|
|
1438
|
-
|
|
1663
|
+
children: /* @__PURE__ */ jsx9(
|
|
1664
|
+
Primitive6.Value,
|
|
1439
1665
|
{
|
|
1440
1666
|
placeholder: display,
|
|
1441
1667
|
children: display
|
|
@@ -1443,7 +1669,7 @@ var Select = (props) => {
|
|
|
1443
1669
|
)
|
|
1444
1670
|
}
|
|
1445
1671
|
),
|
|
1446
|
-
/* @__PURE__ */
|
|
1672
|
+
/* @__PURE__ */ jsx9(Primitive6.Icon, { children: /* @__PURE__ */ jsx9(
|
|
1447
1673
|
ChevronDown3,
|
|
1448
1674
|
{
|
|
1449
1675
|
size: 16,
|
|
@@ -1454,7 +1680,7 @@ var Select = (props) => {
|
|
|
1454
1680
|
]
|
|
1455
1681
|
}
|
|
1456
1682
|
),
|
|
1457
|
-
clearLabel && /* @__PURE__ */
|
|
1683
|
+
clearLabel && /* @__PURE__ */ jsx9(
|
|
1458
1684
|
"button",
|
|
1459
1685
|
{
|
|
1460
1686
|
type: "button",
|
|
@@ -1464,8 +1690,8 @@ var Select = (props) => {
|
|
|
1464
1690
|
change("");
|
|
1465
1691
|
controlRef.current?.focus();
|
|
1466
1692
|
},
|
|
1467
|
-
className:
|
|
1468
|
-
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(
|
|
1469
1695
|
X3,
|
|
1470
1696
|
{
|
|
1471
1697
|
size: 16,
|
|
@@ -1474,7 +1700,7 @@ var Select = (props) => {
|
|
|
1474
1700
|
)
|
|
1475
1701
|
}
|
|
1476
1702
|
),
|
|
1477
|
-
/* @__PURE__ */
|
|
1703
|
+
/* @__PURE__ */ jsx9(
|
|
1478
1704
|
SelectionForm,
|
|
1479
1705
|
{
|
|
1480
1706
|
name,
|
|
@@ -1494,12 +1720,12 @@ var Select = (props) => {
|
|
|
1494
1720
|
]
|
|
1495
1721
|
}
|
|
1496
1722
|
),
|
|
1497
|
-
/* @__PURE__ */
|
|
1498
|
-
|
|
1723
|
+
/* @__PURE__ */ jsx9(
|
|
1724
|
+
Primitive6.Portal,
|
|
1499
1725
|
{
|
|
1500
1726
|
container: portalContainer,
|
|
1501
|
-
children: /* @__PURE__ */
|
|
1502
|
-
|
|
1727
|
+
children: /* @__PURE__ */ jsxs8(
|
|
1728
|
+
Primitive6.Content,
|
|
1503
1729
|
{
|
|
1504
1730
|
...interactionLayerProps2,
|
|
1505
1731
|
position,
|
|
@@ -1549,16 +1775,16 @@ var Select = (props) => {
|
|
|
1549
1775
|
}
|
|
1550
1776
|
},
|
|
1551
1777
|
children: [
|
|
1552
|
-
/* @__PURE__ */
|
|
1778
|
+
/* @__PURE__ */ jsxs8(
|
|
1553
1779
|
"div",
|
|
1554
1780
|
{
|
|
1555
1781
|
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-h-0 gridui-u-select--flex-col",
|
|
1556
1782
|
children: [
|
|
1557
|
-
/* @__PURE__ */
|
|
1558
|
-
|
|
1783
|
+
/* @__PURE__ */ jsx9(
|
|
1784
|
+
Primitive6.ScrollUpButton,
|
|
1559
1785
|
{
|
|
1560
1786
|
className: selectScrollArrowStyles({ direction: "up" }),
|
|
1561
|
-
children: /* @__PURE__ */
|
|
1787
|
+
children: /* @__PURE__ */ jsx9(
|
|
1562
1788
|
ChevronUp,
|
|
1563
1789
|
{
|
|
1564
1790
|
size: 16,
|
|
@@ -1567,7 +1793,7 @@ var Select = (props) => {
|
|
|
1567
1793
|
)
|
|
1568
1794
|
}
|
|
1569
1795
|
),
|
|
1570
|
-
/* @__PURE__ */
|
|
1796
|
+
/* @__PURE__ */ jsx9(
|
|
1571
1797
|
SelectOptions,
|
|
1572
1798
|
{
|
|
1573
1799
|
options,
|
|
@@ -1575,11 +1801,11 @@ var Select = (props) => {
|
|
|
1575
1801
|
label: restProps["aria-label"]
|
|
1576
1802
|
}
|
|
1577
1803
|
),
|
|
1578
|
-
/* @__PURE__ */
|
|
1579
|
-
|
|
1804
|
+
/* @__PURE__ */ jsx9(
|
|
1805
|
+
Primitive6.ScrollDownButton,
|
|
1580
1806
|
{
|
|
1581
1807
|
className: selectScrollArrowStyles({ direction: "down" }),
|
|
1582
|
-
children: /* @__PURE__ */
|
|
1808
|
+
children: /* @__PURE__ */ jsx9(
|
|
1583
1809
|
ChevronDown3,
|
|
1584
1810
|
{
|
|
1585
1811
|
size: 16,
|
|
@@ -1591,7 +1817,7 @@ var Select = (props) => {
|
|
|
1591
1817
|
]
|
|
1592
1818
|
}
|
|
1593
1819
|
),
|
|
1594
|
-
/* @__PURE__ */
|
|
1820
|
+
/* @__PURE__ */ jsx9(
|
|
1595
1821
|
SelectionActions,
|
|
1596
1822
|
{
|
|
1597
1823
|
actions,
|
|
@@ -1653,7 +1879,7 @@ var createOptionsRequest = (loadOptions, onState) => {
|
|
|
1653
1879
|
};
|
|
1654
1880
|
|
|
1655
1881
|
// src/use-async-options/use-async-options.ts
|
|
1656
|
-
import { useEffect as
|
|
1882
|
+
import { useEffect as useEffect4, useState as useState6 } from "react";
|
|
1657
1883
|
var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true }) => {
|
|
1658
1884
|
if (!Number.isFinite(debounceMs) || debounceMs < 0) {
|
|
1659
1885
|
throw new RangeError("Option search debounce must be finite and nonnegative.");
|
|
@@ -1661,7 +1887,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1661
1887
|
const [
|
|
1662
1888
|
state,
|
|
1663
1889
|
setState
|
|
1664
|
-
] =
|
|
1890
|
+
] = useState6({
|
|
1665
1891
|
loader: loadOptions,
|
|
1666
1892
|
result: {
|
|
1667
1893
|
query,
|
|
@@ -1670,7 +1896,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1670
1896
|
error: null
|
|
1671
1897
|
}
|
|
1672
1898
|
});
|
|
1673
|
-
|
|
1899
|
+
useEffect4(() => {
|
|
1674
1900
|
const publish = (result) => {
|
|
1675
1901
|
setState({
|
|
1676
1902
|
loader: loadOptions,
|
|
@@ -1708,6 +1934,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1708
1934
|
};
|
|
1709
1935
|
};
|
|
1710
1936
|
export {
|
|
1937
|
+
Autocomplete,
|
|
1711
1938
|
Combobox,
|
|
1712
1939
|
MultiSelect,
|
|
1713
1940
|
Select,
|