@constructive-io/ui 0.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/dist/components/alert-dialog.d.ts +31 -0
- package/dist/components/alert-dialog.js +314 -0
- package/dist/components/alert-dialog.js.map +1 -0
- package/dist/components/alert.d.ts +14 -0
- package/dist/components/alert.js +38 -0
- package/dist/components/alert.js.map +1 -0
- package/dist/components/autocomplete.d.ts +28 -0
- package/dist/components/autocomplete.js +395 -0
- package/dist/components/autocomplete.js.map +1 -0
- package/dist/components/avatar.d.ts +13 -0
- package/dist/components/avatar.js +37 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +15 -0
- package/dist/components/badge.js +43 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/breadcrumb.d.ts +14 -0
- package/dist/components/breadcrumb.js +154 -0
- package/dist/components/breadcrumb.js.map +1 -0
- package/dist/components/button.d.ts +17 -0
- package/dist/components/button.js +62 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/calendar-rac.d.ts +13 -0
- package/dist/components/calendar-rac.js +82 -0
- package/dist/components/calendar-rac.js.map +1 -0
- package/dist/components/card.d.ts +19 -0
- package/dist/components/card.js +75 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/checkbox-group.d.ts +7 -0
- package/dist/components/checkbox-group.js +16 -0
- package/dist/components/checkbox-group.js.map +1 -0
- package/dist/components/checkbox.d.ts +8 -0
- package/dist/components/checkbox.js +67 -0
- package/dist/components/checkbox.js.map +1 -0
- package/dist/components/collapsible.d.ts +54 -0
- package/dist/components/collapsible.js +121 -0
- package/dist/components/collapsible.js.map +1 -0
- package/dist/components/combobox.d.ts +44 -0
- package/dist/components/combobox.js +486 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/command.d.ts +43 -0
- package/dist/components/command.js +690 -0
- package/dist/components/command.js.map +1 -0
- package/dist/components/dialog.d.ts +35 -0
- package/dist/components/dialog.js +440 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/dock.d.ts +31 -0
- package/dist/components/dock.js +111 -0
- package/dist/components/dock.js.map +1 -0
- package/dist/components/drawer.d.ts +16 -0
- package/dist/components/drawer.js +147 -0
- package/dist/components/drawer.js.map +1 -0
- package/dist/components/dropdown-menu.d.ts +50 -0
- package/dist/components/dropdown-menu.js +380 -0
- package/dist/components/dropdown-menu.js.map +1 -0
- package/dist/components/field.d.ts +51 -0
- package/dist/components/field.js +115 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/flickering-grid.d.ts +15 -0
- package/dist/components/flickering-grid.js +147 -0
- package/dist/components/flickering-grid.js.map +1 -0
- package/dist/components/form-control.d.ts +15 -0
- package/dist/components/form-control.js +173 -0
- package/dist/components/form-control.js.map +1 -0
- package/dist/components/form.d.ts +37 -0
- package/dist/components/form.js +179 -0
- package/dist/components/form.js.map +1 -0
- package/dist/components/input-group.d.ts +18 -0
- package/dist/components/input-group.js +177 -0
- package/dist/components/input-group.js.map +1 -0
- package/dist/components/input.d.ts +11 -0
- package/dist/components/input.js +60 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/json-input.d.ts +25 -0
- package/dist/components/json-input.js +351 -0
- package/dist/components/json-input.js.map +1 -0
- package/dist/components/label.d.ts +11 -0
- package/dist/components/label.js +27 -0
- package/dist/components/label.js.map +1 -0
- package/dist/components/motion-grid.d.ts +20 -0
- package/dist/components/motion-grid.js +81 -0
- package/dist/components/motion-grid.js.map +1 -0
- package/dist/components/multi-select.d.ts +198 -0
- package/dist/components/multi-select.js +882 -0
- package/dist/components/multi-select.js.map +1 -0
- package/dist/components/page-header.d.ts +17 -0
- package/dist/components/page-header.js +17 -0
- package/dist/components/page-header.js.map +1 -0
- package/dist/components/pagination.d.ts +19 -0
- package/dist/components/pagination.js +144 -0
- package/dist/components/pagination.js.map +1 -0
- package/dist/components/popover.d.ts +35 -0
- package/dist/components/popover.js +188 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/portal.d.ts +108 -0
- package/dist/components/portal.js +75 -0
- package/dist/components/portal.js.map +1 -0
- package/dist/components/progress.d.ts +10 -0
- package/dist/components/progress.js +30 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/progressive-blur-scroll-container.d.ts +25 -0
- package/dist/components/progressive-blur-scroll-container.js +142 -0
- package/dist/components/progressive-blur-scroll-container.js.map +1 -0
- package/dist/components/progressive-blur.d.ts +16 -0
- package/dist/components/progressive-blur.js +68 -0
- package/dist/components/progressive-blur.js.map +1 -0
- package/dist/components/radio-group.d.ts +10 -0
- package/dist/components/radio-group.js +37 -0
- package/dist/components/radio-group.js.map +1 -0
- package/dist/components/record-picker.d.ts +16 -0
- package/dist/components/record-picker.js +366 -0
- package/dist/components/record-picker.js.map +1 -0
- package/dist/components/resizable.d.ts +11 -0
- package/dist/components/resizable.js +52 -0
- package/dist/components/resizable.js.map +1 -0
- package/dist/components/responsive-diagram.d.ts +10 -0
- package/dist/components/responsive-diagram.js +63 -0
- package/dist/components/responsive-diagram.js.map +1 -0
- package/dist/components/scroll-area.d.ts +12 -0
- package/dist/components/scroll-area.js +69 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/select.d.ts +47 -0
- package/dist/components/select.js +287 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/separator.d.ts +11 -0
- package/dist/components/separator.js +24 -0
- package/dist/components/separator.js.map +1 -0
- package/dist/components/sheet.d.ts +112 -0
- package/dist/components/sheet.js +600 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/sidebar.d.ts +77 -0
- package/dist/components/sidebar.js +1217 -0
- package/dist/components/sidebar.js.map +1 -0
- package/dist/components/skeleton.d.ts +7 -0
- package/dist/components/skeleton.js +16 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/sonner.d.ts +10 -0
- package/dist/components/sonner.js +23 -0
- package/dist/components/sonner.js.map +1 -0
- package/dist/components/stack/index.d.ts +663 -0
- package/dist/components/stack/index.js +1418 -0
- package/dist/components/stack/index.js.map +1 -0
- package/dist/components/stepper.d.ts +30 -0
- package/dist/components/stepper.js +280 -0
- package/dist/components/stepper.js.map +1 -0
- package/dist/components/switch.d.ts +8 -0
- package/dist/components/switch.js +40 -0
- package/dist/components/switch.js.map +1 -0
- package/dist/components/table.d.ts +15 -0
- package/dist/components/table.js +65 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +10 -0
- package/dist/components/tabs.js +48 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/tags.d.ts +42 -0
- package/dist/components/tags.js +728 -0
- package/dist/components/tags.js.map +1 -0
- package/dist/components/textarea.d.ts +10 -0
- package/dist/components/textarea.js +54 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/toast/index.d.ts +52 -0
- package/dist/components/toast/index.js +221 -0
- package/dist/components/toast/index.js.map +1 -0
- package/dist/components/tooltip.d.ts +29 -0
- package/dist/components/tooltip.js +174 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/components/unlink-button.d.ts +14 -0
- package/dist/components/unlink-button.js +91 -0
- package/dist/components/unlink-button.js.map +1 -0
- package/dist/index.cjs +7692 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2157 -0
- package/dist/index.d.ts +2157 -0
- package/dist/index.js +7375 -0
- package/dist/index.js.map +1 -0
- package/package.json +490 -0
- package/src/styles/globals.css +397 -0
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React5 from 'react';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import { XCircle, XIcon, ChevronDown, SearchIcon, CheckIcon } from 'lucide-react';
|
|
5
|
+
import { clsx } from 'clsx';
|
|
6
|
+
import { twMerge } from 'tailwind-merge';
|
|
7
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
8
|
+
import { Popover as Popover$1 } from '@base-ui/react/popover';
|
|
9
|
+
import { Separator as Separator$1 } from '@base-ui/react/separator';
|
|
10
|
+
|
|
11
|
+
function cn(...inputs) {
|
|
12
|
+
return twMerge(clsx(inputs));
|
|
13
|
+
}
|
|
14
|
+
var badgeVariants = cva(
|
|
15
|
+
"relative inline-flex shrink-0 items-center justify-center gap-1 whitespace-nowrap rounded-sm border border-transparent font-medium outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 [&_svg:not([class*='size-'])]:size-3 [&_svg]:pointer-events-none [&_svg]:shrink-0 [button,a&]:cursor-pointer [button,a&]:pointer-coarse:after:absolute [button,a&]:pointer-coarse:after:size-full [button,a&]:pointer-coarse:after:min-h-11 [button,a&]:pointer-coarse:after:min-w-11",
|
|
16
|
+
{
|
|
17
|
+
defaultVariants: {
|
|
18
|
+
size: "default",
|
|
19
|
+
variant: "default"
|
|
20
|
+
},
|
|
21
|
+
variants: {
|
|
22
|
+
size: {
|
|
23
|
+
default: "px-[calc(--spacing(1)-1px)] text-xs",
|
|
24
|
+
lg: "px-[calc(--spacing(1.5)-1px)] text-sm",
|
|
25
|
+
sm: "rounded-[calc(var(--radius-sm)-2px)] px-[calc(--spacing(1)-1px)] text-[.625rem]"
|
|
26
|
+
},
|
|
27
|
+
variant: {
|
|
28
|
+
default: "bg-primary text-primary-foreground [button,a&]:hover:bg-primary/90",
|
|
29
|
+
destructive: "bg-destructive text-white [button,a&]:hover:bg-destructive/90",
|
|
30
|
+
error: "bg-destructive/8 text-destructive dark:bg-destructive/16",
|
|
31
|
+
info: "bg-info/8 text-info-foreground dark:bg-info/16",
|
|
32
|
+
outline: "border-border/60 bg-transparent dark:bg-input/32 [button,a&]:hover:bg-accent/50 dark:[button,a&]:hover:bg-input/48",
|
|
33
|
+
secondary: "bg-secondary text-secondary-foreground [button,a&]:hover:bg-secondary/90",
|
|
34
|
+
success: "bg-success/8 text-success-foreground dark:bg-success/16",
|
|
35
|
+
warning: "bg-warning/8 text-warning-foreground dark:bg-warning/16"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
var Badge = React5.forwardRef(({ className, variant, size, ...props }, ref) => /* @__PURE__ */ jsx("span", { ref, "data-slot": "badge", className: cn(badgeVariants({ variant, size }), className), ...props }));
|
|
41
|
+
Badge.displayName = "Badge";
|
|
42
|
+
var PORTAL_ROOT_ID = "portal-root";
|
|
43
|
+
var PortalContext = React5.createContext({
|
|
44
|
+
layer: "base",
|
|
45
|
+
depth: 0,
|
|
46
|
+
floatingPortalStrategy: "root",
|
|
47
|
+
floatingZIndex: "default"
|
|
48
|
+
});
|
|
49
|
+
function useRootPortalContainer() {
|
|
50
|
+
const [container, setContainer] = React5.useState(null);
|
|
51
|
+
React5.useLayoutEffect(() => {
|
|
52
|
+
const el = document.getElementById(PORTAL_ROOT_ID);
|
|
53
|
+
setContainer(el);
|
|
54
|
+
}, []);
|
|
55
|
+
return container;
|
|
56
|
+
}
|
|
57
|
+
function useFloatingOverlayPortalProps() {
|
|
58
|
+
const rootContainer = useRootPortalContainer();
|
|
59
|
+
const { floatingPortalStrategy, floatingZIndex } = React5.useContext(PortalContext);
|
|
60
|
+
const container = floatingPortalStrategy === "nested" ? void 0 : rootContainer ?? null;
|
|
61
|
+
const zIndexClass = floatingZIndex === "elevated" ? "z-[var(--z-layer-floating-elevated)]" : "z-[var(--z-layer-floating)]";
|
|
62
|
+
return { container, zIndexClass };
|
|
63
|
+
}
|
|
64
|
+
function composeRefs(...refs) {
|
|
65
|
+
return (node) => {
|
|
66
|
+
refs.forEach((ref) => {
|
|
67
|
+
if (typeof ref === "function") {
|
|
68
|
+
ref(node);
|
|
69
|
+
} else if (ref != null) {
|
|
70
|
+
ref.current = node;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function mergeProps(slotProps, childProps) {
|
|
76
|
+
const overrideProps = { ...childProps };
|
|
77
|
+
for (const propName in childProps) {
|
|
78
|
+
if (propName === "ref") continue;
|
|
79
|
+
const slotPropValue = slotProps[propName];
|
|
80
|
+
const childPropValue = childProps[propName];
|
|
81
|
+
if (/^on[A-Z]/.test(propName) && typeof slotPropValue === "function" && typeof childPropValue === "function") {
|
|
82
|
+
overrideProps[propName] = (...args) => {
|
|
83
|
+
childPropValue(...args);
|
|
84
|
+
slotPropValue(...args);
|
|
85
|
+
};
|
|
86
|
+
} else if (propName === "className" && typeof slotPropValue === "string" && typeof childPropValue === "string") {
|
|
87
|
+
overrideProps[propName] = `${slotPropValue} ${childPropValue}`.trim();
|
|
88
|
+
} else if (propName === "style" && typeof slotPropValue === "object" && typeof childPropValue === "object") {
|
|
89
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { ...slotProps, ...overrideProps };
|
|
93
|
+
}
|
|
94
|
+
function mergePropsWithRef(parentProps, childElement) {
|
|
95
|
+
const childProps = childElement.props;
|
|
96
|
+
const parentRef = parentProps.ref;
|
|
97
|
+
const childRef = childProps.ref;
|
|
98
|
+
const mergedProps = mergeProps(parentProps, childProps);
|
|
99
|
+
if (parentRef || childRef) {
|
|
100
|
+
mergedProps.ref = composeRefs(parentRef, childRef);
|
|
101
|
+
}
|
|
102
|
+
return mergedProps;
|
|
103
|
+
}
|
|
104
|
+
function isSlottable(child) {
|
|
105
|
+
return React5.isValidElement(child);
|
|
106
|
+
}
|
|
107
|
+
var Slot = React5.forwardRef((props, forwardedRef) => {
|
|
108
|
+
const { children, ...slotProps } = props;
|
|
109
|
+
if (isSlottable(children)) {
|
|
110
|
+
const childProps = children.props;
|
|
111
|
+
const childRef = childProps.ref;
|
|
112
|
+
return React5.cloneElement(children, {
|
|
113
|
+
...mergeProps(slotProps, childProps),
|
|
114
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (React5.Children.count(children) > 1) {
|
|
118
|
+
const childrenArray = React5.Children.toArray(children);
|
|
119
|
+
const slottableChild = childrenArray.find(
|
|
120
|
+
(child) => React5.isValidElement(child) && child.type === Slottable
|
|
121
|
+
);
|
|
122
|
+
if (slottableChild) {
|
|
123
|
+
const newElement = slottableChild.props.children;
|
|
124
|
+
if (isSlottable(newElement)) {
|
|
125
|
+
const newElementProps = newElement.props;
|
|
126
|
+
const newChildren = childrenArray.map((child) => {
|
|
127
|
+
if (child === slottableChild) {
|
|
128
|
+
return React5.Children.count(newElementProps.children) > 1 ? React5.Children.only(null) : newElementProps.children;
|
|
129
|
+
}
|
|
130
|
+
return child;
|
|
131
|
+
});
|
|
132
|
+
const childRef = newElementProps.ref;
|
|
133
|
+
return React5.cloneElement(newElement, {
|
|
134
|
+
...mergeProps(slotProps, newElementProps),
|
|
135
|
+
ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef,
|
|
136
|
+
children: newChildren
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
142
|
+
});
|
|
143
|
+
Slot.displayName = "Slot";
|
|
144
|
+
function Slottable({ children }) {
|
|
145
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
146
|
+
}
|
|
147
|
+
function Popover({ ...props }) {
|
|
148
|
+
return /* @__PURE__ */ jsx(Popover$1.Root, { "data-slot": "popover", ...props });
|
|
149
|
+
}
|
|
150
|
+
function PopoverTrigger({ asChild, nativeButton, children, ...props }) {
|
|
151
|
+
if (asChild && React5.isValidElement(children)) {
|
|
152
|
+
return /* @__PURE__ */ jsx(
|
|
153
|
+
Popover$1.Trigger,
|
|
154
|
+
{
|
|
155
|
+
"data-slot": "popover-trigger",
|
|
156
|
+
nativeButton: nativeButton ?? true,
|
|
157
|
+
...props,
|
|
158
|
+
render: (triggerProps) => {
|
|
159
|
+
const { nativeButton: _, ...rest } = triggerProps;
|
|
160
|
+
return React5.cloneElement(
|
|
161
|
+
children,
|
|
162
|
+
mergePropsWithRef(rest, children)
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
return /* @__PURE__ */ jsx(Popover$1.Trigger, { "data-slot": "popover-trigger", nativeButton, ...props, children });
|
|
169
|
+
}
|
|
170
|
+
function PopoverContent({
|
|
171
|
+
className,
|
|
172
|
+
align = "center",
|
|
173
|
+
sideOffset = 4,
|
|
174
|
+
showArrow = false,
|
|
175
|
+
side = "bottom",
|
|
176
|
+
children,
|
|
177
|
+
onOpenAutoFocus: _onOpenAutoFocus,
|
|
178
|
+
onCloseAutoFocus: _onCloseAutoFocus,
|
|
179
|
+
onFocusOutside: _onFocusOutside,
|
|
180
|
+
onEscapeKeyDown: _onEscapeKeyDown,
|
|
181
|
+
...props
|
|
182
|
+
}) {
|
|
183
|
+
const { container, zIndexClass } = useFloatingOverlayPortalProps();
|
|
184
|
+
return /* @__PURE__ */ jsx(Popover$1.Portal, { container, children: /* @__PURE__ */ jsx(
|
|
185
|
+
Popover$1.Positioner,
|
|
186
|
+
{
|
|
187
|
+
side,
|
|
188
|
+
align,
|
|
189
|
+
sideOffset,
|
|
190
|
+
className: zIndexClass,
|
|
191
|
+
children: /* @__PURE__ */ jsxs(
|
|
192
|
+
Popover$1.Popup,
|
|
193
|
+
{
|
|
194
|
+
"data-slot": "popover-content",
|
|
195
|
+
className: cn(
|
|
196
|
+
`bg-popover text-popover-foreground data-[open]:animate-in data-[closed]:animate-out
|
|
197
|
+
data-[closed]:fade-out-0 data-[open]:fade-in-0 data-[closed]:zoom-out-95
|
|
198
|
+
data-[open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2
|
|
199
|
+
data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 w-72 rounded-md border p-4
|
|
200
|
+
shadow-md outline-hidden`,
|
|
201
|
+
className
|
|
202
|
+
),
|
|
203
|
+
...props,
|
|
204
|
+
children: [
|
|
205
|
+
children,
|
|
206
|
+
showArrow && /* @__PURE__ */ jsx(Popover$1.Arrow, { className: "fill-popover -my-px drop-shadow-[0_1px_0_var(--border)]" })
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
) });
|
|
212
|
+
}
|
|
213
|
+
function Separator({ className, orientation = "horizontal", decorative: _decorative, ...props }) {
|
|
214
|
+
return /* @__PURE__ */ jsx(
|
|
215
|
+
Separator$1,
|
|
216
|
+
{
|
|
217
|
+
"data-slot": "separator-root",
|
|
218
|
+
orientation,
|
|
219
|
+
className: cn("bg-border shrink-0", orientation === "horizontal" ? "h-px w-full" : "h-full w-px", className),
|
|
220
|
+
...props
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
var multiSelectVariants = cva("m-0.5 inline-flex items-center gap-0.5 rounded-full border px-2 py-1 text-xs", {
|
|
225
|
+
variants: {
|
|
226
|
+
variant: {
|
|
227
|
+
default: "border-foreground/10 text-foreground bg-card",
|
|
228
|
+
secondary: "border-foreground/10 bg-secondary text-secondary-foreground",
|
|
229
|
+
destructive: "border-transparent bg-destructive text-destructive-foreground",
|
|
230
|
+
inverted: "inverted"
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
defaultVariants: {
|
|
234
|
+
variant: "default"
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
function OptionItem({
|
|
238
|
+
option,
|
|
239
|
+
isSelected,
|
|
240
|
+
onSelect,
|
|
241
|
+
highlightedIndex,
|
|
242
|
+
index,
|
|
243
|
+
setHighlightedIndex
|
|
244
|
+
}) {
|
|
245
|
+
const isHighlighted = highlightedIndex === index;
|
|
246
|
+
return /* @__PURE__ */ jsxs(
|
|
247
|
+
"div",
|
|
248
|
+
{
|
|
249
|
+
role: "option",
|
|
250
|
+
"aria-selected": isSelected,
|
|
251
|
+
"aria-disabled": option.disabled,
|
|
252
|
+
"data-highlighted": isHighlighted,
|
|
253
|
+
"data-selected": isSelected,
|
|
254
|
+
"data-disabled": option.disabled,
|
|
255
|
+
tabIndex: -1,
|
|
256
|
+
className: cn(
|
|
257
|
+
"relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
|
|
258
|
+
"data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground",
|
|
259
|
+
"data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50"
|
|
260
|
+
),
|
|
261
|
+
onClick: (e) => {
|
|
262
|
+
e.preventDefault();
|
|
263
|
+
e.stopPropagation();
|
|
264
|
+
if (!option.disabled) {
|
|
265
|
+
onSelect();
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
onMouseEnter: () => setHighlightedIndex(index),
|
|
269
|
+
children: [
|
|
270
|
+
/* @__PURE__ */ jsx(
|
|
271
|
+
"div",
|
|
272
|
+
{
|
|
273
|
+
className: cn(
|
|
274
|
+
"border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",
|
|
275
|
+
isSelected ? "bg-primary text-primary-foreground" : "opacity-60 [&_svg]:invisible"
|
|
276
|
+
),
|
|
277
|
+
"aria-hidden": "true",
|
|
278
|
+
children: /* @__PURE__ */ jsx(CheckIcon, { className: "h-4 w-4" })
|
|
279
|
+
}
|
|
280
|
+
),
|
|
281
|
+
option.icon && /* @__PURE__ */ jsx(option.icon, { className: "text-muted-foreground mr-2 h-4 w-4", "aria-hidden": "true" }),
|
|
282
|
+
/* @__PURE__ */ jsx("span", { children: option.label }),
|
|
283
|
+
option.description && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground ml-2 text-xs", children: option.description })
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
var MultiSelect = React5.forwardRef(
|
|
289
|
+
({
|
|
290
|
+
options,
|
|
291
|
+
onValueChange,
|
|
292
|
+
variant,
|
|
293
|
+
defaultValue = [],
|
|
294
|
+
placeholder = "Select options",
|
|
295
|
+
maxCount = 3,
|
|
296
|
+
className,
|
|
297
|
+
searchable = true,
|
|
298
|
+
emptyIndicator,
|
|
299
|
+
autoSize = false,
|
|
300
|
+
singleLine = false,
|
|
301
|
+
popoverClassName,
|
|
302
|
+
disabled = false,
|
|
303
|
+
responsive,
|
|
304
|
+
minWidth,
|
|
305
|
+
maxWidth,
|
|
306
|
+
dropdownMaxHeight,
|
|
307
|
+
deduplicateOptions = false,
|
|
308
|
+
footerContent,
|
|
309
|
+
resetOnDefaultValueChange = true,
|
|
310
|
+
closeOnSelect = false,
|
|
311
|
+
onClick,
|
|
312
|
+
...props
|
|
313
|
+
}, ref) => {
|
|
314
|
+
const [selectedValues, setSelectedValues] = React5.useState(defaultValue);
|
|
315
|
+
const [isPopoverOpen, setIsPopoverOpen] = React5.useState(false);
|
|
316
|
+
const [searchValue, setSearchValue] = React5.useState("");
|
|
317
|
+
const [highlightedIndex, setHighlightedIndex] = React5.useState(-1);
|
|
318
|
+
const multiSelectId = React5.useId();
|
|
319
|
+
const listboxId = `${multiSelectId}-listbox`;
|
|
320
|
+
const triggerDescriptionId = `${multiSelectId}-description`;
|
|
321
|
+
const selectedCountId = `${multiSelectId}-count`;
|
|
322
|
+
const searchInputId = `${multiSelectId}-search`;
|
|
323
|
+
const searchInputRef = React5.useRef(null);
|
|
324
|
+
const listRef = React5.useRef(null);
|
|
325
|
+
const prevDefaultValueRef = React5.useRef(defaultValue);
|
|
326
|
+
const isGroupedOptions = React5.useCallback(
|
|
327
|
+
(opts) => {
|
|
328
|
+
return opts.length > 0 && "heading" in opts[0];
|
|
329
|
+
},
|
|
330
|
+
[]
|
|
331
|
+
);
|
|
332
|
+
const arraysEqual = React5.useCallback((a, b) => {
|
|
333
|
+
if (a.length !== b.length) return false;
|
|
334
|
+
const sortedA = [...a].sort();
|
|
335
|
+
const sortedB = [...b].sort();
|
|
336
|
+
return sortedA.every((val, index) => val === sortedB[index]);
|
|
337
|
+
}, []);
|
|
338
|
+
const resetToDefault = React5.useCallback(() => {
|
|
339
|
+
setSelectedValues(defaultValue);
|
|
340
|
+
setIsPopoverOpen(false);
|
|
341
|
+
setSearchValue("");
|
|
342
|
+
onValueChange(defaultValue);
|
|
343
|
+
}, [defaultValue, onValueChange]);
|
|
344
|
+
const buttonRef = React5.useRef(null);
|
|
345
|
+
React5.useImperativeHandle(
|
|
346
|
+
ref,
|
|
347
|
+
() => ({
|
|
348
|
+
reset: resetToDefault,
|
|
349
|
+
getSelectedValues: () => selectedValues,
|
|
350
|
+
setSelectedValues: (values) => {
|
|
351
|
+
setSelectedValues(values);
|
|
352
|
+
onValueChange(values);
|
|
353
|
+
},
|
|
354
|
+
clear: () => {
|
|
355
|
+
setSelectedValues([]);
|
|
356
|
+
onValueChange([]);
|
|
357
|
+
},
|
|
358
|
+
focus: () => {
|
|
359
|
+
if (buttonRef.current) {
|
|
360
|
+
buttonRef.current.focus();
|
|
361
|
+
const originalOutline = buttonRef.current.style.outline;
|
|
362
|
+
const originalOutlineOffset = buttonRef.current.style.outlineOffset;
|
|
363
|
+
buttonRef.current.style.outline = "2px solid hsl(var(--ring))";
|
|
364
|
+
buttonRef.current.style.outlineOffset = "2px";
|
|
365
|
+
setTimeout(() => {
|
|
366
|
+
if (buttonRef.current) {
|
|
367
|
+
buttonRef.current.style.outline = originalOutline;
|
|
368
|
+
buttonRef.current.style.outlineOffset = originalOutlineOffset;
|
|
369
|
+
}
|
|
370
|
+
}, 1e3);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}),
|
|
374
|
+
[resetToDefault, selectedValues, onValueChange]
|
|
375
|
+
);
|
|
376
|
+
const [screenSize, setScreenSize] = React5.useState("desktop");
|
|
377
|
+
React5.useEffect(() => {
|
|
378
|
+
if (typeof window === "undefined") return;
|
|
379
|
+
const handleResize = () => {
|
|
380
|
+
const width = window.innerWidth;
|
|
381
|
+
if (width < 640) {
|
|
382
|
+
setScreenSize("mobile");
|
|
383
|
+
} else if (width < 1024) {
|
|
384
|
+
setScreenSize("tablet");
|
|
385
|
+
} else {
|
|
386
|
+
setScreenSize("desktop");
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
handleResize();
|
|
390
|
+
window.addEventListener("resize", handleResize);
|
|
391
|
+
return () => {
|
|
392
|
+
if (typeof window !== "undefined") {
|
|
393
|
+
window.removeEventListener("resize", handleResize);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}, []);
|
|
397
|
+
const getResponsiveSettings = () => {
|
|
398
|
+
if (!responsive) {
|
|
399
|
+
return {
|
|
400
|
+
maxCount,
|
|
401
|
+
hideIcons: false,
|
|
402
|
+
compactMode: false
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (responsive === true) {
|
|
406
|
+
const defaultResponsive = {
|
|
407
|
+
mobile: { maxCount: 2, hideIcons: false, compactMode: true },
|
|
408
|
+
tablet: { maxCount: 4, hideIcons: false, compactMode: false },
|
|
409
|
+
desktop: { maxCount: 6, hideIcons: false, compactMode: false }
|
|
410
|
+
};
|
|
411
|
+
const currentSettings2 = defaultResponsive[screenSize];
|
|
412
|
+
return {
|
|
413
|
+
maxCount: currentSettings2?.maxCount ?? maxCount,
|
|
414
|
+
hideIcons: currentSettings2?.hideIcons ?? false,
|
|
415
|
+
compactMode: currentSettings2?.compactMode ?? false
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
const currentSettings = responsive[screenSize];
|
|
419
|
+
return {
|
|
420
|
+
maxCount: currentSettings?.maxCount ?? maxCount,
|
|
421
|
+
hideIcons: currentSettings?.hideIcons ?? false,
|
|
422
|
+
compactMode: currentSettings?.compactMode ?? false
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
const responsiveSettings = getResponsiveSettings();
|
|
426
|
+
const getAllOptions = React5.useCallback(() => {
|
|
427
|
+
if (options.length === 0) return [];
|
|
428
|
+
let allOptions;
|
|
429
|
+
if (isGroupedOptions(options)) {
|
|
430
|
+
allOptions = options.flatMap((group) => group.options);
|
|
431
|
+
} else {
|
|
432
|
+
allOptions = options;
|
|
433
|
+
}
|
|
434
|
+
const valueSet = /* @__PURE__ */ new Set();
|
|
435
|
+
const duplicates = [];
|
|
436
|
+
const uniqueOptions = [];
|
|
437
|
+
allOptions.forEach((option) => {
|
|
438
|
+
if (valueSet.has(option.value)) {
|
|
439
|
+
duplicates.push(option.value);
|
|
440
|
+
if (!deduplicateOptions) {
|
|
441
|
+
uniqueOptions.push(option);
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
valueSet.add(option.value);
|
|
445
|
+
uniqueOptions.push(option);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
if (process.env.NODE_ENV === "development" && duplicates.length > 0) {
|
|
449
|
+
const action = deduplicateOptions ? "automatically removed" : "detected";
|
|
450
|
+
console.warn(
|
|
451
|
+
`MultiSelect: Duplicate option values ${action}: ${duplicates.join(", ")}. ${deduplicateOptions ? "Duplicates have been removed automatically." : "This may cause unexpected behavior. Consider setting 'deduplicateOptions={true}' or ensure all option values are unique."}`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
return deduplicateOptions ? uniqueOptions : allOptions;
|
|
455
|
+
}, [options, deduplicateOptions, isGroupedOptions]);
|
|
456
|
+
const getOptionByValue = React5.useCallback(
|
|
457
|
+
(value) => {
|
|
458
|
+
const option = getAllOptions().find((option2) => option2.value === value);
|
|
459
|
+
if (!option && process.env.NODE_ENV === "development") {
|
|
460
|
+
console.warn(`MultiSelect: Option with value "${value}" not found in options list`);
|
|
461
|
+
}
|
|
462
|
+
return option;
|
|
463
|
+
},
|
|
464
|
+
[getAllOptions]
|
|
465
|
+
);
|
|
466
|
+
const filteredOptions = React5.useMemo(() => {
|
|
467
|
+
if (!searchable || !searchValue) return options;
|
|
468
|
+
if (options.length === 0) return [];
|
|
469
|
+
if (isGroupedOptions(options)) {
|
|
470
|
+
return options.map((group) => ({
|
|
471
|
+
...group,
|
|
472
|
+
options: group.options.filter(
|
|
473
|
+
(option) => option.label.toLowerCase().includes(searchValue.toLowerCase()) || option.value.toLowerCase().includes(searchValue.toLowerCase())
|
|
474
|
+
)
|
|
475
|
+
})).filter((group) => group.options.length > 0);
|
|
476
|
+
}
|
|
477
|
+
return options.filter(
|
|
478
|
+
(option) => option.label.toLowerCase().includes(searchValue.toLowerCase()) || option.value.toLowerCase().includes(searchValue.toLowerCase())
|
|
479
|
+
);
|
|
480
|
+
}, [options, searchValue, searchable, isGroupedOptions]);
|
|
481
|
+
const flatFilteredOptions = React5.useMemo(() => {
|
|
482
|
+
if (isGroupedOptions(filteredOptions)) {
|
|
483
|
+
return filteredOptions.flatMap((group) => group.options);
|
|
484
|
+
}
|
|
485
|
+
return filteredOptions;
|
|
486
|
+
}, [filteredOptions, isGroupedOptions]);
|
|
487
|
+
const toggleOption = React5.useCallback(
|
|
488
|
+
(optionValue) => {
|
|
489
|
+
if (disabled) return;
|
|
490
|
+
const option = getOptionByValue(optionValue);
|
|
491
|
+
if (option?.disabled) return;
|
|
492
|
+
const newSelectedValues = selectedValues.includes(optionValue) ? selectedValues.filter((value) => value !== optionValue) : [...selectedValues, optionValue];
|
|
493
|
+
setSelectedValues(newSelectedValues);
|
|
494
|
+
onValueChange(newSelectedValues);
|
|
495
|
+
if (closeOnSelect) {
|
|
496
|
+
setIsPopoverOpen(false);
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
[disabled, getOptionByValue, selectedValues, onValueChange, closeOnSelect]
|
|
500
|
+
);
|
|
501
|
+
const handleClear = () => {
|
|
502
|
+
if (disabled) return;
|
|
503
|
+
setSelectedValues([]);
|
|
504
|
+
onValueChange([]);
|
|
505
|
+
};
|
|
506
|
+
const handleTogglePopover = () => {
|
|
507
|
+
if (disabled) return;
|
|
508
|
+
setIsPopoverOpen((prev) => !prev);
|
|
509
|
+
};
|
|
510
|
+
const clearExtraOptions = () => {
|
|
511
|
+
if (disabled) return;
|
|
512
|
+
const newSelectedValues = selectedValues.slice(0, responsiveSettings.maxCount);
|
|
513
|
+
setSelectedValues(newSelectedValues);
|
|
514
|
+
onValueChange(newSelectedValues);
|
|
515
|
+
};
|
|
516
|
+
const handleKeyDown = React5.useCallback(
|
|
517
|
+
(event) => {
|
|
518
|
+
const optionsCount = flatFilteredOptions.length;
|
|
519
|
+
if (optionsCount === 0) return;
|
|
520
|
+
switch (event.key) {
|
|
521
|
+
case "ArrowDown":
|
|
522
|
+
event.preventDefault();
|
|
523
|
+
setHighlightedIndex((prev) => prev < optionsCount - 1 ? prev + 1 : 0);
|
|
524
|
+
break;
|
|
525
|
+
case "ArrowUp":
|
|
526
|
+
event.preventDefault();
|
|
527
|
+
setHighlightedIndex((prev) => prev > 0 ? prev - 1 : optionsCount - 1);
|
|
528
|
+
break;
|
|
529
|
+
case "Enter":
|
|
530
|
+
event.preventDefault();
|
|
531
|
+
if (highlightedIndex >= 0 && highlightedIndex < optionsCount) {
|
|
532
|
+
const option = flatFilteredOptions[highlightedIndex];
|
|
533
|
+
if (option && !option.disabled) {
|
|
534
|
+
toggleOption(option.value);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
break;
|
|
538
|
+
case "Escape":
|
|
539
|
+
event.preventDefault();
|
|
540
|
+
setIsPopoverOpen(false);
|
|
541
|
+
break;
|
|
542
|
+
case "Backspace":
|
|
543
|
+
if (!searchValue && selectedValues.length > 0) {
|
|
544
|
+
const newSelectedValues = [...selectedValues];
|
|
545
|
+
newSelectedValues.pop();
|
|
546
|
+
setSelectedValues(newSelectedValues);
|
|
547
|
+
onValueChange(newSelectedValues);
|
|
548
|
+
}
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
[flatFilteredOptions, highlightedIndex, toggleOption, searchValue, selectedValues, onValueChange]
|
|
553
|
+
);
|
|
554
|
+
React5.useEffect(() => {
|
|
555
|
+
if (!resetOnDefaultValueChange) return;
|
|
556
|
+
const prevDefaultValue = prevDefaultValueRef.current;
|
|
557
|
+
if (!arraysEqual(prevDefaultValue, defaultValue)) {
|
|
558
|
+
if (!arraysEqual(selectedValues, defaultValue)) {
|
|
559
|
+
setSelectedValues(defaultValue);
|
|
560
|
+
}
|
|
561
|
+
prevDefaultValueRef.current = [...defaultValue];
|
|
562
|
+
}
|
|
563
|
+
}, [defaultValue, selectedValues, arraysEqual, resetOnDefaultValueChange]);
|
|
564
|
+
const getWidthConstraints = () => {
|
|
565
|
+
const defaultMinWidth = screenSize === "mobile" ? "0px" : "200px";
|
|
566
|
+
const effectiveMinWidth = minWidth || defaultMinWidth;
|
|
567
|
+
const effectiveMaxWidth = maxWidth || "100%";
|
|
568
|
+
return {
|
|
569
|
+
minWidth: effectiveMinWidth,
|
|
570
|
+
maxWidth: effectiveMaxWidth,
|
|
571
|
+
width: autoSize ? "auto" : "100%"
|
|
572
|
+
};
|
|
573
|
+
};
|
|
574
|
+
const widthConstraints = getWidthConstraints();
|
|
575
|
+
const effectiveDropdownMaxHeight = React5.useMemo(() => {
|
|
576
|
+
if (dropdownMaxHeight) return dropdownMaxHeight;
|
|
577
|
+
return screenSize === "mobile" ? "70vh" : "60vh";
|
|
578
|
+
}, [dropdownMaxHeight, screenSize]);
|
|
579
|
+
React5.useEffect(() => {
|
|
580
|
+
if (!isPopoverOpen) {
|
|
581
|
+
setSearchValue("");
|
|
582
|
+
setHighlightedIndex(-1);
|
|
583
|
+
}
|
|
584
|
+
}, [isPopoverOpen]);
|
|
585
|
+
React5.useEffect(() => {
|
|
586
|
+
if (isPopoverOpen && searchable && searchInputRef.current) {
|
|
587
|
+
const timer = setTimeout(() => {
|
|
588
|
+
searchInputRef.current?.focus();
|
|
589
|
+
}, 0);
|
|
590
|
+
return () => clearTimeout(timer);
|
|
591
|
+
}
|
|
592
|
+
}, [isPopoverOpen, searchable]);
|
|
593
|
+
React5.useEffect(() => {
|
|
594
|
+
setHighlightedIndex(flatFilteredOptions.length > 0 ? 0 : -1);
|
|
595
|
+
}, [searchValue, flatFilteredOptions.length]);
|
|
596
|
+
const totalFilteredCount = React5.useMemo(() => {
|
|
597
|
+
if (isGroupedOptions(filteredOptions)) {
|
|
598
|
+
return filteredOptions.reduce((acc, group) => acc + group.options.length, 0);
|
|
599
|
+
}
|
|
600
|
+
return filteredOptions.length;
|
|
601
|
+
}, [filteredOptions, isGroupedOptions]);
|
|
602
|
+
let optionIndex = 0;
|
|
603
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Popover, { open: isPopoverOpen, onOpenChange: setIsPopoverOpen, children: [
|
|
604
|
+
/* @__PURE__ */ jsx("div", { id: triggerDescriptionId, className: "sr-only", children: "Multi-select dropdown. Use arrow keys to navigate, Enter to select, and Escape to close." }),
|
|
605
|
+
/* @__PURE__ */ jsx("div", { id: selectedCountId, className: "sr-only", "aria-live": "polite", children: selectedValues.length === 0 ? "No options selected" : `${selectedValues.length} option${selectedValues.length === 1 ? "" : "s"} selected: ${selectedValues.map((value) => getOptionByValue(value)?.label).filter(Boolean).join(", ")}` }),
|
|
606
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
607
|
+
"button",
|
|
608
|
+
{
|
|
609
|
+
ref: buttonRef,
|
|
610
|
+
type: "button",
|
|
611
|
+
...props,
|
|
612
|
+
onClick: (event) => {
|
|
613
|
+
if (disabled) return;
|
|
614
|
+
onClick?.(event);
|
|
615
|
+
handleTogglePopover();
|
|
616
|
+
},
|
|
617
|
+
disabled,
|
|
618
|
+
role: "combobox",
|
|
619
|
+
"aria-expanded": isPopoverOpen,
|
|
620
|
+
"aria-haspopup": "listbox",
|
|
621
|
+
"aria-controls": isPopoverOpen ? listboxId : void 0,
|
|
622
|
+
"aria-describedby": `${triggerDescriptionId} ${selectedCountId}`,
|
|
623
|
+
"aria-label": `Multi-select: ${selectedValues.length} of ${getAllOptions().length} options selected. ${placeholder}`,
|
|
624
|
+
className: cn(
|
|
625
|
+
`border-input/70 focus-visible:border-primary/60 focus-visible:ring-primary/20 flex items-center
|
|
626
|
+
justify-between rounded-md border bg-transparent pr-1 pl-2 shadow-xs transition-[color,box-shadow]
|
|
627
|
+
outline-none focus-visible:ring-[3px] active:scale-100 disabled:pointer-events-none disabled:opacity-50`,
|
|
628
|
+
singleLine ? "h-8 min-h-8 py-0.5 text-xs" : "h-auto min-h-10 py-2 text-sm",
|
|
629
|
+
autoSize && "w-auto",
|
|
630
|
+
!autoSize && "w-full",
|
|
631
|
+
responsiveSettings.compactMode && "min-h-9 py-1.5 text-xs",
|
|
632
|
+
className
|
|
633
|
+
),
|
|
634
|
+
style: {
|
|
635
|
+
minWidth: widthConstraints.minWidth,
|
|
636
|
+
maxWidth: widthConstraints.maxWidth,
|
|
637
|
+
width: widthConstraints.width
|
|
638
|
+
},
|
|
639
|
+
children: selectedValues.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between", children: [
|
|
640
|
+
/* @__PURE__ */ jsxs(
|
|
641
|
+
"div",
|
|
642
|
+
{
|
|
643
|
+
className: cn(
|
|
644
|
+
"flex items-center gap-1",
|
|
645
|
+
singleLine ? "multiselect-singleline-scroll overflow-x-auto" : "flex-wrap",
|
|
646
|
+
responsiveSettings.compactMode && "gap-0.5"
|
|
647
|
+
),
|
|
648
|
+
children: [
|
|
649
|
+
selectedValues.slice(0, responsiveSettings.maxCount).map((value) => {
|
|
650
|
+
const option = getOptionByValue(value);
|
|
651
|
+
const IconComponent = option?.icon;
|
|
652
|
+
const customStyle = option?.style;
|
|
653
|
+
if (!option) {
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
const badgeStyle = {
|
|
657
|
+
...customStyle?.badgeColor && {
|
|
658
|
+
backgroundColor: customStyle.badgeColor
|
|
659
|
+
},
|
|
660
|
+
...customStyle?.gradient && {
|
|
661
|
+
background: customStyle.gradient,
|
|
662
|
+
color: "white"
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
return /* @__PURE__ */ jsxs(
|
|
666
|
+
Badge,
|
|
667
|
+
{
|
|
668
|
+
className: cn(
|
|
669
|
+
multiSelectVariants({ variant }),
|
|
670
|
+
customStyle?.gradient && "border-transparent text-white",
|
|
671
|
+
responsiveSettings.compactMode && "px-1.5 py-0.5 text-xs",
|
|
672
|
+
singleLine && "py-0.5",
|
|
673
|
+
screenSize === "mobile" && "max-w-[120px] truncate",
|
|
674
|
+
singleLine && "flex-shrink-0 whitespace-nowrap",
|
|
675
|
+
"[&>svg]:pointer-events-auto"
|
|
676
|
+
),
|
|
677
|
+
style: badgeStyle,
|
|
678
|
+
children: [
|
|
679
|
+
IconComponent && !responsiveSettings.hideIcons && /* @__PURE__ */ jsx(
|
|
680
|
+
IconComponent,
|
|
681
|
+
{
|
|
682
|
+
className: cn(
|
|
683
|
+
"mr-2 h-4 w-4",
|
|
684
|
+
responsiveSettings.compactMode && "mr-1 h-3 w-3",
|
|
685
|
+
customStyle?.iconColor && "text-current"
|
|
686
|
+
),
|
|
687
|
+
...customStyle?.iconColor && {
|
|
688
|
+
style: { color: customStyle.iconColor }
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
),
|
|
692
|
+
/* @__PURE__ */ jsx("span", { className: cn(screenSize === "mobile" && "truncate"), children: option.label }),
|
|
693
|
+
/* @__PURE__ */ jsx(
|
|
694
|
+
"div",
|
|
695
|
+
{
|
|
696
|
+
role: "button",
|
|
697
|
+
tabIndex: 0,
|
|
698
|
+
onClick: (event) => {
|
|
699
|
+
event.stopPropagation();
|
|
700
|
+
toggleOption(value);
|
|
701
|
+
},
|
|
702
|
+
onKeyDown: (event) => {
|
|
703
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
704
|
+
event.preventDefault();
|
|
705
|
+
event.stopPropagation();
|
|
706
|
+
toggleOption(value);
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
"aria-label": `Remove ${option.label} from selection`,
|
|
710
|
+
className: "-m-0.5 ml-2 h-4 w-4 cursor-pointer rounded-sm p-0.5 hover:bg-white/20 focus:ring-1 focus:ring-white/50 focus:outline-none",
|
|
711
|
+
children: /* @__PURE__ */ jsx(XCircle, { className: cn("h-3 w-3", responsiveSettings.compactMode && "h-2.5 w-2.5") })
|
|
712
|
+
}
|
|
713
|
+
)
|
|
714
|
+
]
|
|
715
|
+
},
|
|
716
|
+
value
|
|
717
|
+
);
|
|
718
|
+
}).filter(Boolean),
|
|
719
|
+
selectedValues.length > responsiveSettings.maxCount && /* @__PURE__ */ jsxs(
|
|
720
|
+
Badge,
|
|
721
|
+
{
|
|
722
|
+
className: cn(
|
|
723
|
+
"text-foreground border-foreground/10 bg-transparent",
|
|
724
|
+
multiSelectVariants({ variant }),
|
|
725
|
+
responsiveSettings.compactMode && "px-1.5 py-0.5 text-xs",
|
|
726
|
+
singleLine && "flex-shrink-0 whitespace-nowrap",
|
|
727
|
+
"[&>svg]:pointer-events-auto"
|
|
728
|
+
),
|
|
729
|
+
children: [
|
|
730
|
+
`+ ${selectedValues.length - responsiveSettings.maxCount} more`,
|
|
731
|
+
/* @__PURE__ */ jsx(
|
|
732
|
+
"div",
|
|
733
|
+
{
|
|
734
|
+
role: "button",
|
|
735
|
+
tabIndex: 0,
|
|
736
|
+
onClick: (event) => {
|
|
737
|
+
event.stopPropagation();
|
|
738
|
+
clearExtraOptions();
|
|
739
|
+
},
|
|
740
|
+
onKeyDown: (event) => {
|
|
741
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
742
|
+
event.preventDefault();
|
|
743
|
+
event.stopPropagation();
|
|
744
|
+
clearExtraOptions();
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
"aria-label": "Clear extra selected options",
|
|
748
|
+
className: "-m-0.5 ml-2 h-4 w-4 cursor-pointer rounded-sm p-0.5 hover:bg-white/20 focus:ring-1\n focus:ring-white/50 focus:outline-none",
|
|
749
|
+
children: /* @__PURE__ */ jsx(XCircle, { className: cn("h-3 w-3", responsiveSettings.compactMode && "h-2.5 w-2.5") })
|
|
750
|
+
}
|
|
751
|
+
)
|
|
752
|
+
]
|
|
753
|
+
}
|
|
754
|
+
)
|
|
755
|
+
]
|
|
756
|
+
}
|
|
757
|
+
),
|
|
758
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
759
|
+
/* @__PURE__ */ jsx(
|
|
760
|
+
"div",
|
|
761
|
+
{
|
|
762
|
+
role: "button",
|
|
763
|
+
tabIndex: 0,
|
|
764
|
+
onClick: (event) => {
|
|
765
|
+
event.stopPropagation();
|
|
766
|
+
handleClear();
|
|
767
|
+
},
|
|
768
|
+
onKeyDown: (event) => {
|
|
769
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
770
|
+
event.preventDefault();
|
|
771
|
+
event.stopPropagation();
|
|
772
|
+
handleClear();
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
"aria-label": `Clear all ${selectedValues.length} selected options`,
|
|
776
|
+
className: "text-muted-foreground hover:text-foreground focus:ring-ring mx-2 flex h-4 w-4\n cursor-pointer items-center justify-center rounded-sm focus:ring-2 focus:ring-offset-1\n focus:outline-none",
|
|
777
|
+
children: /* @__PURE__ */ jsx(XIcon, { className: "h-4 w-4" })
|
|
778
|
+
}
|
|
779
|
+
),
|
|
780
|
+
/* @__PURE__ */ jsx(Separator, { orientation: "vertical", className: "flex h-full min-h-6" }),
|
|
781
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground mx-1 h-4 cursor-pointer" })
|
|
782
|
+
] })
|
|
783
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full items-center justify-between", children: [
|
|
784
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground mx-1 text-sm", children: placeholder }),
|
|
785
|
+
/* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground mx-1 h-4 cursor-pointer" })
|
|
786
|
+
] })
|
|
787
|
+
}
|
|
788
|
+
) }),
|
|
789
|
+
/* @__PURE__ */ jsx(
|
|
790
|
+
PopoverContent,
|
|
791
|
+
{
|
|
792
|
+
id: listboxId,
|
|
793
|
+
"aria-label": "Available options",
|
|
794
|
+
className: cn("w-(--anchor-width) overflow-hidden p-0", popoverClassName),
|
|
795
|
+
style: {
|
|
796
|
+
minWidth: widthConstraints.minWidth,
|
|
797
|
+
maxWidth: widthConstraints.maxWidth,
|
|
798
|
+
width: widthConstraints.width === "auto" ? "auto" : void 0,
|
|
799
|
+
maxHeight: effectiveDropdownMaxHeight,
|
|
800
|
+
touchAction: "manipulation"
|
|
801
|
+
},
|
|
802
|
+
align: "start",
|
|
803
|
+
onEscapeKeyDown: () => setIsPopoverOpen(false),
|
|
804
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex h-full max-h-[inherit] flex-col", onKeyDown: handleKeyDown, children: [
|
|
805
|
+
searchable && /* @__PURE__ */ jsxs("div", { className: "flex items-center border-b px-3", children: [
|
|
806
|
+
/* @__PURE__ */ jsx(SearchIcon, { className: "text-muted-foreground mr-2 h-4 w-4 shrink-0 opacity-50" }),
|
|
807
|
+
/* @__PURE__ */ jsx(
|
|
808
|
+
"input",
|
|
809
|
+
{
|
|
810
|
+
ref: searchInputRef,
|
|
811
|
+
id: searchInputId,
|
|
812
|
+
type: "text",
|
|
813
|
+
placeholder: "Search options...",
|
|
814
|
+
value: searchValue,
|
|
815
|
+
onChange: (e) => setSearchValue(e.target.value),
|
|
816
|
+
"aria-label": "Search through available options",
|
|
817
|
+
className: "placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-none disabled:cursor-not-allowed disabled:opacity-50"
|
|
818
|
+
}
|
|
819
|
+
)
|
|
820
|
+
] }),
|
|
821
|
+
/* @__PURE__ */ jsx(
|
|
822
|
+
"div",
|
|
823
|
+
{
|
|
824
|
+
ref: listRef,
|
|
825
|
+
role: "listbox",
|
|
826
|
+
"aria-multiselectable": "true",
|
|
827
|
+
className: "multiselect-scrollbar scrollbar-neutral-thin overscroll-contain min-h-0 flex-1 overflow-y-auto p-1",
|
|
828
|
+
children: totalFilteredCount === 0 ? /* @__PURE__ */ jsx("div", { className: "text-muted-foreground py-6 text-center text-sm", children: emptyIndicator || "No results found." }) : isGroupedOptions(filteredOptions) ? filteredOptions.map((group) => /* @__PURE__ */ jsxs("div", { role: "group", "aria-labelledby": `group-${group.heading}`, children: [
|
|
829
|
+
/* @__PURE__ */ jsx(
|
|
830
|
+
"div",
|
|
831
|
+
{
|
|
832
|
+
id: `group-${group.heading}`,
|
|
833
|
+
className: "text-muted-foreground px-2 py-1.5 text-xs font-medium",
|
|
834
|
+
children: group.heading
|
|
835
|
+
}
|
|
836
|
+
),
|
|
837
|
+
group.options.map((option) => {
|
|
838
|
+
const currentIndex = optionIndex++;
|
|
839
|
+
const isSelected = selectedValues.includes(option.value);
|
|
840
|
+
return /* @__PURE__ */ jsx(
|
|
841
|
+
OptionItem,
|
|
842
|
+
{
|
|
843
|
+
option,
|
|
844
|
+
isSelected,
|
|
845
|
+
onSelect: () => toggleOption(option.value),
|
|
846
|
+
highlightedIndex,
|
|
847
|
+
index: currentIndex,
|
|
848
|
+
setHighlightedIndex
|
|
849
|
+
},
|
|
850
|
+
option.value
|
|
851
|
+
);
|
|
852
|
+
})
|
|
853
|
+
] }, group.heading)) : filteredOptions.map((option) => {
|
|
854
|
+
const currentIndex = optionIndex++;
|
|
855
|
+
const isSelected = selectedValues.includes(option.value);
|
|
856
|
+
return /* @__PURE__ */ jsx(
|
|
857
|
+
OptionItem,
|
|
858
|
+
{
|
|
859
|
+
option,
|
|
860
|
+
isSelected,
|
|
861
|
+
onSelect: () => toggleOption(option.value),
|
|
862
|
+
highlightedIndex,
|
|
863
|
+
index: currentIndex,
|
|
864
|
+
setHighlightedIndex
|
|
865
|
+
},
|
|
866
|
+
option.value
|
|
867
|
+
);
|
|
868
|
+
})
|
|
869
|
+
}
|
|
870
|
+
),
|
|
871
|
+
footerContent && /* @__PURE__ */ jsx("div", { className: "border-t p-1", children: footerContent })
|
|
872
|
+
] })
|
|
873
|
+
}
|
|
874
|
+
)
|
|
875
|
+
] }) });
|
|
876
|
+
}
|
|
877
|
+
);
|
|
878
|
+
MultiSelect.displayName = "MultiSelect";
|
|
879
|
+
|
|
880
|
+
export { MultiSelect };
|
|
881
|
+
//# sourceMappingURL=multi-select.js.map
|
|
882
|
+
//# sourceMappingURL=multi-select.js.map
|