asterui 0.12.64 → 0.12.66

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,8 +1,8 @@
1
- import { jsxs as w, jsx as s } from "react/jsx-runtime";
2
- import { forwardRef as _, useState as D, useRef as ee, useEffect as L } from "react";
3
- import { Input as te } from "./Input.js";
4
- import { useConfig as ne } from "../providers/ConfigProvider.js";
5
- const x = "btn", Y = "btn-ghost", S = "btn-sm", I = "btn-square", se = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], re = [
1
+ import { jsxs as F, jsx as l } from "react/jsx-runtime";
2
+ import we, { forwardRef as be, useState as Y, useRef as ee, useEffect as O } from "react";
3
+ import { Input as ve } from "./Input.js";
4
+ import { useConfig as ye } from "../providers/ConfigProvider.js";
5
+ const z = "btn", L = "btn-ghost", I = "btn-sm", te = "btn-square", Me = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], $e = [
6
6
  "January",
7
7
  "February",
8
8
  "March",
@@ -16,354 +16,497 @@ const x = "btn", Y = "btn-ghost", S = "btn-sm", I = "btn-square", se = ["Su", "M
16
16
  "November",
17
17
  "December"
18
18
  ];
19
- function A(r, n = "MM/DD/YYYY") {
20
- if (!r) return "";
21
- const m = r.getFullYear(), g = String(r.getMonth() + 1).padStart(2, "0"), R = String(r.getDate()).padStart(2, "0");
22
- return n.replace("YYYY", String(m)).replace("MM", g).replace("DD", R);
19
+ function Z(o, a = "MM/DD/YYYY") {
20
+ if (!o) return "";
21
+ const h = o.getFullYear(), x = String(o.getMonth() + 1).padStart(2, "0"), B = String(o.getDate()).padStart(2, "0");
22
+ return a.replace("YYYY", String(h)).replace("MM", x).replace("DD", B);
23
23
  }
24
- function ae(r, n) {
25
- return new Date(r, n + 1, 0).getDate();
24
+ function ne(o, a) {
25
+ return new Date(o, a + 1, 0).getDate();
26
26
  }
27
- function oe(r, n) {
28
- return new Date(r, n, 1).getDay();
27
+ function xe(o, a) {
28
+ return new Date(o, a, 1).getDay();
29
29
  }
30
- function q(r) {
31
- return new Date(r.getFullYear(), r.getMonth(), r.getDate());
30
+ function re(o) {
31
+ return new Date(o.getFullYear(), o.getMonth(), o.getDate());
32
32
  }
33
- function X(r, n) {
34
- return r.getFullYear() === n.getFullYear() && r.getMonth() === n.getMonth() && r.getDate() === n.getDate();
33
+ function _(o, a) {
34
+ return o.getFullYear() === a.getFullYear() && o.getMonth() === a.getMonth() && o.getDate() === a.getDate();
35
35
  }
36
- function Z(r, n) {
37
- return q(r).getTime() < q(n).getTime();
36
+ function De(o, a) {
37
+ return re(o).getTime() < re(a).getTime();
38
38
  }
39
- function ue(r, n) {
40
- return q(r).getTime() > q(n).getTime();
39
+ function Ye(o, a) {
40
+ return re(o).getTime() > re(a).getTime();
41
41
  }
42
- function fe(r, n = "MM/DD/YYYY") {
43
- const [m, g] = r;
44
- return m && g ? `${A(m, n)} - ${A(g, n)}` : m ? `${A(m, n)} - ` : "";
42
+ function ae(o, a) {
43
+ const h = new Date(o);
44
+ return h.setDate(h.getDate() + a), h;
45
45
  }
46
- const le = _(function({
47
- value: n,
48
- defaultValue: m,
49
- onChange: g,
50
- format: R,
51
- placeholder: $ = "Select date",
52
- disabled: k = !1,
53
- size: V,
54
- "data-testid": y,
55
- className: J = "",
56
- ...G
57
- }, H) {
58
- const { componentSize: W } = ne(), K = V ?? W ?? "md", P = (e) => y ? `${y}-${e}` : void 0, [u, C] = D(
59
- n || m || null
60
- ), [v, h] = D(!1), [o, f] = D(
61
- u ? u.getMonth() : (/* @__PURE__ */ new Date()).getMonth()
62
- ), [c, N] = D(
63
- u ? u.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear()
64
- ), l = ee(null);
65
- L(() => {
66
- n !== void 0 && C(n);
67
- }, [n]), L(() => {
68
- function e(i) {
69
- l.current && !l.current.contains(i.target) && h(!1);
46
+ function Se(o, a = "MM/DD/YYYY") {
47
+ const [h, x] = o;
48
+ return h && x ? `${Z(h, a)} - ${Z(x, a)}` : h ? `${Z(h, a)} - ` : "";
49
+ }
50
+ const ke = be(function({
51
+ value: a,
52
+ defaultValue: h,
53
+ onChange: x,
54
+ format: B,
55
+ placeholder: R,
56
+ disabledDate: d,
57
+ disabled: v = !1,
58
+ size: oe,
59
+ "data-testid": T,
60
+ className: se = "",
61
+ ...le
62
+ }, ce) {
63
+ const { componentSize: ie, locale: j } = ye(), ue = oe ?? ie ?? "md", U = R ?? j?.DatePicker?.placeholder ?? "Select date", G = j?.DatePicker?.today ?? "Today", q = /* @__PURE__ */ new Date(), de = v || d?.(q), W = (e) => T ? `${T}-${e}` : void 0, [p, K] = Y(
64
+ a || h || null
65
+ ), [y, m] = Y(!1), [i, M] = Y(null), [u, c] = Y(
66
+ p ? p.getMonth() : (/* @__PURE__ */ new Date()).getMonth()
67
+ ), [D, P] = Y(
68
+ p ? p.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear()
69
+ ), f = ee(null), k = ee(null), w = we.useId();
70
+ O(() => {
71
+ a !== void 0 && K(a);
72
+ }, [a]), O(() => {
73
+ function e(n) {
74
+ f.current && !f.current.contains(n.target) && m(!1);
75
+ }
76
+ if (y)
77
+ return document.addEventListener("mousedown", e), M(p ?? q), () => document.removeEventListener("mousedown", e);
78
+ }, [y]), O(() => {
79
+ if (!y || !k.current) return;
80
+ k.current.querySelector('[data-calendar-focus="true"]')?.focus();
81
+ }, [y, u, D, i]);
82
+ const A = (e) => {
83
+ const n = new Date(D, u, e);
84
+ v || d?.(n) || (K(n), x?.(n), m(!1));
85
+ }, N = (e, n) => {
86
+ let $ = ae(e, n);
87
+ for (let b = 0; b < 31; b++) {
88
+ if (!d?.($)) return $;
89
+ $ = ae($, n);
70
90
  }
71
- if (v)
72
- return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
73
- }, [v]);
74
- const M = (e) => {
75
- const i = new Date(c, o, e);
76
- C(i), g?.(i), h(!1);
77
- }, p = () => {
78
- o === 0 ? (f(11), N(c - 1)) : f(o - 1);
79
- }, F = () => {
80
- o === 11 ? (f(0), N(c + 1)) : f(o + 1);
81
- }, T = ae(c, o), Q = oe(c, o), O = [];
82
- for (let e = 0; e < Q; e++)
83
- O.push(null);
84
- for (let e = 1; e <= T; e++)
85
- O.push(e);
86
- const B = (e) => !e || !u ? !1 : u.getDate() === e && u.getMonth() === o && u.getFullYear() === c, U = (e) => {
91
+ return e;
92
+ }, V = (e) => {
93
+ if (!i) return;
94
+ let n = i;
95
+ switch (e.key) {
96
+ case "ArrowRight":
97
+ e.preventDefault(), n = N(i, 1);
98
+ break;
99
+ case "ArrowLeft":
100
+ e.preventDefault(), n = N(i, -1);
101
+ break;
102
+ case "ArrowDown":
103
+ e.preventDefault(), n = N(i, 7);
104
+ break;
105
+ case "ArrowUp":
106
+ e.preventDefault(), n = N(i, -7);
107
+ break;
108
+ case "Home":
109
+ e.preventDefault(), n = new Date(i.getFullYear(), i.getMonth(), 1), d?.(n) && (n = N(n, 1));
110
+ break;
111
+ case "End":
112
+ e.preventDefault(), n = new Date(i.getFullYear(), i.getMonth(), ne(i.getFullYear(), i.getMonth())), d?.(n) && (n = N(n, -1));
113
+ break;
114
+ case "Enter":
115
+ case " ":
116
+ e.preventDefault(), A(i.getDate());
117
+ return;
118
+ case "Escape":
119
+ e.preventDefault(), m(!1);
120
+ return;
121
+ default:
122
+ return;
123
+ }
124
+ M(n), c(n.getMonth()), P(n.getFullYear());
125
+ }, Q = () => {
126
+ u === 0 ? (c(11), P(D - 1)) : c(u - 1);
127
+ }, X = () => {
128
+ u === 11 ? (c(0), P(D + 1)) : c(u + 1);
129
+ }, S = ne(D, u), fe = xe(D, u), H = [];
130
+ for (let e = 0; e < fe; e++)
131
+ H.push(null);
132
+ for (let e = 1; e <= S; e++)
133
+ H.push(e);
134
+ const J = (e) => !e || !p ? !1 : p.getDate() === e && p.getMonth() === u && p.getFullYear() === D, ge = (e) => {
87
135
  if (!e) return !1;
88
- const i = /* @__PURE__ */ new Date();
89
- return i.getDate() === e && i.getMonth() === o && i.getFullYear() === c;
136
+ const n = /* @__PURE__ */ new Date();
137
+ return n.getDate() === e && n.getMonth() === u && n.getFullYear() === D;
90
138
  };
91
- return /* @__PURE__ */ w("div", { ref: H || l, className: `relative ${J}`, "data-state": v ? "open" : "closed", "data-testid": y, ...G, children: [
92
- /* @__PURE__ */ s(
93
- te,
139
+ return /* @__PURE__ */ F("div", { ref: ce || f, className: `relative ${se}`, "data-state": y ? "open" : "closed", "data-testid": T, ...le, children: [
140
+ /* @__PURE__ */ l(
141
+ ve,
94
142
  {
95
- value: A(u, R),
96
- placeholder: $,
97
- disabled: k,
98
- size: K,
143
+ value: Z(p, B),
144
+ placeholder: U,
145
+ disabled: v,
146
+ size: ue,
99
147
  readOnly: !0,
100
- onClick: () => !k && h(!v),
148
+ onClick: () => !v && m(!y),
149
+ "aria-haspopup": "dialog",
150
+ "aria-expanded": y,
151
+ "aria-controls": w,
101
152
  className: "cursor-pointer",
102
- "data-testid": P("input")
153
+ "data-testid": W("input")
103
154
  }
104
155
  ),
105
- v && /* @__PURE__ */ w("div", { className: "absolute top-full left-0 mt-2 bg-base-100 border border-base-300 rounded-lg shadow-lg p-4 z-50 w-80", "data-testid": P("calendar"), children: [
106
- /* @__PURE__ */ w("div", { className: "flex items-center justify-between mb-4", children: [
107
- /* @__PURE__ */ s(
108
- "button",
109
- {
110
- type: "button",
111
- onClick: p,
112
- className: `${x} ${Y} ${S} ${I}`,
113
- children: /* @__PURE__ */ s(
114
- "svg",
156
+ y && /* @__PURE__ */ F(
157
+ "div",
158
+ {
159
+ ref: k,
160
+ id: w,
161
+ role: "dialog",
162
+ "aria-label": "Date picker calendar",
163
+ className: "absolute top-full left-0 mt-2 bg-base-100 border border-base-300 rounded-lg shadow-lg p-4 z-50 w-80",
164
+ "data-testid": W("calendar"),
165
+ children: [
166
+ /* @__PURE__ */ F("div", { className: "flex items-center justify-between mb-4", children: [
167
+ /* @__PURE__ */ l(
168
+ "button",
115
169
  {
116
- xmlns: "http://www.w3.org/2000/svg",
117
- className: "h-5 w-5",
118
- viewBox: "0 0 20 20",
119
- fill: "currentColor",
120
- children: /* @__PURE__ */ s(
121
- "path",
170
+ type: "button",
171
+ onClick: Q,
172
+ className: `${z} ${L} ${I} ${te}`,
173
+ children: /* @__PURE__ */ l(
174
+ "svg",
122
175
  {
123
- fillRule: "evenodd",
124
- d: "M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",
125
- clipRule: "evenodd"
176
+ xmlns: "http://www.w3.org/2000/svg",
177
+ className: "h-5 w-5",
178
+ viewBox: "0 0 20 20",
179
+ fill: "currentColor",
180
+ children: /* @__PURE__ */ l(
181
+ "path",
182
+ {
183
+ fillRule: "evenodd",
184
+ d: "M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",
185
+ clipRule: "evenodd"
186
+ }
187
+ )
126
188
  }
127
189
  )
128
190
  }
129
- )
130
- }
131
- ),
132
- /* @__PURE__ */ w("div", { className: "text-base font-semibold", children: [
133
- re[o],
134
- " ",
135
- c
136
- ] }),
137
- /* @__PURE__ */ s(
138
- "button",
139
- {
140
- type: "button",
141
- onClick: F,
142
- className: `${x} ${Y} ${S} ${I}`,
143
- children: /* @__PURE__ */ s(
144
- "svg",
191
+ ),
192
+ /* @__PURE__ */ F("div", { className: "text-base font-semibold", children: [
193
+ $e[u],
194
+ " ",
195
+ D
196
+ ] }),
197
+ /* @__PURE__ */ l(
198
+ "button",
145
199
  {
146
- xmlns: "http://www.w3.org/2000/svg",
147
- className: "h-5 w-5",
148
- viewBox: "0 0 20 20",
149
- fill: "currentColor",
150
- children: /* @__PURE__ */ s(
151
- "path",
200
+ type: "button",
201
+ onClick: X,
202
+ className: `${z} ${L} ${I} ${te}`,
203
+ children: /* @__PURE__ */ l(
204
+ "svg",
152
205
  {
153
- fillRule: "evenodd",
154
- d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
155
- clipRule: "evenodd"
206
+ xmlns: "http://www.w3.org/2000/svg",
207
+ className: "h-5 w-5",
208
+ viewBox: "0 0 20 20",
209
+ fill: "currentColor",
210
+ children: /* @__PURE__ */ l(
211
+ "path",
212
+ {
213
+ fillRule: "evenodd",
214
+ d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
215
+ clipRule: "evenodd"
216
+ }
217
+ )
156
218
  }
157
219
  )
158
220
  }
159
221
  )
160
- }
161
- )
162
- ] }),
163
- /* @__PURE__ */ s("div", { className: "grid grid-cols-7 gap-1 mb-2", children: se.map((e) => /* @__PURE__ */ s(
164
- "div",
165
- {
166
- className: "text-center text-xs font-semibold text-base-content/60 py-2",
167
- children: e
168
- },
169
- e
170
- )) }),
171
- /* @__PURE__ */ s("div", { className: "grid grid-cols-7 gap-1", children: O.map((e, i) => /* @__PURE__ */ s(
172
- "button",
173
- {
174
- type: "button",
175
- disabled: !e,
176
- onClick: () => e && M(e),
177
- className: `
178
- aspect-square flex items-center justify-center text-sm rounded-lg
179
- ${e ? "hover:bg-base-200" : "invisible"}
180
- ${B(e) ? "bg-primary text-primary-content hover:bg-primary/90" : ""}
181
- ${U(e) && !B(e) ? "border border-primary" : ""}
182
- ${e ? "cursor-pointer" : ""}
183
- `,
184
- children: e
185
- },
186
- i
187
- )) }),
188
- /* @__PURE__ */ s("div", { className: "mt-4 flex justify-end", children: /* @__PURE__ */ s(
189
- "button",
190
- {
191
- type: "button",
192
- onClick: () => {
193
- const e = /* @__PURE__ */ new Date();
194
- C(e), f(e.getMonth()), N(e.getFullYear()), g?.(e), h(!1);
195
- },
196
- className: `${x} ${Y} ${S}`,
197
- children: "Today"
198
- }
199
- ) })
200
- ] })
222
+ ] }),
223
+ /* @__PURE__ */ l("div", { className: "grid grid-cols-7 gap-1 mb-2", role: "row", children: Me.map((e) => /* @__PURE__ */ l(
224
+ "div",
225
+ {
226
+ className: "text-center text-xs font-semibold text-base-content/60 py-2",
227
+ role: "columnheader",
228
+ children: e
229
+ },
230
+ e
231
+ )) }),
232
+ /* @__PURE__ */ l("div", { className: "grid grid-cols-7 gap-1", role: "grid", onKeyDown: V, children: H.map((e, n) => {
233
+ const $ = e ? new Date(D, u, e) : null, b = v || !!$ && !!d?.($), C = !!$ && !!i && _($, i);
234
+ return /* @__PURE__ */ l(
235
+ "button",
236
+ {
237
+ type: "button",
238
+ disabled: !e || b,
239
+ "aria-disabled": b || void 0,
240
+ "aria-selected": J(e) || void 0,
241
+ role: "gridcell",
242
+ onClick: () => e && A(e),
243
+ tabIndex: C ? 0 : -1,
244
+ "data-calendar-focus": C ? "true" : void 0,
245
+ className: `
246
+ aspect-square flex items-center justify-center text-sm rounded-lg
247
+ ${e ? "" : "invisible"}
248
+ ${e && !b ? "hover:bg-base-200 cursor-pointer" : ""}
249
+ ${J(e) ? "bg-primary text-primary-content hover:bg-primary/90" : ""}
250
+ ${ge(e) && !J(e) ? "border border-primary" : ""}
251
+ ${b ? "text-base-content/30 cursor-not-allowed" : ""}
252
+ `,
253
+ children: e
254
+ },
255
+ n
256
+ );
257
+ }) }),
258
+ /* @__PURE__ */ l("div", { className: "mt-4 flex justify-end", children: /* @__PURE__ */ l(
259
+ "button",
260
+ {
261
+ type: "button",
262
+ onClick: () => {
263
+ const e = /* @__PURE__ */ new Date();
264
+ d?.(e) || (K(e), c(e.getMonth()), P(e.getFullYear()), x?.(e), m(!1));
265
+ },
266
+ className: `${z} ${L} ${I}`,
267
+ disabled: de,
268
+ children: G
269
+ }
270
+ ) })
271
+ ]
272
+ }
273
+ )
201
274
  ] });
202
- }), ie = _(function({
203
- value: n,
204
- defaultValue: m,
205
- onChange: g,
206
- format: R,
207
- placeholder: $,
208
- disabled: k = !1,
209
- size: V,
210
- "data-testid": y,
211
- className: J = "",
212
- ...G
213
- }, H) {
214
- const { componentSize: W } = ne(), K = V ?? W ?? "md", [P, u] = Array.isArray($) ? $ : [$ ?? "Start date", "End date"], C = Array.isArray($) ? `${P} - ${u}` : $ ?? "Start date - End date", v = (t) => y ? `${y}-${t}` : void 0, [h, o] = D(
215
- n || m || [null, null]
216
- ), [f, c] = D(!1), N = h[0] ?? h[1] ?? /* @__PURE__ */ new Date(), [l, M] = D(N.getMonth()), [p, F] = D(N.getFullYear()), T = ee(null);
217
- L(() => {
218
- n !== void 0 && o(n);
219
- }, [n]), L(() => {
220
- function t(d) {
221
- T.current && !T.current.contains(d.target) && c(!1);
275
+ }), Ne = be(function({
276
+ value: a,
277
+ defaultValue: h,
278
+ onChange: x,
279
+ format: B,
280
+ placeholder: R,
281
+ disabledDate: d,
282
+ disabled: v = !1,
283
+ size: oe,
284
+ "data-testid": T,
285
+ className: se = "",
286
+ ...le
287
+ }, ce) {
288
+ const { componentSize: ie, locale: j } = ye(), ue = oe ?? ie ?? "md", U = j?.DatePicker?.rangePlaceholder, [G, q] = Array.isArray(R) ? R : [
289
+ R ?? U?.[0] ?? "Start date",
290
+ U?.[1] ?? "End date"
291
+ ], de = Array.isArray(R) ? `${G} - ${q}` : R ?? `${G} - ${q}`, W = j?.DatePicker?.today ?? "Today", p = /* @__PURE__ */ new Date(), K = v || d?.(p), y = (t) => T ? `${T}-${t}` : void 0, [m, i] = Y(
292
+ a || h || [null, null]
293
+ ), [M, u] = Y(!1), [c, D] = Y(null), P = m[0] ?? m[1] ?? /* @__PURE__ */ new Date(), [f, k] = Y(P.getMonth()), [w, A] = Y(P.getFullYear()), N = ee(null), V = ee(null), Q = we.useId();
294
+ O(() => {
295
+ a !== void 0 && i(a);
296
+ }, [a]), O(() => {
297
+ function t(r) {
298
+ N.current && !N.current.contains(r.target) && u(!1);
299
+ }
300
+ if (M)
301
+ return document.addEventListener("mousedown", t), D(m[0] ?? m[1] ?? p), () => document.removeEventListener("mousedown", t);
302
+ }, [M]), O(() => {
303
+ if (!M || !V.current) return;
304
+ V.current.querySelector('[data-calendar-focus="true"]')?.focus();
305
+ }, [M, f, w, c]);
306
+ const X = (t) => {
307
+ const r = new Date(w, f, t);
308
+ if (v || d?.(r)) return;
309
+ let [s, g] = m;
310
+ !s || s && g ? (s = r, g = null) : s && !g && (De(r, s) ? (g = s, s = r) : g = r);
311
+ const E = [s, g];
312
+ i(E), x?.(E), s && g && u(!1);
313
+ }, S = (t, r) => {
314
+ let s = ae(t, r);
315
+ for (let g = 0; g < 31; g++) {
316
+ if (!d?.(s)) return s;
317
+ s = ae(s, r);
222
318
  }
223
- if (f)
224
- return document.addEventListener("mousedown", t), () => document.removeEventListener("mousedown", t);
225
- }, [f]);
226
- const Q = (t) => {
227
- const d = new Date(p, l, t);
228
- let [a, b] = h;
229
- !a || a && b ? (a = d, b = null) : a && !b && (Z(d, a) ? (b = a, a = d) : b = d);
230
- const z = [a, b];
231
- o(z), g?.(z), a && b && c(!1);
232
- }, O = () => {
233
- l === 0 ? (M(11), F(p - 1)) : M(l - 1);
234
- }, B = () => {
235
- l === 11 ? (M(0), F(p + 1)) : M(l + 1);
236
- }, U = ae(p, l), e = oe(p, l), i = [];
319
+ return t;
320
+ }, fe = (t) => {
321
+ if (!c) return;
322
+ let r = c;
323
+ switch (t.key) {
324
+ case "ArrowRight":
325
+ t.preventDefault(), r = S(c, 1);
326
+ break;
327
+ case "ArrowLeft":
328
+ t.preventDefault(), r = S(c, -1);
329
+ break;
330
+ case "ArrowDown":
331
+ t.preventDefault(), r = S(c, 7);
332
+ break;
333
+ case "ArrowUp":
334
+ t.preventDefault(), r = S(c, -7);
335
+ break;
336
+ case "Home":
337
+ t.preventDefault(), r = new Date(c.getFullYear(), c.getMonth(), 1), d?.(r) && (r = S(r, 1));
338
+ break;
339
+ case "End":
340
+ t.preventDefault(), r = new Date(c.getFullYear(), c.getMonth(), ne(c.getFullYear(), c.getMonth())), d?.(r) && (r = S(r, -1));
341
+ break;
342
+ case "Enter":
343
+ case " ":
344
+ t.preventDefault(), X(c.getDate());
345
+ return;
346
+ case "Escape":
347
+ t.preventDefault(), u(!1);
348
+ return;
349
+ default:
350
+ return;
351
+ }
352
+ D(r), k(r.getMonth()), A(r.getFullYear());
353
+ }, H = () => {
354
+ f === 0 ? (k(11), A(w - 1)) : k(f - 1);
355
+ }, J = () => {
356
+ f === 11 ? (k(0), A(w + 1)) : k(f + 1);
357
+ }, ge = ne(w, f), e = xe(w, f), n = [];
237
358
  for (let t = 0; t < e; t++)
238
- i.push(null);
239
- for (let t = 1; t <= U; t++)
240
- i.push(t);
241
- const ce = (t) => {
359
+ n.push(null);
360
+ for (let t = 1; t <= ge; t++)
361
+ n.push(t);
362
+ const $ = (t) => {
242
363
  if (!t) return !1;
243
- const d = /* @__PURE__ */ new Date();
244
- return d.getDate() === t && d.getMonth() === l && d.getFullYear() === p;
245
- }, [E, j] = h;
246
- return /* @__PURE__ */ w("div", { ref: H || T, className: `relative ${J}`, "data-state": f ? "open" : "closed", "data-testid": y, ...G, children: [
247
- /* @__PURE__ */ s(
248
- te,
364
+ const r = /* @__PURE__ */ new Date();
365
+ return r.getDate() === t && r.getMonth() === f && r.getFullYear() === w;
366
+ }, [b, C] = m;
367
+ return /* @__PURE__ */ F("div", { ref: ce || N, className: `relative ${se}`, "data-state": M ? "open" : "closed", "data-testid": T, ...le, children: [
368
+ /* @__PURE__ */ l(
369
+ ve,
249
370
  {
250
- value: fe(h, R),
251
- placeholder: C,
252
- disabled: k,
253
- size: K,
371
+ value: Se(m, B),
372
+ placeholder: de,
373
+ disabled: v,
374
+ size: ue,
254
375
  readOnly: !0,
255
- onClick: () => !k && c(!f),
376
+ onClick: () => !v && u(!M),
377
+ "aria-haspopup": "dialog",
378
+ "aria-expanded": M,
379
+ "aria-controls": Q,
256
380
  className: "cursor-pointer",
257
- "data-testid": v("input")
381
+ "data-testid": y("input")
258
382
  }
259
383
  ),
260
- f && /* @__PURE__ */ w("div", { className: "absolute top-full left-0 mt-2 bg-base-100 border border-base-300 rounded-lg shadow-lg p-4 z-50 w-80", "data-testid": v("calendar"), children: [
261
- /* @__PURE__ */ w("div", { className: "flex items-center justify-between mb-4", children: [
262
- /* @__PURE__ */ s(
263
- "button",
264
- {
265
- type: "button",
266
- onClick: O,
267
- className: `${x} ${Y} ${S} ${I}`,
268
- children: /* @__PURE__ */ s(
269
- "svg",
384
+ M && /* @__PURE__ */ F(
385
+ "div",
386
+ {
387
+ ref: V,
388
+ id: Q,
389
+ role: "dialog",
390
+ "aria-label": "Date range picker calendar",
391
+ className: "absolute top-full left-0 mt-2 bg-base-100 border border-base-300 rounded-lg shadow-lg p-4 z-50 w-80",
392
+ "data-testid": y("calendar"),
393
+ children: [
394
+ /* @__PURE__ */ F("div", { className: "flex items-center justify-between mb-4", children: [
395
+ /* @__PURE__ */ l(
396
+ "button",
270
397
  {
271
- xmlns: "http://www.w3.org/2000/svg",
272
- className: "h-5 w-5",
273
- viewBox: "0 0 20 20",
274
- fill: "currentColor",
275
- children: /* @__PURE__ */ s(
276
- "path",
398
+ type: "button",
399
+ onClick: H,
400
+ className: `${z} ${L} ${I} ${te}`,
401
+ children: /* @__PURE__ */ l(
402
+ "svg",
277
403
  {
278
- fillRule: "evenodd",
279
- d: "M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",
280
- clipRule: "evenodd"
404
+ xmlns: "http://www.w3.org/2000/svg",
405
+ className: "h-5 w-5",
406
+ viewBox: "0 0 20 20",
407
+ fill: "currentColor",
408
+ children: /* @__PURE__ */ l(
409
+ "path",
410
+ {
411
+ fillRule: "evenodd",
412
+ d: "M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",
413
+ clipRule: "evenodd"
414
+ }
415
+ )
281
416
  }
282
417
  )
283
418
  }
284
- )
285
- }
286
- ),
287
- /* @__PURE__ */ w("div", { className: "text-base font-semibold", children: [
288
- re[l],
289
- " ",
290
- p
291
- ] }),
292
- /* @__PURE__ */ s(
293
- "button",
294
- {
295
- type: "button",
296
- onClick: B,
297
- className: `${x} ${Y} ${S} ${I}`,
298
- children: /* @__PURE__ */ s(
299
- "svg",
419
+ ),
420
+ /* @__PURE__ */ F("div", { className: "text-base font-semibold", children: [
421
+ $e[f],
422
+ " ",
423
+ w
424
+ ] }),
425
+ /* @__PURE__ */ l(
426
+ "button",
300
427
  {
301
- xmlns: "http://www.w3.org/2000/svg",
302
- className: "h-5 w-5",
303
- viewBox: "0 0 20 20",
304
- fill: "currentColor",
305
- children: /* @__PURE__ */ s(
306
- "path",
428
+ type: "button",
429
+ onClick: J,
430
+ className: `${z} ${L} ${I} ${te}`,
431
+ children: /* @__PURE__ */ l(
432
+ "svg",
307
433
  {
308
- fillRule: "evenodd",
309
- d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
310
- clipRule: "evenodd"
434
+ xmlns: "http://www.w3.org/2000/svg",
435
+ className: "h-5 w-5",
436
+ viewBox: "0 0 20 20",
437
+ fill: "currentColor",
438
+ children: /* @__PURE__ */ l(
439
+ "path",
440
+ {
441
+ fillRule: "evenodd",
442
+ d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
443
+ clipRule: "evenodd"
444
+ }
445
+ )
311
446
  }
312
447
  )
313
448
  }
314
449
  )
315
- }
316
- )
317
- ] }),
318
- /* @__PURE__ */ s("div", { className: "grid grid-cols-7 gap-1 mb-2", children: se.map((t) => /* @__PURE__ */ s(
319
- "div",
320
- {
321
- className: "text-center text-xs font-semibold text-base-content/60 py-2",
322
- children: t
323
- },
324
- t
325
- )) }),
326
- /* @__PURE__ */ s("div", { className: "grid grid-cols-7 gap-1", children: i.map((t, d) => {
327
- const a = t ? new Date(p, l, t) : null, b = !!a && !!E && X(a, E), z = !!a && !!j && X(a, j), de = !!a && !!E && !!j && ue(a, E) && Z(a, j);
328
- return /* @__PURE__ */ s(
329
- "button",
330
- {
331
- type: "button",
332
- disabled: !t,
333
- onClick: () => t && Q(t),
334
- className: `
450
+ ] }),
451
+ /* @__PURE__ */ l("div", { className: "grid grid-cols-7 gap-1 mb-2", role: "row", children: Me.map((t) => /* @__PURE__ */ l(
452
+ "div",
453
+ {
454
+ className: "text-center text-xs font-semibold text-base-content/60 py-2",
455
+ role: "columnheader",
456
+ children: t
457
+ },
458
+ t
459
+ )) }),
460
+ /* @__PURE__ */ l("div", { className: "grid grid-cols-7 gap-1", role: "grid", onKeyDown: fe, children: n.map((t, r) => {
461
+ const s = t ? new Date(w, f, t) : null, g = v || !!s && !!d?.(s), E = !!s && !!b && _(s, b), he = !!s && !!C && _(s, C), pe = !!s && !!b && !!C && Ye(s, b) && De(s, C), me = !!s && !!c && _(s, c);
462
+ return /* @__PURE__ */ l(
463
+ "button",
464
+ {
465
+ type: "button",
466
+ disabled: !t || g,
467
+ "aria-disabled": g || void 0,
468
+ "aria-selected": E || he || pe || void 0,
469
+ role: "gridcell",
470
+ onClick: () => t && X(t),
471
+ tabIndex: me ? 0 : -1,
472
+ "data-calendar-focus": me ? "true" : void 0,
473
+ className: `
335
474
  aspect-square flex items-center justify-center text-sm rounded-lg
336
- ${t ? "hover:bg-base-200" : "invisible"}
337
- ${de ? "bg-primary/10" : ""}
338
- ${b || z ? "bg-primary text-primary-content hover:bg-primary/90" : ""}
339
- ${ce(t) && !b && !z ? "border border-primary" : ""}
340
- ${t ? "cursor-pointer" : ""}
475
+ ${t ? "" : "invisible"}
476
+ ${t && !g ? "hover:bg-base-200 cursor-pointer" : ""}
477
+ ${pe ? "bg-primary/10" : ""}
478
+ ${E || he ? "bg-primary text-primary-content hover:bg-primary/90" : ""}
479
+ ${$(t) && !E && !he ? "border border-primary" : ""}
480
+ ${g ? "text-base-content/30 cursor-not-allowed" : ""}
341
481
  `,
342
- children: t
343
- },
344
- d
345
- );
346
- }) }),
347
- /* @__PURE__ */ s("div", { className: "mt-4 flex justify-end", children: /* @__PURE__ */ s(
348
- "button",
349
- {
350
- type: "button",
351
- onClick: () => {
352
- const t = /* @__PURE__ */ new Date();
353
- o([t, t]), M(t.getMonth()), F(t.getFullYear()), g?.([t, t]), c(!1);
354
- },
355
- className: `${x} ${Y} ${S}`,
356
- children: "Today"
357
- }
358
- ) })
359
- ] })
482
+ children: t
483
+ },
484
+ r
485
+ );
486
+ }) }),
487
+ /* @__PURE__ */ l("div", { className: "mt-4 flex justify-end", children: /* @__PURE__ */ l(
488
+ "button",
489
+ {
490
+ type: "button",
491
+ onClick: () => {
492
+ const t = /* @__PURE__ */ new Date();
493
+ d?.(t) || (i([t, t]), k(t.getMonth()), A(t.getFullYear()), x?.([t, t]), u(!1));
494
+ },
495
+ className: `${z} ${L} ${I}`,
496
+ disabled: K,
497
+ children: W
498
+ }
499
+ ) })
500
+ ]
501
+ }
502
+ )
360
503
  ] });
361
504
  });
362
- le.displayName = "DatePicker";
363
- ie.displayName = "DatePicker.Range";
364
- const me = le;
365
- me.Range = ie;
505
+ ke.displayName = "DatePicker";
506
+ Ne.displayName = "DatePicker.Range";
507
+ const Fe = ke;
508
+ Fe.Range = Ne;
366
509
  export {
367
- me as DatePicker
510
+ Fe as DatePicker
368
511
  };
369
512
  //# sourceMappingURL=DatePicker.js.map