@trsys-tech/matrix-library 1.1.1-canary.0 → 1.1.3
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/accordion.es.js +21 -19
- package/dist/accordion.es.js.map +1 -1
- package/dist/avatar.es.js +19 -19
- package/dist/avatar.es.js.map +1 -1
- package/dist/breadcrumb.es.js +7 -7
- package/dist/breadcrumb.es.js.map +1 -1
- package/dist/calendar.es.js +40 -33
- package/dist/calendar.es.js.map +1 -1
- package/dist/chip.es.js +28 -22
- package/dist/chip.es.js.map +1 -1
- package/dist/command.es.js +35 -32
- package/dist/command.es.js.map +1 -1
- package/dist/components/accordion/Accordion.d.ts.map +1 -1
- package/dist/components/chip/Chip.d.ts.map +1 -1
- package/dist/components/command/Command.d.ts.map +1 -1
- package/dist/components/date-picker/DesktopDatePicker.d.ts +1 -1
- package/dist/components/date-picker/DesktopDatePicker.d.ts.map +1 -1
- package/dist/components/date-picker/DesktopTimePicker.d.ts +2 -2
- package/dist/components/date-picker/DesktopTimePicker.d.ts.map +1 -1
- package/dist/components/date-picker/TimePickerContent.d.ts.map +1 -1
- package/dist/components/date-picker/calendar.d.ts.map +1 -1
- package/dist/components/gantt-chart/GanttChart.d.ts +104 -0
- package/dist/components/gantt-chart/GanttChart.d.ts.map +1 -0
- package/dist/components/gantt-chart/GanttToolbar.d.ts +14 -0
- package/dist/components/gantt-chart/GanttToolbar.d.ts.map +1 -0
- package/dist/components/gantt-chart/gantt-chart.types.d.ts +45 -0
- package/dist/components/gantt-chart/gantt-chart.types.d.ts.map +1 -0
- package/dist/components/gantt-chart/gantt-chart.utils.d.ts +34 -0
- package/dist/components/gantt-chart/gantt-chart.utils.d.ts.map +1 -0
- package/dist/components/multi-select/MultiSelect.d.ts +0 -8
- package/dist/components/multi-select/MultiSelect.d.ts.map +1 -1
- package/dist/components/rating/Rating.d.ts +1 -0
- package/dist/components/rating/Rating.d.ts.map +1 -1
- package/dist/components/sidebar/Sidebar.d.ts +1 -1
- package/dist/components/sidebar/Sidebar.d.ts.map +1 -1
- package/dist/components/tabs/Tabs.d.ts +5 -3
- package/dist/components/tabs/Tabs.d.ts.map +1 -1
- package/dist/components/timeline/Timeline.d.ts +40 -0
- package/dist/components/timeline/Timeline.d.ts.map +1 -0
- package/dist/components/tooltip/Tooltip.d.ts.map +1 -1
- package/dist/desktopdatepicker.es.js +2 -2
- package/dist/desktopdatepicker.es.js.map +1 -1
- package/dist/desktoptimepicker.es.js.map +1 -1
- package/dist/duration.es.js +1 -1
- package/dist/duration.es.js.map +1 -1
- package/dist/gantt-chart.es.js +93 -0
- package/dist/gantt-chart.es.js.map +1 -0
- package/dist/ganttchart.es.js +337 -0
- package/dist/ganttchart.es.js.map +1 -0
- package/dist/gantttoolbar.es.js +49 -0
- package/dist/gantttoolbar.es.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +191 -187
- package/dist/index.es.js.map +1 -1
- package/dist/lib/hooks/use-mobile.d.ts.map +1 -1
- package/dist/multiselect.es.js +121 -130
- package/dist/multiselect.es.js.map +1 -1
- package/dist/rating.es.js +47 -50
- package/dist/rating.es.js.map +1 -1
- package/dist/sidebar.es.js +46 -48
- package/dist/sidebar.es.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/switch.es.js +5 -5
- package/dist/switch.es.js.map +1 -1
- package/dist/tabs.es.js +25 -26
- package/dist/tabs.es.js.map +1 -1
- package/dist/textfield.es.js +18 -18
- package/dist/textfield.es.js.map +1 -1
- package/dist/timeline.es.js +182 -0
- package/dist/timeline.es.js.map +1 -0
- package/dist/timepickercontent.es.js +39 -42
- package/dist/timepickercontent.es.js.map +1 -1
- package/dist/tooltip.es.js +15 -13
- package/dist/tooltip.es.js.map +1 -1
- package/dist/use-mobile.es.js +15 -10
- package/dist/use-mobile.es.js.map +1 -1
- package/package.json +7 -1
package/dist/multiselect.es.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as o, jsx as r, Fragment as j } from "react/jsx-runtime";
|
|
2
2
|
import * as a from "react";
|
|
3
|
-
import { tv as
|
|
4
|
-
import { XMark as
|
|
3
|
+
import { tv as te } from "tailwind-variants";
|
|
4
|
+
import { XMark as A, CircleXmark as re, ChevronDown as me, Check as D } from "@trsys-tech/matrix-icons";
|
|
5
5
|
import { cn as p } from "./utils.es.js";
|
|
6
6
|
import { Status as T } from "./status.es.js";
|
|
7
|
-
import { Button as
|
|
8
|
-
import { Separator as
|
|
9
|
-
import { Popover as oe, PopoverTrigger as
|
|
10
|
-
import { Command as
|
|
11
|
-
const
|
|
7
|
+
import { Button as ae } from "./button.es.js";
|
|
8
|
+
import { Separator as se } from "./separator.es.js";
|
|
9
|
+
import { Popover as oe, PopoverTrigger as le, PopoverContent as ne } from "./popover.es.js";
|
|
10
|
+
import { Command as ce, CommandInput as ie, CommandList as xe, CommandEmpty as de, CommandGroup as pe, CommandItem as O } from "./command.es.js";
|
|
11
|
+
const R = te({
|
|
12
12
|
base: "mtx-flex mtx-gap-1 mtx-items-center mtx-py-0.5 mtx-px-2 mtx-rounded-xl",
|
|
13
13
|
variants: {
|
|
14
14
|
variant: {
|
|
@@ -21,204 +21,195 @@ const K = me({
|
|
|
21
21
|
defaultVariants: {
|
|
22
22
|
variant: "default"
|
|
23
23
|
}
|
|
24
|
-
}),
|
|
25
|
-
options:
|
|
26
|
-
onValueChange:
|
|
27
|
-
value:
|
|
28
|
-
variant:
|
|
29
|
-
disabled:
|
|
30
|
-
defaultValue:
|
|
31
|
-
placeholder:
|
|
32
|
-
maxCount:
|
|
33
|
-
modalPopover:
|
|
24
|
+
}), ue = ({
|
|
25
|
+
options: v,
|
|
26
|
+
onValueChange: l,
|
|
27
|
+
value: w,
|
|
28
|
+
variant: S,
|
|
29
|
+
disabled: N,
|
|
30
|
+
defaultValue: K = [],
|
|
31
|
+
placeholder: L = "Select options",
|
|
32
|
+
maxCount: x = 3,
|
|
33
|
+
modalPopover: V = !1,
|
|
34
34
|
// asChild = false,
|
|
35
|
-
className:
|
|
36
|
-
moreText:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
className: z,
|
|
36
|
+
moreText: B = "more",
|
|
37
|
+
selectAllText: W = "Select All",
|
|
38
|
+
noResultsText: X = "No results found.",
|
|
39
|
+
searchText: _ = "Search...",
|
|
40
|
+
addOptionOnSearchNotFound: u = !1,
|
|
41
|
+
showSelectAll: $ = !0,
|
|
42
|
+
loading: f,
|
|
43
|
+
loadingText: h = "Loading...",
|
|
44
|
+
...G
|
|
45
|
+
}, q) => {
|
|
46
|
+
const s = w !== void 0, [H, i] = a.useState(K), t = s ? w : H, [J, d] = a.useState(!1), b = a.useRef(null), [Q, k] = a.useState(""), [U, C] = a.useState(!1), [M, P] = a.useState(/* @__PURE__ */ new Map()), E = a.useMemo(() => new Map(v.map((e) => [e.value, e])), [v]), c = a.useMemo(() => {
|
|
47
|
+
const e = new Map(E);
|
|
48
|
+
return M.forEach((m, n) => {
|
|
49
|
+
e.has(n) || e.set(n, m);
|
|
50
|
+
}), e;
|
|
51
|
+
}, [M, E]), Y = a.useCallback(
|
|
51
52
|
(e) => {
|
|
52
|
-
if (e.key === "Enter" &&
|
|
53
|
-
if (
|
|
53
|
+
if (e.key === "Enter" && u) {
|
|
54
|
+
if (d(!0), e.preventDefault(), e.stopPropagation(), !e.currentTarget.value) return;
|
|
54
55
|
const m = { value: e.currentTarget.value, label: e.currentTarget.value };
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
56
|
+
if (c.get(m.value) === void 0) {
|
|
57
|
+
P((y) => new Map(y).set(m.value, m));
|
|
58
|
+
const n = [...t, m.value];
|
|
59
|
+
s || i(n), l(n), k("");
|
|
59
60
|
}
|
|
60
61
|
} else if (e.key === "Enter")
|
|
61
|
-
|
|
62
|
+
d(!0);
|
|
62
63
|
else if (e.key === "Backspace" && !e.currentTarget.value) {
|
|
63
|
-
const m = [...
|
|
64
|
-
m.pop(),
|
|
64
|
+
const m = [...t];
|
|
65
|
+
m.pop(), s || i(m), l(m);
|
|
65
66
|
}
|
|
66
67
|
},
|
|
67
|
-
[
|
|
68
|
-
),
|
|
68
|
+
[u, l, c, t, s]
|
|
69
|
+
), I = a.useCallback(
|
|
69
70
|
(e) => {
|
|
70
|
-
const m =
|
|
71
|
-
|
|
71
|
+
const m = t.includes(e) ? t.filter((n) => n !== e) : [...t, e];
|
|
72
|
+
s || i(m), l(m);
|
|
72
73
|
},
|
|
73
|
-
[
|
|
74
|
-
),
|
|
75
|
-
|
|
76
|
-
}, [
|
|
77
|
-
|
|
78
|
-
}, []),
|
|
79
|
-
const e =
|
|
80
|
-
|
|
81
|
-
}, [
|
|
82
|
-
if (
|
|
83
|
-
|
|
74
|
+
[l, t, s]
|
|
75
|
+
), g = a.useCallback(() => {
|
|
76
|
+
s || i([]), l([]), u && P(/* @__PURE__ */ new Map());
|
|
77
|
+
}, [l, u, s]), Z = a.useCallback(() => {
|
|
78
|
+
d((e) => !e);
|
|
79
|
+
}, []), F = a.useCallback(() => {
|
|
80
|
+
const e = t.slice(0, x);
|
|
81
|
+
s || i(e), l(e);
|
|
82
|
+
}, [x, t, l, s]), ee = a.useCallback(() => {
|
|
83
|
+
if (t.length === c.size)
|
|
84
|
+
g();
|
|
84
85
|
else {
|
|
85
|
-
const e = Array.from(
|
|
86
|
-
|
|
86
|
+
const e = Array.from(c.keys());
|
|
87
|
+
s || i(e), l(e);
|
|
87
88
|
}
|
|
88
|
-
}, [
|
|
89
|
-
return a.
|
|
90
|
-
|
|
91
|
-
}, [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/* @__PURE__ */ t(ne, { asChild: !0, children: /* @__PURE__ */ t(
|
|
95
|
-
le,
|
|
89
|
+
}, [g, l, c, t.length, s]);
|
|
90
|
+
return a.useLayoutEffect(() => {
|
|
91
|
+
b.current && (b?.current?.firstChild?.offsetTop < b?.current?.lastChild?.offsetTop ? C(!0) : C(!1));
|
|
92
|
+
}, [t]), /* @__PURE__ */ o(oe, { open: J, onOpenChange: d, modal: V, children: [
|
|
93
|
+
/* @__PURE__ */ r(le, { asChild: !0, children: /* @__PURE__ */ r(
|
|
94
|
+
ae,
|
|
96
95
|
{
|
|
97
|
-
ref:
|
|
96
|
+
ref: q,
|
|
98
97
|
variant: "text",
|
|
99
|
-
loading:
|
|
100
|
-
disabled:
|
|
98
|
+
loading: f,
|
|
99
|
+
disabled: N,
|
|
101
100
|
type: "button",
|
|
102
|
-
...
|
|
103
|
-
onClick:
|
|
101
|
+
...G,
|
|
102
|
+
onClick: Z,
|
|
104
103
|
className: p(
|
|
105
104
|
"mtx-group mtx-flex mtx-max-h-14 mtx-h-8 mtx-w-full mtx-items-center mtx-justify-between mtx-whitespace-nowrap mtx-rounded-sm mtx-border mtx-border-input mtx-bg-transparent mtx-px-3 mtx-py-1.5 mtx-text-sm mtx-ring-offset-background data-[placeholder]:mtx-text-muted-foreground hover:mtx-border hover:mtx-border-primary hover:mtx-bg-transparent focus:mtx-border focus:mtx-border-primary focus:mtx-outline-none focus:mtx-ring focus:mtx-ring-primary-100 disabled:mtx-cursor-not-allowed disabled:mtx-bg-gray-100 disabled:mtx-text-text-300 disabled:mtx-border-gray-100 [&>span]:mtx-line-clamp-1 [&_svg]:disabled:mtx-text-text-300",
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
U && "mtx-h-auto",
|
|
106
|
+
z
|
|
108
107
|
),
|
|
109
|
-
"data-placeholder":
|
|
110
|
-
endIcon: /* @__PURE__ */
|
|
111
|
-
|
|
108
|
+
"data-placeholder": t.length ? void 0 : "",
|
|
109
|
+
endIcon: /* @__PURE__ */ r(
|
|
110
|
+
me,
|
|
112
111
|
{
|
|
113
112
|
role: "button",
|
|
114
113
|
"aria-label": "Expand dropdown",
|
|
115
114
|
className: "!mtx-h-4.5 !mtx-w-4.5 mtx-cursor-pointer group-data-[state=open]:mtx-rotate-180 mtx-transition-transform"
|
|
116
115
|
}
|
|
117
116
|
),
|
|
118
|
-
children: /* @__PURE__ */
|
|
119
|
-
/* @__PURE__ */
|
|
120
|
-
|
|
121
|
-
const m =
|
|
122
|
-
return /* @__PURE__ */
|
|
123
|
-
/* @__PURE__ */
|
|
124
|
-
|
|
117
|
+
children: /* @__PURE__ */ r(j, { children: t.length > 0 ? /* @__PURE__ */ o("div", { className: "mtx-flex mtx-justify-between mtx-items-center mtx-w-full", children: [
|
|
118
|
+
/* @__PURE__ */ o("div", { className: "mtx-flex mtx-flex-wrap mtx-items-center mtx-gap-2", ref: b, children: [
|
|
119
|
+
t.slice(0, x).map((e) => {
|
|
120
|
+
const m = c.get(e), n = m?.icon;
|
|
121
|
+
return /* @__PURE__ */ o(T, { className: p(R({ variant: S }), { "text-gray-400 bg-gray-200": N || f }), children: [
|
|
122
|
+
/* @__PURE__ */ r(
|
|
123
|
+
A,
|
|
125
124
|
{
|
|
126
125
|
className: "mtx-h-4 mtx-w-4 mtx-cursor-pointer",
|
|
127
|
-
onClick: (
|
|
128
|
-
|
|
126
|
+
onClick: (y) => {
|
|
127
|
+
y.stopPropagation(), I(e);
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
130
|
),
|
|
132
|
-
|
|
131
|
+
n && /* @__PURE__ */ r(n, { className: "mtx-h-4 mtx-w-4 mtx-mr-2" }),
|
|
133
132
|
m?.label
|
|
134
133
|
] }, e);
|
|
135
134
|
}),
|
|
136
|
-
|
|
137
|
-
`+ ${
|
|
138
|
-
/* @__PURE__ */
|
|
139
|
-
|
|
135
|
+
t.length > x && /* @__PURE__ */ o(T, { className: p(R({ variant: S })), children: [
|
|
136
|
+
`+ ${t.length - x} ${B}`,
|
|
137
|
+
/* @__PURE__ */ r(
|
|
138
|
+
re,
|
|
140
139
|
{
|
|
141
140
|
role: "button",
|
|
142
141
|
className: "mtx-ml-2 mtx-h-4.5 mtx-w-4.5 mtx-cursor-pointer",
|
|
143
142
|
onClick: (e) => {
|
|
144
|
-
e.stopPropagation(),
|
|
143
|
+
e.stopPropagation(), F();
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
)
|
|
148
147
|
] }),
|
|
149
|
-
|
|
148
|
+
f && h ? h : null
|
|
150
149
|
] }),
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
-
|
|
150
|
+
/* @__PURE__ */ o("div", { className: "mtx-flex mtx-items-center mtx-justify-between mtx-gap-1", children: [
|
|
151
|
+
/* @__PURE__ */ r(
|
|
152
|
+
A,
|
|
154
153
|
{
|
|
155
154
|
role: "button",
|
|
156
155
|
className: "mtx-h-5 mtx-w-5 mtx-text-muted-foreground mtx-cursor-pointer",
|
|
157
156
|
onClick: (e) => {
|
|
158
|
-
e.stopPropagation(),
|
|
157
|
+
e.stopPropagation(), g();
|
|
159
158
|
},
|
|
160
159
|
"aria-label": "Clear"
|
|
161
160
|
}
|
|
162
161
|
),
|
|
163
|
-
/* @__PURE__ */
|
|
162
|
+
/* @__PURE__ */ r(se, { orientation: "vertical", className: "mtx-flex mtx-min-h-5 mtx-h-full" })
|
|
164
163
|
] })
|
|
165
|
-
] }) : /* @__PURE__ */
|
|
164
|
+
] }) : /* @__PURE__ */ r(j, { children: f && h ? h : L }) })
|
|
166
165
|
}
|
|
167
166
|
) }),
|
|
168
|
-
/* @__PURE__ */
|
|
169
|
-
/* @__PURE__ */
|
|
170
|
-
/* @__PURE__ */
|
|
171
|
-
/* @__PURE__ */
|
|
172
|
-
/* @__PURE__ */
|
|
173
|
-
|
|
174
|
-
/* @__PURE__ */
|
|
167
|
+
/* @__PURE__ */ r(ne, { className: "mtx-w-auto mtx-p-0", align: "start", onEscapeKeyDown: () => d(!1), children: /* @__PURE__ */ o(ce, { className: "mtx-w-[--radix-popper-anchor-width] mtx-max-h-[--radix-popper-available-height]", children: [
|
|
168
|
+
/* @__PURE__ */ r(ie, { placeholder: _, onKeyDown: Y, value: Q, onValueChange: k }),
|
|
169
|
+
/* @__PURE__ */ o(xe, { className: "", children: [
|
|
170
|
+
/* @__PURE__ */ r(de, { children: X }),
|
|
171
|
+
/* @__PURE__ */ o(pe, { children: [
|
|
172
|
+
$ && /* @__PURE__ */ o(O, { onSelect: ee, className: "mtx-cursor-pointer", children: [
|
|
173
|
+
/* @__PURE__ */ r(
|
|
175
174
|
"div",
|
|
176
175
|
{
|
|
177
176
|
className: p(
|
|
178
177
|
"mtx-mr-2 mtx-flex mtx-h-4.5 mtx-w-4.5 mtx-items-center mtx-justify-center mtx-rounded-sm mtx-border mtx-border-primary",
|
|
179
|
-
|
|
178
|
+
t.length === c.size ? "mtx-bg-primary mtx-text-primary-foreground" : "mtx-opacity-50 [&_svg]:mtx-invisible"
|
|
180
179
|
),
|
|
181
|
-
children: /* @__PURE__ */
|
|
180
|
+
children: /* @__PURE__ */ r(D, { className: "mtx-h-4.5 mtx-w-4.5" })
|
|
182
181
|
}
|
|
183
182
|
),
|
|
184
|
-
/* @__PURE__ */
|
|
183
|
+
/* @__PURE__ */ o("span", { children: [
|
|
185
184
|
"(",
|
|
186
|
-
|
|
185
|
+
W,
|
|
187
186
|
")"
|
|
188
187
|
] })
|
|
189
188
|
] }, "all"),
|
|
190
|
-
Array.from(
|
|
191
|
-
const m =
|
|
192
|
-
return /* @__PURE__ */
|
|
193
|
-
/* @__PURE__ */
|
|
189
|
+
Array.from(c.values()).map((e) => {
|
|
190
|
+
const m = t.includes(e.value);
|
|
191
|
+
return /* @__PURE__ */ o(O, { onSelect: () => I(e.value), className: "mtx-cursor-pointer", children: [
|
|
192
|
+
/* @__PURE__ */ r(
|
|
194
193
|
"div",
|
|
195
194
|
{
|
|
196
195
|
className: p(
|
|
197
196
|
"mtx-mr-2 mtx-flex mtx-h-4.5 mtx-w-4.5 mtx-items-center mtx-justify-center mtx-rounded-sm mtx-border mtx-border-primary",
|
|
198
197
|
m ? "mtx-bg-primary mtx-text-primary-foreground" : "mtx-opacity-50 [&_svg]:mtx-invisible"
|
|
199
198
|
),
|
|
200
|
-
children: /* @__PURE__ */
|
|
199
|
+
children: /* @__PURE__ */ r(D, { className: "mtx-h-4.5 mtx-w-4.5" })
|
|
201
200
|
}
|
|
202
201
|
),
|
|
203
|
-
e.icon && /* @__PURE__ */
|
|
204
|
-
/* @__PURE__ */
|
|
202
|
+
e.icon && /* @__PURE__ */ r(e.icon, { className: "mtx-mr-2 mtx-h-4.5 mtx-w-4.5 mtx-text-muted-foreground" }),
|
|
203
|
+
/* @__PURE__ */ r("span", { children: e.label })
|
|
205
204
|
] }, e.value);
|
|
206
205
|
})
|
|
207
|
-
] })
|
|
208
|
-
/* @__PURE__ */ t(pe, {}),
|
|
209
|
-
/* @__PURE__ */ t(R, { children: /* @__PURE__ */ s("div", { className: "mtx-flex mtx-items-center mtx-justify-between", children: [
|
|
210
|
-
r.length > 0 && /* @__PURE__ */ s(S, { children: [
|
|
211
|
-
/* @__PURE__ */ t(y, { onSelect: v, className: "mtx-flex-1 mtx-justify-center mtx-cursor-pointer", children: X }),
|
|
212
|
-
/* @__PURE__ */ t(A, { orientation: "vertical", className: "mtx-flex mtx-min-h-6 mtx-h-full" })
|
|
213
|
-
] }),
|
|
214
|
-
/* @__PURE__ */ t(y, { onSelect: () => i(!1), className: "mtx-flex-1 mtx-justify-center mtx-cursor-pointer mtx-max-w-full", children: $ })
|
|
215
|
-
] }) })
|
|
206
|
+
] })
|
|
216
207
|
] })
|
|
217
208
|
] }) })
|
|
218
209
|
] });
|
|
219
|
-
},
|
|
220
|
-
|
|
210
|
+
}, fe = a.forwardRef(ue);
|
|
211
|
+
fe.displayName = "MultiSelect";
|
|
221
212
|
export {
|
|
222
|
-
|
|
213
|
+
fe as MultiSelect
|
|
223
214
|
};
|
|
224
215
|
//# sourceMappingURL=multiselect.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiselect.es.js","sources":["../src/components/multi-select/MultiSelect.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\nimport { tv, type VariantProps } from \"tailwind-variants\";\r\nimport { Check, ChevronDown, CircleXmark, XMark } from \"@trsys-tech/matrix-icons\";\r\n\r\nimport { cn } from \"../../lib/utils\";\r\nimport { Status } from \"../status/Status\";\r\nimport { Button } from \"../button/Button\";\r\nimport { Separator } from \"../separator/Separator\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover/Popover\";\r\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from \"../command/Command\";\r\n\r\n/**\r\n * Variants for the multi-select component to handle different styles.\r\n * Uses tailwind-variants (cva) to define different styles based on \"variant\" prop.\r\n */\r\nconst multiSelectVariants = tv({\r\n base: \"mtx-flex mtx-gap-1 mtx-items-center mtx-py-0.5 mtx-px-2 mtx-rounded-xl\",\r\n variants: {\r\n variant: {\r\n default: \"mtx-border-none mtx-shadow-none mtx-bg-primary-50 mtx-text-primary hover:mtx-bg-primary-50\",\r\n secondary: \"mtx-border-foreground/10 mtx-bg-secondary mtx-text-secondary-foreground hover:mtx-bg-secondary/80\",\r\n destructive: \"mtx-border-transparent mtx-bg-destructive mtx-text-destructive-foreground hover:mtx-bg-destructive/80\",\r\n inverted: \"mtx-inverted\",\r\n },\r\n },\r\n defaultVariants: {\r\n variant: \"default\",\r\n },\r\n});\r\n\r\n/**\r\n * Props for MultiSelect component\r\n */\r\ninterface MultiSelectProps<T extends string | number>\r\n extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"value\" | \"defaultValue\">,\r\n VariantProps<typeof multiSelectVariants> {\r\n /**\r\n * An array of option objects to be displayed in the multi-select component.\r\n * Each option object has a label, value, and an optional icon.\r\n *\r\n * *Important: Use a constant Array*\r\n */\r\n options: {\r\n /** The text to display for the option. */\r\n label: string;\r\n /** The unique value associated with the option. */\r\n value: T;\r\n /** Optional icon component to display alongside the option. */\r\n icon?: React.ComponentType<{ className?: string }>;\r\n }[];\r\n\r\n /**\r\n * Callback function triggered when the selected values change.\r\n * Receives an array of the new selected values.\r\n */\r\n onValueChange: (value: T[]) => void;\r\n\r\n /**\r\n * selected values in the multi-select component.\r\n */\r\n value?: T[];\r\n\r\n /** The default selected values when the component mounts. */\r\n defaultValue?: T[];\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * Optional, defaults to \"Select options\".\r\n */\r\n placeholder?: string;\r\n\r\n /**\r\n * Maximum number of items to display. Extra selected items will be summarized.\r\n * Optional, defaults to 3.\r\n */\r\n maxCount?: number;\r\n\r\n /**\r\n * The modality of the popover. When set to true, interaction with outside elements\r\n * will be disabled and only popover content will be visible to screen readers.\r\n * Optional, defaults to false.\r\n */\r\n modalPopover?: boolean;\r\n\r\n /**\r\n * If true, renders the multi-select component as a child of another component.\r\n * Optional, defaults to false.\r\n */\r\n asChild?: boolean;\r\n\r\n /**\r\n * Additional class names to apply custom styles to the multi-select component.\r\n * Optional, can be used to add custom styles.\r\n */\r\n className?: string;\r\n\r\n /**\r\n * Text to display on the close button when the multi-select component is open.\r\n */\r\n closeText?: string;\r\n\r\n /**\r\n * Whether to show the select all option or not\r\n */\r\n showSelectAll?: boolean;\r\n\r\n /**\r\n * Text to display on the select all button when the multi-select component is open.\r\n */\r\n selectAllText?: string;\r\n\r\n /**\r\n * Text to display in the search input.\r\n */\r\n searchText?: string;\r\n\r\n /**\r\n * If true, a new option will be added when the user submits a search query if it doesn't already exist.\r\n * Optional, defaults to false.\r\n */\r\n addOptionOnSearchNotFound?: boolean;\r\n\r\n /**\r\n * Text to display on the clear button when the multi-select component is open.\r\n */\r\n clearText?: string;\r\n\r\n /**\r\n * Text to display on the more button when the multi-select component is open.\r\n */\r\n moreText?: string;\r\n\r\n /**\r\n * Text to display when no results are found in the search input.\r\n */\r\n noResultsText?: string;\r\n\r\n /**\r\n * If true, the multi-select component will be in a loading state.\r\n */\r\n loading?: boolean;\r\n\r\n /**\r\n * Text to display when the multi-select component is in a loading state.\r\n */\r\n loadingText?: string;\r\n}\r\n\r\nconst MultiSelect = <T extends string | number>(\r\n {\r\n options: _options,\r\n onValueChange,\r\n value,\r\n variant,\r\n disabled,\r\n defaultValue = [],\r\n placeholder = \"Select options\",\r\n maxCount = 3,\r\n modalPopover = false,\r\n // asChild = false,\r\n className,\r\n moreText = \"more\",\r\n clearText = \"Clear\",\r\n closeText = \"Close\",\r\n selectAllText = \"Select All\",\r\n noResultsText = \"No results found.\",\r\n searchText = \"Search...\",\r\n addOptionOnSearchNotFound = false,\r\n showSelectAll = true,\r\n loading,\r\n loadingText = \"Loading...\",\r\n ...props\r\n }: MultiSelectProps<T>,\r\n ref: React.ForwardedRef<HTMLButtonElement>,\r\n) => {\r\n const isControlled = value !== undefined;\r\n const [internalSelectedValues, setInternalSelectedValues] = React.useState<T[]>(defaultValue);\r\n const selectedValues = isControlled ? value : internalSelectedValues;\r\n const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);\r\n const containerRef = React.useRef<HTMLDivElement>(null);\r\n const [searchValue, setSearchValue] = React.useState(\"\");\r\n const [isWrapped, setIsWrapped] = React.useState(false);\r\n const [options, setOptions] = React.useState<Map<T, MultiSelectProps<T>[\"options\"][number]>>(\r\n new Map(_options.map(option => [option.value, option])),\r\n );\r\n\r\n const handleInputKeyDown = React.useCallback(\r\n (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (event.key === \"Enter\" && addOptionOnSearchNotFound) {\r\n setIsPopoverOpen(true);\r\n event.preventDefault();\r\n event.stopPropagation();\r\n if (!event.currentTarget.value) return;\r\n const newOption = { value: event.currentTarget.value as T, label: event.currentTarget.value };\r\n if (options.get(newOption.value) === undefined) {\r\n setOptions(prev => {\r\n return new Map(prev).set(newOption.value, newOption);\r\n });\r\n const newSelectedValues = [...selectedValues, newOption.value];\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n setSearchValue(\"\");\r\n }\r\n } else if (event.key === \"Enter\") {\r\n setIsPopoverOpen(true);\r\n } else if (event.key === \"Backspace\" && !event.currentTarget.value) {\r\n const newSelectedValues = [...selectedValues];\r\n newSelectedValues.pop();\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n }\r\n },\r\n [addOptionOnSearchNotFound, onValueChange, options, selectedValues, isControlled],\r\n );\r\n\r\n const toggleOption = React.useCallback(\r\n (option: T) => {\r\n const newSelectedValues = selectedValues.includes(option) ? selectedValues.filter(value => value !== option) : [...selectedValues, option];\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n },\r\n [onValueChange, selectedValues, isControlled],\r\n );\r\n\r\n const handleClear = React.useCallback(() => {\r\n if (!isControlled) {\r\n setInternalSelectedValues([]);\r\n }\r\n onValueChange([]);\r\n if (addOptionOnSearchNotFound) {\r\n setOptions(new Map(_options.map(option => [option.value, option])));\r\n }\r\n }, [onValueChange, addOptionOnSearchNotFound, _options, isControlled]);\r\n\r\n const handleTogglePopover = React.useCallback(() => {\r\n setIsPopoverOpen(prev => !prev);\r\n }, []);\r\n\r\n const clearExtraOptions = React.useCallback(() => {\r\n const newSelectedValues = selectedValues.slice(0, maxCount);\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n }, [maxCount, selectedValues, onValueChange, isControlled]);\r\n\r\n const toggleAll = React.useCallback(() => {\r\n if (selectedValues.length === options.size) {\r\n handleClear();\r\n } else {\r\n const allValues = Array.from(options.keys());\r\n if (!isControlled) {\r\n setInternalSelectedValues(allValues);\r\n }\r\n onValueChange(allValues);\r\n }\r\n }, [handleClear, onValueChange, options, selectedValues.length, isControlled]);\r\n\r\n React.useEffect(() => {\r\n setOptions(new Map(_options.map(option => [option.value, option])));\r\n }, [_options]);\r\n\r\n React.useLayoutEffect(() => {\r\n if (containerRef.current) {\r\n if ((containerRef?.current?.firstChild as HTMLElement)?.offsetTop < (containerRef?.current?.lastChild as HTMLElement)?.offsetTop) {\r\n setIsWrapped(true);\r\n } else {\r\n setIsWrapped(false);\r\n }\r\n }\r\n }, [selectedValues]);\r\n\r\n return (\r\n <Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen} modal={modalPopover}>\r\n <PopoverTrigger asChild>\r\n <Button\r\n ref={ref}\r\n variant=\"text\"\r\n loading={loading}\r\n disabled={disabled}\r\n type=\"button\"\r\n {...props}\r\n onClick={handleTogglePopover}\r\n className={cn(\r\n \"mtx-group mtx-flex mtx-max-h-14 mtx-h-8 mtx-w-full mtx-items-center mtx-justify-between mtx-whitespace-nowrap mtx-rounded-sm mtx-border mtx-border-input mtx-bg-transparent mtx-px-3 mtx-py-1.5 mtx-text-sm mtx-ring-offset-background data-[placeholder]:mtx-text-muted-foreground hover:mtx-border hover:mtx-border-primary hover:mtx-bg-transparent focus:mtx-border focus:mtx-border-primary focus:mtx-outline-none focus:mtx-ring focus:mtx-ring-primary-100 disabled:mtx-cursor-not-allowed disabled:mtx-bg-gray-100 disabled:mtx-text-text-300 disabled:mtx-border-gray-100 [&>span]:mtx-line-clamp-1 [&_svg]:disabled:mtx-text-text-300\",\r\n isWrapped && \"mtx-h-auto\",\r\n className,\r\n )}\r\n data-placeholder={!selectedValues.length ? \"\" : undefined}\r\n endIcon={\r\n <ChevronDown\r\n role=\"button\"\r\n aria-label=\"Expand dropdown\"\r\n className=\"!mtx-h-4.5 !mtx-w-4.5 mtx-cursor-pointer group-data-[state=open]:mtx-rotate-180 mtx-transition-transform\"\r\n />\r\n }\r\n >\r\n <>\r\n {selectedValues.length > 0 ? (\r\n <div className=\"mtx-flex mtx-justify-between mtx-items-center mtx-w-full\">\r\n <div className=\"mtx-flex mtx-flex-wrap mtx-items-center mtx-gap-2\" ref={containerRef}>\r\n {selectedValues.slice(0, maxCount).map(value => {\r\n const option = options.get(value);\r\n const IconComponent = option?.icon;\r\n return (\r\n <Status key={value} className={cn(multiSelectVariants({ variant }), { \"text-gray-400 bg-gray-200\": disabled || loading })}>\r\n <XMark\r\n className=\"mtx-h-4 mtx-w-4 mtx-cursor-pointer\"\r\n onClick={event => {\r\n event.stopPropagation();\r\n toggleOption(value);\r\n }}\r\n />\r\n {IconComponent && <IconComponent className=\"mtx-h-4 mtx-w-4 mtx-mr-2\" />}\r\n {option?.label}\r\n </Status>\r\n );\r\n })}\r\n {selectedValues.length > maxCount && (\r\n <Status className={cn(multiSelectVariants({ variant }))}>\r\n {`+ ${selectedValues.length - maxCount} ${moreText}`}\r\n <CircleXmark\r\n role=\"button\"\r\n className=\"mtx-ml-2 mtx-h-4.5 mtx-w-4.5 mtx-cursor-pointer\"\r\n onClick={event => {\r\n event.stopPropagation();\r\n clearExtraOptions();\r\n }}\r\n />\r\n </Status>\r\n )}\r\n {loading && loadingText ? loadingText : null}\r\n </div>\r\n <div className=\"mtx-flex mtx-items-center mtx-justify-between mtx-gap-1\">\r\n <XMark\r\n role=\"button\"\r\n className=\"mtx-h-5 mtx-w-5 mtx-text-muted-foreground mtx-cursor-pointer\"\r\n onClick={event => {\r\n event.stopPropagation();\r\n handleClear();\r\n }}\r\n aria-label=\"Clear\"\r\n />\r\n <Separator orientation=\"vertical\" className=\"mtx-flex mtx-min-h-5 mtx-h-full\" />\r\n </div>\r\n </div>\r\n ) : (\r\n <>{loading && loadingText ? loadingText : placeholder}</>\r\n )}\r\n </>\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent className=\"mtx-w-auto mtx-p-0\" align=\"start\" onEscapeKeyDown={() => setIsPopoverOpen(false)}>\r\n <Command className=\"mtx-w-[--radix-popper-anchor-width] mtx-max-h-[--radix-popper-available-height]\">\r\n <CommandInput placeholder={searchText} onKeyDown={handleInputKeyDown} value={searchValue} onValueChange={setSearchValue} />\r\n <CommandList className=\"\">\r\n <CommandEmpty>{noResultsText}</CommandEmpty>\r\n <CommandGroup>\r\n {showSelectAll && (\r\n <CommandItem key=\"all\" onSelect={toggleAll} className=\"mtx-cursor-pointer\">\r\n <div\r\n className={cn(\r\n \"mtx-mr-2 mtx-flex mtx-h-4.5 mtx-w-4.5 mtx-items-center mtx-justify-center mtx-rounded-sm mtx-border mtx-border-primary\",\r\n selectedValues.length === options.size ? \"mtx-bg-primary mtx-text-primary-foreground\" : \"mtx-opacity-50 [&_svg]:mtx-invisible\",\r\n )}\r\n >\r\n <Check className=\"mtx-h-4.5 mtx-w-4.5\" />\r\n </div>\r\n <span>({selectAllText})</span>\r\n </CommandItem>\r\n )}\r\n {Array.from(options.values()).map(option => {\r\n const isSelected = selectedValues.includes(option.value);\r\n return (\r\n <CommandItem key={option.value} onSelect={() => toggleOption(option.value)} className=\"mtx-cursor-pointer\">\r\n <div\r\n className={cn(\r\n \"mtx-mr-2 mtx-flex mtx-h-4.5 mtx-w-4.5 mtx-items-center mtx-justify-center mtx-rounded-sm mtx-border mtx-border-primary\",\r\n isSelected ? \"mtx-bg-primary mtx-text-primary-foreground\" : \"mtx-opacity-50 [&_svg]:mtx-invisible\",\r\n )}\r\n >\r\n <Check className=\"mtx-h-4.5 mtx-w-4.5\" />\r\n </div>\r\n {option.icon && <option.icon className=\"mtx-mr-2 mtx-h-4.5 mtx-w-4.5 mtx-text-muted-foreground\" />}\r\n <span>{option.label}</span>\r\n </CommandItem>\r\n );\r\n })}\r\n </CommandGroup>\r\n <CommandSeparator />\r\n <CommandGroup>\r\n <div className=\"mtx-flex mtx-items-center mtx-justify-between\">\r\n {selectedValues.length > 0 && (\r\n <>\r\n <CommandItem onSelect={handleClear} className=\"mtx-flex-1 mtx-justify-center mtx-cursor-pointer\">\r\n {clearText}\r\n </CommandItem>\r\n <Separator orientation=\"vertical\" className=\"mtx-flex mtx-min-h-6 mtx-h-full\" />\r\n </>\r\n )}\r\n <CommandItem onSelect={() => setIsPopoverOpen(false)} className=\"mtx-flex-1 mtx-justify-center mtx-cursor-pointer mtx-max-w-full\">\r\n {closeText}\r\n </CommandItem>\r\n </div>\r\n </CommandGroup>\r\n </CommandList>\r\n </Command>\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n};\r\n\r\nconst ForwardedMultiSelect = React.forwardRef(MultiSelect) as (<T extends string | number>(\r\n props: MultiSelectProps<T> & { ref?: React.Ref<HTMLButtonElement> },\r\n) => React.ReactElement) & { displayName?: string };\r\n\r\nForwardedMultiSelect.displayName = \"MultiSelect\";\r\n\r\nexport { ForwardedMultiSelect as MultiSelect, type MultiSelectProps };\r\n"],"names":["multiSelectVariants","tv","MultiSelect","_options","onValueChange","value","variant","disabled","defaultValue","placeholder","maxCount","modalPopover","className","moreText","clearText","closeText","selectAllText","noResultsText","searchText","addOptionOnSearchNotFound","showSelectAll","loading","loadingText","props","ref","isControlled","internalSelectedValues","setInternalSelectedValues","React","selectedValues","isPopoverOpen","setIsPopoverOpen","containerRef","searchValue","setSearchValue","isWrapped","setIsWrapped","options","setOptions","option","handleInputKeyDown","event","newOption","prev","newSelectedValues","toggleOption","handleClear","handleTogglePopover","clearExtraOptions","toggleAll","allValues","Popover","jsx","PopoverTrigger","Button","cn","ChevronDown","jsxs","IconComponent","Status","XMark","CircleXmark","Separator","Fragment","PopoverContent","Command","CommandInput","CommandList","CommandEmpty","CommandGroup","CommandItem","Check","isSelected","CommandSeparator","ForwardedMultiSelect"],"mappings":";;;;;;;;;;AAiBA,MAAMA,IAAsBC,GAAG;AAAA,EAC7B,MAAM;AAAA,EACN,UAAU;AAAA,IACR,SAAS;AAAA,MACP,SAAS;AAAA,MACT,WAAW;AAAA,MACX,aAAa;AAAA,MACb,UAAU;AAAA,IAAA;AAAA,EACZ;AAAA,EAEF,iBAAiB;AAAA,IACf,SAAS;AAAA,EAAA;AAEb,CAAC,GAwHKC,KAAc,CAClB;AAAA,EACE,SAASC;AAAA,EACT,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,SAAAC;A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AAMvC,EAAiB,EAAK,GAAG,WAAU,mEAC7D,UAAAhB,EAAA,CACH;AAAA,QAAA,EAAA,CACF,EAAA,CACF;AAAA,MAAA,EAAA,CACF;AAAA,IAAA,EAAA,CACF,EAAA,CACF;AAAA,EAAA,GACF;AAEJ,GAEM2D,KAAuB9C,EAAM,WAAW1B,EAAW;AAIzDwE,GAAqB,cAAc;"}
|
|
1
|
+
{"version":3,"file":"multiselect.es.js","sources":["../src/components/multi-select/MultiSelect.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\nimport { tv, type VariantProps } from \"tailwind-variants\";\r\nimport { Check, ChevronDown, CircleXmark, XMark } from \"@trsys-tech/matrix-icons\";\r\n\r\nimport { cn } from \"../../lib/utils\";\r\nimport { Status } from \"../status/Status\";\r\nimport { Button } from \"../button/Button\";\r\nimport { Separator } from \"../separator/Separator\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover/Popover\";\r\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from \"../command/Command\";\r\n\r\n/**\r\n * Variants for the multi-select component to handle different styles.\r\n * Uses tailwind-variants (cva) to define different styles based on \"variant\" prop.\r\n */\r\nconst multiSelectVariants = tv({\r\n base: \"mtx-flex mtx-gap-1 mtx-items-center mtx-py-0.5 mtx-px-2 mtx-rounded-xl\",\r\n variants: {\r\n variant: {\r\n default: \"mtx-border-none mtx-shadow-none mtx-bg-primary-50 mtx-text-primary hover:mtx-bg-primary-50\",\r\n secondary: \"mtx-border-foreground/10 mtx-bg-secondary mtx-text-secondary-foreground hover:mtx-bg-secondary/80\",\r\n destructive: \"mtx-border-transparent mtx-bg-destructive mtx-text-destructive-foreground hover:mtx-bg-destructive/80\",\r\n inverted: \"mtx-inverted\",\r\n },\r\n },\r\n defaultVariants: {\r\n variant: \"default\",\r\n },\r\n});\r\n\r\n/**\r\n * Props for MultiSelect component\r\n */\r\ninterface MultiSelectProps<T extends string | number>\r\n extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"value\" | \"defaultValue\">,\r\n VariantProps<typeof multiSelectVariants> {\r\n /**\r\n * An array of option objects to be displayed in the multi-select component.\r\n * Each option object has a label, value, and an optional icon.\r\n *\r\n * *Important: Use a constant Array*\r\n */\r\n options: {\r\n /** The text to display for the option. */\r\n label: string;\r\n /** The unique value associated with the option. */\r\n value: T;\r\n /** Optional icon component to display alongside the option. */\r\n icon?: React.ComponentType<{ className?: string }>;\r\n }[];\r\n\r\n /**\r\n * Callback function triggered when the selected values change.\r\n * Receives an array of the new selected values.\r\n */\r\n onValueChange: (value: T[]) => void;\r\n\r\n /**\r\n * selected values in the multi-select component.\r\n */\r\n value?: T[];\r\n\r\n /** The default selected values when the component mounts. */\r\n defaultValue?: T[];\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * Optional, defaults to \"Select options\".\r\n */\r\n placeholder?: string;\r\n\r\n /**\r\n * Maximum number of items to display. Extra selected items will be summarized.\r\n * Optional, defaults to 3.\r\n */\r\n maxCount?: number;\r\n\r\n /**\r\n * The modality of the popover. When set to true, interaction with outside elements\r\n * will be disabled and only popover content will be visible to screen readers.\r\n * Optional, defaults to false.\r\n */\r\n modalPopover?: boolean;\r\n\r\n /**\r\n * If true, renders the multi-select component as a child of another component.\r\n * Optional, defaults to false.\r\n */\r\n asChild?: boolean;\r\n\r\n /**\r\n * Additional class names to apply custom styles to the multi-select component.\r\n * Optional, can be used to add custom styles.\r\n */\r\n className?: string;\r\n\r\n /**\r\n * Whether to show the select all option or not\r\n */\r\n showSelectAll?: boolean;\r\n\r\n /**\r\n * Text to display on the select all button when the multi-select component is open.\r\n */\r\n selectAllText?: string;\r\n\r\n /**\r\n * Text to display in the search input.\r\n */\r\n searchText?: string;\r\n\r\n /**\r\n * If true, a new option will be added when the user submits a search query if it doesn't already exist.\r\n * Optional, defaults to false.\r\n */\r\n addOptionOnSearchNotFound?: boolean;\r\n\r\n /**\r\n * Text to display on the more button when the multi-select component is open.\r\n */\r\n moreText?: string;\r\n\r\n /**\r\n * Text to display when no results are found in the search input.\r\n */\r\n noResultsText?: string;\r\n\r\n /**\r\n * If true, the multi-select component will be in a loading state.\r\n */\r\n loading?: boolean;\r\n\r\n /**\r\n * Text to display when the multi-select component is in a loading state.\r\n */\r\n loadingText?: string;\r\n}\r\n\r\nconst MultiSelect = <T extends string | number>(\r\n {\r\n options: _options,\r\n onValueChange,\r\n value,\r\n variant,\r\n disabled,\r\n defaultValue = [],\r\n placeholder = \"Select options\",\r\n maxCount = 3,\r\n modalPopover = false,\r\n // asChild = false,\r\n className,\r\n moreText = \"more\",\r\n selectAllText = \"Select All\",\r\n noResultsText = \"No results found.\",\r\n searchText = \"Search...\",\r\n addOptionOnSearchNotFound = false,\r\n showSelectAll = true,\r\n loading,\r\n loadingText = \"Loading...\",\r\n ...props\r\n }: MultiSelectProps<T>,\r\n ref: React.ForwardedRef<HTMLButtonElement>,\r\n) => {\r\n const isControlled = value !== undefined;\r\n const [internalSelectedValues, setInternalSelectedValues] = React.useState<T[]>(defaultValue);\r\n const selectedValues = isControlled ? value : internalSelectedValues;\r\n const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);\r\n const containerRef = React.useRef<HTMLDivElement>(null);\r\n const [searchValue, setSearchValue] = React.useState(\"\");\r\n const [isWrapped, setIsWrapped] = React.useState(false);\r\n type MultiSelectOption = MultiSelectProps<T>[\"options\"][number];\r\n const [addedOptions, setAddedOptions] = React.useState<Map<T, MultiSelectOption>>(new Map());\r\n const propOptions = React.useMemo(() => new Map<T, MultiSelectOption>(_options.map(option => [option.value, option] as const)), [_options]);\r\n const options = React.useMemo(() => {\r\n const mergedOptions = new Map(propOptions);\r\n\r\n addedOptions.forEach((option, value) => {\r\n if (!mergedOptions.has(value)) {\r\n mergedOptions.set(value, option);\r\n }\r\n });\r\n\r\n return mergedOptions;\r\n }, [addedOptions, propOptions]);\r\n\r\n const handleInputKeyDown = React.useCallback(\r\n (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (event.key === \"Enter\" && addOptionOnSearchNotFound) {\r\n setIsPopoverOpen(true);\r\n event.preventDefault();\r\n event.stopPropagation();\r\n if (!event.currentTarget.value) return;\r\n const newOption = { value: event.currentTarget.value as T, label: event.currentTarget.value };\r\n if (options.get(newOption.value) === undefined) {\r\n setAddedOptions(prev => {\r\n return new Map(prev).set(newOption.value, newOption);\r\n });\r\n const newSelectedValues = [...selectedValues, newOption.value];\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n setSearchValue(\"\");\r\n }\r\n } else if (event.key === \"Enter\") {\r\n setIsPopoverOpen(true);\r\n } else if (event.key === \"Backspace\" && !event.currentTarget.value) {\r\n const newSelectedValues = [...selectedValues];\r\n newSelectedValues.pop();\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n }\r\n },\r\n [addOptionOnSearchNotFound, onValueChange, options, selectedValues, isControlled],\r\n );\r\n\r\n const toggleOption = React.useCallback(\r\n (option: T) => {\r\n const newSelectedValues = selectedValues.includes(option) ? selectedValues.filter(value => value !== option) : [...selectedValues, option];\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n },\r\n [onValueChange, selectedValues, isControlled],\r\n );\r\n\r\n const handleClear = React.useCallback(() => {\r\n if (!isControlled) {\r\n setInternalSelectedValues([]);\r\n }\r\n onValueChange([]);\r\n if (addOptionOnSearchNotFound) {\r\n setAddedOptions(new Map());\r\n }\r\n }, [onValueChange, addOptionOnSearchNotFound, isControlled]);\r\n\r\n const handleTogglePopover = React.useCallback(() => {\r\n setIsPopoverOpen(prev => !prev);\r\n }, []);\r\n\r\n const clearExtraOptions = React.useCallback(() => {\r\n const newSelectedValues = selectedValues.slice(0, maxCount);\r\n if (!isControlled) {\r\n setInternalSelectedValues(newSelectedValues);\r\n }\r\n onValueChange(newSelectedValues);\r\n }, [maxCount, selectedValues, onValueChange, isControlled]);\r\n\r\n const toggleAll = React.useCallback(() => {\r\n if (selectedValues.length === options.size) {\r\n handleClear();\r\n } else {\r\n const allValues = Array.from(options.keys());\r\n if (!isControlled) {\r\n setInternalSelectedValues(allValues);\r\n }\r\n onValueChange(allValues);\r\n }\r\n }, [handleClear, onValueChange, options, selectedValues.length, isControlled]);\r\n\r\n React.useLayoutEffect(() => {\r\n if (containerRef.current) {\r\n if ((containerRef?.current?.firstChild as HTMLElement)?.offsetTop < (containerRef?.current?.lastChild as HTMLElement)?.offsetTop) {\r\n setIsWrapped(true);\r\n } else {\r\n setIsWrapped(false);\r\n }\r\n }\r\n }, [selectedValues]);\r\n\r\n return (\r\n <Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen} modal={modalPopover}>\r\n <PopoverTrigger asChild>\r\n <Button\r\n ref={ref}\r\n variant=\"text\"\r\n loading={loading}\r\n disabled={disabled}\r\n type=\"button\"\r\n {...props}\r\n onClick={handleTogglePopover}\r\n className={cn(\r\n \"mtx-group mtx-flex mtx-max-h-14 mtx-h-8 mtx-w-full mtx-items-center mtx-justify-between mtx-whitespace-nowrap mtx-rounded-sm mtx-border mtx-border-input mtx-bg-transparent mtx-px-3 mtx-py-1.5 mtx-text-sm mtx-ring-offset-background data-[placeholder]:mtx-text-muted-foreground hover:mtx-border hover:mtx-border-primary hover:mtx-bg-transparent focus:mtx-border focus:mtx-border-primary focus:mtx-outline-none focus:mtx-ring focus:mtx-ring-primary-100 disabled:mtx-cursor-not-allowed disabled:mtx-bg-gray-100 disabled:mtx-text-text-300 disabled:mtx-border-gray-100 [&>span]:mtx-line-clamp-1 [&_svg]:disabled:mtx-text-text-300\",\r\n isWrapped && \"mtx-h-auto\",\r\n className,\r\n )}\r\n data-placeholder={!selectedValues.length ? \"\" : undefined}\r\n endIcon={\r\n <ChevronDown\r\n role=\"button\"\r\n aria-label=\"Expand dropdown\"\r\n className=\"!mtx-h-4.5 !mtx-w-4.5 mtx-cursor-pointer group-data-[state=open]:mtx-rotate-180 mtx-transition-transform\"\r\n />\r\n }\r\n >\r\n <>\r\n {selectedValues.length > 0 ? (\r\n <div className=\"mtx-flex mtx-justify-between mtx-items-center mtx-w-full\">\r\n <div className=\"mtx-flex mtx-flex-wrap mtx-items-center mtx-gap-2\" ref={containerRef}>\r\n {selectedValues.slice(0, maxCount).map(value => {\r\n const option = options.get(value);\r\n const IconComponent = option?.icon;\r\n return (\r\n <Status key={value} className={cn(multiSelectVariants({ variant }), { \"text-gray-400 bg-gray-200\": disabled || loading })}>\r\n <XMark\r\n className=\"mtx-h-4 mtx-w-4 mtx-cursor-pointer\"\r\n onClick={event => {\r\n event.stopPropagation();\r\n toggleOption(value);\r\n }}\r\n />\r\n {IconComponent && <IconComponent className=\"mtx-h-4 mtx-w-4 mtx-mr-2\" />}\r\n {option?.label}\r\n </Status>\r\n );\r\n })}\r\n {selectedValues.length > maxCount && (\r\n <Status className={cn(multiSelectVariants({ variant }))}>\r\n {`+ ${selectedValues.length - maxCount} ${moreText}`}\r\n <CircleXmark\r\n role=\"button\"\r\n className=\"mtx-ml-2 mtx-h-4.5 mtx-w-4.5 mtx-cursor-pointer\"\r\n onClick={event => {\r\n event.stopPropagation();\r\n clearExtraOptions();\r\n }}\r\n />\r\n </Status>\r\n )}\r\n {loading && loadingText ? loadingText : null}\r\n </div>\r\n <div className=\"mtx-flex mtx-items-center mtx-justify-between mtx-gap-1\">\r\n <XMark\r\n role=\"button\"\r\n className=\"mtx-h-5 mtx-w-5 mtx-text-muted-foreground mtx-cursor-pointer\"\r\n onClick={event => {\r\n event.stopPropagation();\r\n handleClear();\r\n }}\r\n aria-label=\"Clear\"\r\n />\r\n <Separator orientation=\"vertical\" className=\"mtx-flex mtx-min-h-5 mtx-h-full\" />\r\n </div>\r\n </div>\r\n ) : (\r\n <>{loading && loadingText ? loadingText : placeholder}</>\r\n )}\r\n </>\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent className=\"mtx-w-auto mtx-p-0\" align=\"start\" onEscapeKeyDown={() => setIsPopoverOpen(false)}>\r\n <Command className=\"mtx-w-[--radix-popper-anchor-width] mtx-max-h-[--radix-popper-available-height]\">\r\n <CommandInput placeholder={searchText} onKeyDown={handleInputKeyDown} value={searchValue} onValueChange={setSearchValue} />\r\n <CommandList className=\"\">\r\n <CommandEmpty>{noResultsText}</CommandEmpty>\r\n <CommandGroup>\r\n {showSelectAll && (\r\n <CommandItem key=\"all\" onSelect={toggleAll} className=\"mtx-cursor-pointer\">\r\n <div\r\n className={cn(\r\n \"mtx-mr-2 mtx-flex mtx-h-4.5 mtx-w-4.5 mtx-items-center mtx-justify-center mtx-rounded-sm mtx-border mtx-border-primary\",\r\n selectedValues.length === options.size ? \"mtx-bg-primary mtx-text-primary-foreground\" : \"mtx-opacity-50 [&_svg]:mtx-invisible\",\r\n )}\r\n >\r\n <Check className=\"mtx-h-4.5 mtx-w-4.5\" />\r\n </div>\r\n <span>({selectAllText})</span>\r\n </CommandItem>\r\n )}\r\n {Array.from(options.values()).map(option => {\r\n const isSelected = selectedValues.includes(option.value);\r\n return (\r\n <CommandItem key={option.value} onSelect={() => toggleOption(option.value)} className=\"mtx-cursor-pointer\">\r\n <div\r\n className={cn(\r\n \"mtx-mr-2 mtx-flex mtx-h-4.5 mtx-w-4.5 mtx-items-center mtx-justify-center mtx-rounded-sm mtx-border mtx-border-primary\",\r\n isSelected ? \"mtx-bg-primary mtx-text-primary-foreground\" : \"mtx-opacity-50 [&_svg]:mtx-invisible\",\r\n )}\r\n >\r\n <Check className=\"mtx-h-4.5 mtx-w-4.5\" />\r\n </div>\r\n {option.icon && <option.icon className=\"mtx-mr-2 mtx-h-4.5 mtx-w-4.5 mtx-text-muted-foreground\" />}\r\n <span>{option.label}</span>\r\n </CommandItem>\r\n );\r\n })}\r\n </CommandGroup>\r\n </CommandList>\r\n </Command>\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n};\r\n\r\nconst ForwardedMultiSelect = React.forwardRef(MultiSelect) as (<T extends string | number>(\r\n props: MultiSelectProps<T> & { ref?: React.Ref<HTMLButtonElement> },\r\n) => React.ReactElement) & { displayName?: string };\r\n\r\nForwardedMultiSelect.displayName = \"MultiSelect\";\r\n\r\nexport { ForwardedMultiSelect as MultiSelect, type MultiSelectProps };\r\n"],"names":["multiSelectVariants","tv","MultiSelect","_options","onValueChange","value","variant","disabled","defaultValue","placeholder","maxCount","modalPopover","className","moreText","selectAllText","noResultsText","searchText","addOptionOnSearchNotFound","showSelectAll","loading","loadingText","props","ref","isControlled","internalSelectedValues","setInternalSelectedValues","React","selectedValues","isPopoverOpen","setIsPopoverOpen","containerRef","searchValue","setSearchValue","isWrapped","setIsWrapped","addedOptions","setAddedOptions","propOptions","option","options","mergedOptions","handleInputKeyDown","event","newOption","prev","newSelectedValues","toggleOption","handleClear","handleTogglePopover","clearExtraOptions","toggleAll","allValues","Popover","jsx","PopoverTrigger","Button","cn","ChevronDown","jsxs","IconComponent","Status","XMark","CircleXmark","Separator","Fragment","PopoverContent","Command","CommandInput","CommandList","CommandEmpty","CommandGroup","CommandItem","Check","isSelected","ForwardedMultiSelect"],"mappings":";;;;;;;;;;AAiBA,MAAMA,IAAsBC,GAAG;AAAA,EAC7B,MAAM;AAAA,EACN,UAAU;AAAA,IACR,SAAS;AAAA,MACP,SAAS;AAAA,MACT,WAAW;AAAA,MACX,aAAa;AAAA,MACb,UAAU;AAAA,IAAA;AAAA,EACZ;AAAA,EAEF,iBAAiB;AAAA,IACf,SAAS;AAAA,EAAA;AAEb,CAAC,GA8GKC,KAAc,CAClB;AAAA,EACE,SAASC;AAAA,EACT,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC,IAAe,CAAA;AAAA,EACf,aAAAC,IAAc;AAAA,EACd,UAAAC,IAAW;AAAA,EACX,cAAAC,IAAe;AAAA;AAAA,EAEf,WAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,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