@gridui/select 1.0.0 → 1.0.2
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 +10 -3
- package/dist/index.js +255 -271
- package/dist/index.js.map +4 -4
- package/dist/shared/selection-popup.d.ts +17 -0
- package/dist/styles.css +13 -14
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/shared/style.ts
|
|
2
|
-
import {
|
|
2
|
+
import { dropdownItemStyles } from "@gridui/dropdown-menu";
|
|
3
|
+
import { overlaySurfaceStyles } from "@gridui/overlay";
|
|
3
4
|
import { cn } from "@gridui/style-utils";
|
|
4
5
|
import { cva } from "class-variance-authority";
|
|
5
6
|
var selectItemStyles = cva(cn(dropdownItemStyles(), "min-w-0"));
|
|
@@ -14,7 +15,8 @@ var selectActionStyles = cva(cn(
|
|
|
14
15
|
"w-full text-start whitespace-normal wrap-anywhere hover:bg-surface focus-visible:bg-surface"
|
|
15
16
|
));
|
|
16
17
|
var comboboxContentStyles = cva(cn(
|
|
17
|
-
|
|
18
|
+
overlaySurfaceStyles(),
|
|
19
|
+
"z-(--gridui-z-popover) p-gridui-4 type-data",
|
|
18
20
|
"gridui-combobox-content box-border flex flex-col overflow-hidden min-w-0 w-(--anchor-width) max-h-(--available-height) max-w-(--available-width)"
|
|
19
21
|
));
|
|
20
22
|
|
|
@@ -199,7 +201,8 @@ var SelectionActions = (props) => {
|
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
// src/shared/selection-form.tsx
|
|
202
|
-
import {
|
|
204
|
+
import { focusInvalidControl, useFormReset } from "@gridui/form";
|
|
205
|
+
import { useLayoutEffect, useRef } from "react";
|
|
203
206
|
import { flushSync } from "react-dom";
|
|
204
207
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
205
208
|
var SelectionForm = (props) => {
|
|
@@ -224,27 +227,14 @@ var SelectionForm = (props) => {
|
|
|
224
227
|
onReset,
|
|
225
228
|
selectedValue
|
|
226
229
|
]);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
});
|
|
236
|
-
if (nativeRef.current) {
|
|
237
|
-
nativeRef.current.value = currentValue.current;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}, 0);
|
|
241
|
-
};
|
|
242
|
-
owner?.addEventListener("reset", reset);
|
|
243
|
-
return () => {
|
|
244
|
-
mounted = false;
|
|
245
|
-
owner?.removeEventListener("reset", reset);
|
|
246
|
-
};
|
|
247
|
-
}, [form]);
|
|
230
|
+
useFormReset(nativeRef, () => {
|
|
231
|
+
flushSync(() => {
|
|
232
|
+
resetSelection.current();
|
|
233
|
+
});
|
|
234
|
+
if (nativeRef.current) {
|
|
235
|
+
nativeRef.current.value = currentValue.current;
|
|
236
|
+
}
|
|
237
|
+
}, form);
|
|
248
238
|
return /* @__PURE__ */ jsxs3(
|
|
249
239
|
"select",
|
|
250
240
|
{
|
|
@@ -261,8 +251,7 @@ var SelectionForm = (props) => {
|
|
|
261
251
|
onValueChange(event.currentTarget.value);
|
|
262
252
|
},
|
|
263
253
|
onInvalid: (event) => {
|
|
264
|
-
event
|
|
265
|
-
onInvalid();
|
|
254
|
+
focusInvalidControl(event, onInvalid);
|
|
266
255
|
},
|
|
267
256
|
children: [
|
|
268
257
|
!allOptions.some((option) => {
|
|
@@ -298,6 +287,59 @@ var SelectionForm = (props) => {
|
|
|
298
287
|
);
|
|
299
288
|
};
|
|
300
289
|
|
|
290
|
+
// src/shared/selection-popup.tsx
|
|
291
|
+
import * as Primitive from "@radix-ui/react-popover";
|
|
292
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
293
|
+
var SelectionPopup = (props) => {
|
|
294
|
+
const { container, anchorRef, initialFocus, finalFocus, onEscape, onDismiss, ...restProps } = props;
|
|
295
|
+
return /* @__PURE__ */ jsx4(
|
|
296
|
+
Primitive.Portal,
|
|
297
|
+
{
|
|
298
|
+
container,
|
|
299
|
+
children: /* @__PURE__ */ jsx4(
|
|
300
|
+
Primitive.Content,
|
|
301
|
+
{
|
|
302
|
+
...restProps,
|
|
303
|
+
sideOffset: 8,
|
|
304
|
+
align: "start",
|
|
305
|
+
collisionPadding: 16,
|
|
306
|
+
className: comboboxContentStyles(),
|
|
307
|
+
onOpenAutoFocus: (event) => {
|
|
308
|
+
event.preventDefault();
|
|
309
|
+
initialFocus?.();
|
|
310
|
+
},
|
|
311
|
+
onCloseAutoFocus: (event) => {
|
|
312
|
+
event.preventDefault();
|
|
313
|
+
const target = finalFocus();
|
|
314
|
+
if (target) {
|
|
315
|
+
target.focus();
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
onInteractOutside: (event) => {
|
|
319
|
+
if (anchorRef?.current?.contains(event.target)) {
|
|
320
|
+
event.preventDefault();
|
|
321
|
+
} else {
|
|
322
|
+
onDismiss?.();
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
onEscapeKeyDown: (event) => {
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
event.stopPropagation();
|
|
328
|
+
if (!event.isComposing) {
|
|
329
|
+
onEscape();
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
onKeyDown: (event) => {
|
|
333
|
+
if (event.key === "Escape") {
|
|
334
|
+
event.stopPropagation();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
};
|
|
342
|
+
|
|
301
343
|
// src/shared/options.ts
|
|
302
344
|
var flattenOptions = (options) => {
|
|
303
345
|
return options.flatMap((entry) => {
|
|
@@ -343,7 +385,7 @@ var scrollOption = (id) => {
|
|
|
343
385
|
};
|
|
344
386
|
|
|
345
387
|
// src/shared/use-search-options.ts
|
|
346
|
-
import { useEffect
|
|
388
|
+
import { useEffect, useState } from "react";
|
|
347
389
|
var INITIAL_SEARCH = {
|
|
348
390
|
query: null,
|
|
349
391
|
highlighted: null
|
|
@@ -371,12 +413,12 @@ var useSearchOptions = (options, selected, listId, open) => {
|
|
|
371
413
|
})}`;
|
|
372
414
|
};
|
|
373
415
|
const activeOptionId = active ? optionId(active.value) : void 0;
|
|
374
|
-
|
|
416
|
+
useEffect(() => {
|
|
375
417
|
if (!open) {
|
|
376
418
|
setSearch(INITIAL_SEARCH);
|
|
377
419
|
}
|
|
378
420
|
}, [open]);
|
|
379
|
-
|
|
421
|
+
useEffect(() => {
|
|
380
422
|
if (open && activeOptionId !== void 0) {
|
|
381
423
|
scrollOption(activeOptionId);
|
|
382
424
|
}
|
|
@@ -421,7 +463,7 @@ var useSearchOptions = (options, selected, listId, open) => {
|
|
|
421
463
|
};
|
|
422
464
|
|
|
423
465
|
// src/shared/use-selection-popup.ts
|
|
424
|
-
import { useEffect as
|
|
466
|
+
import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
425
467
|
import { flushSync as flushSync2 } from "react-dom";
|
|
426
468
|
var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
|
|
427
469
|
const [
|
|
@@ -431,7 +473,7 @@ var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
|
|
|
431
473
|
const popupRef = useRef2(null);
|
|
432
474
|
const restoreFocus = useRef2(true);
|
|
433
475
|
const unavailable = Boolean(disabled || readOnly);
|
|
434
|
-
|
|
476
|
+
useEffect2(() => {
|
|
435
477
|
if (unavailable) {
|
|
436
478
|
setLocalOpen(false);
|
|
437
479
|
}
|
|
@@ -529,10 +571,10 @@ var comboboxTriggerStyles = cva2("absolute inset-y-0 right-0 flex w-9 items-cent
|
|
|
529
571
|
// src/combobox/combobox.tsx
|
|
530
572
|
import { controlVariants } from "@gridui/input";
|
|
531
573
|
import { cn as cn2 } from "@gridui/style-utils";
|
|
532
|
-
import * as
|
|
574
|
+
import * as Primitive2 from "@radix-ui/react-popover";
|
|
533
575
|
import { ChevronDown, X } from "lucide-react";
|
|
534
576
|
import { useId, useRef as useRef4 } from "react";
|
|
535
|
-
import { jsx as
|
|
577
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
536
578
|
var Combobox = (props) => {
|
|
537
579
|
const {
|
|
538
580
|
options,
|
|
@@ -559,6 +601,7 @@ var Combobox = (props) => {
|
|
|
559
601
|
...restProps
|
|
560
602
|
} = props;
|
|
561
603
|
const controlRef = useRef4(null);
|
|
604
|
+
const anchorRef = useRef4(null);
|
|
562
605
|
const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
|
|
563
606
|
disabled,
|
|
564
607
|
readOnly,
|
|
@@ -589,7 +632,7 @@ var Combobox = (props) => {
|
|
|
589
632
|
focus();
|
|
590
633
|
};
|
|
591
634
|
return /* @__PURE__ */ jsxs4(
|
|
592
|
-
|
|
635
|
+
Primitive2.Root,
|
|
593
636
|
{
|
|
594
637
|
open,
|
|
595
638
|
onOpenChange: changeOpen,
|
|
@@ -600,16 +643,17 @@ var Combobox = (props) => {
|
|
|
600
643
|
className: "relative flex min-w-0 w-full items-stretch gap-gridui-4",
|
|
601
644
|
dir,
|
|
602
645
|
children: [
|
|
603
|
-
/* @__PURE__ */
|
|
604
|
-
|
|
646
|
+
/* @__PURE__ */ jsx5(
|
|
647
|
+
Primitive2.Anchor,
|
|
605
648
|
{
|
|
606
649
|
asChild: true,
|
|
607
650
|
children: /* @__PURE__ */ jsxs4(
|
|
608
651
|
"div",
|
|
609
652
|
{
|
|
653
|
+
ref: anchorRef,
|
|
610
654
|
className: "relative flex min-w-0 flex-1 items-stretch",
|
|
611
655
|
children: [
|
|
612
|
-
/* @__PURE__ */
|
|
656
|
+
/* @__PURE__ */ jsx5(
|
|
613
657
|
"input",
|
|
614
658
|
{
|
|
615
659
|
...restProps,
|
|
@@ -694,7 +738,7 @@ var Combobox = (props) => {
|
|
|
694
738
|
}
|
|
695
739
|
}
|
|
696
740
|
),
|
|
697
|
-
/* @__PURE__ */
|
|
741
|
+
/* @__PURE__ */ jsx5(
|
|
698
742
|
"button",
|
|
699
743
|
{
|
|
700
744
|
type: "button",
|
|
@@ -709,7 +753,7 @@ var Combobox = (props) => {
|
|
|
709
753
|
}
|
|
710
754
|
focus();
|
|
711
755
|
},
|
|
712
|
-
children: /* @__PURE__ */
|
|
756
|
+
children: /* @__PURE__ */ jsx5(
|
|
713
757
|
ChevronDown,
|
|
714
758
|
{
|
|
715
759
|
size: 16,
|
|
@@ -723,7 +767,7 @@ var Combobox = (props) => {
|
|
|
723
767
|
)
|
|
724
768
|
}
|
|
725
769
|
),
|
|
726
|
-
clearLabel && /* @__PURE__ */
|
|
770
|
+
clearLabel && /* @__PURE__ */ jsx5(
|
|
727
771
|
"button",
|
|
728
772
|
{
|
|
729
773
|
type: "button",
|
|
@@ -735,7 +779,7 @@ var Combobox = (props) => {
|
|
|
735
779
|
focus();
|
|
736
780
|
},
|
|
737
781
|
className: cn2(controlVariants({ size: controlSize }), "flex w-auto shrink-0 items-center justify-center min-w-11 cursor-pointer hover:enabled:bg-surface"),
|
|
738
|
-
children: /* @__PURE__ */
|
|
782
|
+
children: /* @__PURE__ */ jsx5(
|
|
739
783
|
X,
|
|
740
784
|
{
|
|
741
785
|
size: 16,
|
|
@@ -744,7 +788,7 @@ var Combobox = (props) => {
|
|
|
744
788
|
)
|
|
745
789
|
}
|
|
746
790
|
),
|
|
747
|
-
/* @__PURE__ */
|
|
791
|
+
/* @__PURE__ */ jsx5(
|
|
748
792
|
SelectionForm,
|
|
749
793
|
{
|
|
750
794
|
name,
|
|
@@ -764,82 +808,50 @@ var Combobox = (props) => {
|
|
|
764
808
|
]
|
|
765
809
|
}
|
|
766
810
|
),
|
|
767
|
-
/* @__PURE__ */
|
|
768
|
-
|
|
811
|
+
/* @__PURE__ */ jsxs4(
|
|
812
|
+
SelectionPopup,
|
|
769
813
|
{
|
|
770
814
|
container: portalContainer,
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
children: [
|
|
812
|
-
visible.length === 0 && /* @__PURE__ */ jsx4(
|
|
813
|
-
"div",
|
|
814
|
-
{
|
|
815
|
-
role: "status",
|
|
816
|
-
className: selectEmptyStyles(),
|
|
817
|
-
children: emptyLabel
|
|
818
|
-
}
|
|
819
|
-
),
|
|
820
|
-
/* @__PURE__ */ jsx4(
|
|
821
|
-
ComboboxOptions,
|
|
822
|
-
{
|
|
823
|
-
id: listId,
|
|
824
|
-
label: searchLabel,
|
|
825
|
-
options: filtered,
|
|
826
|
-
selected: selectedValue,
|
|
827
|
-
active,
|
|
828
|
-
optionId,
|
|
829
|
-
onSelect: choose,
|
|
830
|
-
onHighlight: search.highlight
|
|
831
|
-
}
|
|
832
|
-
),
|
|
833
|
-
/* @__PURE__ */ jsx4(
|
|
834
|
-
SelectionActions,
|
|
835
|
-
{
|
|
836
|
-
actions,
|
|
837
|
-
onAction: runAction
|
|
838
|
-
}
|
|
839
|
-
)
|
|
840
|
-
]
|
|
841
|
-
}
|
|
842
|
-
)
|
|
815
|
+
ref: popupRef,
|
|
816
|
+
role: "presentation",
|
|
817
|
+
dir,
|
|
818
|
+
finalFocus,
|
|
819
|
+
anchorRef,
|
|
820
|
+
onDismiss: close,
|
|
821
|
+
onEscape: () => {
|
|
822
|
+
close();
|
|
823
|
+
focus();
|
|
824
|
+
},
|
|
825
|
+
children: [
|
|
826
|
+
visible.length === 0 && /* @__PURE__ */ jsx5(
|
|
827
|
+
"div",
|
|
828
|
+
{
|
|
829
|
+
role: "status",
|
|
830
|
+
className: selectEmptyStyles(),
|
|
831
|
+
children: emptyLabel
|
|
832
|
+
}
|
|
833
|
+
),
|
|
834
|
+
/* @__PURE__ */ jsx5(
|
|
835
|
+
ComboboxOptions,
|
|
836
|
+
{
|
|
837
|
+
id: listId,
|
|
838
|
+
label: searchLabel,
|
|
839
|
+
options: filtered,
|
|
840
|
+
selected: selectedValue,
|
|
841
|
+
active,
|
|
842
|
+
optionId,
|
|
843
|
+
onSelect: choose,
|
|
844
|
+
onHighlight: search.highlight
|
|
845
|
+
}
|
|
846
|
+
),
|
|
847
|
+
/* @__PURE__ */ jsx5(
|
|
848
|
+
SelectionActions,
|
|
849
|
+
{
|
|
850
|
+
actions,
|
|
851
|
+
onAction: runAction
|
|
852
|
+
}
|
|
853
|
+
)
|
|
854
|
+
]
|
|
843
855
|
}
|
|
844
856
|
)
|
|
845
857
|
]
|
|
@@ -848,13 +860,13 @@ var Combobox = (props) => {
|
|
|
848
860
|
};
|
|
849
861
|
|
|
850
862
|
// src/multi-select/multi-select.tsx
|
|
851
|
-
import { useListField } from "@gridui/form";
|
|
863
|
+
import { ListFieldControl, useListField } from "@gridui/form";
|
|
852
864
|
import { controlVariants as controlVariants2 } from "@gridui/input";
|
|
853
865
|
import { cn as cn3 } from "@gridui/style-utils";
|
|
854
|
-
import * as
|
|
866
|
+
import * as Primitive3 from "@radix-ui/react-popover";
|
|
855
867
|
import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
|
|
856
868
|
import { useId as useId2, useRef as useRef5 } from "react";
|
|
857
|
-
import { jsx as
|
|
869
|
+
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
858
870
|
var MultiSelect = (props) => {
|
|
859
871
|
const {
|
|
860
872
|
value,
|
|
@@ -908,7 +920,7 @@ var MultiSelect = (props) => {
|
|
|
908
920
|
search.current?.focus({ preventScroll: true });
|
|
909
921
|
};
|
|
910
922
|
return /* @__PURE__ */ jsxs5(
|
|
911
|
-
|
|
923
|
+
Primitive3.Root,
|
|
912
924
|
{
|
|
913
925
|
open,
|
|
914
926
|
onOpenChange: changeOpen,
|
|
@@ -919,8 +931,8 @@ var MultiSelect = (props) => {
|
|
|
919
931
|
className: "flex min-w-0 items-stretch gap-gridui-4",
|
|
920
932
|
dir: restProps.dir,
|
|
921
933
|
children: [
|
|
922
|
-
/* @__PURE__ */
|
|
923
|
-
|
|
934
|
+
/* @__PURE__ */ jsx6(
|
|
935
|
+
Primitive3.Trigger,
|
|
924
936
|
{
|
|
925
937
|
asChild: true,
|
|
926
938
|
children: /* @__PURE__ */ jsxs5(
|
|
@@ -950,7 +962,7 @@ var MultiSelect = (props) => {
|
|
|
950
962
|
}
|
|
951
963
|
},
|
|
952
964
|
children: [
|
|
953
|
-
/* @__PURE__ */
|
|
965
|
+
/* @__PURE__ */ jsx6(
|
|
954
966
|
"span",
|
|
955
967
|
{
|
|
956
968
|
className: "min-w-0 flex-1 wrap-anywhere",
|
|
@@ -961,7 +973,7 @@ var MultiSelect = (props) => {
|
|
|
961
973
|
}).join(", ") : placeholder
|
|
962
974
|
}
|
|
963
975
|
),
|
|
964
|
-
/* @__PURE__ */
|
|
976
|
+
/* @__PURE__ */ jsx6(
|
|
965
977
|
ChevronDown2,
|
|
966
978
|
{
|
|
967
979
|
size: 16,
|
|
@@ -973,7 +985,7 @@ var MultiSelect = (props) => {
|
|
|
973
985
|
)
|
|
974
986
|
}
|
|
975
987
|
),
|
|
976
|
-
clearLabel && /* @__PURE__ */
|
|
988
|
+
clearLabel && /* @__PURE__ */ jsx6(
|
|
977
989
|
"button",
|
|
978
990
|
{
|
|
979
991
|
type: "button",
|
|
@@ -984,7 +996,7 @@ var MultiSelect = (props) => {
|
|
|
984
996
|
change([]);
|
|
985
997
|
control.current?.focus();
|
|
986
998
|
},
|
|
987
|
-
children: /* @__PURE__ */
|
|
999
|
+
children: /* @__PURE__ */ jsx6(
|
|
988
1000
|
X2,
|
|
989
1001
|
{
|
|
990
1002
|
size: 16,
|
|
@@ -994,30 +1006,21 @@ var MultiSelect = (props) => {
|
|
|
994
1006
|
}
|
|
995
1007
|
),
|
|
996
1008
|
/* @__PURE__ */ jsxs5(
|
|
997
|
-
|
|
1009
|
+
ListFieldControl,
|
|
998
1010
|
{
|
|
999
1011
|
ref: native,
|
|
1000
|
-
multiple: true,
|
|
1001
|
-
className: "sr-only",
|
|
1002
|
-
"aria-hidden": "true",
|
|
1003
|
-
tabIndex: -1,
|
|
1004
1012
|
name,
|
|
1005
1013
|
form,
|
|
1006
1014
|
required,
|
|
1007
1015
|
disabled,
|
|
1008
1016
|
value: selected,
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
return option.value;
|
|
1012
|
-
}));
|
|
1013
|
-
},
|
|
1014
|
-
onInvalid: (event) => {
|
|
1015
|
-
event.preventDefault();
|
|
1017
|
+
onValueChange: change,
|
|
1018
|
+
onInvalidFocus: () => {
|
|
1016
1019
|
control.current?.focus();
|
|
1017
1020
|
},
|
|
1018
1021
|
children: [
|
|
1019
1022
|
all.map((option) => {
|
|
1020
|
-
return /* @__PURE__ */
|
|
1023
|
+
return /* @__PURE__ */ jsx6(
|
|
1021
1024
|
"option",
|
|
1022
1025
|
{
|
|
1023
1026
|
value: option.value,
|
|
@@ -1032,7 +1035,7 @@ var MultiSelect = (props) => {
|
|
|
1032
1035
|
return option.value === entry;
|
|
1033
1036
|
});
|
|
1034
1037
|
}).map((entry) => {
|
|
1035
|
-
return /* @__PURE__ */
|
|
1038
|
+
return /* @__PURE__ */ jsx6(
|
|
1036
1039
|
"option",
|
|
1037
1040
|
{
|
|
1038
1041
|
value: entry,
|
|
@@ -1047,100 +1050,80 @@ var MultiSelect = (props) => {
|
|
|
1047
1050
|
]
|
|
1048
1051
|
}
|
|
1049
1052
|
),
|
|
1050
|
-
/* @__PURE__ */
|
|
1051
|
-
|
|
1053
|
+
/* @__PURE__ */ jsxs5(
|
|
1054
|
+
SelectionPopup,
|
|
1052
1055
|
{
|
|
1053
1056
|
container: portalContainer,
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
{
|
|
1087
|
-
ref: search,
|
|
1088
|
-
type: "text",
|
|
1089
|
-
role: "combobox",
|
|
1090
|
-
"aria-label": searchLabel,
|
|
1091
|
-
"aria-expanded": "true",
|
|
1092
|
-
"aria-autocomplete": "list",
|
|
1093
|
-
"aria-controls": `${id}-list`,
|
|
1094
|
-
"aria-activedescendant": activeOptionId,
|
|
1095
|
-
value: query ?? "",
|
|
1096
|
-
className: cn3(controlVariants2({ size: "small" }), "mb-gridui-4 shrink-0"),
|
|
1097
|
-
onChange: (event) => {
|
|
1098
|
-
searchOptions.changeQuery(event.target.value);
|
|
1099
|
-
},
|
|
1100
|
-
onKeyDown: (event) => {
|
|
1101
|
-
if (event.nativeEvent.isComposing) {
|
|
1102
|
-
event.stopPropagation();
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
1106
|
-
event.preventDefault();
|
|
1107
|
-
searchOptions.moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
1108
|
-
}
|
|
1109
|
-
if (event.key === "Enter") {
|
|
1110
|
-
event.preventDefault();
|
|
1111
|
-
const option = searchOptions.activeOption;
|
|
1112
|
-
if (option) {
|
|
1113
|
-
choose(option);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1057
|
+
ref: popup,
|
|
1058
|
+
"aria-label": searchLabel,
|
|
1059
|
+
dir: restProps.dir,
|
|
1060
|
+
finalFocus,
|
|
1061
|
+
initialFocus: () => {
|
|
1062
|
+
search.current?.focus({ preventScroll: true });
|
|
1063
|
+
},
|
|
1064
|
+
onEscape: () => {
|
|
1065
|
+
close();
|
|
1066
|
+
focus();
|
|
1067
|
+
},
|
|
1068
|
+
children: [
|
|
1069
|
+
/* @__PURE__ */ jsx6(
|
|
1070
|
+
"input",
|
|
1071
|
+
{
|
|
1072
|
+
ref: search,
|
|
1073
|
+
type: "text",
|
|
1074
|
+
role: "combobox",
|
|
1075
|
+
"aria-label": searchLabel,
|
|
1076
|
+
"aria-expanded": "true",
|
|
1077
|
+
"aria-autocomplete": "list",
|
|
1078
|
+
"aria-controls": `${id}-list`,
|
|
1079
|
+
"aria-activedescendant": activeOptionId,
|
|
1080
|
+
value: query ?? "",
|
|
1081
|
+
className: cn3(controlVariants2({ size: "small" }), "mb-gridui-4 shrink-0"),
|
|
1082
|
+
onChange: (event) => {
|
|
1083
|
+
searchOptions.changeQuery(event.target.value);
|
|
1084
|
+
},
|
|
1085
|
+
onKeyDown: (event) => {
|
|
1086
|
+
if (event.nativeEvent.isComposing) {
|
|
1087
|
+
event.stopPropagation();
|
|
1088
|
+
return;
|
|
1117
1089
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
{
|
|
1122
|
-
id: `${id}-list`,
|
|
1123
|
-
label: searchLabel,
|
|
1124
|
-
options: filtered,
|
|
1125
|
-
selected,
|
|
1126
|
-
multiple: true,
|
|
1127
|
-
active,
|
|
1128
|
-
optionId,
|
|
1129
|
-
onSelect: choose,
|
|
1130
|
-
onHighlight: searchOptions.highlight
|
|
1090
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
1091
|
+
event.preventDefault();
|
|
1092
|
+
searchOptions.moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
1131
1093
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
children: emptyLabel
|
|
1094
|
+
if (event.key === "Enter") {
|
|
1095
|
+
event.preventDefault();
|
|
1096
|
+
const option = searchOptions.activeOption;
|
|
1097
|
+
if (option) {
|
|
1098
|
+
choose(option);
|
|
1099
|
+
}
|
|
1139
1100
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
),
|
|
1104
|
+
/* @__PURE__ */ jsx6(
|
|
1105
|
+
ComboboxOptions,
|
|
1106
|
+
{
|
|
1107
|
+
id: `${id}-list`,
|
|
1108
|
+
label: searchLabel,
|
|
1109
|
+
options: filtered,
|
|
1110
|
+
selected,
|
|
1111
|
+
multiple: true,
|
|
1112
|
+
active,
|
|
1113
|
+
optionId,
|
|
1114
|
+
onSelect: choose,
|
|
1115
|
+
onHighlight: searchOptions.highlight
|
|
1116
|
+
}
|
|
1117
|
+
),
|
|
1118
|
+
!visible.length && /* @__PURE__ */ jsx6(
|
|
1119
|
+
"div",
|
|
1120
|
+
{
|
|
1121
|
+
role: "status",
|
|
1122
|
+
className: selectEmptyStyles(),
|
|
1123
|
+
children: emptyLabel
|
|
1124
|
+
}
|
|
1125
|
+
)
|
|
1126
|
+
]
|
|
1144
1127
|
}
|
|
1145
1128
|
)
|
|
1146
1129
|
]
|
|
@@ -1149,11 +1132,12 @@ var MultiSelect = (props) => {
|
|
|
1149
1132
|
};
|
|
1150
1133
|
|
|
1151
1134
|
// src/select/style.ts
|
|
1152
|
-
import {
|
|
1135
|
+
import { overlaySurfaceStyles as overlaySurfaceStyles2 } from "@gridui/overlay";
|
|
1153
1136
|
import { cn as cn4 } from "@gridui/style-utils";
|
|
1154
1137
|
import { cva as cva3 } from "class-variance-authority";
|
|
1155
1138
|
var selectContentStyles = cva3(cn4(
|
|
1156
|
-
|
|
1139
|
+
overlaySurfaceStyles2(),
|
|
1140
|
+
"z-(--gridui-z-popover) p-gridui-4 type-data",
|
|
1157
1141
|
"gridui-select-content box-border relative flex flex-col overflow-hidden min-w-0 w-(--anchor-width) max-w-(--available-width) max-h-(--available-height)"
|
|
1158
1142
|
));
|
|
1159
1143
|
var selectMenuItemStyles = cva3(cn4(selectItemStyles(), "relative px-gridui-4 pr-9"));
|
|
@@ -1169,14 +1153,14 @@ var selectScrollArrowStyles = cva3("absolute inset-x-0 z-(--gridui-z-content) fl
|
|
|
1169
1153
|
|
|
1170
1154
|
// src/select/select-options.tsx
|
|
1171
1155
|
import { dropdownLabelStyles as dropdownLabelStyles2 } from "@gridui/dropdown-menu";
|
|
1172
|
-
import * as
|
|
1156
|
+
import * as Primitive4 from "@radix-ui/react-select";
|
|
1173
1157
|
import { Check as Check2 } from "lucide-react";
|
|
1174
1158
|
import { useId as useId3 } from "react";
|
|
1175
|
-
import { jsx as
|
|
1159
|
+
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1176
1160
|
var SelectOptions = (props) => {
|
|
1177
1161
|
const { options, id, label } = props;
|
|
1178
|
-
return /* @__PURE__ */
|
|
1179
|
-
|
|
1162
|
+
return /* @__PURE__ */ jsx7(
|
|
1163
|
+
Primitive4.Viewport,
|
|
1180
1164
|
{
|
|
1181
1165
|
className: selectListStyles(),
|
|
1182
1166
|
role: "listbox",
|
|
@@ -1184,7 +1168,7 @@ var SelectOptions = (props) => {
|
|
|
1184
1168
|
"aria-label": label,
|
|
1185
1169
|
children: options.map((entry) => {
|
|
1186
1170
|
if (!("options" in entry)) {
|
|
1187
|
-
return /* @__PURE__ */
|
|
1171
|
+
return /* @__PURE__ */ jsx7(
|
|
1188
1172
|
SelectOptionItem,
|
|
1189
1173
|
{
|
|
1190
1174
|
option: entry
|
|
@@ -1193,18 +1177,18 @@ var SelectOptions = (props) => {
|
|
|
1193
1177
|
);
|
|
1194
1178
|
}
|
|
1195
1179
|
return /* @__PURE__ */ jsxs6(
|
|
1196
|
-
|
|
1180
|
+
Primitive4.Group,
|
|
1197
1181
|
{
|
|
1198
1182
|
children: [
|
|
1199
|
-
/* @__PURE__ */
|
|
1200
|
-
|
|
1183
|
+
/* @__PURE__ */ jsx7(
|
|
1184
|
+
Primitive4.Label,
|
|
1201
1185
|
{
|
|
1202
1186
|
className: dropdownLabelStyles2(),
|
|
1203
1187
|
children: entry.label
|
|
1204
1188
|
}
|
|
1205
1189
|
),
|
|
1206
1190
|
entry.options.map((option) => {
|
|
1207
|
-
return /* @__PURE__ */
|
|
1191
|
+
return /* @__PURE__ */ jsx7(
|
|
1208
1192
|
SelectOptionItem,
|
|
1209
1193
|
{
|
|
1210
1194
|
option
|
|
@@ -1225,7 +1209,7 @@ var SelectOptionItem = (props) => {
|
|
|
1225
1209
|
const labelId = useId3();
|
|
1226
1210
|
const descriptionId = `${labelId}-description`;
|
|
1227
1211
|
return /* @__PURE__ */ jsxs6(
|
|
1228
|
-
|
|
1212
|
+
Primitive4.Item,
|
|
1229
1213
|
{
|
|
1230
1214
|
value: `gridui:${option.value}`,
|
|
1231
1215
|
"aria-labelledby": labelId,
|
|
@@ -1234,7 +1218,7 @@ var SelectOptionItem = (props) => {
|
|
|
1234
1218
|
disabled: option.disabled,
|
|
1235
1219
|
className: selectMenuItemStyles(),
|
|
1236
1220
|
children: [
|
|
1237
|
-
option.icon && /* @__PURE__ */
|
|
1221
|
+
option.icon && /* @__PURE__ */ jsx7(
|
|
1238
1222
|
"span",
|
|
1239
1223
|
{
|
|
1240
1224
|
className: selectIconStyles(),
|
|
@@ -1247,14 +1231,14 @@ var SelectOptionItem = (props) => {
|
|
|
1247
1231
|
{
|
|
1248
1232
|
className: selectOptionContentStyles(),
|
|
1249
1233
|
children: [
|
|
1250
|
-
/* @__PURE__ */
|
|
1251
|
-
|
|
1234
|
+
/* @__PURE__ */ jsx7(
|
|
1235
|
+
Primitive4.ItemText,
|
|
1252
1236
|
{
|
|
1253
1237
|
id: labelId,
|
|
1254
1238
|
children: option.label
|
|
1255
1239
|
}
|
|
1256
1240
|
),
|
|
1257
|
-
option.description && /* @__PURE__ */
|
|
1241
|
+
option.description && /* @__PURE__ */ jsx7(
|
|
1258
1242
|
"span",
|
|
1259
1243
|
{
|
|
1260
1244
|
id: descriptionId,
|
|
@@ -1265,12 +1249,12 @@ var SelectOptionItem = (props) => {
|
|
|
1265
1249
|
]
|
|
1266
1250
|
}
|
|
1267
1251
|
),
|
|
1268
|
-
/* @__PURE__ */
|
|
1269
|
-
|
|
1252
|
+
/* @__PURE__ */ jsx7(
|
|
1253
|
+
Primitive4.ItemIndicator,
|
|
1270
1254
|
{
|
|
1271
1255
|
className: selectIndicatorStyles(),
|
|
1272
1256
|
"aria-hidden": "true",
|
|
1273
|
-
children: /* @__PURE__ */
|
|
1257
|
+
children: /* @__PURE__ */ jsx7(
|
|
1274
1258
|
Check2,
|
|
1275
1259
|
{
|
|
1276
1260
|
size: 16
|
|
@@ -1286,10 +1270,10 @@ var SelectOptionItem = (props) => {
|
|
|
1286
1270
|
// src/select/select.tsx
|
|
1287
1271
|
import { controlVariants as controlVariants3 } from "@gridui/input";
|
|
1288
1272
|
import { cn as cn5 } from "@gridui/style-utils";
|
|
1289
|
-
import * as
|
|
1273
|
+
import * as Primitive5 from "@radix-ui/react-select";
|
|
1290
1274
|
import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
|
|
1291
1275
|
import { useId as useId4, useRef as useRef6, useState as useState4 } from "react";
|
|
1292
|
-
import { jsx as
|
|
1276
|
+
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1293
1277
|
var Select = (props) => {
|
|
1294
1278
|
const {
|
|
1295
1279
|
options,
|
|
@@ -1342,7 +1326,7 @@ var Select = (props) => {
|
|
|
1342
1326
|
const fallback = selectedValue === "" ? placeholder ?? "" : selectedValue;
|
|
1343
1327
|
const display = selected?.label ?? fallback;
|
|
1344
1328
|
return /* @__PURE__ */ jsxs7(
|
|
1345
|
-
|
|
1329
|
+
Primitive5.Root,
|
|
1346
1330
|
{
|
|
1347
1331
|
form: `${listId}-detached`,
|
|
1348
1332
|
value: selected ? `gridui:${selectedValue}` : "",
|
|
@@ -1366,7 +1350,7 @@ var Select = (props) => {
|
|
|
1366
1350
|
dir,
|
|
1367
1351
|
children: [
|
|
1368
1352
|
/* @__PURE__ */ jsxs7(
|
|
1369
|
-
|
|
1353
|
+
Primitive5.Trigger,
|
|
1370
1354
|
{
|
|
1371
1355
|
...restProps,
|
|
1372
1356
|
form,
|
|
@@ -1383,7 +1367,7 @@ var Select = (props) => {
|
|
|
1383
1367
|
},
|
|
1384
1368
|
className: cn5(controlVariants3({ size: controlSize }), "flex flex-1 items-center gap-gridui-8 text-start", className),
|
|
1385
1369
|
children: [
|
|
1386
|
-
selected?.icon && /* @__PURE__ */
|
|
1370
|
+
selected?.icon && /* @__PURE__ */ jsx8(
|
|
1387
1371
|
"span",
|
|
1388
1372
|
{
|
|
1389
1373
|
className: selectIconStyles(),
|
|
@@ -1391,12 +1375,12 @@ var Select = (props) => {
|
|
|
1391
1375
|
children: selected.icon
|
|
1392
1376
|
}
|
|
1393
1377
|
),
|
|
1394
|
-
/* @__PURE__ */
|
|
1378
|
+
/* @__PURE__ */ jsx8(
|
|
1395
1379
|
"span",
|
|
1396
1380
|
{
|
|
1397
1381
|
className: "min-w-0 flex-1 whitespace-normal wrap-anywhere",
|
|
1398
|
-
children: /* @__PURE__ */
|
|
1399
|
-
|
|
1382
|
+
children: /* @__PURE__ */ jsx8(
|
|
1383
|
+
Primitive5.Value,
|
|
1400
1384
|
{
|
|
1401
1385
|
placeholder: display,
|
|
1402
1386
|
children: display
|
|
@@ -1404,7 +1388,7 @@ var Select = (props) => {
|
|
|
1404
1388
|
)
|
|
1405
1389
|
}
|
|
1406
1390
|
),
|
|
1407
|
-
/* @__PURE__ */
|
|
1391
|
+
/* @__PURE__ */ jsx8(Primitive5.Icon, { children: /* @__PURE__ */ jsx8(
|
|
1408
1392
|
ChevronDown3,
|
|
1409
1393
|
{
|
|
1410
1394
|
size: 16,
|
|
@@ -1415,7 +1399,7 @@ var Select = (props) => {
|
|
|
1415
1399
|
]
|
|
1416
1400
|
}
|
|
1417
1401
|
),
|
|
1418
|
-
clearLabel && /* @__PURE__ */
|
|
1402
|
+
clearLabel && /* @__PURE__ */ jsx8(
|
|
1419
1403
|
"button",
|
|
1420
1404
|
{
|
|
1421
1405
|
type: "button",
|
|
@@ -1426,7 +1410,7 @@ var Select = (props) => {
|
|
|
1426
1410
|
controlRef.current?.focus();
|
|
1427
1411
|
},
|
|
1428
1412
|
className: cn5(controlVariants3({ size: controlSize }), "flex w-auto shrink-0 items-center justify-center min-w-11 cursor-pointer hover:enabled:bg-surface"),
|
|
1429
|
-
children: /* @__PURE__ */
|
|
1413
|
+
children: /* @__PURE__ */ jsx8(
|
|
1430
1414
|
X3,
|
|
1431
1415
|
{
|
|
1432
1416
|
size: 16,
|
|
@@ -1435,7 +1419,7 @@ var Select = (props) => {
|
|
|
1435
1419
|
)
|
|
1436
1420
|
}
|
|
1437
1421
|
),
|
|
1438
|
-
/* @__PURE__ */
|
|
1422
|
+
/* @__PURE__ */ jsx8(
|
|
1439
1423
|
SelectionForm,
|
|
1440
1424
|
{
|
|
1441
1425
|
name,
|
|
@@ -1455,12 +1439,12 @@ var Select = (props) => {
|
|
|
1455
1439
|
]
|
|
1456
1440
|
}
|
|
1457
1441
|
),
|
|
1458
|
-
/* @__PURE__ */
|
|
1459
|
-
|
|
1442
|
+
/* @__PURE__ */ jsx8(
|
|
1443
|
+
Primitive5.Portal,
|
|
1460
1444
|
{
|
|
1461
1445
|
container: portalContainer,
|
|
1462
1446
|
children: /* @__PURE__ */ jsxs7(
|
|
1463
|
-
|
|
1447
|
+
Primitive5.Content,
|
|
1464
1448
|
{
|
|
1465
1449
|
position,
|
|
1466
1450
|
align: "start",
|
|
@@ -1514,11 +1498,11 @@ var Select = (props) => {
|
|
|
1514
1498
|
{
|
|
1515
1499
|
className: "relative flex min-h-0 flex-col",
|
|
1516
1500
|
children: [
|
|
1517
|
-
/* @__PURE__ */
|
|
1518
|
-
|
|
1501
|
+
/* @__PURE__ */ jsx8(
|
|
1502
|
+
Primitive5.ScrollUpButton,
|
|
1519
1503
|
{
|
|
1520
1504
|
className: selectScrollArrowStyles({ direction: "up" }),
|
|
1521
|
-
children: /* @__PURE__ */
|
|
1505
|
+
children: /* @__PURE__ */ jsx8(
|
|
1522
1506
|
ChevronUp,
|
|
1523
1507
|
{
|
|
1524
1508
|
size: 16,
|
|
@@ -1527,7 +1511,7 @@ var Select = (props) => {
|
|
|
1527
1511
|
)
|
|
1528
1512
|
}
|
|
1529
1513
|
),
|
|
1530
|
-
/* @__PURE__ */
|
|
1514
|
+
/* @__PURE__ */ jsx8(
|
|
1531
1515
|
SelectOptions,
|
|
1532
1516
|
{
|
|
1533
1517
|
options,
|
|
@@ -1535,11 +1519,11 @@ var Select = (props) => {
|
|
|
1535
1519
|
label: restProps["aria-label"]
|
|
1536
1520
|
}
|
|
1537
1521
|
),
|
|
1538
|
-
/* @__PURE__ */
|
|
1539
|
-
|
|
1522
|
+
/* @__PURE__ */ jsx8(
|
|
1523
|
+
Primitive5.ScrollDownButton,
|
|
1540
1524
|
{
|
|
1541
1525
|
className: selectScrollArrowStyles({ direction: "down" }),
|
|
1542
|
-
children: /* @__PURE__ */
|
|
1526
|
+
children: /* @__PURE__ */ jsx8(
|
|
1543
1527
|
ChevronDown3,
|
|
1544
1528
|
{
|
|
1545
1529
|
size: 16,
|
|
@@ -1551,7 +1535,7 @@ var Select = (props) => {
|
|
|
1551
1535
|
]
|
|
1552
1536
|
}
|
|
1553
1537
|
),
|
|
1554
|
-
/* @__PURE__ */
|
|
1538
|
+
/* @__PURE__ */ jsx8(
|
|
1555
1539
|
SelectionActions,
|
|
1556
1540
|
{
|
|
1557
1541
|
actions,
|