laif-ds 0.1.86 → 0.1.88

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,131 +1,155 @@
1
1
  "use client";
2
- import { jsx as r, jsxs as l, Fragment as B } from "react/jsx-runtime";
3
- import * as n from "react";
4
- import { cn as C } from "../../lib/utils.js";
5
- import { Label as F } from "./label.js";
6
- import { Badge as E } from "./badge.js";
7
- import { Button as y } from "./button.js";
8
- import { Command as G, CommandList as V, CommandEmpty as X, CommandGroup as $, CommandItem as q } from "./command.js";
9
- import { inputVariants as H } from "./input.js";
10
- import { Checkbox as I } from "./checkbox.js";
11
- import { Icon as J } from "./icon.js";
12
- import { CommandPortal as K } from "./command-portal.js";
13
- import Q from "../../node_modules/lucide-react/dist/esm/icons/x.js";
14
- import T from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js";
15
- const U = n.createContext({ size: "default" });
16
- function ie({
2
+ import { jsx as r, jsxs as l, Fragment as F } from "react/jsx-runtime";
3
+ import * as t from "react";
4
+ import { useEffect as T } from "react";
5
+ import { cn as p } from "../../lib/utils.js";
6
+ import { Label as G } from "./label.js";
7
+ import { Badge as V } from "./badge.js";
8
+ import { Button as N } from "./button.js";
9
+ import { Popover as X, PopoverTrigger as $, PopoverContent as q } from "./popover.js";
10
+ import { Command as H, CommandList as I, CommandEmpty as J, CommandGroup as K, CommandItem as Q } from "./command.js";
11
+ import { inputVariants as U } from "./input.js";
12
+ import { Checkbox as Y } from "./checkbox.js";
13
+ import { Icon as y } from "./icon.js";
14
+ import Z from "../../node_modules/lucide-react/dist/esm/icons/chevron-down.js";
15
+ const _ = t.createContext({ size: "default" });
16
+ function me({
17
17
  options: s,
18
- value: a,
18
+ value: n,
19
19
  onChange: o,
20
- onClear: f,
20
+ onClear: h,
21
21
  placeholder: k = "Seleziona...",
22
22
  disabled: z = !1,
23
- size: p = "default",
24
- label: h,
23
+ size: g = "default",
24
+ label: b,
25
25
  labelClassName: M,
26
- emptyMessage: j = "Nessun risultato trovato",
27
- className: P,
28
- filterPlaceholder: D = "Cerca...",
29
- filterable: L = !1,
30
- cancelLabel: R = "Cancella selezione",
26
+ emptyMessage: P = "Nessun risultato trovato",
27
+ className: R,
28
+ filterPlaceholder: j = "Cerca...",
29
+ filterable: D = !1,
30
+ cancelLabel: O = "Cancella selezione",
31
31
  cancelButtonLabel: S = "Cancella",
32
- maxSelectedItems: t
32
+ maxSelectedItems: a
33
33
  }) {
34
- const m = n.useId(), [u, b] = n.useState(!1), [d, g] = n.useState(""), v = n.useRef(null), w = n.useCallback(
34
+ const m = t.useId(), [d, L] = t.useState(!1), [c, v] = t.useState(""), [B, W] = t.useState(
35
+ void 0
36
+ ), A = t.useRef(null), f = t.useRef(null), w = t.useCallback(
35
37
  (e) => {
36
- if (a.includes(e))
37
- o(a.filter((i) => i !== e));
38
+ if (n.includes(e))
39
+ o(n.filter((i) => i !== e));
38
40
  else {
39
- if (t && a.length >= t)
41
+ if (a && n.length >= a)
40
42
  return;
41
- o([...a, e]);
43
+ o([...n, e]);
42
44
  }
43
45
  },
44
- [a, o, t]
45
- ), x = n.useCallback(() => {
46
- o([]), g(""), f && f();
47
- }, [o]), c = n.useMemo(() => s.filter((e) => a.includes(e.value)), [s, a]), O = n.useMemo(() => d ? s.filter(
48
- (e) => e.label.toLowerCase().includes(d.toLowerCase())
49
- ) : s, [s, d]), N = n.useMemo(() => t ? a.length >= t : !1, [a, t]);
50
- return /* @__PURE__ */ r(U.Provider, { value: { size: p, id: m }, children: /* @__PURE__ */ l("div", { className: "space-y-1.5", children: [
51
- h && /* @__PURE__ */ r(F, { htmlFor: m, className: M, children: h }),
52
- /* @__PURE__ */ l(
46
+ [n, o, a]
47
+ ), x = t.useCallback(() => {
48
+ o([]), v(""), h && h();
49
+ }, [o]), u = t.useMemo(() => s.filter((e) => n.includes(e.value)), [s, n]), E = t.useMemo(() => c ? s.filter(
50
+ (e) => e.label.toLowerCase().includes(c.toLowerCase())
51
+ ) : s, [s, c]), C = t.useMemo(() => a ? n.length >= a : !1, [n, a]);
52
+ return T(() => {
53
+ if (d && f.current) {
54
+ const e = f.current.getBoundingClientRect();
55
+ W(e.width);
56
+ }
57
+ }, [d]), /* @__PURE__ */ r(_.Provider, { value: { size: g, id: m }, children: /* @__PURE__ */ l("div", { className: "space-y-1.5", children: [
58
+ b && /* @__PURE__ */ r(G, { htmlFor: m, className: M, children: b }),
59
+ /* @__PURE__ */ r(
53
60
  "div",
54
61
  {
55
- ref: v,
62
+ ref: A,
56
63
  className: "relative w-full",
57
64
  "data-slot": "app-multiple-select-dropdown",
58
- children: [
59
- /* @__PURE__ */ l(
60
- y,
65
+ children: /* @__PURE__ */ l(X, { open: d, onOpenChange: L, children: [
66
+ /* @__PURE__ */ r($, { asChild: !0, children: /* @__PURE__ */ l(
67
+ N,
61
68
  {
62
69
  id: m,
63
70
  type: "button",
64
71
  variant: "outline",
65
72
  role: "combobox",
66
- "aria-expanded": u,
73
+ "aria-expanded": d,
67
74
  disabled: z,
68
- className: C(
75
+ ref: f,
76
+ className: p(
69
77
  "!bg-d-input relative w-full justify-between border font-normal",
70
78
  "border-d-input ring-offset-background focus:ring-ring flex items-center rounded-md border whitespace-nowrap shadow-sm focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",
71
79
  "aria-invalid:ring-d-destructive/20 dark:aria-invalid:ring-d-destructive/40 aria-invalid:border-d-destructive",
72
- P
80
+ R
73
81
  ),
74
- onClick: () => b(!u),
75
82
  children: [
76
- /* @__PURE__ */ r("div", { className: "flex w-full items-center gap-2 overflow-hidden", children: c.length > 0 ? /* @__PURE__ */ l(B, { children: [
83
+ /* @__PURE__ */ r("div", { className: "flex w-full items-center justify-between gap-2 overflow-hidden", children: u.length > 0 ? /* @__PURE__ */ l(F, { children: [
77
84
  /* @__PURE__ */ l(
78
- E,
85
+ V,
79
86
  {
80
87
  variant: "secondary",
81
- className: "flex items-center gap-1",
88
+ className: "!bg-d-accent flex items-center gap-1",
82
89
  children: [
83
- /* @__PURE__ */ r("span", { children: c.length }),
84
- c.length === 1 ? " elemento selezionato" : " elementi selezionati"
90
+ /* @__PURE__ */ r("span", { children: u.length }),
91
+ u.length === 1 ? " elemento selezionato" : " elementi selezionati"
85
92
  ]
86
93
  }
87
94
  ),
88
- /* @__PURE__ */ l(
95
+ /* @__PURE__ */ r(
89
96
  "div",
90
97
  {
91
- className: "hover:bg-d-secondary flex h-5 w-5 items-center justify-center gap-1 rounded-full p-0",
98
+ className: "border-d-input bg-d-accent cursor-pointer rounded-full p-1",
92
99
  onClick: (e) => {
93
100
  e.stopPropagation(), e.preventDefault(), x();
94
101
  },
95
- children: [
96
- /* @__PURE__ */ r(Q, { className: "h-3 w-3" }),
97
- /* @__PURE__ */ r("span", { className: "sr-only", children: R })
98
- ]
102
+ onMouseDown: (e) => e.preventDefault(),
103
+ "aria-label": O,
104
+ children: /* @__PURE__ */ r(
105
+ y,
106
+ {
107
+ name: "X",
108
+ size: "xs",
109
+ className: "!text-d-foreground opacity-50"
110
+ }
111
+ )
99
112
  }
100
113
  )
101
114
  ] }) : /* @__PURE__ */ r("span", { className: "text-d-muted-foreground", children: k }) }),
102
- /* @__PURE__ */ r(T, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" })
115
+ /* @__PURE__ */ r(Z, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" })
103
116
  ]
104
117
  }
105
- ),
118
+ ) }),
106
119
  /* @__PURE__ */ r(
107
- K,
120
+ q,
108
121
  {
109
- open: u,
110
- triggerRef: v,
111
- onClose: () => b(!1),
112
- children: /* @__PURE__ */ r("div", { children: /* @__PURE__ */ l(G, { className: "bg-d-popover border-d-border w-full rounded-md border shadow-md", children: [
113
- L && /* @__PURE__ */ l("div", { className: "border-d-border flex items-center justify-between border-b px-3", children: [
122
+ className: p("p-0"),
123
+ style: { width: B },
124
+ align: "start",
125
+ side: "bottom",
126
+ sideOffset: 4,
127
+ onWheel: (e) => e.stopPropagation(),
128
+ avoidCollisions: !1,
129
+ children: /* @__PURE__ */ l(H, { className: "bg-d-popover w-full rounded-md border border-none shadow-lg", children: [
130
+ D && /* @__PURE__ */ l("div", { className: "border-d-border flex items-center justify-between border-b px-3", children: [
114
131
  /* @__PURE__ */ l("div", { className: "flex items-center", children: [
115
- /* @__PURE__ */ r(J, { name: "Search", className: "text-d-accent", size: "sm" }),
132
+ /* @__PURE__ */ r(
133
+ y,
134
+ {
135
+ name: "Search",
136
+ className: "text-d-accent-foreground",
137
+ size: "sm"
138
+ }
139
+ ),
116
140
  /* @__PURE__ */ r(
117
141
  "input",
118
142
  {
119
143
  id: "app-multiple-select-dropdown-filter",
120
- placeholder: D,
121
- value: d,
122
- onChange: (e) => g(e.target.value),
123
- className: `focus-visible:ring-none border-none focus-visible:border-none disabled:opacity-50 ${H({ size: p })} !shadow-none`
144
+ placeholder: j,
145
+ value: c,
146
+ onChange: (e) => v(e.target.value),
147
+ className: `focus-visible:ring-none border-none focus-visible:border-none disabled:opacity-50 ${U({ size: g })} !shadow-none`
124
148
  }
125
149
  )
126
150
  ] }),
127
- c.length > 0 && /* @__PURE__ */ r(
128
- y,
151
+ u.length > 0 && /* @__PURE__ */ r(
152
+ N,
129
153
  {
130
154
  variant: "ghost",
131
155
  size: "sm",
@@ -135,24 +159,23 @@ function ie({
135
159
  }
136
160
  )
137
161
  ] }),
138
- /* @__PURE__ */ l(V, { className: "max-h-60 w-full overflow-auto", children: [
139
- /* @__PURE__ */ r(X, { children: j }),
140
- /* @__PURE__ */ r($, { children: O.map((e) => {
141
- const i = a.includes(e.value);
162
+ /* @__PURE__ */ l(I, { className: "max-h-60 w-full", children: [
163
+ /* @__PURE__ */ r(J, { children: P }),
164
+ /* @__PURE__ */ r(K, { children: E.map((e) => {
165
+ const i = n.includes(e.value);
142
166
  return /* @__PURE__ */ l(
143
- q,
167
+ Q,
144
168
  {
145
169
  value: e.value,
146
- disabled: e.disabled || !i && N,
170
+ disabled: e.disabled || !i && C,
147
171
  onSelect: () => w(e.value),
148
- className: C(
172
+ className: p(
149
173
  "aria-selected:!bg-d-accent aria-selected:text-d-accent-foreground flex cursor-pointer items-center gap-2 px-2 py-1.5",
150
- (e.disabled || !i && N) && "cursor-not-allowed opacity-50"
174
+ (e.disabled || !i && C) && "cursor-not-allowed opacity-50"
151
175
  ),
152
- onPointerDown: (A) => A.stopPropagation(),
153
176
  children: [
154
177
  /* @__PURE__ */ r(
155
- I,
178
+ Y,
156
179
  {
157
180
  checked: i,
158
181
  className: "z-10 mr-2 flex-shrink-0",
@@ -168,14 +191,14 @@ function ie({
168
191
  );
169
192
  }) })
170
193
  ] })
171
- ] }) })
194
+ ] })
172
195
  }
173
196
  )
174
- ]
197
+ ] })
175
198
  }
176
199
  )
177
200
  ] }) });
178
201
  }
179
202
  export {
180
- ie as AppMultipleSelectDropdown
203
+ me as AppMultipleSelectDropdown
181
204
  };