@gridui/select 1.3.0 → 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 +42 -1
- package/dist/autocomplete-suggestions/autocomplete-suggestions.d.ts +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +326 -292
- package/dist/index.js.map +4 -4
- 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/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/package.json +7 -6
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,21 +219,10 @@ 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";
|
|
@@ -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,
|
|
@@ -909,8 +937,8 @@ var Combobox = (props) => {
|
|
|
909
937
|
selectionAppearance = "filled",
|
|
910
938
|
...restProps
|
|
911
939
|
} = props;
|
|
912
|
-
const controlRef =
|
|
913
|
-
const anchorRef =
|
|
940
|
+
const controlRef = useRef7(null);
|
|
941
|
+
const anchorRef = useRef7(null);
|
|
914
942
|
const { open, popupRef, available, changeOpen, close, focus, runAction, finalFocus } = useSelectionPopup({
|
|
915
943
|
disabled,
|
|
916
944
|
readOnly,
|
|
@@ -939,7 +967,7 @@ var Combobox = (props) => {
|
|
|
939
967
|
changeOpen(true);
|
|
940
968
|
};
|
|
941
969
|
const choose = (option) => {
|
|
942
|
-
if (option.disabled || loading
|
|
970
|
+
if (option.disabled || !searchResultsAvailable2({ loading, errorLabel }) || !available()) {
|
|
943
971
|
return;
|
|
944
972
|
}
|
|
945
973
|
change(option.value);
|
|
@@ -958,7 +986,7 @@ var Combobox = (props) => {
|
|
|
958
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",
|
|
959
987
|
dir,
|
|
960
988
|
children: [
|
|
961
|
-
/* @__PURE__ */
|
|
989
|
+
/* @__PURE__ */ jsx7(
|
|
962
990
|
Primitive3.Anchor,
|
|
963
991
|
{
|
|
964
992
|
asChild: true,
|
|
@@ -968,7 +996,7 @@ var Combobox = (props) => {
|
|
|
968
996
|
ref: anchorRef,
|
|
969
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",
|
|
970
998
|
children: [
|
|
971
|
-
/* @__PURE__ */
|
|
999
|
+
/* @__PURE__ */ jsx7(
|
|
972
1000
|
"input",
|
|
973
1001
|
{
|
|
974
1002
|
...restProps,
|
|
@@ -1054,7 +1082,7 @@ var Combobox = (props) => {
|
|
|
1054
1082
|
}
|
|
1055
1083
|
}
|
|
1056
1084
|
),
|
|
1057
|
-
/* @__PURE__ */
|
|
1085
|
+
/* @__PURE__ */ jsx7(
|
|
1058
1086
|
"button",
|
|
1059
1087
|
{
|
|
1060
1088
|
type: "button",
|
|
@@ -1069,7 +1097,7 @@ var Combobox = (props) => {
|
|
|
1069
1097
|
}
|
|
1070
1098
|
focus();
|
|
1071
1099
|
},
|
|
1072
|
-
children: /* @__PURE__ */
|
|
1100
|
+
children: /* @__PURE__ */ jsx7(
|
|
1073
1101
|
ChevronDown,
|
|
1074
1102
|
{
|
|
1075
1103
|
size: 16,
|
|
@@ -1083,7 +1111,7 @@ var Combobox = (props) => {
|
|
|
1083
1111
|
)
|
|
1084
1112
|
}
|
|
1085
1113
|
),
|
|
1086
|
-
clearLabel && /* @__PURE__ */
|
|
1114
|
+
clearLabel && /* @__PURE__ */ jsx7(
|
|
1087
1115
|
"button",
|
|
1088
1116
|
{
|
|
1089
1117
|
type: "button",
|
|
@@ -1095,7 +1123,7 @@ var Combobox = (props) => {
|
|
|
1095
1123
|
focus();
|
|
1096
1124
|
},
|
|
1097
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"),
|
|
1098
|
-
children: /* @__PURE__ */
|
|
1126
|
+
children: /* @__PURE__ */ jsx7(
|
|
1099
1127
|
X,
|
|
1100
1128
|
{
|
|
1101
1129
|
size: 16,
|
|
@@ -1104,7 +1132,7 @@ var Combobox = (props) => {
|
|
|
1104
1132
|
)
|
|
1105
1133
|
}
|
|
1106
1134
|
),
|
|
1107
|
-
/* @__PURE__ */
|
|
1135
|
+
/* @__PURE__ */ jsx7(
|
|
1108
1136
|
SelectionForm,
|
|
1109
1137
|
{
|
|
1110
1138
|
name,
|
|
@@ -1140,13 +1168,13 @@ var Combobox = (props) => {
|
|
|
1140
1168
|
focus();
|
|
1141
1169
|
},
|
|
1142
1170
|
children: [
|
|
1143
|
-
/* @__PURE__ */
|
|
1171
|
+
/* @__PURE__ */ jsx7(
|
|
1144
1172
|
"div",
|
|
1145
1173
|
{
|
|
1146
1174
|
role: "status",
|
|
1147
1175
|
"aria-atomic": "true",
|
|
1148
1176
|
className: cn3(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
1149
|
-
children:
|
|
1177
|
+
children: getSearchResultLabel(visible.length, {
|
|
1150
1178
|
loading,
|
|
1151
1179
|
loadingLabel,
|
|
1152
1180
|
errorLabel,
|
|
@@ -1155,7 +1183,7 @@ var Combobox = (props) => {
|
|
|
1155
1183
|
})
|
|
1156
1184
|
}
|
|
1157
1185
|
),
|
|
1158
|
-
/* @__PURE__ */
|
|
1186
|
+
/* @__PURE__ */ jsx7(
|
|
1159
1187
|
ComboboxOptions,
|
|
1160
1188
|
{
|
|
1161
1189
|
selectionAppearance,
|
|
@@ -1169,7 +1197,7 @@ var Combobox = (props) => {
|
|
|
1169
1197
|
onHighlight: search.highlight
|
|
1170
1198
|
}
|
|
1171
1199
|
),
|
|
1172
|
-
/* @__PURE__ */
|
|
1200
|
+
/* @__PURE__ */ jsx7(
|
|
1173
1201
|
SelectionActions,
|
|
1174
1202
|
{
|
|
1175
1203
|
actions,
|
|
@@ -1187,12 +1215,12 @@ var Combobox = (props) => {
|
|
|
1187
1215
|
// src/multi-select/multi-select.tsx
|
|
1188
1216
|
import { ListFieldControl, useListField } from "@gridui/form";
|
|
1189
1217
|
import { controlVariants as controlVariants2 } from "@gridui/input";
|
|
1190
|
-
import { isComposingKeyEvent as isComposingKeyEvent4 } from "@gridui/interaction";
|
|
1218
|
+
import { isComposingKeyEvent as isComposingKeyEvent4, searchResultsAvailable as searchResultsAvailable3 } from "@gridui/interaction";
|
|
1191
1219
|
import { cn as cn4 } from "@gridui/style-utils";
|
|
1192
1220
|
import * as Primitive4 from "@radix-ui/react-popover";
|
|
1193
1221
|
import { ChevronDown as ChevronDown2, X as X2 } from "lucide-react";
|
|
1194
|
-
import { useId as useId3, useRef as
|
|
1195
|
-
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";
|
|
1196
1224
|
var MultiSelect = (props) => {
|
|
1197
1225
|
const {
|
|
1198
1226
|
value,
|
|
@@ -1222,7 +1250,7 @@ var MultiSelect = (props) => {
|
|
|
1222
1250
|
selectionAppearance = "filled",
|
|
1223
1251
|
...restProps
|
|
1224
1252
|
} = props;
|
|
1225
|
-
const search =
|
|
1253
|
+
const search = useRef8(null);
|
|
1226
1254
|
const id = useId3();
|
|
1227
1255
|
const { selected, native, control, change } = useListField({
|
|
1228
1256
|
value,
|
|
@@ -1248,7 +1276,7 @@ var MultiSelect = (props) => {
|
|
|
1248
1276
|
});
|
|
1249
1277
|
const { all, filtered, visible, query, active, optionId, activeOptionId, getOption } = searchOptions;
|
|
1250
1278
|
const choose = (option) => {
|
|
1251
|
-
if (option.disabled || loading
|
|
1279
|
+
if (option.disabled || !searchResultsAvailable3({ loading, errorLabel }) || !available()) {
|
|
1252
1280
|
return;
|
|
1253
1281
|
}
|
|
1254
1282
|
change(selected.includes(option.value) ? selected.filter((entry) => {
|
|
@@ -1271,7 +1299,7 @@ var MultiSelect = (props) => {
|
|
|
1271
1299
|
className: "gridui-u-select--flex gridui-u-select--min-w-0 gridui-u-select--items-stretch gridui-u-select--gap-gridui-4",
|
|
1272
1300
|
dir: restProps.dir,
|
|
1273
1301
|
children: [
|
|
1274
|
-
/* @__PURE__ */
|
|
1302
|
+
/* @__PURE__ */ jsx8(
|
|
1275
1303
|
Primitive4.Trigger,
|
|
1276
1304
|
{
|
|
1277
1305
|
asChild: true,
|
|
@@ -1302,7 +1330,7 @@ var MultiSelect = (props) => {
|
|
|
1302
1330
|
}
|
|
1303
1331
|
},
|
|
1304
1332
|
children: [
|
|
1305
|
-
/* @__PURE__ */
|
|
1333
|
+
/* @__PURE__ */ jsx8(
|
|
1306
1334
|
"span",
|
|
1307
1335
|
{
|
|
1308
1336
|
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--wrap-anywhere",
|
|
@@ -1311,7 +1339,7 @@ var MultiSelect = (props) => {
|
|
|
1311
1339
|
}).join(", ") : placeholder
|
|
1312
1340
|
}
|
|
1313
1341
|
),
|
|
1314
|
-
/* @__PURE__ */
|
|
1342
|
+
/* @__PURE__ */ jsx8(
|
|
1315
1343
|
ChevronDown2,
|
|
1316
1344
|
{
|
|
1317
1345
|
size: 16,
|
|
@@ -1323,7 +1351,7 @@ var MultiSelect = (props) => {
|
|
|
1323
1351
|
)
|
|
1324
1352
|
}
|
|
1325
1353
|
),
|
|
1326
|
-
clearLabel && /* @__PURE__ */
|
|
1354
|
+
clearLabel && /* @__PURE__ */ jsx8(
|
|
1327
1355
|
"button",
|
|
1328
1356
|
{
|
|
1329
1357
|
type: "button",
|
|
@@ -1334,7 +1362,7 @@ var MultiSelect = (props) => {
|
|
|
1334
1362
|
change([]);
|
|
1335
1363
|
control.current?.focus();
|
|
1336
1364
|
},
|
|
1337
|
-
children: /* @__PURE__ */
|
|
1365
|
+
children: /* @__PURE__ */ jsx8(
|
|
1338
1366
|
X2,
|
|
1339
1367
|
{
|
|
1340
1368
|
size: 16,
|
|
@@ -1358,7 +1386,7 @@ var MultiSelect = (props) => {
|
|
|
1358
1386
|
},
|
|
1359
1387
|
children: [
|
|
1360
1388
|
all.map((option) => {
|
|
1361
|
-
return /* @__PURE__ */
|
|
1389
|
+
return /* @__PURE__ */ jsx8(
|
|
1362
1390
|
"option",
|
|
1363
1391
|
{
|
|
1364
1392
|
value: option.value,
|
|
@@ -1371,7 +1399,7 @@ var MultiSelect = (props) => {
|
|
|
1371
1399
|
selected.filter((entry) => {
|
|
1372
1400
|
return getOption(entry) === void 0;
|
|
1373
1401
|
}).map((entry) => {
|
|
1374
|
-
return /* @__PURE__ */
|
|
1402
|
+
return /* @__PURE__ */ jsx8(
|
|
1375
1403
|
"option",
|
|
1376
1404
|
{
|
|
1377
1405
|
value: entry,
|
|
@@ -1403,7 +1431,7 @@ var MultiSelect = (props) => {
|
|
|
1403
1431
|
focus();
|
|
1404
1432
|
},
|
|
1405
1433
|
children: [
|
|
1406
|
-
/* @__PURE__ */
|
|
1434
|
+
/* @__PURE__ */ jsx8(
|
|
1407
1435
|
"input",
|
|
1408
1436
|
{
|
|
1409
1437
|
ref: search,
|
|
@@ -1439,7 +1467,7 @@ var MultiSelect = (props) => {
|
|
|
1439
1467
|
}
|
|
1440
1468
|
}
|
|
1441
1469
|
),
|
|
1442
|
-
/* @__PURE__ */
|
|
1470
|
+
/* @__PURE__ */ jsx8(
|
|
1443
1471
|
ComboboxOptions,
|
|
1444
1472
|
{
|
|
1445
1473
|
selectionAppearance,
|
|
@@ -1454,13 +1482,13 @@ var MultiSelect = (props) => {
|
|
|
1454
1482
|
onHighlight: searchOptions.highlight
|
|
1455
1483
|
}
|
|
1456
1484
|
),
|
|
1457
|
-
/* @__PURE__ */
|
|
1485
|
+
/* @__PURE__ */ jsx8(
|
|
1458
1486
|
"div",
|
|
1459
1487
|
{
|
|
1460
1488
|
role: "status",
|
|
1461
1489
|
"aria-atomic": "true",
|
|
1462
1490
|
className: cn4(selectEmptyStyles(), "gridui-u-select--empty:hidden"),
|
|
1463
|
-
children:
|
|
1491
|
+
children: getSearchResultLabel(visible.length, {
|
|
1464
1492
|
loading,
|
|
1465
1493
|
loadingLabel,
|
|
1466
1494
|
errorLabel,
|
|
@@ -1477,12 +1505,15 @@ var MultiSelect = (props) => {
|
|
|
1477
1505
|
);
|
|
1478
1506
|
};
|
|
1479
1507
|
|
|
1508
|
+
// src/select/select.tsx
|
|
1509
|
+
import { useMotionStyle as useMotionStyle2 } from "@gridui/motion/policy";
|
|
1510
|
+
|
|
1480
1511
|
// src/select/select-options.tsx
|
|
1481
1512
|
import { overlayListIndicatorStyles as overlayListIndicatorStyles2, overlayListItemStyles as overlayListItemStyles3, overlayListLabelStyles as overlayListLabelStyles2, useInteractionOutline as useInteractionOutline2, useScrollbars as useScrollbars2 } from "@gridui/overlay";
|
|
1482
1513
|
import * as Primitive5 from "@radix-ui/react-select";
|
|
1483
1514
|
import { Check as Check2 } from "lucide-react";
|
|
1484
1515
|
import { useId as useId4 } from "react";
|
|
1485
|
-
import { jsx as
|
|
1516
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1486
1517
|
var SelectOptions = (props) => {
|
|
1487
1518
|
const { options, id, label, selectionAppearance } = props;
|
|
1488
1519
|
const scrollbarRef = useScrollbars2();
|
|
@@ -1490,7 +1521,7 @@ var SelectOptions = (props) => {
|
|
|
1490
1521
|
ref: scrollbarRef,
|
|
1491
1522
|
selector: '[role="option"]'
|
|
1492
1523
|
});
|
|
1493
|
-
return /* @__PURE__ */
|
|
1524
|
+
return /* @__PURE__ */ jsx9(
|
|
1494
1525
|
Primitive5.Viewport,
|
|
1495
1526
|
{
|
|
1496
1527
|
ref,
|
|
@@ -1500,7 +1531,7 @@ var SelectOptions = (props) => {
|
|
|
1500
1531
|
"aria-label": label,
|
|
1501
1532
|
children: options.map((entry) => {
|
|
1502
1533
|
if (!("options" in entry)) {
|
|
1503
|
-
return /* @__PURE__ */
|
|
1534
|
+
return /* @__PURE__ */ jsx9(
|
|
1504
1535
|
SelectOptionItem,
|
|
1505
1536
|
{
|
|
1506
1537
|
option: entry,
|
|
@@ -1513,7 +1544,7 @@ var SelectOptions = (props) => {
|
|
|
1513
1544
|
Primitive5.Group,
|
|
1514
1545
|
{
|
|
1515
1546
|
children: [
|
|
1516
|
-
/* @__PURE__ */
|
|
1547
|
+
/* @__PURE__ */ jsx9(
|
|
1517
1548
|
Primitive5.Label,
|
|
1518
1549
|
{
|
|
1519
1550
|
className: overlayListLabelStyles2(),
|
|
@@ -1521,7 +1552,7 @@ var SelectOptions = (props) => {
|
|
|
1521
1552
|
}
|
|
1522
1553
|
),
|
|
1523
1554
|
entry.options.map((option) => {
|
|
1524
|
-
return /* @__PURE__ */
|
|
1555
|
+
return /* @__PURE__ */ jsx9(
|
|
1525
1556
|
SelectOptionItem,
|
|
1526
1557
|
{
|
|
1527
1558
|
option,
|
|
@@ -1552,7 +1583,7 @@ var SelectOptionItem = (props) => {
|
|
|
1552
1583
|
disabled: option.disabled,
|
|
1553
1584
|
className: overlayListItemStyles3({ selectionAppearance }),
|
|
1554
1585
|
children: [
|
|
1555
|
-
option.icon && /* @__PURE__ */
|
|
1586
|
+
option.icon && /* @__PURE__ */ jsx9(
|
|
1556
1587
|
"span",
|
|
1557
1588
|
{
|
|
1558
1589
|
className: selectIconStyles(),
|
|
@@ -1565,14 +1596,14 @@ var SelectOptionItem = (props) => {
|
|
|
1565
1596
|
{
|
|
1566
1597
|
className: selectOptionContentStyles(),
|
|
1567
1598
|
children: [
|
|
1568
|
-
/* @__PURE__ */
|
|
1599
|
+
/* @__PURE__ */ jsx9(
|
|
1569
1600
|
Primitive5.ItemText,
|
|
1570
1601
|
{
|
|
1571
1602
|
id: labelId,
|
|
1572
1603
|
children: option.label
|
|
1573
1604
|
}
|
|
1574
1605
|
),
|
|
1575
|
-
option.description && /* @__PURE__ */
|
|
1606
|
+
option.description && /* @__PURE__ */ jsx9(
|
|
1576
1607
|
"span",
|
|
1577
1608
|
{
|
|
1578
1609
|
id: descriptionId,
|
|
@@ -1583,12 +1614,12 @@ var SelectOptionItem = (props) => {
|
|
|
1583
1614
|
]
|
|
1584
1615
|
}
|
|
1585
1616
|
),
|
|
1586
|
-
/* @__PURE__ */
|
|
1617
|
+
/* @__PURE__ */ jsx9(
|
|
1587
1618
|
"span",
|
|
1588
1619
|
{
|
|
1589
1620
|
className: overlayListIndicatorStyles2(),
|
|
1590
1621
|
"aria-hidden": "true",
|
|
1591
|
-
children: /* @__PURE__ */
|
|
1622
|
+
children: /* @__PURE__ */ jsx9(Primitive5.ItemIndicator, { children: /* @__PURE__ */ jsx9(
|
|
1592
1623
|
Check2,
|
|
1593
1624
|
{
|
|
1594
1625
|
size: 16
|
|
@@ -1624,9 +1655,10 @@ import { interactionLayerProps as interactionLayerProps2 } from "@gridui/overlay
|
|
|
1624
1655
|
import { cn as cn6 } from "@gridui/style-utils";
|
|
1625
1656
|
import * as Primitive6 from "@radix-ui/react-select";
|
|
1626
1657
|
import { ChevronDown as ChevronDown3, ChevronUp, X as X3 } from "lucide-react";
|
|
1627
|
-
import { useId as useId5, useRef as
|
|
1628
|
-
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";
|
|
1629
1660
|
var Select = (props) => {
|
|
1661
|
+
const motionStyle = useMotionStyle2();
|
|
1630
1662
|
const {
|
|
1631
1663
|
options,
|
|
1632
1664
|
actions = [],
|
|
@@ -1648,7 +1680,7 @@ var Select = (props) => {
|
|
|
1648
1680
|
ref,
|
|
1649
1681
|
...restProps
|
|
1650
1682
|
} = props;
|
|
1651
|
-
const controlRef =
|
|
1683
|
+
const controlRef = useRef9(null);
|
|
1652
1684
|
const {
|
|
1653
1685
|
open,
|
|
1654
1686
|
popupRef,
|
|
@@ -1671,7 +1703,7 @@ var Select = (props) => {
|
|
|
1671
1703
|
const [
|
|
1672
1704
|
triggerWidth,
|
|
1673
1705
|
setTriggerWidth
|
|
1674
|
-
] =
|
|
1706
|
+
] = useState6();
|
|
1675
1707
|
const allOptions = flattenOptions(options);
|
|
1676
1708
|
const selected = allOptions.find((option) => {
|
|
1677
1709
|
return option.value === selectedValue;
|
|
@@ -1720,7 +1752,7 @@ var Select = (props) => {
|
|
|
1720
1752
|
},
|
|
1721
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),
|
|
1722
1754
|
children: [
|
|
1723
|
-
selected?.icon && /* @__PURE__ */
|
|
1755
|
+
selected?.icon && /* @__PURE__ */ jsx10(
|
|
1724
1756
|
"span",
|
|
1725
1757
|
{
|
|
1726
1758
|
className: selectIconStyles(),
|
|
@@ -1728,11 +1760,11 @@ var Select = (props) => {
|
|
|
1728
1760
|
children: selected.icon
|
|
1729
1761
|
}
|
|
1730
1762
|
),
|
|
1731
|
-
/* @__PURE__ */
|
|
1763
|
+
/* @__PURE__ */ jsx10(
|
|
1732
1764
|
"span",
|
|
1733
1765
|
{
|
|
1734
1766
|
className: "gridui-u-select--min-w-0 gridui-u-select--flex-1 gridui-u-select--whitespace-normal gridui-u-select--wrap-anywhere",
|
|
1735
|
-
children: /* @__PURE__ */
|
|
1767
|
+
children: /* @__PURE__ */ jsx10(
|
|
1736
1768
|
Primitive6.Value,
|
|
1737
1769
|
{
|
|
1738
1770
|
placeholder: display,
|
|
@@ -1741,7 +1773,7 @@ var Select = (props) => {
|
|
|
1741
1773
|
)
|
|
1742
1774
|
}
|
|
1743
1775
|
),
|
|
1744
|
-
/* @__PURE__ */
|
|
1776
|
+
/* @__PURE__ */ jsx10(Primitive6.Icon, { children: /* @__PURE__ */ jsx10(
|
|
1745
1777
|
ChevronDown3,
|
|
1746
1778
|
{
|
|
1747
1779
|
size: 16,
|
|
@@ -1752,7 +1784,7 @@ var Select = (props) => {
|
|
|
1752
1784
|
]
|
|
1753
1785
|
}
|
|
1754
1786
|
),
|
|
1755
|
-
clearLabel && /* @__PURE__ */
|
|
1787
|
+
clearLabel && /* @__PURE__ */ jsx10(
|
|
1756
1788
|
"button",
|
|
1757
1789
|
{
|
|
1758
1790
|
type: "button",
|
|
@@ -1763,7 +1795,7 @@ var Select = (props) => {
|
|
|
1763
1795
|
controlRef.current?.focus();
|
|
1764
1796
|
},
|
|
1765
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"),
|
|
1766
|
-
children: /* @__PURE__ */
|
|
1798
|
+
children: /* @__PURE__ */ jsx10(
|
|
1767
1799
|
X3,
|
|
1768
1800
|
{
|
|
1769
1801
|
size: 16,
|
|
@@ -1772,7 +1804,7 @@ var Select = (props) => {
|
|
|
1772
1804
|
)
|
|
1773
1805
|
}
|
|
1774
1806
|
),
|
|
1775
|
-
/* @__PURE__ */
|
|
1807
|
+
/* @__PURE__ */ jsx10(
|
|
1776
1808
|
SelectionForm,
|
|
1777
1809
|
{
|
|
1778
1810
|
name,
|
|
@@ -1792,7 +1824,7 @@ var Select = (props) => {
|
|
|
1792
1824
|
]
|
|
1793
1825
|
}
|
|
1794
1826
|
),
|
|
1795
|
-
/* @__PURE__ */
|
|
1827
|
+
/* @__PURE__ */ jsx10(
|
|
1796
1828
|
Primitive6.Portal,
|
|
1797
1829
|
{
|
|
1798
1830
|
container: portalContainer,
|
|
@@ -1846,17 +1878,18 @@ var Select = (props) => {
|
|
|
1846
1878
|
event.stopPropagation();
|
|
1847
1879
|
}
|
|
1848
1880
|
},
|
|
1881
|
+
style: motionStyle,
|
|
1849
1882
|
children: [
|
|
1850
1883
|
/* @__PURE__ */ jsxs8(
|
|
1851
1884
|
"div",
|
|
1852
1885
|
{
|
|
1853
1886
|
className: "gridui-u-select--relative gridui-u-select--flex gridui-u-select--min-h-0 gridui-u-select--flex-col",
|
|
1854
1887
|
children: [
|
|
1855
|
-
/* @__PURE__ */
|
|
1888
|
+
/* @__PURE__ */ jsx10(
|
|
1856
1889
|
Primitive6.ScrollUpButton,
|
|
1857
1890
|
{
|
|
1858
1891
|
className: selectScrollArrowStyles({ direction: "up" }),
|
|
1859
|
-
children: /* @__PURE__ */
|
|
1892
|
+
children: /* @__PURE__ */ jsx10(
|
|
1860
1893
|
ChevronUp,
|
|
1861
1894
|
{
|
|
1862
1895
|
size: 16,
|
|
@@ -1865,7 +1898,7 @@ var Select = (props) => {
|
|
|
1865
1898
|
)
|
|
1866
1899
|
}
|
|
1867
1900
|
),
|
|
1868
|
-
/* @__PURE__ */
|
|
1901
|
+
/* @__PURE__ */ jsx10(
|
|
1869
1902
|
SelectOptions,
|
|
1870
1903
|
{
|
|
1871
1904
|
selectionAppearance,
|
|
@@ -1874,11 +1907,11 @@ var Select = (props) => {
|
|
|
1874
1907
|
label: restProps["aria-label"]
|
|
1875
1908
|
}
|
|
1876
1909
|
),
|
|
1877
|
-
/* @__PURE__ */
|
|
1910
|
+
/* @__PURE__ */ jsx10(
|
|
1878
1911
|
Primitive6.ScrollDownButton,
|
|
1879
1912
|
{
|
|
1880
1913
|
className: selectScrollArrowStyles({ direction: "down" }),
|
|
1881
|
-
children: /* @__PURE__ */
|
|
1914
|
+
children: /* @__PURE__ */ jsx10(
|
|
1882
1915
|
ChevronDown3,
|
|
1883
1916
|
{
|
|
1884
1917
|
size: 16,
|
|
@@ -1890,7 +1923,7 @@ var Select = (props) => {
|
|
|
1890
1923
|
]
|
|
1891
1924
|
}
|
|
1892
1925
|
),
|
|
1893
|
-
/* @__PURE__ */
|
|
1926
|
+
/* @__PURE__ */ jsx10(
|
|
1894
1927
|
SelectionActions,
|
|
1895
1928
|
{
|
|
1896
1929
|
actions,
|
|
@@ -1952,7 +1985,7 @@ var createOptionsRequest = (loadOptions, onState) => {
|
|
|
1952
1985
|
};
|
|
1953
1986
|
|
|
1954
1987
|
// src/use-async-options/use-async-options.ts
|
|
1955
|
-
import { useEffect as useEffect4, useState as
|
|
1988
|
+
import { useEffect as useEffect4, useState as useState7 } from "react";
|
|
1956
1989
|
var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true }) => {
|
|
1957
1990
|
if (!Number.isFinite(debounceMs) || debounceMs < 0) {
|
|
1958
1991
|
throw new RangeError("Option search debounce must be finite and nonnegative.");
|
|
@@ -1960,7 +1993,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
1960
1993
|
const [
|
|
1961
1994
|
state,
|
|
1962
1995
|
setState
|
|
1963
|
-
] =
|
|
1996
|
+
] = useState7({
|
|
1964
1997
|
loader: loadOptions,
|
|
1965
1998
|
result: {
|
|
1966
1999
|
query,
|
|
@@ -2008,6 +2041,7 @@ var useAsyncOptions = ({ query, loadOptions, debounceMs = 150, enabled = true })
|
|
|
2008
2041
|
};
|
|
2009
2042
|
export {
|
|
2010
2043
|
Autocomplete,
|
|
2044
|
+
AutocompleteSuggestions,
|
|
2011
2045
|
Combobox,
|
|
2012
2046
|
MultiSelect,
|
|
2013
2047
|
Select,
|