@nexus-cross/design-system 1.0.13 → 1.1.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/claude-rules/nexus/CLAUDE.md +85 -0
- package/claude-rules/nexus/commands/nexus-audit.md +79 -0
- package/claude-rules/nexus/commands/nexus-component-map.md +85 -0
- package/claude-rules/nexus/commands/nexus-token-check.md +68 -0
- package/claude-rules/nexus/skills/nexus-design-system/SKILL.md +92 -0
- package/cursor-rules/nexus-ui-api.mdc +824 -41
- package/cursor-rules/nexus-ui-decisions.mdc +259 -0
- package/dist/accordion.js +0 -1
- package/dist/accordion.mjs +0 -1
- package/dist/alert.js +0 -1
- package/dist/alert.mjs +0 -1
- package/dist/avatar.js +0 -1
- package/dist/avatar.mjs +0 -1
- package/dist/badge.js +0 -1
- package/dist/badge.mjs +0 -1
- package/dist/breadcrumb.js +0 -1
- package/dist/breadcrumb.mjs +0 -1
- package/dist/button.js +0 -1
- package/dist/button.mjs +0 -1
- package/dist/carousel.js +0 -1
- package/dist/carousel.mjs +0 -1
- package/dist/checkbox.js +0 -1
- package/dist/checkbox.mjs +0 -1
- package/dist/chip.js +0 -1
- package/dist/chip.mjs +0 -1
- package/dist/chunks/chunk-2Z52NPWB.js +78 -0
- package/dist/chunks/chunk-46P52MFM.mjs +56 -0
- package/dist/chunks/{chunk-X3CTJ7TD.js → chunk-4KBFVIKX.js} +41 -11
- package/dist/chunks/chunk-56ZOOQFE.mjs +514 -0
- package/dist/chunks/chunk-5ASTWFJW.js +538 -0
- package/dist/chunks/{chunk-33UFQJIO.mjs → chunk-BJMXZJWO.mjs} +16 -5
- package/dist/chunks/chunk-EILXBLEV.mjs +5 -0
- package/dist/chunks/chunk-G3RLK2HS.js +7 -0
- package/dist/chunks/{chunk-YZV6FWE7.js → chunk-JLDQNDFT.js} +16 -5
- package/dist/chunks/{chunk-K574BYHQ.js → chunk-K3CK7NTP.js} +22 -4
- package/dist/chunks/{chunk-Z4YM7LU3.mjs → chunk-PIGHBDK5.mjs} +22 -4
- package/dist/chunks/{chunk-PEIEVKD5.js → chunk-RCIBLLSF.js} +11 -12
- package/dist/chunks/{chunk-MMCA33FW.mjs → chunk-RSFLNWOM.mjs} +41 -11
- package/dist/chunks/{chunk-K2TBLM3F.mjs → chunk-THBE27U3.mjs} +11 -12
- package/dist/client-only.js +0 -1
- package/dist/client-only.mjs +0 -1
- package/dist/combobox.js +16 -0
- package/dist/combobox.mjs +3 -0
- package/dist/components/Combobox.d.ts +48 -0
- package/dist/components/Combobox.d.ts.map +1 -0
- package/dist/components/DataGrid.d.ts +44 -0
- package/dist/components/DataGrid.d.ts.map +1 -0
- package/dist/components/DataList.d.ts +3 -1
- package/dist/components/DataList.d.ts.map +1 -1
- package/dist/components/RadioGroup.d.ts +4 -0
- package/dist/components/RadioGroup.d.ts.map +1 -1
- package/dist/components/Stepper.d.ts.map +1 -1
- package/dist/components/ToggleGroup.d.ts +2 -1
- package/dist/components/ToggleGroup.d.ts.map +1 -1
- package/dist/countdown.js +0 -1
- package/dist/countdown.mjs +0 -1
- package/dist/counter.js +0 -1
- package/dist/counter.mjs +0 -1
- package/dist/data-grid.js +14 -0
- package/dist/data-grid.mjs +5 -0
- package/dist/data-list.js +2 -3
- package/dist/data-list.mjs +1 -2
- package/dist/date-picker.js +0 -1
- package/dist/date-picker.mjs +0 -1
- package/dist/divider.js +0 -1
- package/dist/divider.mjs +0 -1
- package/dist/drawer.js +0 -1
- package/dist/drawer.mjs +0 -1
- package/dist/dropdown-menu.js +0 -1
- package/dist/dropdown-menu.mjs +0 -1
- package/dist/ellipsis.js +0 -1
- package/dist/ellipsis.mjs +0 -1
- package/dist/empty-state.js +0 -1
- package/dist/empty-state.mjs +0 -1
- package/dist/error-boundary.js +0 -1
- package/dist/error-boundary.mjs +0 -1
- package/dist/hooks/useCheckDevice.js +0 -1
- package/dist/hooks/useCheckDevice.mjs +0 -1
- package/dist/hooks/useClickOutside.js +0 -1
- package/dist/hooks/useClickOutside.mjs +0 -1
- package/dist/hooks/useDraggableBottomSheet.js +0 -1
- package/dist/hooks/useDraggableBottomSheet.mjs +0 -1
- package/dist/hooks/useDraggableWindow.js +0 -1
- package/dist/hooks/useDraggableWindow.mjs +0 -1
- package/dist/hooks/useInView.js +0 -1
- package/dist/hooks/useInView.mjs +0 -1
- package/dist/hooks/useModal.js +0 -1
- package/dist/hooks/useModal.mjs +0 -1
- package/dist/image-upload.js +0 -1
- package/dist/image-upload.mjs +0 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +92 -88
- package/dist/index.mjs +12 -12
- package/dist/infinite-scroll.js +0 -1
- package/dist/infinite-scroll.mjs +0 -1
- package/dist/marquee.js +0 -1
- package/dist/marquee.mjs +0 -1
- package/dist/modal/index.js +11 -12
- package/dist/modal/index.mjs +2 -3
- package/dist/number-input.js +0 -1
- package/dist/number-input.mjs +0 -1
- package/dist/nx-image.js +0 -1
- package/dist/nx-image.mjs +0 -1
- package/dist/pagination.js +0 -1
- package/dist/pagination.mjs +0 -1
- package/dist/popover.js +0 -1
- package/dist/popover.mjs +0 -1
- package/dist/price-input.js +0 -1
- package/dist/price-input.mjs +0 -1
- package/dist/progress.js +0 -1
- package/dist/progress.mjs +0 -1
- package/dist/radio-group.js +5 -6
- package/dist/radio-group.mjs +1 -2
- package/dist/schemas/_all.json +308 -117
- package/dist/schemas/accordion.d.ts.map +1 -1
- package/dist/schemas/accordion.json +1 -1
- package/dist/schemas/alert.d.ts.map +1 -1
- package/dist/schemas/alert.json +1 -1
- package/dist/schemas/avatar.d.ts.map +1 -1
- package/dist/schemas/avatar.json +1 -1
- package/dist/schemas/badge.d.ts.map +1 -1
- package/dist/schemas/badge.json +1 -1
- package/dist/schemas/breadcrumb.d.ts.map +1 -1
- package/dist/schemas/breadcrumb.json +1 -1
- package/dist/schemas/button.d.ts.map +1 -1
- package/dist/schemas/button.json +1 -1
- package/dist/schemas/carousel.d.ts.map +1 -1
- package/dist/schemas/carousel.json +1 -1
- package/dist/schemas/checkBox.json +1 -1
- package/dist/schemas/checkbox.d.ts.map +1 -1
- package/dist/schemas/chip.d.ts.map +1 -1
- package/dist/schemas/chip.json +1 -1
- package/dist/schemas/client-only.d.ts.map +1 -1
- package/dist/schemas/clientOnly.json +1 -1
- package/dist/schemas/combobox.d.ts +85 -0
- package/dist/schemas/combobox.d.ts.map +1 -0
- package/dist/schemas/combobox.json +98 -0
- package/dist/schemas/comboboxOption.json +30 -0
- package/dist/schemas/countdown.d.ts.map +1 -1
- package/dist/schemas/countdown.json +1 -1
- package/dist/schemas/counter.d.ts.map +1 -1
- package/dist/schemas/counter.json +1 -1
- package/dist/schemas/data-grid.d.ts +74 -0
- package/dist/schemas/data-grid.d.ts.map +1 -0
- package/dist/schemas/data-list.d.ts.map +1 -1
- package/dist/schemas/dataGrid.json +102 -0
- package/dist/schemas/dataList.json +1 -1
- package/dist/schemas/date-picker.d.ts.map +1 -1
- package/dist/schemas/datePicker.json +1 -1
- package/dist/schemas/divider.d.ts.map +1 -1
- package/dist/schemas/divider.json +1 -1
- package/dist/schemas/drawer.d.ts.map +1 -1
- package/dist/schemas/drawer.json +1 -1
- package/dist/schemas/dropdown-menu.d.ts.map +1 -1
- package/dist/schemas/dropdownMenu.json +1 -1
- package/dist/schemas/ellipsis.d.ts.map +1 -1
- package/dist/schemas/ellipsis.json +1 -1
- package/dist/schemas/empty-state.d.ts.map +1 -1
- package/dist/schemas/emptyState.json +1 -1
- package/dist/schemas/error-boundary.d.ts.map +1 -1
- package/dist/schemas/errorBoundary.json +1 -1
- package/dist/schemas/image-upload.d.ts.map +1 -1
- package/dist/schemas/imageUpload.json +1 -1
- package/dist/schemas/index.d.ts +2 -1
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/infinite-scroll.d.ts.map +1 -1
- package/dist/schemas/infiniteScroll.json +1 -1
- package/dist/schemas/marquee.d.ts.map +1 -1
- package/dist/schemas/marquee.json +1 -1
- package/dist/schemas/modal.d.ts.map +1 -1
- package/dist/schemas/modalTemplate.json +1 -1
- package/dist/schemas/number-input.d.ts.map +1 -1
- package/dist/schemas/numberInput.json +1 -1
- package/dist/schemas/nx-image.d.ts.map +1 -1
- package/dist/schemas/nxImage.json +1 -1
- package/dist/schemas/pagination.d.ts.map +1 -1
- package/dist/schemas/pagination.json +1 -1
- package/dist/schemas/popover.d.ts.map +1 -1
- package/dist/schemas/popover.json +1 -1
- package/dist/schemas/price-input.d.ts.map +1 -1
- package/dist/schemas/priceInput.json +1 -1
- package/dist/schemas/progress.d.ts.map +1 -1
- package/dist/schemas/progress.json +1 -1
- package/dist/schemas/radio-group.d.ts +9 -0
- package/dist/schemas/radio-group.d.ts.map +1 -1
- package/dist/schemas/radioGroup.json +10 -1
- package/dist/schemas/radioItem.json +11 -0
- package/dist/schemas/select.d.ts.map +1 -1
- package/dist/schemas/select.json +1 -1
- package/dist/schemas/skeleton.d.ts.map +1 -1
- package/dist/schemas/skeleton.json +1 -1
- package/dist/schemas/slider.d.ts.map +1 -1
- package/dist/schemas/slider.json +1 -1
- package/dist/schemas/spinner.d.ts.map +1 -1
- package/dist/schemas/spinner.json +1 -1
- package/dist/schemas/stepper.d.ts.map +1 -1
- package/dist/schemas/stepper.json +1 -1
- package/dist/schemas/switch.d.ts.map +1 -1
- package/dist/schemas/switch.json +1 -1
- package/dist/schemas/tab.d.ts.map +1 -1
- package/dist/schemas/tab.json +1 -1
- package/dist/schemas/table.d.ts.map +1 -1
- package/dist/schemas/table.json +1 -1
- package/dist/schemas/tableRow.json +1 -1
- package/dist/schemas/tag-input.d.ts.map +1 -1
- package/dist/schemas/tagInput.json +1 -1
- package/dist/schemas/tdColumn.json +1 -1
- package/dist/schemas/text-area.d.ts.map +1 -1
- package/dist/schemas/text-input.d.ts +2 -2
- package/dist/schemas/text-input.d.ts.map +1 -1
- package/dist/schemas/textArea.json +1 -1
- package/dist/schemas/textInput.json +1 -1
- package/dist/schemas/toast.d.ts.map +1 -1
- package/dist/schemas/toastOptions.json +1 -1
- package/dist/schemas/toaster.json +1 -1
- package/dist/schemas/toggle-group.d.ts +6 -3
- package/dist/schemas/toggle-group.d.ts.map +1 -1
- package/dist/schemas/toggleGroup.json +9 -3
- package/dist/schemas/tooltip.d.ts.map +1 -1
- package/dist/schemas/tooltip.json +1 -1
- package/dist/schemas/virtual-scroll.d.ts.map +1 -1
- package/dist/schemas/virtualGrid.json +1 -1
- package/dist/schemas/virtualList.json +1 -1
- package/dist/schemas.js +867 -66
- package/dist/schemas.mjs +865 -66
- package/dist/select.js +0 -1
- package/dist/select.mjs +0 -1
- package/dist/skeleton.js +0 -1
- package/dist/skeleton.mjs +0 -1
- package/dist/slider.js +0 -1
- package/dist/slider.mjs +0 -1
- package/dist/spinner.js +0 -1
- package/dist/spinner.mjs +0 -1
- package/dist/stepper.js +3 -4
- package/dist/stepper.mjs +1 -2
- package/dist/styles/.generated/built.d.ts +1 -1
- package/dist/styles/.generated/built.d.ts.map +1 -1
- package/dist/styles/layer.js +2 -3
- package/dist/styles/layer.mjs +1 -2
- package/dist/styles.css +554 -51
- package/dist/styles.js +2 -3
- package/dist/styles.layered.css +554 -51
- package/dist/styles.mjs +1 -2
- package/dist/switch.js +0 -1
- package/dist/switch.mjs +0 -1
- package/dist/tab.js +0 -1
- package/dist/tab.mjs +0 -1
- package/dist/table.js +0 -1
- package/dist/table.mjs +0 -1
- package/dist/tag-input.js +0 -1
- package/dist/tag-input.mjs +0 -1
- package/dist/text-area.js +0 -1
- package/dist/text-area.mjs +0 -1
- package/dist/text-input.js +0 -1
- package/dist/text-input.mjs +0 -1
- package/dist/toast.js +0 -1
- package/dist/toast.mjs +0 -1
- package/dist/toggle-group.js +3 -4
- package/dist/toggle-group.mjs +1 -2
- package/dist/tooltip.js +0 -1
- package/dist/tooltip.mjs +0 -1
- package/dist/utils/cn.js +0 -1
- package/dist/utils/cn.mjs +0 -1
- package/dist/utils/scroll.js +0 -1
- package/dist/utils/scroll.mjs +0 -1
- package/dist/virtual-scroll.js +0 -1
- package/dist/virtual-scroll.mjs +0 -1
- package/package.json +14 -8
- package/scripts/setup-cursor-rules.cjs +164 -27
- package/dist/chunks/chunk-22ULI3BF.js +0 -21
- package/dist/chunks/chunk-6ECGMUT6.mjs +0 -5
- package/dist/chunks/chunk-CVYXRSXT.mjs +0 -8
- package/dist/chunks/chunk-I252NERB.mjs +0 -21
- package/dist/chunks/chunk-JNMCYWGY.js +0 -10
- package/dist/chunks/chunk-V35IEPRL.js +0 -7
- package/dist/components/ThemeProvider.d.ts +0 -25
- package/dist/components/ThemeProvider.d.ts.map +0 -1
- package/dist/schemas/theme-provider.d.ts +0 -36
- package/dist/schemas/theme-provider.d.ts.map +0 -1
- package/dist/schemas/themeProvider.json +0 -65
- package/dist/theme-provider.js +0 -15
- package/dist/theme-provider.mjs +0 -2
- package/dist/chunks/{chunk-CWMLTXOH.mjs → chunk-5ZVPTIL3.mjs} +1 -1
- package/dist/chunks/{chunk-HFBTS42N.js → chunk-7F4SOLAC.js} +1 -1
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import { Spinner } from './chunk-BPUQ2CO2.mjs';
|
|
2
|
+
import { cn } from './chunk-MCKOWMLS.mjs';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var comboboxInputVariants = cva("nexus-combobox", {
|
|
9
|
+
variants: {
|
|
10
|
+
size: {
|
|
11
|
+
md: "nexus-combobox--md",
|
|
12
|
+
lg: "nexus-combobox--lg",
|
|
13
|
+
xl: "nexus-combobox--xl"
|
|
14
|
+
},
|
|
15
|
+
state: {
|
|
16
|
+
default: "nexus-combobox--default",
|
|
17
|
+
error: "nexus-combobox--error"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: { size: "md", state: "default" }
|
|
21
|
+
});
|
|
22
|
+
var ChevronDown = ({ className }) => /* @__PURE__ */ jsx(
|
|
23
|
+
"svg",
|
|
24
|
+
{
|
|
25
|
+
className,
|
|
26
|
+
width: "16",
|
|
27
|
+
height: "16",
|
|
28
|
+
viewBox: "0 0 16 16",
|
|
29
|
+
fill: "none",
|
|
30
|
+
stroke: "currentColor",
|
|
31
|
+
strokeWidth: "2",
|
|
32
|
+
strokeLinecap: "round",
|
|
33
|
+
strokeLinejoin: "round",
|
|
34
|
+
"aria-hidden": true,
|
|
35
|
+
children: /* @__PURE__ */ jsx("path", { d: "M4 6l4 4 4-4" })
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
var ClearIcon = ({ className }) => /* @__PURE__ */ jsx(
|
|
39
|
+
"svg",
|
|
40
|
+
{
|
|
41
|
+
className,
|
|
42
|
+
width: "14",
|
|
43
|
+
height: "14",
|
|
44
|
+
viewBox: "0 0 14 14",
|
|
45
|
+
fill: "none",
|
|
46
|
+
stroke: "currentColor",
|
|
47
|
+
strokeWidth: "1.5",
|
|
48
|
+
strokeLinecap: "round",
|
|
49
|
+
"aria-hidden": true,
|
|
50
|
+
children: /* @__PURE__ */ jsx("path", { d: "M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5" })
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
var CloseIcon = ({ className }) => /* @__PURE__ */ jsx(
|
|
54
|
+
"svg",
|
|
55
|
+
{
|
|
56
|
+
className,
|
|
57
|
+
width: "12",
|
|
58
|
+
height: "12",
|
|
59
|
+
viewBox: "0 0 16 16",
|
|
60
|
+
fill: "none",
|
|
61
|
+
stroke: "currentColor",
|
|
62
|
+
strokeWidth: "2",
|
|
63
|
+
strokeLinecap: "round",
|
|
64
|
+
"aria-hidden": true,
|
|
65
|
+
children: /* @__PURE__ */ jsx("path", { d: "M4 4l8 8M12 4l-8 8" })
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
function defaultFilter(option, query) {
|
|
69
|
+
if (!query) return true;
|
|
70
|
+
const label = typeof option.label === "string" ? option.label : typeof option.label === "number" ? String(option.label) : option.value;
|
|
71
|
+
return label.toLowerCase().includes(query.toLowerCase());
|
|
72
|
+
}
|
|
73
|
+
function useDebouncedCallback(callback, delay) {
|
|
74
|
+
const cbRef = React.useRef(callback);
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
cbRef.current = callback;
|
|
77
|
+
}, [callback]);
|
|
78
|
+
const timer = React.useRef(null);
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
return () => {
|
|
81
|
+
if (timer.current) clearTimeout(timer.current);
|
|
82
|
+
};
|
|
83
|
+
}, []);
|
|
84
|
+
return React.useCallback(
|
|
85
|
+
(...args) => {
|
|
86
|
+
if (timer.current) clearTimeout(timer.current);
|
|
87
|
+
timer.current = setTimeout(() => cbRef.current?.(...args), delay);
|
|
88
|
+
},
|
|
89
|
+
[delay]
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
var Combobox = React.forwardRef(
|
|
93
|
+
function Combobox2(props, ref) {
|
|
94
|
+
const {
|
|
95
|
+
options,
|
|
96
|
+
onSearch,
|
|
97
|
+
searchDebounce = 250,
|
|
98
|
+
loading = false,
|
|
99
|
+
filter,
|
|
100
|
+
placeholder,
|
|
101
|
+
emptyMessage = "\uAC80\uC0C9 \uACB0\uACFC \uC5C6\uC74C",
|
|
102
|
+
loadingMessage = "\uAC80\uC0C9 \uC911\u2026",
|
|
103
|
+
size,
|
|
104
|
+
disabled,
|
|
105
|
+
error,
|
|
106
|
+
clearable = true,
|
|
107
|
+
autoOpenOnFocus = true,
|
|
108
|
+
label,
|
|
109
|
+
description,
|
|
110
|
+
className,
|
|
111
|
+
popoverClassName,
|
|
112
|
+
id,
|
|
113
|
+
multiple,
|
|
114
|
+
value: controlledValue,
|
|
115
|
+
defaultValue,
|
|
116
|
+
onValueChange
|
|
117
|
+
} = props;
|
|
118
|
+
const isMultiple = !!multiple;
|
|
119
|
+
const fallbackId = React.useRef(
|
|
120
|
+
`nexus-cmbx-${Math.random().toString(36).slice(2, 9)}`
|
|
121
|
+
);
|
|
122
|
+
const inputId = id || fallbackId.current;
|
|
123
|
+
const listboxId = `${inputId}-listbox`;
|
|
124
|
+
const inputRef = React.useRef(null);
|
|
125
|
+
const anchorRef = React.useRef(null);
|
|
126
|
+
const setInputRef = React.useCallback(
|
|
127
|
+
(node) => {
|
|
128
|
+
inputRef.current = node;
|
|
129
|
+
if (typeof ref === "function") ref(node);
|
|
130
|
+
else if (ref)
|
|
131
|
+
ref.current = node;
|
|
132
|
+
},
|
|
133
|
+
[ref]
|
|
134
|
+
);
|
|
135
|
+
const isControlled = controlledValue !== void 0;
|
|
136
|
+
const initialInternal = React.useMemo(() => {
|
|
137
|
+
if (isMultiple) {
|
|
138
|
+
return Array.isArray(defaultValue) ? defaultValue : [];
|
|
139
|
+
}
|
|
140
|
+
return typeof defaultValue === "string" ? defaultValue : null;
|
|
141
|
+
}, [isMultiple, defaultValue]);
|
|
142
|
+
const [internalValue, setInternalValue] = React.useState(initialInternal);
|
|
143
|
+
const currentValue = isControlled ? controlledValue : internalValue;
|
|
144
|
+
const selectedValues = React.useMemo(() => {
|
|
145
|
+
if (isMultiple) return Array.isArray(currentValue) ? currentValue : [];
|
|
146
|
+
return typeof currentValue === "string" ? [currentValue] : [];
|
|
147
|
+
}, [isMultiple, currentValue]);
|
|
148
|
+
const updateValue = React.useCallback(
|
|
149
|
+
(next) => {
|
|
150
|
+
if (!isControlled) setInternalValue(next);
|
|
151
|
+
if (isMultiple) {
|
|
152
|
+
onValueChange?.(
|
|
153
|
+
next ?? []
|
|
154
|
+
);
|
|
155
|
+
} else {
|
|
156
|
+
onValueChange?.(
|
|
157
|
+
next ?? null
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
[isControlled, isMultiple, onValueChange]
|
|
162
|
+
);
|
|
163
|
+
const [open, setOpen] = React.useState(false);
|
|
164
|
+
const [query, setQuery] = React.useState("");
|
|
165
|
+
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
166
|
+
const debouncedSearch = useDebouncedCallback(onSearch, searchDebounce);
|
|
167
|
+
const visibleOptions = React.useMemo(() => {
|
|
168
|
+
if (onSearch) return options;
|
|
169
|
+
const filterFn = filter ?? defaultFilter;
|
|
170
|
+
return options.filter((o) => filterFn(o, query));
|
|
171
|
+
}, [onSearch, options, filter, query]);
|
|
172
|
+
React.useEffect(() => {
|
|
173
|
+
if (activeIndex >= visibleOptions.length) {
|
|
174
|
+
setActiveIndex(visibleOptions.length > 0 ? 0 : -1);
|
|
175
|
+
}
|
|
176
|
+
}, [visibleOptions, activeIndex]);
|
|
177
|
+
const handleInputChange = (e) => {
|
|
178
|
+
const next = e.target.value;
|
|
179
|
+
setQuery(next);
|
|
180
|
+
setOpen(true);
|
|
181
|
+
setActiveIndex(0);
|
|
182
|
+
if (onSearch) debouncedSearch(next);
|
|
183
|
+
};
|
|
184
|
+
const handleFocus = () => {
|
|
185
|
+
if (autoOpenOnFocus && !disabled) setOpen(true);
|
|
186
|
+
};
|
|
187
|
+
const selectOption = (option) => {
|
|
188
|
+
if (option.disabled) return;
|
|
189
|
+
if (isMultiple) {
|
|
190
|
+
const set = new Set(selectedValues);
|
|
191
|
+
if (set.has(option.value)) set.delete(option.value);
|
|
192
|
+
else set.add(option.value);
|
|
193
|
+
updateValue(Array.from(set));
|
|
194
|
+
setQuery("");
|
|
195
|
+
if (onSearch) debouncedSearch("");
|
|
196
|
+
inputRef.current?.focus();
|
|
197
|
+
} else {
|
|
198
|
+
updateValue(option.value);
|
|
199
|
+
const labelText = typeof option.label === "string" ? option.label : option.value;
|
|
200
|
+
setQuery(labelText);
|
|
201
|
+
setOpen(false);
|
|
202
|
+
inputRef.current?.blur();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const removeChip = (val) => {
|
|
206
|
+
if (!isMultiple) return;
|
|
207
|
+
updateValue(selectedValues.filter((v) => v !== val));
|
|
208
|
+
inputRef.current?.focus();
|
|
209
|
+
};
|
|
210
|
+
const clearAll = () => {
|
|
211
|
+
if (isMultiple) updateValue([]);
|
|
212
|
+
else updateValue(null);
|
|
213
|
+
setQuery("");
|
|
214
|
+
if (onSearch) debouncedSearch("");
|
|
215
|
+
inputRef.current?.focus();
|
|
216
|
+
};
|
|
217
|
+
const handleKeyDown = (e) => {
|
|
218
|
+
if (disabled) return;
|
|
219
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
220
|
+
if (e.key === "ArrowDown") {
|
|
221
|
+
e.preventDefault();
|
|
222
|
+
if (!open) {
|
|
223
|
+
setOpen(true);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (visibleOptions.length === 0) return;
|
|
227
|
+
let next = activeIndex + 1;
|
|
228
|
+
while (next < visibleOptions.length && visibleOptions[next].disabled)
|
|
229
|
+
next++;
|
|
230
|
+
if (next < visibleOptions.length) setActiveIndex(next);
|
|
231
|
+
else setActiveIndex(visibleOptions.findIndex((o) => !o.disabled));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (e.key === "ArrowUp") {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
if (!open) {
|
|
237
|
+
setOpen(true);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (visibleOptions.length === 0) return;
|
|
241
|
+
let next = activeIndex - 1;
|
|
242
|
+
while (next >= 0 && visibleOptions[next].disabled) next--;
|
|
243
|
+
if (next >= 0) setActiveIndex(next);
|
|
244
|
+
else {
|
|
245
|
+
for (let i = visibleOptions.length - 1; i >= 0; i--) {
|
|
246
|
+
if (!visibleOptions[i].disabled) {
|
|
247
|
+
setActiveIndex(i);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (e.key === "Home") {
|
|
255
|
+
e.preventDefault();
|
|
256
|
+
const idx = visibleOptions.findIndex((o) => !o.disabled);
|
|
257
|
+
if (idx >= 0) setActiveIndex(idx);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (e.key === "End") {
|
|
261
|
+
e.preventDefault();
|
|
262
|
+
for (let i = visibleOptions.length - 1; i >= 0; i--) {
|
|
263
|
+
if (!visibleOptions[i].disabled) {
|
|
264
|
+
setActiveIndex(i);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (e.key === "Enter") {
|
|
271
|
+
if (open && activeIndex >= 0 && visibleOptions[activeIndex]) {
|
|
272
|
+
e.preventDefault();
|
|
273
|
+
selectOption(visibleOptions[activeIndex]);
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (e.key === "Escape") {
|
|
278
|
+
if (open) {
|
|
279
|
+
e.preventDefault();
|
|
280
|
+
setOpen(false);
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
if (e.key === "Backspace" && isMultiple && query === "" && selectedValues.length > 0) {
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
removeChip(selectedValues[selectedValues.length - 1]);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const selectedOptionMap = React.useMemo(() => {
|
|
290
|
+
const map = /* @__PURE__ */ new Map();
|
|
291
|
+
for (const opt of options) map.set(opt.value, opt);
|
|
292
|
+
return map;
|
|
293
|
+
}, [options]);
|
|
294
|
+
const prevValueRef = React.useRef(
|
|
295
|
+
currentValue
|
|
296
|
+
);
|
|
297
|
+
React.useEffect(() => {
|
|
298
|
+
if (isMultiple) {
|
|
299
|
+
prevValueRef.current = currentValue;
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const valueChanged = prevValueRef.current !== currentValue;
|
|
303
|
+
prevValueRef.current = currentValue;
|
|
304
|
+
if (typeof currentValue !== "string") {
|
|
305
|
+
if (valueChanged) setQuery("");
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const opt = selectedOptionMap.get(currentValue);
|
|
309
|
+
const labelText = opt ? typeof opt.label === "string" ? opt.label : currentValue : currentValue;
|
|
310
|
+
if (valueChanged) {
|
|
311
|
+
setQuery(labelText);
|
|
312
|
+
} else {
|
|
313
|
+
setQuery((prev) => prev === currentValue ? labelText : prev);
|
|
314
|
+
}
|
|
315
|
+
}, [isMultiple, currentValue, selectedOptionMap]);
|
|
316
|
+
const hasValue = isMultiple && selectedValues.length > 0 || !isMultiple && typeof currentValue === "string" && currentValue !== "";
|
|
317
|
+
const showClear = clearable && !disabled && (hasValue || query.length > 0);
|
|
318
|
+
const state = error ? "error" : "default";
|
|
319
|
+
const hasField = !!(label || description);
|
|
320
|
+
const inputBox = /* @__PURE__ */ jsxs(
|
|
321
|
+
"div",
|
|
322
|
+
{
|
|
323
|
+
ref: anchorRef,
|
|
324
|
+
className: cn(
|
|
325
|
+
comboboxInputVariants({ size, state }),
|
|
326
|
+
disabled && "nexus-combobox--disabled",
|
|
327
|
+
open && "nexus-combobox--open",
|
|
328
|
+
!hasField && className
|
|
329
|
+
),
|
|
330
|
+
onClick: () => !disabled && inputRef.current?.focus(),
|
|
331
|
+
children: [
|
|
332
|
+
/* @__PURE__ */ jsxs("div", { className: "nexus-combobox__content", children: [
|
|
333
|
+
isMultiple && selectedValues.map((val) => {
|
|
334
|
+
const opt = selectedOptionMap.get(val);
|
|
335
|
+
return /* @__PURE__ */ jsxs("span", { className: "nexus-combobox__chip", children: [
|
|
336
|
+
/* @__PURE__ */ jsx("span", { className: "nexus-combobox__chip-label", children: opt?.label ?? val }),
|
|
337
|
+
!disabled && /* @__PURE__ */ jsx(
|
|
338
|
+
"button",
|
|
339
|
+
{
|
|
340
|
+
type: "button",
|
|
341
|
+
className: "nexus-combobox__chip-remove",
|
|
342
|
+
onClick: (e) => {
|
|
343
|
+
e.stopPropagation();
|
|
344
|
+
removeChip(val);
|
|
345
|
+
},
|
|
346
|
+
"aria-label": `Remove ${val}`,
|
|
347
|
+
tabIndex: -1,
|
|
348
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { className: "nexus-combobox__chip-remove-icon" })
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
] }, val);
|
|
352
|
+
}),
|
|
353
|
+
/* @__PURE__ */ jsx(
|
|
354
|
+
"input",
|
|
355
|
+
{
|
|
356
|
+
ref: setInputRef,
|
|
357
|
+
id: inputId,
|
|
358
|
+
type: "text",
|
|
359
|
+
role: "combobox",
|
|
360
|
+
autoComplete: "off",
|
|
361
|
+
spellCheck: false,
|
|
362
|
+
className: "nexus-combobox__input",
|
|
363
|
+
placeholder: isMultiple && selectedValues.length > 0 ? "" : placeholder,
|
|
364
|
+
value: query,
|
|
365
|
+
disabled,
|
|
366
|
+
"aria-expanded": open,
|
|
367
|
+
"aria-controls": listboxId,
|
|
368
|
+
"aria-autocomplete": "list",
|
|
369
|
+
"aria-activedescendant": open && activeIndex >= 0 && visibleOptions[activeIndex] ? `${inputId}-opt-${activeIndex}` : void 0,
|
|
370
|
+
"aria-invalid": error || void 0,
|
|
371
|
+
"aria-describedby": description ? `${inputId}-desc` : void 0,
|
|
372
|
+
onChange: handleInputChange,
|
|
373
|
+
onFocus: handleFocus,
|
|
374
|
+
onKeyDown: handleKeyDown
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
] }),
|
|
378
|
+
/* @__PURE__ */ jsxs("div", { className: "nexus-combobox__suffix", children: [
|
|
379
|
+
loading && /* @__PURE__ */ jsx("span", { className: "nexus-combobox__icon nexus-combobox__icon--loading", children: /* @__PURE__ */ jsx(Spinner, { size: 16 }) }),
|
|
380
|
+
showClear && !loading && /* @__PURE__ */ jsx(
|
|
381
|
+
"button",
|
|
382
|
+
{
|
|
383
|
+
type: "button",
|
|
384
|
+
className: "nexus-combobox__clear",
|
|
385
|
+
onClick: (e) => {
|
|
386
|
+
e.stopPropagation();
|
|
387
|
+
clearAll();
|
|
388
|
+
},
|
|
389
|
+
tabIndex: -1,
|
|
390
|
+
"aria-label": "Clear",
|
|
391
|
+
children: /* @__PURE__ */ jsx(ClearIcon, {})
|
|
392
|
+
}
|
|
393
|
+
),
|
|
394
|
+
/* @__PURE__ */ jsx(
|
|
395
|
+
"span",
|
|
396
|
+
{
|
|
397
|
+
className: cn(
|
|
398
|
+
"nexus-combobox__chevron",
|
|
399
|
+
open && "nexus-combobox__chevron--open"
|
|
400
|
+
),
|
|
401
|
+
"aria-hidden": true,
|
|
402
|
+
children: /* @__PURE__ */ jsx(ChevronDown, {})
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
] })
|
|
406
|
+
]
|
|
407
|
+
}
|
|
408
|
+
);
|
|
409
|
+
const popoverBody = /* @__PURE__ */ jsxs(PopoverPrimitive.Root, { open, onOpenChange: setOpen, children: [
|
|
410
|
+
/* @__PURE__ */ jsx(PopoverPrimitive.Anchor, { asChild: true, children: inputBox }),
|
|
411
|
+
/* @__PURE__ */ jsx(PopoverPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
412
|
+
PopoverPrimitive.Content,
|
|
413
|
+
{
|
|
414
|
+
align: "start",
|
|
415
|
+
side: "bottom",
|
|
416
|
+
sideOffset: 4,
|
|
417
|
+
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
418
|
+
onCloseAutoFocus: (e) => e.preventDefault(),
|
|
419
|
+
onPointerDownOutside: (e) => {
|
|
420
|
+
if (anchorRef.current && e.target instanceof Node && anchorRef.current.contains(e.target)) {
|
|
421
|
+
e.preventDefault();
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
onInteractOutside: (e) => {
|
|
425
|
+
if (anchorRef.current && e.target instanceof Node && anchorRef.current.contains(e.target)) {
|
|
426
|
+
e.preventDefault();
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
className: cn("nexus-combobox-popover", popoverClassName),
|
|
430
|
+
style: { width: "var(--radix-popover-trigger-width)" },
|
|
431
|
+
children: /* @__PURE__ */ jsx(
|
|
432
|
+
"div",
|
|
433
|
+
{
|
|
434
|
+
role: "listbox",
|
|
435
|
+
id: listboxId,
|
|
436
|
+
className: "nexus-combobox-listbox",
|
|
437
|
+
children: loading ? /* @__PURE__ */ jsxs("div", { className: "nexus-combobox-popover__status", children: [
|
|
438
|
+
/* @__PURE__ */ jsx(Spinner, { size: 16 }),
|
|
439
|
+
/* @__PURE__ */ jsx("span", { children: loadingMessage })
|
|
440
|
+
] }) : visibleOptions.length === 0 ? /* @__PURE__ */ jsx("div", { className: "nexus-combobox-popover__status", children: /* @__PURE__ */ jsx("span", { children: emptyMessage }) }) : visibleOptions.map((option, idx) => {
|
|
441
|
+
const selected = selectedValues.includes(option.value);
|
|
442
|
+
const active = idx === activeIndex;
|
|
443
|
+
return /* @__PURE__ */ jsxs(
|
|
444
|
+
"div",
|
|
445
|
+
{
|
|
446
|
+
id: `${inputId}-opt-${idx}`,
|
|
447
|
+
role: "option",
|
|
448
|
+
"aria-selected": selected,
|
|
449
|
+
"data-disabled": option.disabled || void 0,
|
|
450
|
+
"data-active": active || void 0,
|
|
451
|
+
"data-selected": selected || void 0,
|
|
452
|
+
className: cn(
|
|
453
|
+
"nexus-combobox-option",
|
|
454
|
+
active && "nexus-combobox-option--active",
|
|
455
|
+
selected && "nexus-combobox-option--selected",
|
|
456
|
+
option.disabled && "nexus-combobox-option--disabled"
|
|
457
|
+
),
|
|
458
|
+
onMouseEnter: () => setActiveIndex(idx),
|
|
459
|
+
onMouseDown: (e) => {
|
|
460
|
+
e.preventDefault();
|
|
461
|
+
selectOption(option);
|
|
462
|
+
},
|
|
463
|
+
children: [
|
|
464
|
+
/* @__PURE__ */ jsxs("div", { className: "nexus-combobox-option__body", children: [
|
|
465
|
+
/* @__PURE__ */ jsx("div", { className: "nexus-combobox-option__label", children: option.label }),
|
|
466
|
+
option.description && /* @__PURE__ */ jsx("div", { className: "nexus-combobox-option__description", children: option.description })
|
|
467
|
+
] }),
|
|
468
|
+
selected && /* @__PURE__ */ jsx(
|
|
469
|
+
"svg",
|
|
470
|
+
{
|
|
471
|
+
className: "nexus-combobox-option__check",
|
|
472
|
+
width: "14",
|
|
473
|
+
height: "14",
|
|
474
|
+
viewBox: "0 0 16 16",
|
|
475
|
+
fill: "none",
|
|
476
|
+
stroke: "currentColor",
|
|
477
|
+
strokeWidth: "2",
|
|
478
|
+
strokeLinecap: "round",
|
|
479
|
+
strokeLinejoin: "round",
|
|
480
|
+
"aria-hidden": true,
|
|
481
|
+
children: /* @__PURE__ */ jsx("path", { d: "M3 8l4 4 6-8" })
|
|
482
|
+
}
|
|
483
|
+
)
|
|
484
|
+
]
|
|
485
|
+
},
|
|
486
|
+
option.value
|
|
487
|
+
);
|
|
488
|
+
})
|
|
489
|
+
}
|
|
490
|
+
)
|
|
491
|
+
}
|
|
492
|
+
) })
|
|
493
|
+
] });
|
|
494
|
+
if (!hasField) return popoverBody;
|
|
495
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("nexus-combobox-field", className), children: [
|
|
496
|
+
label && /* @__PURE__ */ jsx("label", { className: "nexus-combobox-field__label", htmlFor: inputId, children: label }),
|
|
497
|
+
popoverBody,
|
|
498
|
+
description && /* @__PURE__ */ jsx(
|
|
499
|
+
"p",
|
|
500
|
+
{
|
|
501
|
+
id: `${inputId}-desc`,
|
|
502
|
+
className: cn(
|
|
503
|
+
"nexus-combobox-field__description",
|
|
504
|
+
error && "nexus-combobox-field__description--error"
|
|
505
|
+
),
|
|
506
|
+
children: description
|
|
507
|
+
}
|
|
508
|
+
)
|
|
509
|
+
] });
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
Combobox.displayName = "Combobox";
|
|
513
|
+
|
|
514
|
+
export { Combobox, comboboxInputVariants };
|