laif-ds 0.2.52 → 0.2.54

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