@gridui/select 1.2.2 → 1.5.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 +53 -3
- package/dist/autocomplete-suggestions/autocomplete-suggestions.d.ts +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +341 -299
- package/dist/index.js.map +4 -4
- package/dist/select/select-options.d.ts +1 -1
- package/dist/select/select.d.ts +0 -6
- package/dist/shared/popup/selection-popup.d.ts +0 -6
- package/dist/shared/search/calculate-search-options.d.ts +3 -5
- package/dist/shared/search/use-search-options.d.ts +2 -1
- package/dist/shared/types.d.ts +8 -2
- package/dist/styles.css +1 -0
- package/docs/catalog.json +17 -1
- package/docs/reference/README.md +1 -0
- package/docs/reference/autocomplete-suggestions.md +77 -0
- package/docs/reference/combobox.md +8 -0
- package/docs/reference/multi-select.md +8 -0
- package/docs/reference/select.md +8 -0
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/shared/popup/selection-popup.tsx
|
|
2
|
+
import { useMotionStyle } from "@gridui/motion/policy";
|
|
3
|
+
|
|
1
4
|
// src/shared/style.ts
|
|
2
5
|
import { overlayListItemStyles, overlayListStyles } from "@gridui/overlay";
|
|
3
6
|
import { cn } from "@gridui/style-utils";
|
|
@@ -23,6 +26,7 @@ import { ExitSnapshot, interactionLayerProps } from "@gridui/overlay";
|
|
|
23
26
|
import * as Primitive from "@radix-ui/react-popover";
|
|
24
27
|
import { jsx } from "react/jsx-runtime";
|
|
25
28
|
var SelectionPopup = (props) => {
|
|
29
|
+
const motionStyle = useMotionStyle();
|
|
26
30
|
const { open, children, container, anchorRef, initialFocus, finalFocus, onEscape, onDismiss, ...restProps } = props;
|
|
27
31
|
return /* @__PURE__ */ jsx(
|
|
28
32
|
Primitive.Portal,
|
|
@@ -67,6 +71,7 @@ var SelectionPopup = (props) => {
|
|
|
67
71
|
event.stopPropagation();
|
|
68
72
|
}
|
|
69
73
|
},
|
|
74
|
+
style: motionStyle,
|
|
70
75
|
children: /* @__PURE__ */ jsx(
|
|
71
76
|
ExitSnapshot,
|
|
72
77
|
{
|
|
@@ -97,7 +102,7 @@ var useSelectionPopup = ({ disabled, readOnly, controlRef }) => {
|
|
|
97
102
|
}
|
|
98
103
|
}, [unavailable]);
|
|
99
104
|
const available = () => {
|
|
100
|
-
return !unavailable && !controlRef.current?.matches(":disabled");
|
|
105
|
+
return !unavailable && !controlRef.current?.matches(":disabled, [readonly]");
|
|
101
106
|
};
|
|
102
107
|
const changeOpen = (next) => {
|
|
103
108
|
if (next && !available()) {
|
|
@@ -178,23 +183,21 @@ var filterOptions = (options, query) => {
|
|
|
178
183
|
};
|
|
179
184
|
|
|
180
185
|
// src/shared/search/calculate-search-options.ts
|
|
186
|
+
import { calculateSearchList } from "@gridui/interaction";
|
|
187
|
+
import { getSearchResultLabel } from "@gridui/interaction";
|
|
181
188
|
var calculateSearchOptions = (input) => {
|
|
182
189
|
const { options, selected, listId, query, highlighted, filterOptions: shouldFilter = true, loading, errorLabel } = input;
|
|
183
190
|
const all = flattenOptions(options);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const highlightedOption = visible.find((option) => {
|
|
192
|
-
return option.value === highlighted;
|
|
191
|
+
const matches = shouldFilter ? filterOptions(options, query ?? "") : options;
|
|
192
|
+
const list = calculateSearchList(flattenOptions(matches), {
|
|
193
|
+
key: (option) => option.value,
|
|
194
|
+
highlighted,
|
|
195
|
+
preferred: query === null ? (option) => selected.includes(option.value) : void 0,
|
|
196
|
+
loading,
|
|
197
|
+
errorLabel
|
|
193
198
|
});
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
}) : void 0;
|
|
197
|
-
const activeOption = highlightedOption ?? selectedOption ?? visible[0];
|
|
199
|
+
const filtered = list.available ? matches : [];
|
|
200
|
+
const { visible, active: activeOption } = list;
|
|
198
201
|
const optionLookup = /* @__PURE__ */ new Map();
|
|
199
202
|
all.forEach((option, index) => {
|
|
200
203
|
optionLookup.set(option.value, {
|
|
@@ -216,28 +219,17 @@ var calculateSearchOptions = (input) => {
|
|
|
216
219
|
activeOption,
|
|
217
220
|
activeOptionId: activeOption ? optionId(activeOption.value) : void 0,
|
|
218
221
|
optionId,
|
|
219
|
-
getOption
|
|
222
|
+
getOption,
|
|
223
|
+
navigate: list.navigate
|
|
220
224
|
};
|
|
221
225
|
};
|
|
222
|
-
var getSearchStatus = (count, props) => {
|
|
223
|
-
if (props.loading) {
|
|
224
|
-
return props.loadingLabel;
|
|
225
|
-
}
|
|
226
|
-
if (props.errorLabel !== void 0) {
|
|
227
|
-
return props.errorLabel;
|
|
228
|
-
}
|
|
229
|
-
if (count === 0) {
|
|
230
|
-
return props.emptyLabel;
|
|
231
|
-
}
|
|
232
|
-
return props.resultCountLabel?.(count);
|
|
233
|
-
};
|
|
234
226
|
|
|
235
227
|
// src/shared/search/combobox-options.tsx
|
|
236
228
|
import { overlayListIndicatorStyles, overlayListItemStyles as overlayListItemStyles2, overlayListLabelStyles, useInteractionOutline, useScrollbars } from "@gridui/overlay";
|
|
237
229
|
import { Check } from "lucide-react";
|
|
238
230
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
239
231
|
var ComboboxOptions = (props) => {
|
|
240
|
-
const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight } = props;
|
|
232
|
+
const { id, label, options, selected, multiple, active, optionId, onSelect, onHighlight, selectionAppearance } = props;
|
|
241
233
|
const scrollbarRef = useScrollbars();
|
|
242
234
|
const ref = useInteractionOutline({
|
|
243
235
|
ref: scrollbarRef,
|
|
@@ -257,7 +249,7 @@ var ComboboxOptions = (props) => {
|
|
|
257
249
|
"aria-describedby": option.description ? `${itemId}-description` : void 0,
|
|
258
250
|
"data-disabled": option.disabled ? "" : void 0,
|
|
259
251
|
"data-highlighted": active === option.value ? "" : void 0,
|
|
260
|
-
className: overlayListItemStyles2(),
|
|
252
|
+
className: overlayListItemStyles2({ selectionAppearance }),
|
|
261
253
|
onPointerMove: () => {
|
|
262
254
|
onHighlight(option.value);
|
|
263
255
|
},
|
|
@@ -396,7 +388,7 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
396
388
|
loading,
|
|
397
389
|
errorLabel
|
|
398
390
|
});
|
|
399
|
-
const {
|
|
391
|
+
const { activeOptionId } = result;
|
|
400
392
|
useEffect2(() => {
|
|
401
393
|
if (!open && wasOpen.current) {
|
|
402
394
|
setSearch(INITIAL_SEARCH);
|
|
@@ -435,10 +427,7 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
435
427
|
});
|
|
436
428
|
},
|
|
437
429
|
moveActive: (direction) => {
|
|
438
|
-
const
|
|
439
|
-
return option.value === activeValue;
|
|
440
|
-
});
|
|
441
|
-
const next = visible[Math.max(0, Math.min(visible.length - 1, index + direction))];
|
|
430
|
+
const next = result.navigate(direction > 0 ? "next" : "previous");
|
|
442
431
|
if (next) {
|
|
443
432
|
highlight(next.value);
|
|
444
433
|
}
|
|
@@ -446,19 +435,16 @@ var useSearchOptions = (options, selected, listId, open, searchProps = {}) => {
|
|
|
446
435
|
};
|
|
447
436
|
};
|
|
448
437
|
|
|
449
|
-
// src/autocomplete/autocomplete.tsx
|
|
438
|
+
// src/autocomplete-suggestions/autocomplete-suggestions.tsx
|
|
450
439
|
import { useFormReset } from "@gridui/form";
|
|
451
|
-
import {
|
|
452
|
-
import { isComposingKeyEvent as isComposingKeyEvent2 } from "@gridui/interaction";
|
|
440
|
+
import { isComposingKeyEvent as isComposingKeyEvent2, searchResultsAvailable } from "@gridui/interaction";
|
|
453
441
|
import { cn as cn2 } from "@gridui/style-utils";
|
|
454
442
|
import * as Primitive2 from "@radix-ui/react-popover";
|
|
455
|
-
import { useEffect as useEffect3, useId,
|
|
443
|
+
import { useEffect as useEffect3, useId, useRef as useRef3, useState as useState3 } from "react";
|
|
456
444
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
457
|
-
var
|
|
445
|
+
var AutocompleteSuggestions = (props) => {
|
|
458
446
|
const {
|
|
459
447
|
value,
|
|
460
|
-
defaultValue = "",
|
|
461
|
-
onValueChange,
|
|
462
448
|
options,
|
|
463
449
|
searchLabel,
|
|
464
450
|
emptyLabel,
|
|
@@ -470,33 +456,17 @@ var Autocomplete = (props) => {
|
|
|
470
456
|
portalContainer,
|
|
471
457
|
rootClassName,
|
|
472
458
|
onOptionSelect,
|
|
473
|
-
|
|
474
|
-
|
|
459
|
+
disabled,
|
|
460
|
+
readOnly,
|
|
461
|
+
dir,
|
|
462
|
+
form,
|
|
475
463
|
onKeyDown,
|
|
476
|
-
|
|
477
|
-
onClick,
|
|
478
|
-
...restProps
|
|
464
|
+
children
|
|
479
465
|
} = props;
|
|
480
|
-
const [
|
|
481
|
-
local,
|
|
482
|
-
setLocal
|
|
483
|
-
] = useState3(defaultValue);
|
|
484
|
-
const [
|
|
485
|
-
navigating,
|
|
486
|
-
setNavigating
|
|
487
|
-
] = useState3(false);
|
|
488
|
-
const text = value ?? local;
|
|
489
466
|
const input = useRef3(null);
|
|
490
467
|
const anchor = useRef3(null);
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
return input.current;
|
|
494
|
-
});
|
|
495
|
-
const popup = useSelectionPopup({
|
|
496
|
-
disabled: restProps.disabled,
|
|
497
|
-
readOnly: restProps.readOnly,
|
|
498
|
-
controlRef: input
|
|
499
|
-
});
|
|
468
|
+
const [navigating, setNavigating] = useState3(false);
|
|
469
|
+
const popup = useSelectionPopup({ disabled, readOnly, controlRef: input });
|
|
500
470
|
useEffect3(() => {
|
|
501
471
|
if (!popup.open) {
|
|
502
472
|
setNavigating(false);
|
|
@@ -505,7 +475,7 @@ var Autocomplete = (props) => {
|
|
|
505
475
|
const generatedId = useId();
|
|
506
476
|
const listId = `${generatedId}-list`;
|
|
507
477
|
const search = useSearchOptions(options, [], listId, popup.open, {
|
|
508
|
-
query:
|
|
478
|
+
query: value,
|
|
509
479
|
filterOptions: filterOptions2,
|
|
510
480
|
loading,
|
|
511
481
|
errorLabel
|
|
@@ -514,8 +484,173 @@ var Autocomplete = (props) => {
|
|
|
514
484
|
popup.close();
|
|
515
485
|
setNavigating(false);
|
|
516
486
|
};
|
|
487
|
+
useFormReset(input, close, form);
|
|
488
|
+
const choose = (option) => {
|
|
489
|
+
if (!popup.available() || option.disabled || !searchResultsAvailable({ loading, errorLabel })) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
close();
|
|
493
|
+
popup.focus();
|
|
494
|
+
onOptionSelect(option);
|
|
495
|
+
};
|
|
496
|
+
const getInputProps = (inputProps) => ({
|
|
497
|
+
...inputProps,
|
|
498
|
+
id: inputProps.id ?? generatedId,
|
|
499
|
+
disabled: disabled ?? inputProps.disabled,
|
|
500
|
+
readOnly: readOnly ?? inputProps.readOnly,
|
|
501
|
+
form: form ?? inputProps.form,
|
|
502
|
+
dir: inputProps.dir ?? dir,
|
|
503
|
+
ref: (element) => {
|
|
504
|
+
input.current = element;
|
|
505
|
+
if (typeof inputProps.ref === "function") {
|
|
506
|
+
const cleanup = inputProps.ref(element);
|
|
507
|
+
if (typeof cleanup === "function") {
|
|
508
|
+
return () => {
|
|
509
|
+
input.current = null;
|
|
510
|
+
cleanup();
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
return void 0;
|
|
514
|
+
}
|
|
515
|
+
if (inputProps.ref) {
|
|
516
|
+
inputProps.ref.current = element;
|
|
517
|
+
}
|
|
518
|
+
return void 0;
|
|
519
|
+
},
|
|
520
|
+
role: "combobox",
|
|
521
|
+
"aria-label": inputProps["aria-label"] ?? (inputProps.id || inputProps["aria-labelledby"] ? void 0 : searchLabel),
|
|
522
|
+
"aria-autocomplete": "list",
|
|
523
|
+
"aria-expanded": popup.open,
|
|
524
|
+
"aria-busy": loading || void 0,
|
|
525
|
+
"aria-controls": popup.open ? listId : void 0,
|
|
526
|
+
"aria-activedescendant": popup.open && navigating ? search.activeOptionId : void 0,
|
|
527
|
+
onChange: (event) => {
|
|
528
|
+
inputProps.onChange?.(event);
|
|
529
|
+
search.changeQuery(event.currentTarget.value);
|
|
530
|
+
setNavigating(false);
|
|
531
|
+
popup.changeOpen(true);
|
|
532
|
+
},
|
|
533
|
+
onFocus: (event) => {
|
|
534
|
+
inputProps.onFocus?.(event);
|
|
535
|
+
if (!event.defaultPrevented) {
|
|
536
|
+
popup.changeOpen(true);
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
onClick: (event) => {
|
|
540
|
+
inputProps.onClick?.(event);
|
|
541
|
+
if (!event.defaultPrevented) {
|
|
542
|
+
popup.changeOpen(true);
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
onKeyDown: (event) => {
|
|
546
|
+
onKeyDown?.(event);
|
|
547
|
+
if (event.defaultPrevented || !popup.available()) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (isComposingKeyEvent2(event.nativeEvent)) {
|
|
551
|
+
if (event.key === "Enter" || event.key === "Escape") {
|
|
552
|
+
event.stopPropagation();
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
557
|
+
event.preventDefault();
|
|
558
|
+
popup.changeOpen(true);
|
|
559
|
+
if (navigating && popup.open) {
|
|
560
|
+
search.moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
561
|
+
}
|
|
562
|
+
setNavigating(true);
|
|
563
|
+
return;
|
|
564
|
+
} else if (event.key === "Enter" && popup.open && navigating && search.activeOption) {
|
|
565
|
+
event.preventDefault();
|
|
566
|
+
choose(search.activeOption);
|
|
567
|
+
return;
|
|
568
|
+
} else if (event.key === "Escape" && popup.open) {
|
|
569
|
+
event.preventDefault();
|
|
570
|
+
event.stopPropagation();
|
|
571
|
+
close();
|
|
572
|
+
return;
|
|
573
|
+
} else if (event.key === "Tab") {
|
|
574
|
+
close();
|
|
575
|
+
}
|
|
576
|
+
inputProps.onKeyDown?.(event);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
return /* @__PURE__ */ jsxs2(Primitive2.Root, { open: popup.open, onOpenChange: popup.changeOpen, children: [
|
|
580
|
+
/* @__PURE__ */ jsx3(Primitive2.Anchor, { asChild: true, children: /* @__PURE__ */ jsx3("div", { ref: anchor, dir, className: cn2("gridui-autocomplete gridui-u-select--min-w-0 gridui-u-select--w-full", rootClassName), children: children(getInputProps) }) }),
|
|
581
|
+
/* @__PURE__ */ jsxs2(
|
|
582
|
+
SelectionPopup,
|
|
583
|
+
{
|
|
584
|
+
open: popup.open,
|
|
585
|
+
ref: popup.popupRef,
|
|
586
|
+
container: portalContainer,
|
|
587
|
+
anchorRef: anchor,
|
|
588
|
+
dir,
|
|
589
|
+
role: "presentation",
|
|
590
|
+
finalFocus: popup.finalFocus,
|
|
591
|
+
onDismiss: close,
|
|
592
|
+
onEscape: () => {
|
|
593
|
+
close();
|
|
594
|
+
popup.focus();
|
|
595
|
+
},
|
|
596
|
+
children: [
|
|
597
|
+
/* @__PURE__ */ jsx3("div", { role: "status", "aria-atomic": "true", className: cn2(selectEmptyStyles(), "gridui-u-select--empty:hidden"), children: getSearchResultLabel(search.visible.length, { loading, loadingLabel, errorLabel, resultCountLabel, emptyLabel }) }),
|
|
598
|
+
/* @__PURE__ */ jsx3(
|
|
599
|
+
ComboboxOptions,
|
|
600
|
+
{
|
|
601
|
+
id: listId,
|
|
602
|
+
label: searchLabel,
|
|
603
|
+
options: search.filtered,
|
|
604
|
+
selected: [],
|
|
605
|
+
active: navigating ? search.active : null,
|
|
606
|
+
optionId: search.optionId,
|
|
607
|
+
onSelect: choose,
|
|
608
|
+
onHighlight: (next) => {
|
|
609
|
+
setNavigating(true);
|
|
610
|
+
search.highlight(next);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
)
|
|
614
|
+
]
|
|
615
|
+
}
|
|
616
|
+
)
|
|
617
|
+
] });
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// src/autocomplete/autocomplete.tsx
|
|
621
|
+
import { useFormReset as useFormReset2 } from "@gridui/form";
|
|
622
|
+
import { Input } from "@gridui/input";
|
|
623
|
+
import { useImperativeHandle, useRef as useRef4, useState as useState4 } from "react";
|
|
624
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
625
|
+
var Autocomplete = (props) => {
|
|
626
|
+
const {
|
|
627
|
+
value,
|
|
628
|
+
defaultValue = "",
|
|
629
|
+
onValueChange,
|
|
630
|
+
options,
|
|
631
|
+
searchLabel,
|
|
632
|
+
emptyLabel,
|
|
633
|
+
filterOptions: filterOptions2,
|
|
634
|
+
loading,
|
|
635
|
+
loadingLabel,
|
|
636
|
+
errorLabel,
|
|
637
|
+
resultCountLabel,
|
|
638
|
+
portalContainer,
|
|
639
|
+
rootClassName,
|
|
640
|
+
onOptionSelect,
|
|
641
|
+
ref,
|
|
642
|
+
onChange,
|
|
643
|
+
onKeyDown,
|
|
644
|
+
controlSize,
|
|
645
|
+
...restProps
|
|
646
|
+
} = props;
|
|
647
|
+
const [local, setLocal] = useState4(defaultValue);
|
|
648
|
+
const text = value ?? local;
|
|
649
|
+
const input = useRef4(null);
|
|
650
|
+
const initial = useRef4(defaultValue);
|
|
651
|
+
useImperativeHandle(ref, () => input.current);
|
|
517
652
|
const change = (next) => {
|
|
518
|
-
if (
|
|
653
|
+
if (restProps.disabled || restProps.readOnly || input.current?.matches(":disabled")) {
|
|
519
654
|
return;
|
|
520
655
|
}
|
|
521
656
|
if (value === void 0) {
|
|
@@ -523,173 +658,66 @@ var Autocomplete = (props) => {
|
|
|
523
658
|
}
|
|
524
659
|
onValueChange?.(next);
|
|
525
660
|
};
|
|
526
|
-
|
|
661
|
+
useFormReset2(input, () => {
|
|
527
662
|
if (value === void 0) {
|
|
528
663
|
setLocal(initial.current);
|
|
529
664
|
}
|
|
530
|
-
close();
|
|
531
665
|
}, restProps.form);
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
return;
|
|
535
|
-
}
|
|
536
|
-
change(option.label);
|
|
537
|
-
close();
|
|
538
|
-
popup.focus();
|
|
539
|
-
onOptionSelect?.(option);
|
|
540
|
-
};
|
|
541
|
-
return /* @__PURE__ */ jsxs2(
|
|
542
|
-
Primitive2.Root,
|
|
666
|
+
return /* @__PURE__ */ jsx4(
|
|
667
|
+
AutocompleteSuggestions,
|
|
543
668
|
{
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
onFocus?.(event);
|
|
582
|
-
if (!event.defaultPrevented) {
|
|
583
|
-
popup.changeOpen(true);
|
|
584
|
-
}
|
|
585
|
-
},
|
|
586
|
-
onClick: (event) => {
|
|
587
|
-
onClick?.(event);
|
|
588
|
-
if (!event.defaultPrevented) {
|
|
589
|
-
popup.changeOpen(true);
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
onKeyDown: (event) => {
|
|
593
|
-
onKeyDown?.(event);
|
|
594
|
-
if (event.defaultPrevented || !popup.available()) {
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
if (isComposingKeyEvent2(event.nativeEvent)) {
|
|
598
|
-
if (event.key === "Enter" || event.key === "Escape") {
|
|
599
|
-
event.stopPropagation();
|
|
600
|
-
}
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
603
|
-
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
604
|
-
event.preventDefault();
|
|
605
|
-
popup.changeOpen(true);
|
|
606
|
-
if (navigating && popup.open) {
|
|
607
|
-
search.moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
608
|
-
}
|
|
609
|
-
setNavigating(true);
|
|
610
|
-
} else if (event.key === "Enter" && popup.open && navigating && search.activeOption) {
|
|
611
|
-
event.preventDefault();
|
|
612
|
-
choose(search.activeOption);
|
|
613
|
-
} else if (event.key === "Escape" && popup.open) {
|
|
614
|
-
event.preventDefault();
|
|
615
|
-
event.stopPropagation();
|
|
616
|
-
close();
|
|
617
|
-
} else if (event.key === "Tab") {
|
|
618
|
-
close();
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
)
|
|
623
|
-
}
|
|
624
|
-
)
|
|
625
|
-
}
|
|
626
|
-
),
|
|
627
|
-
/* @__PURE__ */ jsxs2(
|
|
628
|
-
SelectionPopup,
|
|
629
|
-
{
|
|
630
|
-
open: popup.open,
|
|
631
|
-
ref: popup.popupRef,
|
|
632
|
-
container: portalContainer,
|
|
633
|
-
anchorRef: anchor,
|
|
634
|
-
dir: restProps.dir,
|
|
635
|
-
role: "presentation",
|
|
636
|
-
finalFocus: popup.finalFocus,
|
|
637
|
-
onDismiss: close,
|
|
638
|
-
onEscape: () => {
|
|
639
|
-
close();
|
|
640
|
-
popup.focus();
|
|
641
|
-
},
|
|
642
|
-
children: [
|
|
643
|
-
/* @__PURE__ */ jsx3(
|
|
644
|
-
"div",
|
|
645
|
-
{
|
|
646
|
-
role: "status",
|
|
647
|
-
"aria-atomic": "true",
|
|
648
|
-
className: cn2(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
649
|
-
children: getSearchStatus(search.visible.length, {
|
|
650
|
-
loading,
|
|
651
|
-
loadingLabel,
|
|
652
|
-
errorLabel,
|
|
653
|
-
resultCountLabel,
|
|
654
|
-
emptyLabel
|
|
655
|
-
})
|
|
656
|
-
}
|
|
657
|
-
),
|
|
658
|
-
/* @__PURE__ */ jsx3(
|
|
659
|
-
ComboboxOptions,
|
|
660
|
-
{
|
|
661
|
-
id: listId,
|
|
662
|
-
label: searchLabel,
|
|
663
|
-
options: search.filtered,
|
|
664
|
-
selected: [],
|
|
665
|
-
active: navigating ? search.active : null,
|
|
666
|
-
optionId: search.optionId,
|
|
667
|
-
onSelect: choose,
|
|
668
|
-
onHighlight: (next) => {
|
|
669
|
-
setNavigating(true);
|
|
670
|
-
search.highlight(next);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
)
|
|
674
|
-
]
|
|
675
|
-
}
|
|
676
|
-
)
|
|
677
|
-
]
|
|
669
|
+
value: text,
|
|
670
|
+
options,
|
|
671
|
+
searchLabel,
|
|
672
|
+
emptyLabel,
|
|
673
|
+
filterOptions: filterOptions2,
|
|
674
|
+
loading,
|
|
675
|
+
loadingLabel,
|
|
676
|
+
errorLabel,
|
|
677
|
+
resultCountLabel,
|
|
678
|
+
portalContainer,
|
|
679
|
+
rootClassName,
|
|
680
|
+
disabled: restProps.disabled,
|
|
681
|
+
readOnly: restProps.readOnly,
|
|
682
|
+
dir: restProps.dir,
|
|
683
|
+
form: restProps.form,
|
|
684
|
+
onKeyDown,
|
|
685
|
+
onOptionSelect: (option) => {
|
|
686
|
+
change(option.label);
|
|
687
|
+
onOptionSelect?.(option);
|
|
688
|
+
},
|
|
689
|
+
children: (getInputProps) => /* @__PURE__ */ jsx4(
|
|
690
|
+
Input,
|
|
691
|
+
{
|
|
692
|
+
...getInputProps({
|
|
693
|
+
...restProps,
|
|
694
|
+
ref: input,
|
|
695
|
+
type: "text",
|
|
696
|
+
autoComplete: restProps.autoComplete ?? "off",
|
|
697
|
+
value: text,
|
|
698
|
+
onChange: (event) => {
|
|
699
|
+
onChange?.(event);
|
|
700
|
+
change(event.currentTarget.value);
|
|
701
|
+
}
|
|
702
|
+
}),
|
|
703
|
+
...controlSize === void 0 ? {} : { controlSize }
|
|
704
|
+
}
|
|
705
|
+
)
|
|
678
706
|
}
|
|
679
707
|
);
|
|
680
708
|
};
|
|
681
709
|
|
|
682
710
|
// src/shared/popup/selection-actions.tsx
|
|
683
|
-
import { Fragment, jsx as
|
|
711
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
684
712
|
var SelectionActions = (props) => {
|
|
685
713
|
const { actions, onAction } = props;
|
|
686
|
-
return /* @__PURE__ */
|
|
714
|
+
return /* @__PURE__ */ jsx5(Fragment, { children: actions.length > 0 && /* @__PURE__ */ jsx5(
|
|
687
715
|
"div",
|
|
688
716
|
{
|
|
689
717
|
className: selectActionsStyles(),
|
|
690
718
|
children: actions.map((action) => {
|
|
691
719
|
const content = /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
692
|
-
action.icon && /* @__PURE__ */
|
|
720
|
+
action.icon && /* @__PURE__ */ jsx5(
|
|
693
721
|
"span",
|
|
694
722
|
{
|
|
695
723
|
className: selectIconStyles(),
|
|
@@ -701,7 +729,7 @@ var SelectionActions = (props) => {
|
|
|
701
729
|
] });
|
|
702
730
|
const actionClass = selectActionStyles();
|
|
703
731
|
if (action.href !== void 0) {
|
|
704
|
-
return /* @__PURE__ */
|
|
732
|
+
return /* @__PURE__ */ jsx5(
|
|
705
733
|
"a",
|
|
706
734
|
{
|
|
707
735
|
href: action.disabled ? void 0 : action.href,
|
|
@@ -725,7 +753,7 @@ var SelectionActions = (props) => {
|
|
|
725
753
|
action.id
|
|
726
754
|
);
|
|
727
755
|
}
|
|
728
|
-
return /* @__PURE__ */
|
|
756
|
+
return /* @__PURE__ */ jsx5(
|
|
729
757
|
"button",
|
|
730
758
|
{
|
|
731
759
|
type: "button",
|
|
@@ -745,10 +773,10 @@ var SelectionActions = (props) => {
|
|
|
745
773
|
};
|
|
746
774
|
|
|
747
775
|
// src/shared/selection-form.tsx
|
|
748
|
-
import { focusInvalidControl, useFormReset as
|
|
749
|
-
import { useLayoutEffect, useRef as
|
|
776
|
+
import { focusInvalidControl, useFormReset as useFormReset3 } from "@gridui/form";
|
|
777
|
+
import { useLayoutEffect, useRef as useRef5 } from "react";
|
|
750
778
|
import { flushSync as flushSync2 } from "react-dom";
|
|
751
|
-
import { jsx as
|
|
779
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
752
780
|
var SelectionForm = (props) => {
|
|
753
781
|
const {
|
|
754
782
|
name,
|
|
@@ -761,9 +789,9 @@ var SelectionForm = (props) => {
|
|
|
761
789
|
onReset,
|
|
762
790
|
onInvalid
|
|
763
791
|
} = props;
|
|
764
|
-
const nativeRef =
|
|
765
|
-
const resetSelection =
|
|
766
|
-
const currentValue =
|
|
792
|
+
const nativeRef = useRef5(null);
|
|
793
|
+
const resetSelection = useRef5(onReset);
|
|
794
|
+
const currentValue = useRef5(selectedValue);
|
|
767
795
|
useLayoutEffect(() => {
|
|
768
796
|
resetSelection.current = onReset;
|
|
769
797
|
currentValue.current = selectedValue;
|
|
@@ -771,7 +799,7 @@ var SelectionForm = (props) => {
|
|
|
771
799
|
onReset,
|
|
772
800
|
selectedValue
|
|
773
801
|
]);
|
|
774
|
-
|
|
802
|
+
useFormReset3(nativeRef, () => {
|
|
775
803
|
flushSync2(() => {
|
|
776
804
|
resetSelection.current();
|
|
777
805
|
});
|
|
@@ -800,7 +828,7 @@ var SelectionForm = (props) => {
|
|
|
800
828
|
children: [
|
|
801
829
|
!allOptions.some((option) => {
|
|
802
830
|
return option.value === "";
|
|
803
|
-
}) && /* @__PURE__ */
|
|
831
|
+
}) && /* @__PURE__ */ jsx6(
|
|
804
832
|
"option",
|
|
805
833
|
{
|
|
806
834
|
value: ""
|
|
@@ -808,7 +836,7 @@ var SelectionForm = (props) => {
|
|
|
808
836
|
),
|
|
809
837
|
selectedValue !== "" && !allOptions.some((option) => {
|
|
810
838
|
return option.value === selectedValue;
|
|
811
|
-
}) && /* @__PURE__ */
|
|
839
|
+
}) && /* @__PURE__ */ jsx6(
|
|
812
840
|
"option",
|
|
813
841
|
{
|
|
814
842
|
value: selectedValue,
|
|
@@ -816,7 +844,7 @@ var SelectionForm = (props) => {
|
|
|
816
844
|
}
|
|
817
845
|
),
|
|
818
846
|
allOptions.map((option) => {
|
|
819
|
-
return /* @__PURE__ */
|
|
847
|
+
return /* @__PURE__ */ jsx6(
|
|
820
848
|
"option",
|
|
821
849
|
{
|
|
822
850
|
value: option.value,
|
|
@@ -832,15 +860,15 @@ var SelectionForm = (props) => {
|
|
|
832
860
|
};
|
|
833
861
|
|
|
834
862
|
// src/shared/use-selection-value.ts
|
|
835
|
-
import { useRef as
|
|
863
|
+
import { useRef as useRef6, useState as useState5 } from "react";
|
|
836
864
|
var useSelectionValue = (props, available) => {
|
|
837
865
|
const { value, defaultValue = "", onValueChange } = props;
|
|
838
866
|
const [
|
|
839
867
|
localValue,
|
|
840
868
|
setLocalValue
|
|
841
|
-
] =
|
|
869
|
+
] = useState5(defaultValue);
|
|
842
870
|
const selectedValue = value ?? localValue;
|
|
843
|
-
const initialValue =
|
|
871
|
+
const initialValue = useRef6(selectedValue);
|
|
844
872
|
const update = (next) => {
|
|
845
873
|
if (next === selectedValue) {
|
|
846
874
|
return;
|
|
@@ -870,12 +898,12 @@ var comboboxTriggerStyles = cva2("gridui-u-select--absolute gridui-u-select--ins
|
|
|
870
898
|
|
|
871
899
|
// src/combobox/combobox.tsx
|
|
872
900
|
import { controlVariants } from "@gridui/input";
|
|
873
|
-
import { isComposingKeyEvent as isComposingKeyEvent3 } from "@gridui/interaction";
|
|
901
|
+
import { isComposingKeyEvent as isComposingKeyEvent3, searchResultsAvailable as searchResultsAvailable2 } from "@gridui/interaction";
|
|
874
902
|
import { cn as cn3 } from "@gridui/style-utils";
|
|
875
903
|
import * as Primitive3 from "@radix-ui/react-popover";
|
|
876
904
|
import { ChevronDown, X } from "lucide-react";
|
|
877
|
-
import { useId as useId2, useRef as
|
|
878
|
-
import { jsx as
|
|
905
|
+
import { useId as useId2, useRef as useRef7 } from "react";
|
|
906
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
879
907
|
var Combobox = (props) => {
|
|
880
908
|
const {
|
|
881
909
|
options,
|
|
@@ -906,10 +934,11 @@ var Combobox = (props) => {
|
|
|
906
934
|
loadingLabel,
|
|
907
935
|
errorLabel,
|
|
908
936
|
resultCountLabel,
|
|
937
|
+
selectionAppearance = "filled",
|
|
909
938
|
...restProps
|
|
910
939
|
} = props;
|
|
911
|
-
const controlRef =
|
|
912
|
-
const anchorRef =
|
|
940
|
+
const controlRef = useRef7(null);
|
|
941
|
+
const anchorRef = useRef7(null);
|
|
913
942
|
const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
|
|
914
943
|
disabled,
|
|
915
944
|
readOnly,
|
|
@@ -938,7 +967,7 @@ var Combobox = (props) => {
|
|
|
938
967
|
changeOpen(true);
|
|
939
968
|
};
|
|
940
969
|
const choose = (option) => {
|
|
941
|
-
if (option.disabled || loading
|
|
970
|
+
if (option.disabled || !searchResultsAvailable2({ loading, errorLabel }) || !available()) {
|
|
942
971
|
return;
|
|
943
972
|
}
|
|
944
973
|
change(option.value);
|
|
@@ -957,7 +986,7 @@ var Combobox = (props) => {
|
|
|
957
986
|
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",
|
|
958
987
|
dir,
|
|
959
988
|
children: [
|
|
960
|
-
/* @__PURE__ */
|
|
989
|
+
/* @__PURE__ */ jsx7(
|
|
961
990
|
Primitive3.Anchor,
|
|
962
991
|
{
|
|
963
992
|
asChild: true,
|
|
@@ -967,7 +996,7 @@ var Combobox = (props) => {
|
|
|
967
996
|
ref: anchorRef,
|
|
968
997
|
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",
|
|
969
998
|
children: [
|
|
970
|
-
/* @__PURE__ */
|
|
999
|
+
/* @__PURE__ */ jsx7(
|
|
971
1000
|
"input",
|
|
972
1001
|
{
|
|
973
1002
|
...restProps,
|
|
@@ -1053,7 +1082,7 @@ var Combobox = (props) => {
|
|
|
1053
1082
|
}
|
|
1054
1083
|
}
|
|
1055
1084
|
),
|
|
1056
|
-
/* @__PURE__ */
|
|
1085
|
+
/* @__PURE__ */ jsx7(
|
|
1057
1086
|
"button",
|
|
1058
1087
|
{
|
|
1059
1088
|
type: "button",
|
|
@@ -1068,7 +1097,7 @@ var Combobox = (props) => {
|
|
|
1068
1097
|
}
|
|
1069
1098
|
focus();
|
|
1070
1099
|
},
|
|
1071
|
-
children: /* @__PURE__ */
|
|
1100
|
+
children: /* @__PURE__ */ jsx7(
|
|
1072
1101
|
ChevronDown,
|
|
1073
1102
|
{
|
|
1074
1103
|
size: 16,
|
|
@@ -1082,7 +1111,7 @@ var Combobox = (props) => {
|
|
|
1082
1111
|
)
|
|
1083
1112
|
}
|
|
1084
1113
|
),
|
|
1085
|
-
clearLabel && /* @__PURE__ */
|
|
1114
|
+
clearLabel && /* @__PURE__ */ jsx7(
|
|
1086
1115
|
"button",
|
|
1087
1116
|
{
|
|
1088
1117
|
type: "button",
|
|
@@ -1094,7 +1123,7 @@ var Combobox = (props) => {
|
|
|
1094
1123
|
focus();
|
|
1095
1124
|
},
|
|
1096
1125
|
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"),
|
|
1097
|
-
children: /* @__PURE__ */
|
|
1126
|
+
children: /* @__PURE__ */ jsx7(
|
|
1098
1127
|
X,
|
|
1099
1128
|
{
|
|
1100
1129
|
size: 16,
|
|
@@ -1103,7 +1132,7 @@ var Combobox = (props) => {
|
|
|
1103
1132
|
)
|
|
1104
1133
|
}
|
|
1105
1134
|
),
|
|
1106
|
-
/* @__PURE__ */
|
|
1135
|
+
/* @__PURE__ */ jsx7(
|
|
1107
1136
|
SelectionForm,
|
|
1108
1137
|
{
|
|
1109
1138
|
name,
|
|
@@ -1139,13 +1168,13 @@ var Combobox = (props) => {
|
|
|
1139
1168
|
focus();
|
|
1140
1169
|
},
|
|
1141
1170
|
children: [
|
|
1142
|
-
/* @__PURE__ */
|
|
1171
|
+
/* @__PURE__ */ jsx7(
|
|
1143
1172
|
"div",
|
|
1144
1173
|
{
|
|
1145
1174
|
role: "status",
|
|
1146
1175
|
"aria-atomic": "true",
|
|
1147
1176
|
className: cn3(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
1148
|
-
children:
|
|
1177
|
+
children: getSearchResultLabel(visible.length, {
|
|
1149
1178
|
loading,
|
|
1150
1179
|
loadingLabel,
|
|
1151
1180
|
errorLabel,
|
|
@@ -1154,9 +1183,10 @@ var Combobox = (props) => {
|
|
|
1154
1183
|
})
|
|
1155
1184
|
}
|
|
1156
1185
|
),
|
|
1157
|
-
/* @__PURE__ */
|
|
1186
|
+
/* @__PURE__ */ jsx7(
|
|
1158
1187
|
ComboboxOptions,
|
|
1159
1188
|
{
|
|
1189
|
+
selectionAppearance,
|
|
1160
1190
|
id: listId,
|
|
1161
1191
|
label: searchLabel,
|
|
1162
1192
|
options: filtered,
|
|
@@ -1167,7 +1197,7 @@ var Combobox = (props) => {
|
|
|
1167
1197
|
onHighlight: search.highlight
|
|
1168
1198
|
}
|
|
1169
1199
|
),
|
|
1170
|
-
/* @__PURE__ */
|
|
1200
|
+
/* @__PURE__ */ jsx7(
|
|
1171
1201
|
SelectionActions,
|
|
1172
1202
|
{
|
|
1173
1203
|
actions,
|
|
@@ -1185,12 +1215,12 @@ var Combobox = (props) => {
|
|
|
1185
1215
|
// src/multi-select/multi-select.tsx
|
|
1186
1216
|
import { ListFieldControl, useListField } from "@gridui/form";
|
|
1187
1217
|
import { controlVariants as controlVariants2 } from "@gridui/input";
|
|
1188
|
-
import { isComposingKeyEvent as isComposingKeyEvent4 } from "@gridui/interaction";
|
|
1218
|
+
import { isComposingKeyEvent as isComposingKeyEvent4, searchResultsAvailable as searchResultsAvailable3 } from "@gridui/interaction";
|
|
1189
1219
|
import { cn as cn4 } from "@gridui/style-utils";
|
|
1190
1220
|
import * as Primitive4 from "@radix-ui/react-popover";
|
|
1191
1221
|
import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
|
|
1192
|
-
import { useId as useId3, useRef as
|
|
1193
|
-
import { jsx as
|
|
1222
|
+
import { useId as useId3, useRef as useRef8 } from "react";
|
|
1223
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1194
1224
|
var MultiSelect = (props) => {
|
|
1195
1225
|
const {
|
|
1196
1226
|
value,
|
|
@@ -1217,9 +1247,10 @@ var MultiSelect = (props) => {
|
|
|
1217
1247
|
loadingLabel,
|
|
1218
1248
|
errorLabel,
|
|
1219
1249
|
resultCountLabel,
|
|
1250
|
+
selectionAppearance = "filled",
|
|
1220
1251
|
...restProps
|
|
1221
1252
|
} = props;
|
|
1222
|
-
const search =
|
|
1253
|
+
const search = useRef8(null);
|
|
1223
1254
|
const id = useId3();
|
|
1224
1255
|
const { selected, native, control, change } = useListField({
|
|
1225
1256
|
value,
|
|
@@ -1245,7 +1276,7 @@ var MultiSelect = (props) => {
|
|
|
1245
1276
|
});
|
|
1246
1277
|
const { all, filtered, visible, query, active, optionId, activeOptionId, getOption } = searchOptions;
|
|
1247
1278
|
const choose = (option) => {
|
|
1248
|
-
if (option.disabled || loading
|
|
1279
|
+
if (option.disabled || !searchResultsAvailable3({ loading, errorLabel }) || !available()) {
|
|
1249
1280
|
return;
|
|
1250
1281
|
}
|
|
1251
1282
|
change(selected.includes(option.value) ? selected.filter((entry) => {
|
|
@@ -1268,7 +1299,7 @@ var MultiSelect = (props) => {
|
|
|
1268
1299
|
className: "gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
|
|
1269
1300
|
dir: restProps.dir,
|
|
1270
1301
|
children: [
|
|
1271
|
-
/* @__PURE__ */
|
|
1302
|
+
/* @__PURE__ */ jsx8(
|
|
1272
1303
|
Primitive4.Trigger,
|
|
1273
1304
|
{
|
|
1274
1305
|
asChild: true,
|
|
@@ -1299,7 +1330,7 @@ var MultiSelect = (props) => {
|
|
|
1299
1330
|
}
|
|
1300
1331
|
},
|
|
1301
1332
|
children: [
|
|
1302
|
-
/* @__PURE__ */
|
|
1333
|
+
/* @__PURE__ */ jsx8(
|
|
1303
1334
|
"span",
|
|
1304
1335
|
{
|
|
1305
1336
|
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--wrap-anywhere",
|
|
@@ -1308,7 +1339,7 @@ var MultiSelect = (props) => {
|
|
|
1308
1339
|
}).join(", ") : placeholder
|
|
1309
1340
|
}
|
|
1310
1341
|
),
|
|
1311
|
-
/* @__PURE__ */
|
|
1342
|
+
/* @__PURE__ */ jsx8(
|
|
1312
1343
|
ChevronDown2,
|
|
1313
1344
|
{
|
|
1314
1345
|
size: 16,
|
|
@@ -1320,7 +1351,7 @@ var MultiSelect = (props) => {
|
|
|
1320
1351
|
)
|
|
1321
1352
|
}
|
|
1322
1353
|
),
|
|
1323
|
-
clearLabel && /* @__PURE__ */
|
|
1354
|
+
clearLabel && /* @__PURE__ */ jsx8(
|
|
1324
1355
|
"button",
|
|
1325
1356
|
{
|
|
1326
1357
|
type: "button",
|
|
@@ -1331,7 +1362,7 @@ var MultiSelect = (props) => {
|
|
|
1331
1362
|
change([]);
|
|
1332
1363
|
control.current?.focus();
|
|
1333
1364
|
},
|
|
1334
|
-
children: /* @__PURE__ */
|
|
1365
|
+
children: /* @__PURE__ */ jsx8(
|
|
1335
1366
|
X2,
|
|
1336
1367
|
{
|
|
1337
1368
|
size: 16,
|
|
@@ -1355,7 +1386,7 @@ var MultiSelect = (props) => {
|
|
|
1355
1386
|
},
|
|
1356
1387
|
children: [
|
|
1357
1388
|
all.map((option) => {
|
|
1358
|
-
return /* @__PURE__ */
|
|
1389
|
+
return /* @__PURE__ */ jsx8(
|
|
1359
1390
|
"option",
|
|
1360
1391
|
{
|
|
1361
1392
|
value: option.value,
|
|
@@ -1368,7 +1399,7 @@ var MultiSelect = (props) => {
|
|
|
1368
1399
|
selected.filter((entry) => {
|
|
1369
1400
|
return getOption(entry) === void 0;
|
|
1370
1401
|
}).map((entry) => {
|
|
1371
|
-
return /* @__PURE__ */
|
|
1402
|
+
return /* @__PURE__ */ jsx8(
|
|
1372
1403
|
"option",
|
|
1373
1404
|
{
|
|
1374
1405
|
value: entry,
|
|
@@ -1400,7 +1431,7 @@ var MultiSelect = (props) => {
|
|
|
1400
1431
|
focus();
|
|
1401
1432
|
},
|
|
1402
1433
|
children: [
|
|
1403
|
-
/* @__PURE__ */
|
|
1434
|
+
/* @__PURE__ */ jsx8(
|
|
1404
1435
|
"input",
|
|
1405
1436
|
{
|
|
1406
1437
|
ref: search,
|
|
@@ -1436,9 +1467,10 @@ var MultiSelect = (props) => {
|
|
|
1436
1467
|
}
|
|
1437
1468
|
}
|
|
1438
1469
|
),
|
|
1439
|
-
/* @__PURE__ */
|
|
1470
|
+
/* @__PURE__ */ jsx8(
|
|
1440
1471
|
ComboboxOptions,
|
|
1441
1472
|
{
|
|
1473
|
+
selectionAppearance,
|
|
1442
1474
|
id: `${id}-list`,
|
|
1443
1475
|
label: searchLabel,
|
|
1444
1476
|
options: filtered,
|
|
@@ -1450,13 +1482,13 @@ var MultiSelect = (props) => {
|
|
|
1450
1482
|
onHighlight: searchOptions.highlight
|
|
1451
1483
|
}
|
|
1452
1484
|
),
|
|
1453
|
-
/* @__PURE__ */
|
|
1485
|
+
/* @__PURE__ */ jsx8(
|
|
1454
1486
|
"div",
|
|
1455
1487
|
{
|
|
1456
1488
|
role: "status",
|
|
1457
1489
|
"aria-atomic": "true",
|
|
1458
1490
|
className: cn4(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
1459
|
-
children:
|
|
1491
|
+
children: getSearchResultLabel(visible.length, {
|
|
1460
1492
|
loading,
|
|
1461
1493
|
loadingLabel,
|
|
1462
1494
|
errorLabel,
|
|
@@ -1473,20 +1505,23 @@ var MultiSelect = (props) => {
|
|
|
1473
1505
|
);
|
|
1474
1506
|
};
|
|
1475
1507
|
|
|
1508
|
+
// src/select/select.tsx
|
|
1509
|
+
import { useMotionStyle as useMotionStyle2 } from "@gridui/motion/policy";
|
|
1510
|
+
|
|
1476
1511
|
// src/select/select-options.tsx
|
|
1477
1512
|
import { overlayListIndicatorStyles as overlayListIndicatorStyles2, overlayListItemStyles as overlayListItemStyles3, overlayListLabelStyles as overlayListLabelStyles2, useInteractionOutline as useInteractionOutline2, useScrollbars as useScrollbars2 } from "@gridui/overlay";
|
|
1478
1513
|
import * as Primitive5 from "@radix-ui/react-select";
|
|
1479
1514
|
import { Check as Check2 } from "lucide-react";
|
|
1480
1515
|
import { useId as useId4 } from "react";
|
|
1481
|
-
import { jsx as
|
|
1516
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1482
1517
|
var SelectOptions = (props) => {
|
|
1483
|
-
const { options, id, label } = props;
|
|
1518
|
+
const { options, id, label, selectionAppearance } = props;
|
|
1484
1519
|
const scrollbarRef = useScrollbars2();
|
|
1485
1520
|
const ref = useInteractionOutline2({
|
|
1486
1521
|
ref: scrollbarRef,
|
|
1487
1522
|
selector: '[role="option"]'
|
|
1488
1523
|
});
|
|
1489
|
-
return /* @__PURE__ */
|
|
1524
|
+
return /* @__PURE__ */ jsx9(
|
|
1490
1525
|
Primitive5.Viewport,
|
|
1491
1526
|
{
|
|
1492
1527
|
ref,
|
|
@@ -1496,10 +1531,11 @@ var SelectOptions = (props) => {
|
|
|
1496
1531
|
"aria-label": label,
|
|
1497
1532
|
children: options.map((entry) => {
|
|
1498
1533
|
if (!("options" in entry)) {
|
|
1499
|
-
return /* @__PURE__ */
|
|
1534
|
+
return /* @__PURE__ */ jsx9(
|
|
1500
1535
|
SelectOptionItem,
|
|
1501
1536
|
{
|
|
1502
|
-
option: entry
|
|
1537
|
+
option: entry,
|
|
1538
|
+
selectionAppearance
|
|
1503
1539
|
},
|
|
1504
1540
|
entry.value
|
|
1505
1541
|
);
|
|
@@ -1508,7 +1544,7 @@ var SelectOptions = (props) => {
|
|
|
1508
1544
|
Primitive5.Group,
|
|
1509
1545
|
{
|
|
1510
1546
|
children: [
|
|
1511
|
-
/* @__PURE__ */
|
|
1547
|
+
/* @__PURE__ */ jsx9(
|
|
1512
1548
|
Primitive5.Label,
|
|
1513
1549
|
{
|
|
1514
1550
|
className: overlayListLabelStyles2(),
|
|
@@ -1516,10 +1552,11 @@ var SelectOptions = (props) => {
|
|
|
1516
1552
|
}
|
|
1517
1553
|
),
|
|
1518
1554
|
entry.options.map((option) => {
|
|
1519
|
-
return /* @__PURE__ */
|
|
1555
|
+
return /* @__PURE__ */ jsx9(
|
|
1520
1556
|
SelectOptionItem,
|
|
1521
1557
|
{
|
|
1522
|
-
option
|
|
1558
|
+
option,
|
|
1559
|
+
selectionAppearance
|
|
1523
1560
|
},
|
|
1524
1561
|
option.value
|
|
1525
1562
|
);
|
|
@@ -1533,7 +1570,7 @@ var SelectOptions = (props) => {
|
|
|
1533
1570
|
);
|
|
1534
1571
|
};
|
|
1535
1572
|
var SelectOptionItem = (props) => {
|
|
1536
|
-
const { option } = props;
|
|
1573
|
+
const { option, selectionAppearance } = props;
|
|
1537
1574
|
const labelId = useId4();
|
|
1538
1575
|
const descriptionId = `${labelId}-description`;
|
|
1539
1576
|
return /* @__PURE__ */ jsxs7(
|
|
@@ -1544,9 +1581,9 @@ var SelectOptionItem = (props) => {
|
|
|
1544
1581
|
"aria-describedby": option.description ? descriptionId : void 0,
|
|
1545
1582
|
textValue: option.label,
|
|
1546
1583
|
disabled: option.disabled,
|
|
1547
|
-
className: overlayListItemStyles3(),
|
|
1584
|
+
className: overlayListItemStyles3({ selectionAppearance }),
|
|
1548
1585
|
children: [
|
|
1549
|
-
option.icon && /* @__PURE__ */
|
|
1586
|
+
option.icon && /* @__PURE__ */ jsx9(
|
|
1550
1587
|
"span",
|
|
1551
1588
|
{
|
|
1552
1589
|
className: selectIconStyles(),
|
|
@@ -1559,14 +1596,14 @@ var SelectOptionItem = (props) => {
|
|
|
1559
1596
|
{
|
|
1560
1597
|
className: selectOptionContentStyles(),
|
|
1561
1598
|
children: [
|
|
1562
|
-
/* @__PURE__ */
|
|
1599
|
+
/* @__PURE__ */ jsx9(
|
|
1563
1600
|
Primitive5.ItemText,
|
|
1564
1601
|
{
|
|
1565
1602
|
id: labelId,
|
|
1566
1603
|
children: option.label
|
|
1567
1604
|
}
|
|
1568
1605
|
),
|
|
1569
|
-
option.description && /* @__PURE__ */
|
|
1606
|
+
option.description && /* @__PURE__ */ jsx9(
|
|
1570
1607
|
"span",
|
|
1571
1608
|
{
|
|
1572
1609
|
id: descriptionId,
|
|
@@ -1577,12 +1614,12 @@ var SelectOptionItem = (props) => {
|
|
|
1577
1614
|
]
|
|
1578
1615
|
}
|
|
1579
1616
|
),
|
|
1580
|
-
/* @__PURE__ */
|
|
1617
|
+
/* @__PURE__ */ jsx9(
|
|
1581
1618
|
"span",
|
|
1582
1619
|
{
|
|
1583
1620
|
className: overlayListIndicatorStyles2(),
|
|
1584
1621
|
"aria-hidden": "true",
|
|
1585
|
-
children: /* @__PURE__ */
|
|
1622
|
+
children: /* @__PURE__ */ jsx9(Primitive5.ItemIndicator, { children: /* @__PURE__ */ jsx9(
|
|
1586
1623
|
Check2,
|
|
1587
1624
|
{
|
|
1588
1625
|
size: 16
|
|
@@ -1618,9 +1655,10 @@ import { interactionLayerProps as interactionLayerProps2 } from "@gridui/overlay
|
|
|
1618
1655
|
import { cn as cn6 } from "@gridui/style-utils";
|
|
1619
1656
|
import * as Primitive6 from "@radix-ui/react-select";
|
|
1620
1657
|
import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
|
|
1621
|
-
import { useId as useId5, useRef as
|
|
1622
|
-
import { jsx as
|
|
1658
|
+
import { useId as useId5, useRef as useRef9, useState as useState6 } from "react";
|
|
1659
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1623
1660
|
var Select = (props) => {
|
|
1661
|
+
const motionStyle = useMotionStyle2();
|
|
1624
1662
|
const {
|
|
1625
1663
|
options,
|
|
1626
1664
|
actions = [],
|
|
@@ -1637,11 +1675,12 @@ var Select = (props) => {
|
|
|
1637
1675
|
form,
|
|
1638
1676
|
dir,
|
|
1639
1677
|
portalContainer,
|
|
1678
|
+
selectionAppearance = "filled",
|
|
1640
1679
|
className,
|
|
1641
1680
|
ref,
|
|
1642
1681
|
...restProps
|
|
1643
1682
|
} = props;
|
|
1644
|
-
const controlRef =
|
|
1683
|
+
const controlRef = useRef9(null);
|
|
1645
1684
|
const {
|
|
1646
1685
|
open,
|
|
1647
1686
|
popupRef,
|
|
@@ -1664,7 +1703,7 @@ var Select = (props) => {
|
|
|
1664
1703
|
const [
|
|
1665
1704
|
triggerWidth,
|
|
1666
1705
|
setTriggerWidth
|
|
1667
|
-
] =
|
|
1706
|
+
] = useState6();
|
|
1668
1707
|
const allOptions = flattenOptions(options);
|
|
1669
1708
|
const selected = allOptions.find((option) => {
|
|
1670
1709
|
return option.value === selectedValue;
|
|
@@ -1713,7 +1752,7 @@ var Select = (props) => {
|
|
|
1713
1752
|
},
|
|
1714
1753
|
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),
|
|
1715
1754
|
children: [
|
|
1716
|
-
selected?.icon && /* @__PURE__ */
|
|
1755
|
+
selected?.icon && /* @__PURE__ */ jsx10(
|
|
1717
1756
|
"span",
|
|
1718
1757
|
{
|
|
1719
1758
|
className: selectIconStyles(),
|
|
@@ -1721,11 +1760,11 @@ var Select = (props) => {
|
|
|
1721
1760
|
children: selected.icon
|
|
1722
1761
|
}
|
|
1723
1762
|
),
|
|
1724
|
-
/* @__PURE__ */
|
|
1763
|
+
/* @__PURE__ */ jsx10(
|
|
1725
1764
|
"span",
|
|
1726
1765
|
{
|
|
1727
1766
|
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere",
|
|
1728
|
-
children: /* @__PURE__ */
|
|
1767
|
+
children: /* @__PURE__ */ jsx10(
|
|
1729
1768
|
Primitive6.Value,
|
|
1730
1769
|
{
|
|
1731
1770
|
placeholder: display,
|
|
@@ -1734,7 +1773,7 @@ var Select = (props) => {
|
|
|
1734
1773
|
)
|
|
1735
1774
|
}
|
|
1736
1775
|
),
|
|
1737
|
-
/* @__PURE__ */
|
|
1776
|
+
/* @__PURE__ */ jsx10(Primitive6.Icon, { children: /* @__PURE__ */ jsx10(
|
|
1738
1777
|
ChevronDown3,
|
|
1739
1778
|
{
|
|
1740
1779
|
size: 16,
|
|
@@ -1745,7 +1784,7 @@ var Select = (props) => {
|
|
|
1745
1784
|
]
|
|
1746
1785
|
}
|
|
1747
1786
|
),
|
|
1748
|
-
clearLabel && /* @__PURE__ */
|
|
1787
|
+
clearLabel && /* @__PURE__ */ jsx10(
|
|
1749
1788
|
"button",
|
|
1750
1789
|
{
|
|
1751
1790
|
type: "button",
|
|
@@ -1756,7 +1795,7 @@ var Select = (props) => {
|
|
|
1756
1795
|
controlRef.current?.focus();
|
|
1757
1796
|
},
|
|
1758
1797
|
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"),
|
|
1759
|
-
children: /* @__PURE__ */
|
|
1798
|
+
children: /* @__PURE__ */ jsx10(
|
|
1760
1799
|
X3,
|
|
1761
1800
|
{
|
|
1762
1801
|
size: 16,
|
|
@@ -1765,7 +1804,7 @@ var Select = (props) => {
|
|
|
1765
1804
|
)
|
|
1766
1805
|
}
|
|
1767
1806
|
),
|
|
1768
|
-
/* @__PURE__ */
|
|
1807
|
+
/* @__PURE__ */ jsx10(
|
|
1769
1808
|
SelectionForm,
|
|
1770
1809
|
{
|
|
1771
1810
|
name,
|
|
@@ -1785,7 +1824,7 @@ var Select = (props) => {
|
|
|
1785
1824
|
]
|
|
1786
1825
|
}
|
|
1787
1826
|
),
|
|
1788
|
-
/* @__PURE__ */
|
|
1827
|
+
/* @__PURE__ */ jsx10(
|
|
1789
1828
|
Primitive6.Portal,
|
|
1790
1829
|
{
|
|
1791
1830
|
container: portalContainer,
|
|
@@ -1839,17 +1878,18 @@ var Select = (props) => {
|
|
|
1839
1878
|
event.stopPropagation();
|
|
1840
1879
|
}
|
|
1841
1880
|
},
|
|
1881
|
+
style: motionStyle,
|
|
1842
1882
|
children: [
|
|
1843
1883
|
/* @__PURE__ */ jsxs8(
|
|
1844
1884
|
"div",
|
|
1845
1885
|
{
|
|
1846
1886
|
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-h-0 gridui-u-select--flex-col",
|
|
1847
1887
|
children: [
|
|
1848
|
-
/* @__PURE__ */
|
|
1888
|
+
/* @__PURE__ */ jsx10(
|
|
1849
1889
|
Primitive6.ScrollUpButton,
|
|
1850
1890
|
{
|
|
1851
1891
|
className: selectScrollArrowStyles({ direction: "up" }),
|
|
1852
|
-
children: /* @__PURE__ */
|
|
1892
|
+
children: /* @__PURE__ */ jsx10(
|
|
1853
1893
|
ChevronUp,
|
|
1854
1894
|
{
|
|
1855
1895
|
size: 16,
|
|
@@ -1858,19 +1898,20 @@ var Select = (props) => {
|
|
|
1858
1898
|
)
|
|
1859
1899
|
}
|
|
1860
1900
|
),
|
|
1861
|
-
/* @__PURE__ */
|
|
1901
|
+
/* @__PURE__ */ jsx10(
|
|
1862
1902
|
SelectOptions,
|
|
1863
1903
|
{
|
|
1904
|
+
selectionAppearance,
|
|
1864
1905
|
options,
|
|
1865
1906
|
id: listId,
|
|
1866
1907
|
label: restProps["aria-label"]
|
|
1867
1908
|
}
|
|
1868
1909
|
),
|
|
1869
|
-
/* @__PURE__ */
|
|
1910
|
+
/* @__PURE__ */ jsx10(
|
|
1870
1911
|
Primitive6.ScrollDownButton,
|
|
1871
1912
|
{
|
|
1872
1913
|
className: selectScrollArrowStyles({ direction: "down" }),
|
|
1873
|
-
children: /* @__PURE__ */
|
|
1914
|
+
children: /* @__PURE__ */ jsx10(
|
|
1874
1915
|
ChevronDown3,
|
|
1875
1916
|
{
|
|
1876
1917
|
size: 16,
|
|
@@ -1882,7 +1923,7 @@ var Select = (props) => {
|
|
|
1882
1923
|
]
|
|
1883
1924
|
}
|
|
1884
1925
|
),
|
|
1885
|
-
/* @__PURE__ */
|
|
1926
|
+
/* @__PURE__ */ jsx10(
|
|
1886
1927
|
SelectionActions,
|
|
1887
1928
|
{
|
|
1888
1929
|
actions,
|
|
@@ -1944,7 +1985,7 @@ var createOptionsRequest = (loadOptions, onState) => {
|
|
|
1944
1985
|
};
|
|
1945
1986
|
|
|
1946
1987
|
// src/use-async-options/use-async-options.ts
|
|
1947
|
-
import { useEffect as useEffect4, useState as
|
|
1988
|
+
import { useEffect as useEffect4, useState as useState7 } from "react";
|
|
1948
1989
|
var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true }) => {
|
|
1949
1990
|
if (!Number.isFinite(debounceMs) || debounceMs < 0) {
|
|
1950
1991
|
throw new RangeError("Option search debounce must be finite and nonnegative.");
|
|
@@ -1952,7 +1993,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1952
1993
|
const [
|
|
1953
1994
|
state,
|
|
1954
1995
|
setState
|
|
1955
|
-
] =
|
|
1996
|
+
] = useState7({
|
|
1956
1997
|
loader: loadOptions,
|
|
1957
1998
|
result: {
|
|
1958
1999
|
query,
|
|
@@ -2000,6 +2041,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
2000
2041
|
};
|
|
2001
2042
|
export {
|
|
2002
2043
|
Autocomplete,
|
|
2044
|
+
AutocompleteSuggestions,
|
|
2003
2045
|
Combobox,
|
|
2004
2046
|
MultiSelect,
|
|
2005
2047
|
Select,
|