laif-ds 0.2.69 → 0.2.71

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,135 +1,231 @@
1
1
  "use client";
2
- import { jsxs as h, jsx as n } from "react/jsx-runtime";
3
- import { designTokens as r } from "../design-tokens.js";
4
- import { Calendar as O } from "./calendar.js";
5
- import { Icon as J } from "./icon.js";
6
- import { Label as K } from "./label.js";
7
- import { Popover as Q, PopoverTrigger as U, PopoverContent as W } from "./popover.js";
8
- import { cn as k } from "../../lib/utils.js";
9
- import * as d from "react";
10
- import { useEffect as X } from "react";
11
- import { it as Y } from "../../node_modules/date-fns/locale/it.js";
12
- import { formatDate as v } from "../../node_modules/date-fns/format.js";
13
- import { isSameDay as Z } from "../../node_modules/date-fns/isSameDay.js";
14
- function de(e) {
2
+ import { jsxs as m, jsx as s } from "react/jsx-runtime";
3
+ import { designTokens as i } from "../design-tokens.js";
4
+ import { TimePickerColumn as M } from "./app-time-picker.js";
5
+ import { Calendar as V } from "./calendar.js";
6
+ import { Icon as q } from "./icon.js";
7
+ import { Label as de } from "./label.js";
8
+ import { Popover as ce, PopoverTrigger as me, PopoverContent as ue } from "./popover.js";
9
+ import { cn as E } from "../../lib/utils.js";
10
+ import * as f from "react";
11
+ import { useCallback as L, useMemo as p, useEffect as fe } from "react";
12
+ import { it as he } from "../../node_modules/date-fns/locale/it.js";
13
+ import { formatDate as w } from "../../node_modules/date-fns/format.js";
14
+ import { isSameDay as ge } from "../../node_modules/date-fns/isSameDay.js";
15
+ function Pe(t) {
15
16
  const {
16
- placeholder: F = "Seleziona data",
17
- dateFormat: g = "dd/MM/yyyy",
18
- className: R,
19
- disabled: s = !1,
20
- size: m = "default",
21
- firstDate: p,
22
- lastDate: b,
23
- availableDates: C,
24
- locale: l = Y,
25
- initialCalendarMonth: c,
26
- customCalendarProps: x,
27
- label: D,
28
- wrpClassName: T,
29
- id: j,
30
- "data-testid": V,
31
- minDate: M,
32
- maxDate: S,
33
- numberOfMonths: q
34
- } = e, a = e.mode === "range", [f, y] = d.useState(
35
- a ? void 0 : e.value
36
- ), [o, I] = d.useState(
37
- a ? e.value : void 0
38
- ), [z, u] = d.useState(
39
- c
40
- ), [N, E] = d.useState(!1), L = (t) => {
41
- y(t), t && u(t), !a && e.onChange && e.onChange(t);
42
- }, w = (t) => {
43
- I(t), t?.from && u(t.from), a && e.onChange && e.onChange(t);
17
+ placeholder: X = "Seleziona data",
18
+ dateFormat: B,
19
+ className: G,
20
+ disabled: l = !1,
21
+ size: h = "default",
22
+ firstDate: N,
23
+ lastDate: S,
24
+ availableDates: H,
25
+ locale: u = he,
26
+ initialCalendarMonth: g,
27
+ customCalendarProps: P,
28
+ label: k,
29
+ labelClassName: J,
30
+ wrpClassName: K,
31
+ id: Q,
32
+ "data-testid": U,
33
+ minDate: O,
34
+ maxDate: z,
35
+ numberOfMonths: W,
36
+ clearable: Y = !1,
37
+ onClear: I
38
+ } = t, o = t.mode === "range", C = !o && t.showTime === !0, T = !o && t.withSeconds === !0, x = B ?? (C ? T ? "dd/MM/yyyy HH:mm:ss" : "dd/MM/yyyy HH:mm" : "dd/MM/yyyy"), [n, b] = f.useState(
39
+ o ? void 0 : t.value
40
+ ), [r, y] = f.useState(
41
+ o ? t.value : void 0
42
+ ), [F, v] = f.useState(
43
+ g
44
+ ), [j, A] = f.useState(!1), Z = (e) => {
45
+ const a = e ? new Date(e) : void 0;
46
+ C && a && n && a.setHours(
47
+ n.getHours(),
48
+ n.getMinutes(),
49
+ n.getSeconds()
50
+ ), b(a), a && v(a), !o && t.onChange && t.onChange(a), !C && a && A(!1);
51
+ }, $ = L(() => {
52
+ o ? (y(void 0), t.onChange && t.onChange(void 0)) : (b(void 0), t.onChange && t.onChange(void 0)), I?.();
53
+ }, [o, t.onChange, I]), ee = n?.getHours(), te = n?.getMinutes(), ae = n?.getSeconds(), oe = p(
54
+ () => Array.from({ length: 24 }, (e, a) => a),
55
+ []
56
+ ), ne = p(
57
+ () => Array.from({ length: 60 }, (e, a) => a),
58
+ []
59
+ ), se = p(
60
+ () => Array.from({ length: 60 }, (e, a) => a),
61
+ []
62
+ ), D = L(
63
+ (e, a) => {
64
+ const c = n ? new Date(n) : /* @__PURE__ */ new Date();
65
+ n || c.setHours(0, 0, 0, 0), e === "hour" ? c.setHours(a) : e === "minute" ? c.setMinutes(a) : e === "second" && c.setSeconds(a), b(c), !o && t.onChange && t.onChange(c);
66
+ },
67
+ [n, o, t.onChange]
68
+ ), re = (e) => {
69
+ y(e), e?.from && v(e.from), o && t.onChange && t.onChange(e);
44
70
  };
45
- let i = [];
46
- p && i.push({ before: p }), b && i.push({ after: b }), C?.length && i.push(
47
- (t) => !C.some(
48
- (H) => Z(H, t)
71
+ let d = [];
72
+ N && d.push({ before: N }), S && d.push({ after: S }), H?.length && d.push(
73
+ (e) => !H.some(
74
+ (a) => ge(a, e)
49
75
  )
50
- ), s && (i = [!0]), X(() => {
51
- if (a) {
52
- I(e.value);
53
- const t = e.value?.from;
54
- u(t ?? c);
76
+ ), l && (d = [!0]), fe(() => {
77
+ if (o) {
78
+ y(t.value);
79
+ const e = t.value?.from;
80
+ v(e ?? g);
55
81
  } else
56
- y(e.value), u(
57
- e.value ?? c
82
+ b(t.value), v(
83
+ t.value ?? g
58
84
  );
59
- }, [e.value, a, c]);
60
- const A = d.useId(), P = j ?? A, B = a ? !!o?.from : !!f, G = () => a && o ? /* @__PURE__ */ h("span", { children: [
61
- o.from && v(o.from, g, { locale: l }),
62
- o.from && o.to && " - ",
63
- o.to && v(o.to, g, { locale: l })
64
- ] }) : !a && f ? /* @__PURE__ */ n("span", { children: v(f, g, { locale: l }) }) : /* @__PURE__ */ n("span", { className: "text-d-muted-foreground", children: F });
65
- return /* @__PURE__ */ h("div", { className: k("flex flex-col gap-1.5", T), children: [
66
- D && /* @__PURE__ */ n(K, { htmlFor: P, children: D }),
67
- /* @__PURE__ */ h(Q, { open: s ? !1 : N, onOpenChange: E, children: [
68
- /* @__PURE__ */ n(U, { asChild: !0, children: /* @__PURE__ */ h(
69
- "div",
70
- {
71
- id: P,
72
- "data-testid": V,
73
- className: k(
74
- r.input.base,
75
- r.radius.default,
76
- r.text.base,
77
- r.interaction.disabled,
78
- "flex items-center gap-2 font-normal whitespace-nowrap [&>span]:line-clamp-1",
79
- r.focusRing,
80
- N && r.activeRing,
81
- "hover:border-d-ring cursor-pointer transition-colors",
82
- !B && "text-d-muted-foreground",
83
- s && "cursor-not-allowed opacity-50",
84
- m === "default" && r.sizes.default,
85
- m === "sm" && r.sizes.sm,
86
- m === "lg" && r.sizes.lg,
87
- R
88
- ),
89
- "aria-disabled": s,
90
- role: "button",
91
- tabIndex: s ? -1 : 0,
92
- onClick: s ? void 0 : () => {
93
- },
94
- children: [
95
- /* @__PURE__ */ n(J, { name: "Calendar", size: m === "lg" ? "sm" : "xs" }),
96
- /* @__PURE__ */ n("div", { children: G() })
97
- ]
98
- }
99
- ) }),
100
- /* @__PURE__ */ n(W, { className: "w-auto p-0 shadow", children: a ? /* @__PURE__ */ n(
101
- O,
102
- {
103
- ...x || {},
104
- mode: "range",
105
- selected: o,
106
- onSelect: w,
107
- autoFocus: !0,
108
- disabled: i,
109
- locale: l,
110
- defaultMonth: z,
111
- numberOfMonths: q ?? 1,
112
- minDate: M,
113
- maxDate: S
114
- }
115
- ) : /* @__PURE__ */ n(
116
- O,
117
- {
118
- ...x || {},
119
- mode: "single",
120
- selected: f,
121
- onSelect: L,
122
- autoFocus: !0,
123
- disabled: i,
124
- locale: l,
125
- defaultMonth: z,
126
- minDate: M,
127
- maxDate: S
128
- }
129
- ) })
130
- ] })
85
+ }, [t.value, o, g]);
86
+ const ie = f.useId(), R = Q ?? ie, _ = o ? !!r?.from : !!n, le = () => o && r ? /* @__PURE__ */ m("span", { children: [
87
+ r.from && w(r.from, x, { locale: u }),
88
+ r.from && r.to && " - ",
89
+ r.to && w(r.to, x, { locale: u })
90
+ ] }) : !o && n ? /* @__PURE__ */ s("span", { children: w(n, x, { locale: u }) }) : /* @__PURE__ */ s("span", { className: "text-d-muted-foreground", children: X });
91
+ return /* @__PURE__ */ m("div", { className: E("flex flex-col gap-1.5", K), children: [
92
+ k && /* @__PURE__ */ s(de, { htmlFor: R, className: J, children: k }),
93
+ /* @__PURE__ */ m(
94
+ ce,
95
+ {
96
+ open: l ? !1 : j,
97
+ onOpenChange: A,
98
+ modal: !0,
99
+ children: [
100
+ /* @__PURE__ */ s(me, { asChild: !0, children: /* @__PURE__ */ m(
101
+ "div",
102
+ {
103
+ id: R,
104
+ "data-testid": U,
105
+ className: E(
106
+ i.input.base,
107
+ i.radius.default,
108
+ i.text.base,
109
+ i.interaction.disabled,
110
+ "flex items-center gap-2 font-normal whitespace-nowrap [&>span]:line-clamp-1",
111
+ i.focusRing,
112
+ j && i.activeRing,
113
+ "hover:border-d-ring cursor-pointer transition-colors",
114
+ !_ && "text-d-muted-foreground",
115
+ l && "cursor-not-allowed opacity-50",
116
+ h === "default" && i.sizes.default,
117
+ h === "sm" && i.sizes.sm,
118
+ h === "lg" && i.sizes.lg,
119
+ G
120
+ ),
121
+ "aria-disabled": l,
122
+ role: "button",
123
+ tabIndex: l ? -1 : 0,
124
+ onClick: l ? void 0 : () => {
125
+ },
126
+ children: [
127
+ /* @__PURE__ */ s(q, { name: "Calendar", size: h === "lg" ? "sm" : "xs" }),
128
+ /* @__PURE__ */ s("div", { className: "min-w-0 flex-1", children: le() }),
129
+ Y && _ && /* @__PURE__ */ s(
130
+ "div",
131
+ {
132
+ role: "button",
133
+ className: "bg-d-accent hover:bg-d-accent/80 border-d-border flex shrink-0 cursor-pointer items-center justify-center rounded-full border p-1 transition-colors",
134
+ onClick: (e) => {
135
+ e.stopPropagation(), e.preventDefault(), $();
136
+ },
137
+ onMouseDown: (e) => e.preventDefault(),
138
+ "aria-label": "Clear selection",
139
+ children: /* @__PURE__ */ s(
140
+ q,
141
+ {
142
+ name: "X",
143
+ size: "xs",
144
+ className: "!text-d-foreground opacity-50"
145
+ }
146
+ )
147
+ }
148
+ )
149
+ ]
150
+ }
151
+ ) }),
152
+ " ",
153
+ /* @__PURE__ */ m(
154
+ ue,
155
+ {
156
+ className: "flex min-h-0 w-auto flex-row p-0 shadow",
157
+ align: "start",
158
+ children: [
159
+ o ? /* @__PURE__ */ s(
160
+ V,
161
+ {
162
+ ...P || {},
163
+ mode: "range",
164
+ selected: r,
165
+ onSelect: re,
166
+ autoFocus: !0,
167
+ disabled: d,
168
+ locale: u,
169
+ defaultMonth: F,
170
+ numberOfMonths: W ?? 1,
171
+ minDate: O,
172
+ maxDate: z
173
+ }
174
+ ) : /* @__PURE__ */ s(
175
+ V,
176
+ {
177
+ ...P || {},
178
+ mode: "single",
179
+ selected: n,
180
+ onSelect: Z,
181
+ autoFocus: !0,
182
+ disabled: d,
183
+ locale: u,
184
+ defaultMonth: F,
185
+ minDate: O,
186
+ maxDate: z
187
+ }
188
+ ),
189
+ C && /* @__PURE__ */ m("div", { className: "border-d-border/50 flex max-h-[300px] min-h-0 flex-1 flex-row border-l", children: [
190
+ /* @__PURE__ */ s(
191
+ M,
192
+ {
193
+ type: "hour",
194
+ value: ee,
195
+ options: oe,
196
+ onChange: (e) => D("hour", e),
197
+ className: "flex flex-1"
198
+ }
199
+ ),
200
+ /* @__PURE__ */ s(
201
+ M,
202
+ {
203
+ type: "minute",
204
+ value: te,
205
+ options: ne,
206
+ onChange: (e) => D("minute", e),
207
+ className: "flex flex-1"
208
+ }
209
+ ),
210
+ T && /* @__PURE__ */ s(
211
+ M,
212
+ {
213
+ type: "second",
214
+ value: ae,
215
+ options: se,
216
+ onChange: (e) => D("second", e),
217
+ className: "flex flex-1"
218
+ }
219
+ )
220
+ ] })
221
+ ]
222
+ }
223
+ )
224
+ ]
225
+ }
226
+ )
131
227
  ] });
132
228
  }
133
229
  export {
134
- de as DatePicker
230
+ Pe as DatePicker
135
231
  };