laif-ds 0.2.49 → 0.2.50

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.
@@ -1,104 +1,107 @@
1
1
  "use client";
2
- import { jsxs as s, jsx as l, Fragment as le } from "react/jsx-runtime";
3
- import { Badge as re } from "./badge.js";
4
- import { Command as ne, CommandInput as ae, CommandList as te, CommandEmpty as se, CommandGroup as j, CommandItem as M } from "./command.js";
5
- import { Label as ie } from "./label.js";
6
- import { cn as w } from "../../lib/utils.js";
7
- import { useState as h, useRef as oe, useMemo as N, useCallback as de, useEffect as ce } from "react";
8
- import { Checkbox as ue } from "./checkbox.js";
2
+ import { jsxs as s, jsx as l, Fragment as re } from "react/jsx-runtime";
3
+ import { Badge as ne } from "./badge.js";
4
+ import { Command as ae, CommandInput as te, CommandList as se, CommandEmpty as ie, CommandGroup as A, CommandItem as B } from "./command.js";
5
+ import { Label as oe } from "./label.js";
6
+ import { designTokens as p } from "../../lib/design-tokens.js";
7
+ import { cn as N } from "../../lib/utils.js";
8
+ import { useState as h, useRef as de, useMemo as y, useCallback as ce, useEffect as ue } from "react";
9
+ import { Checkbox as me } from "./checkbox.js";
9
10
  import { Icon as S } from "./icon.js";
10
- import { Popover as me, PopoverTrigger as fe, PopoverContent as he } from "./popover.js";
11
- import pe from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js";
12
- const ge = {
13
- sm: "min-h-8 h-8 text-xs py-1.5",
14
- default: "min-h-9 h-9 text-sm py-2",
15
- lg: "min-h-10 h-10 text-base py-2"
11
+ import { Popover as fe, PopoverTrigger as pe, PopoverContent as he } from "./popover.js";
12
+ import ge from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js";
13
+ const ve = {
14
+ sm: p.sizes.sm,
15
+ default: p.sizes.default,
16
+ lg: p.sizes.lg
16
17
  };
17
- function Oe(P) {
18
+ function Ve(z) {
18
19
  const {
19
20
  multiple: n = !1,
20
- options: m,
21
- value: A,
22
- defaultValue: B,
23
- onValueChange: R,
24
- onClear: p,
25
- placeholder: X = "Seleziona...",
26
- emptyPlaceholder: E = "Nessun risultato",
27
- searchPlaceholder: F = "Cerca...",
28
- addItemPlaceholder: L = "Aggiungi",
29
- itemCountMessage: T = (e) => `${e} elementi selezionati`,
30
- maxSelectedMessage: W = (e) => `Puoi selezionare fino a ${e} elementi`,
31
- label: D,
32
- className: $ = "",
33
- wrpClassName: G = "",
34
- searchable: O = !1,
35
- creatable: q = !1,
36
- groupBy: g = "group",
21
+ options: d,
22
+ value: R,
23
+ defaultValue: T,
24
+ onValueChange: X,
25
+ onClear: g,
26
+ placeholder: E = "Seleziona...",
27
+ emptyPlaceholder: F = "Nessun risultato",
28
+ searchPlaceholder: L = "Cerca...",
29
+ addItemPlaceholder: W = "Aggiungi",
30
+ itemCountMessage: $ = (e) => `${e} elementi selezionati`,
31
+ maxSelectedMessage: G = (e) => `Puoi selezionare fino a ${e} elementi`,
32
+ label: P,
33
+ className: q = "",
34
+ wrpClassName: H = "",
35
+ searchable: D = !1,
36
+ creatable: J = !1,
37
+ groupBy: v = "group",
37
38
  maxSelected: o,
38
- showChipsInsteadOfCount: H = !1,
39
+ showChipsInsteadOfCount: K = !1,
39
40
  disabled: b,
40
- size: J = "default",
41
- isSingleSelectClearable: K = !1
42
- } = P, [v, x] = h(!1), [d, C] = h(""), y = oe(null), [Q, U] = h(0), V = P.hasOwnProperty("value"), [Y, Z] = h(B), i = V ? A : Y, c = (e) => {
43
- V || Z(e), R?.(e);
44
- }, a = N(() => n ? Array.isArray(i) ? i : [] : i != null ? [i] : [], [i, n]), u = N(() => {
45
- const e = m.filter((t) => a.includes(t.value));
41
+ size: Q = "default",
42
+ isSingleSelectClearable: U = !1
43
+ } = z, [O, x] = h(!1), [c, C] = h(""), w = de(null), [V, Y] = h(0), k = z.hasOwnProperty("value"), [Z, _] = h(T), i = k ? R : Z, u = (e) => {
44
+ k || _(e), X?.(e);
45
+ }, a = y(() => n ? Array.isArray(i) ? i : [] : i != null ? [i] : [], [i, n]), m = y(() => {
46
+ const e = d.filter((t) => a.includes(t.value));
46
47
  if (n) {
47
48
  const t = a.filter((r) => !e.find((f) => f.value === r)).map((r) => ({ value: r, label: r }));
48
49
  return [...e, ...t];
49
50
  } else if (a.length && !e.length)
50
51
  return [{ value: a[0], label: a[0] }];
51
52
  return e;
52
- }, [m, a, n]), z = (e) => {
53
+ }, [d, a, n]), I = (e) => {
53
54
  if (!e.disabled)
54
55
  if (n) {
55
56
  const t = a.includes(e.value);
56
57
  if (!t && o !== void 0 && a.length >= o)
57
58
  return;
58
- c(
59
+ u(
59
60
  t ? a.filter((r) => r !== e.value) : [...a, e.value]
60
61
  );
61
62
  } else
62
- c(e.value), x(!1);
63
- }, k = de(() => {
64
- c(n ? [] : void 0), C(""), p && p();
65
- }, [c, p, n]), _ = N(() => g ? m.reduce(
63
+ u(e.value), x(!1);
64
+ }, j = ce(() => {
65
+ u(n ? [] : void 0), C(""), g && g();
66
+ }, [u, g, n]), ee = y(() => v ? d.reduce(
66
67
  (e, t) => {
67
- const r = t[g] || "";
68
+ const r = t[v] || "";
68
69
  return e[r] = e[r] || [], e[r].push(t), e;
69
70
  },
70
71
  {}
71
- ) : { "": m }, [m, g]);
72
- return ce(() => {
73
- v && y.current && U(y.current.getBoundingClientRect().width);
74
- }, [v]), /* @__PURE__ */ s("div", { className: w("flex flex-col gap-2", G), children: [
75
- D && /* @__PURE__ */ l(ie, { children: D }),
72
+ ) : { "": d }, [d, v]);
73
+ return ue(() => {
74
+ w.current && Y(w.current.getBoundingClientRect().width);
75
+ }, [O, a, d]), /* @__PURE__ */ s("div", { className: N("flex flex-col gap-2", H), children: [
76
+ P && /* @__PURE__ */ l(oe, { children: P }),
76
77
  /* @__PURE__ */ s(
77
- me,
78
+ fe,
78
79
  {
79
- open: b ? !1 : v,
80
+ open: b ? !1 : O,
80
81
  onOpenChange: (e) => !b && x(e),
81
82
  modal: !0,
82
83
  children: [
83
- /* @__PURE__ */ l(fe, { asChild: !0, children: /* @__PURE__ */ s(
84
+ /* @__PURE__ */ l(pe, { asChild: !0, children: /* @__PURE__ */ s(
84
85
  "div",
85
86
  {
86
- ref: y,
87
- className: w(
88
- "bg-d-input border-d-border/50 focus-within:ring-d-ring flex min-h-10 w-full min-w-[100px] cursor-pointer items-center justify-between gap-2 rounded-md border px-3 py-2 text-sm focus-within:ring-1",
89
- ge[J],
87
+ ref: w,
88
+ className: N(
89
+ p.input.base,
90
+ p.radius.default,
91
+ "focus-within:ring-d-ring/50 focus-within:border-d-ring flex w-full min-w-[100px] cursor-pointer items-center justify-between gap-2 focus-within:ring-[3px]",
92
+ ve[Q],
90
93
  b && "cursor-not-allowed opacity-50",
91
- $
94
+ q
92
95
  ),
93
96
  children: [
94
- u.length === 0 ? /* @__PURE__ */ l("span", { className: "text-d-muted-foreground", children: X }) : n ? /* @__PURE__ */ s("div", { className: "flex h-full w-full min-w-0 items-center justify-between gap-2", children: [
95
- /* @__PURE__ */ l("div", { className: "flex min-w-0 flex-nowrap gap-1 overflow-auto", children: H ? /* @__PURE__ */ l(le, { children: u.map((e) => /* @__PURE__ */ s(
96
- re,
97
+ m.length === 0 ? /* @__PURE__ */ l("span", { className: "text-d-muted-foreground", children: E }) : n ? /* @__PURE__ */ s("div", { className: "flex h-full w-full min-w-0 items-center justify-between gap-2", children: [
98
+ /* @__PURE__ */ l("div", { className: "flex min-w-0 flex-nowrap gap-1 overflow-auto", children: K ? /* @__PURE__ */ l(re, { children: m.map((e) => /* @__PURE__ */ s(
99
+ ne,
97
100
  {
98
101
  variant: "secondary",
99
102
  className: "hover:bg-d-secondary/100 bg-d-secondary/50 border-d-border flex cursor-pointer items-center gap-1 border",
100
103
  onClick: (t) => {
101
- t.stopPropagation(), z(e);
104
+ t.stopPropagation(), I(e);
102
105
  },
103
106
  children: [
104
107
  e.label,
@@ -106,13 +109,13 @@ function Oe(P) {
106
109
  ]
107
110
  },
108
111
  e.value
109
- )) }) : /* @__PURE__ */ l("div", { children: T(u.length) }) }),
112
+ )) }) : /* @__PURE__ */ l("div", { children: $(m.length) }) }),
110
113
  n && /* @__PURE__ */ l(
111
114
  "div",
112
115
  {
113
116
  className: "border-d-input bg-d-accent cursor-pointer rounded-full p-1",
114
117
  onClick: (e) => {
115
- e.stopPropagation(), e.preventDefault(), k();
118
+ e.stopPropagation(), e.preventDefault(), j();
116
119
  },
117
120
  onMouseDown: (e) => e.preventDefault(),
118
121
  "aria-label": "Clear selection",
@@ -127,13 +130,13 @@ function Oe(P) {
127
130
  }
128
131
  )
129
132
  ] }) : /* @__PURE__ */ s("div", { className: "flex h-full w-full min-w-0 items-center justify-between gap-2", children: [
130
- /* @__PURE__ */ l("div", { className: "min-w-0 flex-1 truncate", children: typeof u[0]?.label == "string" ? /* @__PURE__ */ l("span", { children: u[0]?.label }) : u[0]?.label }),
131
- K && i !== void 0 && i !== null && /* @__PURE__ */ l(
133
+ /* @__PURE__ */ l("div", { className: "min-w-0 flex-1 truncate", children: typeof m[0]?.label == "string" ? /* @__PURE__ */ l("span", { children: m[0]?.label }) : m[0]?.label }),
134
+ U && i !== void 0 && i !== null && /* @__PURE__ */ l(
132
135
  "div",
133
136
  {
134
137
  className: "border-d-input bg-d-accent cursor-pointer rounded-full p-1",
135
138
  onClick: (e) => {
136
- e.stopPropagation(), e.preventDefault(), k();
139
+ e.stopPropagation(), e.preventDefault(), j();
137
140
  },
138
141
  onMouseDown: (e) => e.preventDefault(),
139
142
  "aria-label": "Clear selection",
@@ -148,7 +151,7 @@ function Oe(P) {
148
151
  }
149
152
  )
150
153
  ] }),
151
- /* @__PURE__ */ l(pe, { className: "h-4 w-4 opacity-50" })
154
+ /* @__PURE__ */ l(ge, { className: "h-4 w-4 opacity-50" })
152
155
  ]
153
156
  }
154
157
  ) }),
@@ -156,50 +159,50 @@ function Oe(P) {
156
159
  he,
157
160
  {
158
161
  className: "p-0",
159
- style: { width: Q },
162
+ style: { width: V > 0 ? V : "auto" },
160
163
  align: "start",
161
164
  sideOffset: 4,
162
- children: /* @__PURE__ */ s(ne, { shouldFilter: !!O, className: "w-full", children: [
163
- O && /* @__PURE__ */ l(
164
- ae,
165
+ children: /* @__PURE__ */ s(ae, { shouldFilter: !!D, className: "w-full", children: [
166
+ D && /* @__PURE__ */ l(
167
+ te,
165
168
  {
166
- placeholder: F,
169
+ placeholder: L,
167
170
  className: "placeholder:text-d-muted-foreground",
168
- value: d,
171
+ value: c,
169
172
  onValueChange: C
170
173
  }
171
174
  ),
172
- /* @__PURE__ */ s(te, { className: "max-h-60 overflow-auto overscroll-contain", children: [
173
- /* @__PURE__ */ l(se, { children: E }),
174
- q && d && /* @__PURE__ */ l(j, { children: /* @__PURE__ */ l(
175
- M,
175
+ /* @__PURE__ */ s(se, { className: "max-h-60 overflow-auto overscroll-contain", children: [
176
+ /* @__PURE__ */ l(ie, { children: F }),
177
+ J && c && /* @__PURE__ */ l(A, { children: /* @__PURE__ */ l(
178
+ B,
176
179
  {
177
180
  className: "cursor-pointer",
178
181
  onSelect: () => {
179
- d && (c(n ? [...a, d] : d), C(""), !n && x(!1));
182
+ c && (u(n ? [...a, c] : c), C(""), !n && x(!1));
180
183
  },
181
184
  children: /* @__PURE__ */ s("div", { className: "text-d-foreground text-xs", children: [
182
- L,
185
+ W,
183
186
  " “",
184
- d,
187
+ c,
185
188
  "”"
186
189
  ] })
187
190
  }
188
191
  ) }),
189
- Object.entries(_).map(([e, t]) => /* @__PURE__ */ l(j, { heading: e || void 0, children: t.map((r) => {
190
- const f = a.includes(r.value), ee = n && o !== void 0 && !f && a.length >= o, I = r.disabled || ee;
192
+ Object.entries(ee).map(([e, t]) => /* @__PURE__ */ l(A, { heading: e || void 0, children: t.map((r) => {
193
+ const f = a.includes(r.value), le = n && o !== void 0 && !f && a.length >= o, M = r.disabled || le;
191
194
  return /* @__PURE__ */ s(
192
- M,
195
+ B,
193
196
  {
194
197
  value: typeof r.label == "string" ? r.label : String(r.value),
195
- onSelect: () => !I && z(r),
196
- className: w(
198
+ onSelect: () => !M && I(r),
199
+ className: N(
197
200
  "cursor-pointer",
198
- I && "cursor-not-allowed opacity-50",
201
+ M && "cursor-not-allowed opacity-50",
199
202
  !n && f && "bg-d-accent/75 text-d-accent-foreground"
200
203
  ),
201
204
  children: [
202
- n && /* @__PURE__ */ l(ue, { checked: f, className: "mr-1" }),
205
+ n && /* @__PURE__ */ l(me, { checked: f, className: "mr-1" }),
203
206
  typeof r.label == "string" ? /* @__PURE__ */ l("span", { children: r.label }) : r.label
204
207
  ]
205
208
  },
@@ -207,7 +210,7 @@ function Oe(P) {
207
210
  );
208
211
  }) }, e))
209
212
  ] }),
210
- n && o !== void 0 && a.length >= o && /* @__PURE__ */ l("div", { className: "border-d-border text-d-muted-foreground border-t px-2 py-1 text-xs", children: W(o) })
213
+ n && o !== void 0 && a.length >= o && /* @__PURE__ */ l("div", { className: "border-d-border text-d-muted-foreground border-t px-2 py-1 text-xs", children: G(o) })
211
214
  ] })
212
215
  }
213
216
  )
@@ -217,5 +220,5 @@ function Oe(P) {
217
220
  ] });
218
221
  }
219
222
  export {
220
- Oe as AppSelect
223
+ Ve as AppSelect
221
224
  };