react-modular-datepicker 0.0.7 → 0.0.9

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.
package/dist/index.js CHANGED
@@ -1,45 +1,44 @@
1
- import { n as e, r as t, t as n } from "./useDates-CjPuu-VA.js";
1
+ import { n as e, r as t, t as n } from "./useDates-BVAPuyDo.js";
2
2
  import { addMonth as r, composeEventHandlers as i, getCalendars as a, isBackDisabled as o, isForwardDisabled as s, subtractMonth as c } from "./utils.js";
3
- import { useEffect as l, useRef as u, useState as d } from "react";
4
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
5
- //#region src/components/Day.tsx
6
- var m = ({ dateObj: e, getDateProps: t, dayProps: n, classNames: r }) => {
7
- if (!e) return /* @__PURE__ */ f("div", { className: "aspect-square bg-white" });
8
- let { date: i, selected: a, selectable: o, isRangeStart: s, isRangeEnd: c, isRangeBetween: l, isRangeHovering: u, isRangeActive: d } = e, p = r.day, m = "rounded-full";
9
- m = s && c ? `${p.selected} rounded-full` : s ? `${p.rangeStart} ${d ? "rounded-l-full rounded-r-none" : "rounded-full"}` : c ? `${p.rangeEnd} ${d ? "rounded-r-full rounded-l-none" : "rounded-full"}` : l ? p.rangeBetween || "" : u ? p.rangeHovering || "" : a ? p.selected || "" : o ? p.unselected || "" : p.disabled || "";
10
- let h = [
11
- p.day,
12
- m,
13
- ...(e.modifiers || []).map((e) => p[e] || e)
14
- ].filter(Boolean).join(" ");
15
- return /* @__PURE__ */ f("button", {
16
- ...t({
17
- dateObj: e,
18
- ...n
19
- }),
20
- className: h,
21
- children: i.getDate()
22
- });
23
- };
3
+ import { useEffect as l, useMemo as u, useRef as d, useState as f } from "react";
4
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
5
+ //#region ../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
6
+ function h(e) {
7
+ var t, n, r = "";
8
+ if (typeof e == "string" || typeof e == "number") r += e;
9
+ else if (typeof e == "object") {
10
+ if (Array.isArray(e)) {
11
+ var i = e.length;
12
+ for (t = 0; t < i; t++) e[t] && (n = h(e[t])) && (r && (r += " "), r += n);
13
+ } else for (n in e) e[n] && (r && (r += " "), r += n);
14
+ }
15
+ return r;
16
+ }
17
+ function g() {
18
+ for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = h(e)) && (r && (r += " "), r += t);
19
+ return r;
20
+ }
24
21
  //#endregion
25
22
  //#region src/i18n.ts
26
- function h(e = t, n) {
23
+ function _(e = t, n) {
27
24
  return {
28
25
  months: e.getMonths(n),
29
26
  weekdays: e.getWeekdays(n),
30
27
  back: "Previous month",
31
- forward: "Next month"
28
+ forward: "Next month",
29
+ selectMonth: "Select month",
30
+ selectYear: "Select year"
32
31
  };
33
32
  }
34
- function g(e = t, n, r) {
33
+ function v(e = t, n, r) {
35
34
  return {
36
- ...h(e, n),
35
+ ..._(e, n),
37
36
  ...r
38
37
  };
39
38
  }
40
39
  //#endregion
41
40
  //#region src/components/CalendarHeader.tsx
42
- var _ = () => /* @__PURE__ */ f("svg", {
41
+ var y = () => /* @__PURE__ */ p("svg", {
43
42
  width: "20",
44
43
  height: "20",
45
44
  viewBox: "0 0 24 24",
@@ -48,8 +47,8 @@ var _ = () => /* @__PURE__ */ f("svg", {
48
47
  strokeWidth: "2",
49
48
  strokeLinecap: "round",
50
49
  strokeLinejoin: "round",
51
- children: /* @__PURE__ */ f("polyline", { points: "15 18 9 12 15 6" })
52
- }), v = () => /* @__PURE__ */ f("svg", {
50
+ children: /* @__PURE__ */ p("polyline", { points: "15 18 9 12 15 6" })
51
+ }), b = () => /* @__PURE__ */ p("svg", {
53
52
  width: "20",
54
53
  height: "20",
55
54
  viewBox: "0 0 24 24",
@@ -58,258 +57,467 @@ var _ = () => /* @__PURE__ */ f("svg", {
58
57
  strokeWidth: "2",
59
58
  strokeLinecap: "round",
60
59
  strokeLinejoin: "round",
61
- children: /* @__PURE__ */ f("polyline", { points: "9 18 15 12 9 6" })
62
- }), y = ({ calendars: e, getBackProps: t, getForwardProps: n, setView: r, monthNames: i, t: a, classNames: o, slideDirection: s, currentView: c }) => /* @__PURE__ */ p("div", {
63
- className: o.header,
64
- children: [
65
- /* @__PURE__ */ f("button", {
66
- ...t({ calendars: e }),
67
- onMouseDown: (e) => e.preventDefault(),
68
- className: `${o.navButton} ${c && c !== "days" ? "invisible pointer-events-none" : ""}`,
69
- "aria-label": a.back,
70
- children: /* @__PURE__ */ f(_, {})
71
- }),
72
- /* @__PURE__ */ f("div", {
73
- className: o.monthYearContainer,
74
- children: e.length === 1 ? /* @__PURE__ */ p("div", {
75
- className: `${o.monthYearLabel} ${s === "left" ? "animate-slide-in-left" : s === "right" ? "animate-slide-in-right" : ""}`,
76
- children: [/* @__PURE__ */ f("button", {
77
- onMouseDown: (e) => e.preventDefault(),
78
- onClick: () => r(c === "months" ? "days" : "months"),
79
- className: o.monthYearButton,
80
- children: i[e[0].month]
81
- }), /* @__PURE__ */ f("button", {
82
- onMouseDown: (e) => e.preventDefault(),
83
- onClick: () => r(c === "years" ? "days" : "years"),
84
- className: o.monthYearButton,
85
- children: e[0].year
86
- })]
87
- }, `${e[0].month}-${e[0].year}`) : /* @__PURE__ */ f("div", {
88
- className: `${o.monthYearLabel} ${s === "left" ? "animate-slide-in-left" : s === "right" ? "animate-slide-in-right" : ""}`,
89
- children: (() => {
90
- let t = e[0], n = e[e.length - 1];
91
- return e.length === 12 && t.month === 0 && n.month === 11 && t.year === n.year ? /* @__PURE__ */ f("span", { children: t.year }) : t.year === n.year ? /* @__PURE__ */ p("span", { children: [
92
- i[t.month],
93
- " - ",
94
- i[n.month],
95
- " ",
96
- t.year
97
- ] }) : /* @__PURE__ */ p("span", { children: [
98
- i[t.month],
99
- " ",
100
- t.year,
101
- " - ",
102
- i[n.month],
103
- " ",
104
- n.year
105
- ] });
106
- })()
60
+ children: /* @__PURE__ */ p("polyline", { points: "9 18 15 12 9 6" })
61
+ }), x = ({ calendars: e, getBackProps: t, getForwardProps: n, setView: r, monthNames: i, t: a, classNames: o, slideDirection: s, currentView: c }) => {
62
+ if (e.length > 1 && e.length < 12) return null;
63
+ let l = e[0], u = e[e.length - 1], d = !!(c && c !== "days"), f = g("rmd-nav-button", d && "rmd-nav-button-hidden", o?.navButton, d && o?.navButtonHidden), h = g("rmd-month-year-label", s === "left" && "rmd-slide-left", s === "right" && "rmd-slide-right", o?.monthYearLabel);
64
+ return /* @__PURE__ */ m("div", {
65
+ className: g("rmd-header", e.length > 1 && "rmd-header-multi-month", o?.header, e.length > 1 && o?.headerMultiMonth),
66
+ children: [
67
+ /* @__PURE__ */ p("button", {
68
+ ...t({ calendars: e }),
69
+ className: f,
70
+ "aria-label": a.back,
71
+ children: /* @__PURE__ */ p(y, {})
72
+ }),
73
+ /* @__PURE__ */ p("div", {
74
+ className: g("rmd-month-year-container", o?.monthYearContainer),
75
+ children: e.length === 1 ? /* @__PURE__ */ m("div", {
76
+ className: h,
77
+ children: [/* @__PURE__ */ p("button", {
78
+ onClick: () => r(c === "months" ? "days" : "months"),
79
+ className: g("rmd-month-year-button", o?.monthYearButton),
80
+ "aria-label": `${i[e[0].month]}, ${a.selectMonth || "Select month"}`,
81
+ "aria-expanded": c === "months",
82
+ children: i[e[0].month]
83
+ }), /* @__PURE__ */ p("button", {
84
+ onClick: () => r(c === "years" ? "days" : "years"),
85
+ className: g("rmd-month-year-button", o?.monthYearButton),
86
+ "aria-label": `${e[0].year}, ${a.selectYear || "Select year"}`,
87
+ "aria-expanded": c === "years",
88
+ children: e[0].year
89
+ })]
90
+ }, `${e[0].month}-${e[0].year}`) : /* @__PURE__ */ p("div", {
91
+ className: h,
92
+ children: /* @__PURE__ */ p("span", { children: l.year === u.year ? l.year : `${l.year} - ${u.year}` })
93
+ })
94
+ }),
95
+ /* @__PURE__ */ p("button", {
96
+ ...n({ calendars: e }),
97
+ className: f,
98
+ "aria-label": a.forward,
99
+ children: /* @__PURE__ */ p(b, {})
107
100
  })
108
- }),
109
- /* @__PURE__ */ f("button", {
110
- ...n({ calendars: e }),
111
- onMouseDown: (e) => e.preventDefault(),
112
- className: `${o.navButton} ${c && c !== "days" ? "invisible pointer-events-none" : ""}`,
113
- "aria-label": a.forward,
114
- children: /* @__PURE__ */ f(v, {})
115
- })
116
- ]
117
- }), b = {
118
- root: "w-fit flex flex-col p-4 bg-white rounded-lg shadow-lg",
119
- header: "flex items-center justify-between border-b-2 border-brand-gray-light/40 pb-2",
120
- calendarsContainer: "flex flex-wrap gap-4",
121
- calendarContainer: "flex-1 min-w-[280px] max-w-full",
122
- weekdayGrid: "grid grid-cols-7 gap-1 mb-1 border-b border-brand-gray-light/40",
123
- weekday: "text-center text-xs text-gray-400 py-2",
124
- daysGrid: "grid grid-cols-7 gap-px bg-brand-gray-light/20",
125
- footer: "mt-4",
126
- navButton: "p-2 text-brand-text hover:bg-gray-100 rounded-full transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none",
127
- monthYearContainer: "flex gap-8",
128
- monthYearLabel: "flex gap-1 items-center font-semibold text-brand-text",
129
- monthYearButton: "hover:bg-gray-100 px-2 py-1 rounded cursor-pointer",
130
- day: {
131
- day: "aspect-square flex items-center justify-center text-sm font-medium transition-all relative group cursor-pointer p-px",
132
- selected: "bg-brand-gold text-white rounded-full",
133
- unselected: "bg-white hover:bg-brand-gray-light text-brand-text",
134
- disabled: "bg-white text-gray-300 cursor-not-allowed",
135
- rangeStart: "bg-brand-gold text-white",
136
- rangeEnd: "bg-brand-gold text-white",
137
- rangeBetween: "bg-brand-gold/25 text-brand-text",
138
- rangeHovering: "bg-brand-gold/25 text-brand-text"
139
- },
140
- monthsGrid: "grid grid-cols-3 gap-2 animate-slide-in-top",
141
- monthButton: "py-3 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none",
142
- monthButtonSelected: "bg-brand-gold text-white",
143
- monthButtonUnselected: "text-brand-text",
144
- yearsGrid: "grid grid-cols-3 gap-2 max-h-[210px] overflow-y-auto pr-2 animate-slide-in-top rmdp-scrollbar",
145
- yearButton: "py-3 rounded-lg hover:bg-brand-gray-light transition-colors cursor-pointer disabled:opacity-30 disabled:pointer-events-none",
146
- yearButtonSelected: "bg-brand-gold text-white",
147
- yearButtonUnselected: "text-brand-text"
148
- }, x = (e) => {
149
- let t = { ...b };
150
- if (!e) return t;
151
- for (let n in e) {
152
- let r = n;
153
- r === "day" && e.day ? t.day = {
154
- ...b.day,
155
- ...e.day
156
- } : e[r] && (t[r] = e[r]);
157
- }
158
- return t;
159
- }, S = ({ year: e, month: t, monthNames: n, minDate: r, maxDate: i, onMonthSelect: a, classNames: o }) => {
160
- let s = (t) => !!(r && e === r.getFullYear() && t < r.getMonth() || i && e === i.getFullYear() && t > i.getMonth());
161
- return /* @__PURE__ */ f("div", {
162
- className: o.monthsGrid,
101
+ ]
102
+ });
103
+ }, S = ({ dateObj: e, getDateProps: t, dayProps: n, classNames: r, tabIndex: i = -1, adapter: a, locale: o, onKeyDown: s, onFocus: c, buttonRef: l }) => {
104
+ if (!e) return /* @__PURE__ */ p("div", {
105
+ role: "gridcell",
106
+ "aria-hidden": "true",
107
+ className: g("rmd-day-empty", r?.day?.empty)
108
+ });
109
+ let { date: u, selected: d, selectable: f, isRangeStart: m, isRangeEnd: h, isRangeBetween: _, isRangeHovering: v, isRangeActive: y } = e, b = r?.day, x = "", S = "";
110
+ m && h ? (x = "rmd-day-selected", S = b?.selected || "") : m ? (x = g("rmd-day-range-start", y && "rmd-day-range-active"), S = b?.rangeStart || "") : h ? (x = g("rmd-day-range-end", y && "rmd-day-range-active"), S = b?.rangeEnd || "") : _ ? (x = "rmd-day-range-between", S = b?.rangeBetween || "") : v ? (x = "rmd-day-range-hovering", S = b?.rangeHovering || "") : d ? (x = "rmd-day-selected", S = b?.selected || "") : f ? (x = "rmd-day-unselected", S = b?.unselected || "") : (x = "rmd-day-disabled", S = b?.disabled || "");
111
+ let C = (e.modifiers || []).map((e) => b?.[e] || e).filter(Boolean), w = a ? a.format(a.date(u), "dddd, MMMM D, YYYY", o) : u.toDateString(), T = !!(d || m || h), E = t({
112
+ dateObj: e,
113
+ ...n
114
+ });
115
+ return /* @__PURE__ */ p("button", {
116
+ role: "gridcell",
117
+ "aria-selected": T,
118
+ "aria-disabled": !f,
119
+ "aria-label": w,
120
+ tabIndex: i,
121
+ ...E,
122
+ ref: l,
123
+ onKeyDown: (t) => {
124
+ E.onKeyDown?.(t), s?.(t, e);
125
+ },
126
+ onFocus: (t) => {
127
+ E.onFocus?.(t), c?.(e);
128
+ },
129
+ className: g("rmd-day", b?.day, x, S, C),
130
+ children: u.getDate()
131
+ });
132
+ }, C = ({ year: e, month: t, monthNames: n, minDate: r, maxDate: i, onMonthSelect: a, classNames: o }) => {
133
+ let [s, c] = f(t), u = d([]);
134
+ l(() => {
135
+ u.current[s]?.focus();
136
+ }, [s]);
137
+ let m = (t) => !!(r && e === r.getFullYear() && t < r.getMonth() || i && e === i.getFullYear() && t > i.getMonth()), h = (e, t) => {
138
+ let n = s;
139
+ switch (e.key) {
140
+ case "ArrowLeft":
141
+ e.preventDefault(), n = (t - 1 + 12) % 12;
142
+ break;
143
+ case "ArrowRight":
144
+ e.preventDefault(), n = (t + 1) % 12;
145
+ break;
146
+ case "ArrowUp":
147
+ e.preventDefault(), n = (t - 3 + 12) % 12;
148
+ break;
149
+ case "ArrowDown":
150
+ e.preventDefault(), n = (t + 3) % 12;
151
+ break;
152
+ case "Home":
153
+ e.preventDefault(), n = 0;
154
+ break;
155
+ case "End":
156
+ e.preventDefault(), n = 11;
157
+ break;
158
+ case "Enter":
159
+ case " ":
160
+ e.preventDefault(), m(t) || a(t);
161
+ return;
162
+ default: return;
163
+ }
164
+ c(n);
165
+ }, _ = g("rmd-months-grid", o?.monthsGrid);
166
+ return /* @__PURE__ */ p("div", {
167
+ role: "grid",
168
+ "aria-label": "Select month",
169
+ className: _,
163
170
  children: n.map((e, n) => {
164
- let r = s(n);
165
- return /* @__PURE__ */ f("button", {
166
- onMouseDown: (e) => e.preventDefault(),
171
+ let r = m(n), i = n === t, l = n === s, d = g("rmd-month-button", i ? "rmd-month-button-selected" : "rmd-month-button-unselected", o?.monthButton, i ? o?.monthButtonSelected : o?.monthButtonUnselected);
172
+ return /* @__PURE__ */ p("button", {
173
+ ref: (e) => {
174
+ u.current[n] = e;
175
+ },
176
+ role: "gridcell",
177
+ "aria-selected": i,
178
+ "aria-disabled": r,
179
+ tabIndex: l ? 0 : -1,
167
180
  onClick: () => !r && a(n),
168
- className: `${o.monthButton} ${n === t ? o.monthButtonSelected : o.monthButtonUnselected}`,
181
+ onKeyDown: (e) => h(e, n),
182
+ onFocus: () => c(n),
183
+ className: d,
169
184
  disabled: r,
170
185
  children: e
171
186
  }, e);
172
187
  })
173
188
  });
174
- }, C = ({ year: e, minDate: t, maxDate: n, adapter: r, onYearSelect: i, classNames: a }) => {
175
- let o = u(null);
189
+ }, w = ({ year: e, minDate: t, maxDate: n, adapter: r, onYearSelect: i, classNames: a }) => {
190
+ let o = d(null), [s, c] = f(e), u = d(/* @__PURE__ */ new Map()), m = t ? r.get(r.date(t), "year") : e - 50, h = n ? r.get(r.date(n), "year") : e + 50, _ = [];
191
+ for (let e = m; e <= h; e++) _.push(e);
176
192
  l(() => {
177
193
  if (o.current) {
178
- let e = o.current.querySelector("[data-selected=\"true\"]");
179
- e && e.scrollIntoView({ block: "center" });
194
+ let e = o.current, t = e.querySelector("[data-selected=\"true\"]");
195
+ if (t) {
196
+ let n = t.offsetTop - e.clientHeight / 2 + t.clientHeight / 2;
197
+ e.scrollTop = Math.max(0, n);
198
+ }
180
199
  }
181
- }, []);
182
- let s = t ? r.get(r.date(t), "year") : e - 50, c = n ? r.get(r.date(n), "year") : e + 50, d = [];
183
- for (let e = s; e <= c; e++) d.push(e);
184
- return /* @__PURE__ */ f("div", {
200
+ }, []), l(() => {
201
+ let e = u.current.get(s);
202
+ e && e.focus();
203
+ }, [s]);
204
+ let v = (e, t) => {
205
+ let n = s;
206
+ switch (e.key) {
207
+ case "ArrowLeft":
208
+ e.preventDefault(), n = Math.max(m, t - 1);
209
+ break;
210
+ case "ArrowRight":
211
+ e.preventDefault(), n = Math.min(h, t + 1);
212
+ break;
213
+ case "ArrowUp":
214
+ e.preventDefault(), n = Math.max(m, t - 3);
215
+ break;
216
+ case "ArrowDown":
217
+ e.preventDefault(), n = Math.min(h, t + 3);
218
+ break;
219
+ case "PageUp":
220
+ e.preventDefault(), n = Math.max(m, t - 10);
221
+ break;
222
+ case "PageDown":
223
+ e.preventDefault(), n = Math.min(h, t + 10);
224
+ break;
225
+ case "Home":
226
+ e.preventDefault(), n = m;
227
+ break;
228
+ case "End":
229
+ e.preventDefault(), n = h;
230
+ break;
231
+ case "Enter":
232
+ case " ":
233
+ e.preventDefault(), i(t);
234
+ return;
235
+ default: return;
236
+ }
237
+ c(n);
238
+ };
239
+ return /* @__PURE__ */ p("div", {
185
240
  ref: o,
186
- className: a.yearsGrid,
187
- children: d.map((t) => /* @__PURE__ */ f("button", {
188
- "data-selected": t === e,
189
- onMouseDown: (e) => e.preventDefault(),
190
- onClick: () => i(t),
191
- className: `${a.yearButton} ${t === e ? a.yearButtonSelected : a.yearButtonUnselected}`,
192
- children: t
193
- }, t))
241
+ role: "grid",
242
+ "aria-label": "Select year",
243
+ className: g("rmd-years-grid", a?.yearsGrid),
244
+ children: _.map((t) => {
245
+ let n = t === e, r = t === s, o = g("rmd-year-button", n ? "rmd-year-button-selected" : "rmd-year-button-unselected", a?.yearButton, n ? a?.yearButtonSelected : a?.yearButtonUnselected);
246
+ return /* @__PURE__ */ p("button", {
247
+ ref: (e) => {
248
+ e ? u.current.set(t, e) : u.current.delete(t);
249
+ },
250
+ "data-selected": n,
251
+ role: "gridcell",
252
+ "aria-selected": n,
253
+ tabIndex: r ? 0 : -1,
254
+ onClick: () => i(t),
255
+ onKeyDown: (e) => v(e, t),
256
+ onFocus: () => c(t),
257
+ className: o,
258
+ children: t
259
+ }, t);
260
+ })
194
261
  });
195
- }, w = (e) => {
196
- let { classNames: r, locale: i, translations: a, adapter: o = t, firstDayOfWeek: s = 0, header: c, footer: l, getDayProps: u, ...h } = e, _ = x(r), [v, b] = d("days"), [w, T] = d(null), E = g(o, i, a), D = E.weekdays, O = E.months, { calendars: k, getBackProps: A, getForwardProps: j, getDateProps: M, setOffset: N } = n({
197
- ...h,
262
+ }, T = (e) => `${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`, E = (e) => {
263
+ let { classNames: r, locale: i, translations: a, adapter: o = t, firstDayOfWeek: s = 0, header: c, footer: h, getDayProps: _, ...E } = e, [D, O] = f("days"), [k, A] = f(null), [j, M] = f(null), [N, P] = f(null), [F, I] = f(""), L = d(null), R = d(null), z = d(/* @__PURE__ */ new Map()), B = d(!1), V = v(o, i, a), H = V.weekdays, U = V.months, { calendars: W, getBackProps: G, getForwardProps: ee, getDateProps: K, setOffset: q } = n({
264
+ ...E,
198
265
  adapter: o,
199
266
  firstDayOfWeek: s
200
- }), P = [...D.slice(s), ...D.slice(0, s)], { month: F, year: I } = k[0], L = (t) => {
201
- let n = o.set(o.set(o.date(e.date || /* @__PURE__ */ new Date()), "year", I), "month", F), r = o.set(n, "month", t), i = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), a = o.diff(r, i, "month");
202
- T(null), N(a), b("days");
203
- }, R = (t) => {
204
- let n = o.set(o.set(o.date(e.date || /* @__PURE__ */ new Date()), "year", I), "month", F), r = o.set(n, "year", t), i = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), a = o.diff(r, i, "month");
205
- T(null), N(a), b("days");
206
- }, z = (e) => {
207
- let t = A(e);
267
+ });
268
+ l(() => {
269
+ if (D === "days" && L.current) {
270
+ let e = L.current, t = () => {
271
+ e.offsetHeight > 0 && M(e.offsetHeight);
272
+ };
273
+ if (t(), typeof ResizeObserver < "u") {
274
+ let n = new ResizeObserver(() => {
275
+ t();
276
+ });
277
+ return n.observe(e), () => n.disconnect();
278
+ }
279
+ }
280
+ }, [D, W]), l(() => {
281
+ D === "days" && W.length > 0 ? W.length === 1 ? I(`${U[W[0].month]} ${W[0].year}`) : I(`${U[W[0].month]} ${W[0].year} to ${U[W[W.length - 1].month]} ${W[W.length - 1].year}`) : D === "months" ? I("Month selection view") : D === "years" && I("Year selection view");
282
+ }, [
283
+ D,
284
+ W,
285
+ U
286
+ ]);
287
+ let te = u(() => {
288
+ for (let e of W) for (let t of e.weeks) for (let e of t) if (e?.selectable && e.selected) return e.date;
289
+ for (let e of W) for (let t of e.weeks) for (let e of t) if (e?.selectable && e.today) return e.date;
290
+ for (let e of W) for (let t of e.weeks) for (let e of t) if (e?.selectable && !e.prevMonth && !e.nextMonth) return e.date;
291
+ return W[0]?.weeks[0]?.find((e) => e?.selectable)?.date || /* @__PURE__ */ new Date();
292
+ }, [W]), J = N || te;
293
+ l(() => {
294
+ if (D === "days" && J && B.current) {
295
+ let e = T(J), t = z.current.get(e);
296
+ t && t.focus();
297
+ }
298
+ }, [
299
+ J,
300
+ W,
301
+ D
302
+ ]);
303
+ let ne = [...H.slice(s), ...H.slice(0, s)], { month: Y, year: X } = W[0], re = (t) => {
304
+ let n = o.set(o.set(o.date(e.date || /* @__PURE__ */ new Date()), "year", X), "month", Y), r = o.set(n, "month", t), i = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), a = o.diff(r, i, "month");
305
+ A(null), q(a), O("days");
306
+ }, ie = (t) => {
307
+ let n = o.set(o.set(o.date(e.date || /* @__PURE__ */ new Date()), "year", X), "month", Y), r = o.set(n, "year", t), i = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), a = o.diff(r, i, "month");
308
+ A(null), q(a), O("days");
309
+ }, Z = E.monthsToDisplay || 1, Q = (e) => {
310
+ let t = G({
311
+ offset: Z,
312
+ ...e
313
+ });
208
314
  return {
209
315
  ...t,
210
316
  onClick: (e) => {
211
- T("left"), t.onClick?.(e);
317
+ A("left"), t.onClick?.(e);
212
318
  }
213
319
  };
214
- }, B = (e) => {
215
- let t = j(e);
320
+ }, $ = (e) => {
321
+ let t = ee({
322
+ offset: Z,
323
+ ...e
324
+ });
216
325
  return {
217
326
  ...t,
218
327
  onClick: (e) => {
219
- T("right"), t.onClick?.(e);
328
+ A("right"), t.onClick?.(e);
220
329
  }
221
330
  };
331
+ }, ae = (t, n) => {
332
+ let r = !!(R.current?.closest("[dir=\"rtl\"]") || typeof document < "u" && document.documentElement.dir === "rtl"), i = null, a = o.date(n.date);
333
+ switch (t.key) {
334
+ case "ArrowLeft":
335
+ t.preventDefault(), i = o.toDate(o.add(a, r ? 1 : -1, "day"));
336
+ break;
337
+ case "ArrowRight":
338
+ t.preventDefault(), i = o.toDate(o.add(a, r ? -1 : 1, "day"));
339
+ break;
340
+ case "ArrowUp":
341
+ t.preventDefault(), i = o.toDate(o.subtract(a, 7, "day"));
342
+ break;
343
+ case "ArrowDown":
344
+ t.preventDefault(), i = o.toDate(o.add(a, 7, "day"));
345
+ break;
346
+ case "Home": {
347
+ t.preventDefault();
348
+ let e = (o.toDate(a).getDay() - s + 7) % 7;
349
+ i = o.toDate(o.subtract(a, e, "day"));
350
+ break;
351
+ }
352
+ case "End": {
353
+ t.preventDefault();
354
+ let e = 6 - (o.toDate(a).getDay() - s + 7) % 7;
355
+ i = o.toDate(o.add(a, e, "day"));
356
+ break;
357
+ }
358
+ case "PageUp": {
359
+ t.preventDefault();
360
+ let e = t.shiftKey ? "year" : "month";
361
+ i = o.toDate(o.subtract(a, 1, e));
362
+ break;
363
+ }
364
+ case "PageDown": {
365
+ t.preventDefault();
366
+ let e = t.shiftKey ? "year" : "month";
367
+ i = o.toDate(o.add(a, 1, e));
368
+ break;
369
+ }
370
+ case "Enter":
371
+ case " ": return;
372
+ default: return;
373
+ }
374
+ if (i) {
375
+ B.current = !0, P(i);
376
+ let t = o.startOf(o.date(e.date || /* @__PURE__ */ new Date()), "month"), n = o.startOf(o.date(i), "month"), r = o.diff(n, t, "month");
377
+ q(r);
378
+ }
222
379
  };
223
- return /* @__PURE__ */ p("div", {
224
- className: `rmdp ${_.root}`,
380
+ return /* @__PURE__ */ m("div", {
381
+ ref: R,
382
+ className: g("rmd", "rmd-root", r?.root),
225
383
  children: [
384
+ /* @__PURE__ */ p("div", {
385
+ className: "rmd-sr-only",
386
+ "aria-live": "polite",
387
+ "aria-atomic": "true",
388
+ children: F
389
+ }),
226
390
  typeof c == "function" ? c({
227
- calendars: k,
228
- getBackProps: z,
229
- getForwardProps: B,
230
- setView: b,
231
- monthNames: O,
232
- t: E,
233
- slideDirection: w,
234
- currentView: v
235
- }) : c || /* @__PURE__ */ f(y, {
236
- calendars: k,
237
- getBackProps: z,
238
- getForwardProps: B,
239
- setView: b,
240
- monthNames: O,
241
- t: E,
242
- classNames: _,
243
- slideDirection: w,
244
- currentView: v
391
+ calendars: W,
392
+ getBackProps: Q,
393
+ getForwardProps: $,
394
+ setView: O,
395
+ monthNames: U,
396
+ t: V,
397
+ slideDirection: k,
398
+ currentView: D
399
+ }) : c || /* @__PURE__ */ p(x, {
400
+ calendars: W,
401
+ getBackProps: Q,
402
+ getForwardProps: $,
403
+ setView: O,
404
+ monthNames: U,
405
+ t: V,
406
+ classNames: r,
407
+ slideDirection: k,
408
+ currentView: D
245
409
  }),
246
- /* @__PURE__ */ p("div", {
247
- className: _.calendarsContainer,
410
+ /* @__PURE__ */ m("div", {
411
+ className: g("rmd-calendars-container", r?.calendarsContainer),
248
412
  children: [
249
- v === "months" && k.map((t) => /* @__PURE__ */ f("div", {
250
- className: _.calendarContainer,
251
- children: /* @__PURE__ */ f(S, {
413
+ D === "months" && W.map((t) => /* @__PURE__ */ p("div", {
414
+ className: g("rmd-calendar-container", r?.calendarContainer),
415
+ style: j ? { height: `${j}px` } : void 0,
416
+ children: /* @__PURE__ */ p(C, {
252
417
  year: t.year,
253
418
  month: t.month,
254
- monthNames: O,
419
+ monthNames: U,
255
420
  minDate: e.minDate,
256
421
  maxDate: e.maxDate,
257
- onMonthSelect: L,
258
- classNames: _
422
+ onMonthSelect: re,
423
+ classNames: r
259
424
  })
260
425
  }, `months-${t.year}`)),
261
- v === "years" && k.map((t) => /* @__PURE__ */ f("div", {
262
- className: _.calendarContainer,
263
- children: /* @__PURE__ */ f(C, {
426
+ D === "years" && W.map((t) => /* @__PURE__ */ p("div", {
427
+ className: g("rmd-calendar-container", r?.calendarContainer),
428
+ style: j ? { height: `${j}px` } : void 0,
429
+ children: /* @__PURE__ */ p(w, {
264
430
  year: t.year,
265
431
  minDate: e.minDate,
266
432
  maxDate: e.maxDate,
267
433
  adapter: o,
268
- onYearSelect: R,
269
- classNames: _
434
+ onYearSelect: ie,
435
+ classNames: r
270
436
  })
271
437
  }, `years-${t.year}`)),
272
- v === "days" && k.map((e) => /* @__PURE__ */ p("div", {
273
- className: _.calendarContainer,
438
+ D === "days" && W.map((e, t) => /* @__PURE__ */ m("div", {
439
+ ref: t === 0 ? L : void 0,
440
+ role: "grid",
441
+ "aria-label": `${U[e.month]} ${e.year}`,
442
+ className: g("rmd-calendar-container", r?.calendarContainer),
274
443
  children: [
275
- k.length > 1 && /* @__PURE__ */ p("button", {
276
- type: "button",
277
- "aria-label": O[e.month],
278
- className: "block w-full text-center font-semibold mb-2 text-brand-text",
444
+ W.length > 1 && /* @__PURE__ */ m("div", {
445
+ className: g("rmd-header", r?.header),
279
446
  children: [
280
- O[e.month],
281
- " ",
282
- k[0].year === k[k.length - 1].year ? "" : e.year
447
+ /* @__PURE__ */ p("div", {
448
+ className: g("rmd-nav-button-slot-start", r?.navButtonSlotStart),
449
+ children: t === 0 && W.length < 12 && /* @__PURE__ */ p("button", {
450
+ ...Q({ calendars: W }),
451
+ className: g("rmd-nav-button", r?.navButton),
452
+ "aria-label": V.back,
453
+ children: /* @__PURE__ */ p(y, {})
454
+ })
455
+ }),
456
+ /* @__PURE__ */ m("span", {
457
+ className: g("rmd-header-title-container", r?.headerTitleContainer),
458
+ children: [U[e.month], W.length < 12 ? ` ${e.year}` : ""]
459
+ }),
460
+ /* @__PURE__ */ p("div", {
461
+ className: g("rmd-nav-button-slot-end", r?.navButtonSlotEnd),
462
+ children: t === W.length - 1 && W.length < 12 && /* @__PURE__ */ p("button", {
463
+ ...$({ calendars: W }),
464
+ className: g("rmd-nav-button", r?.navButton),
465
+ "aria-label": V.forward,
466
+ children: /* @__PURE__ */ p(b, {})
467
+ })
468
+ })
283
469
  ]
284
470
  }),
285
- /* @__PURE__ */ f("div", {
286
- className: _.weekdayGrid,
287
- children: P.map((e) => /* @__PURE__ */ f("div", {
288
- className: _.weekday,
471
+ /* @__PURE__ */ p("div", {
472
+ role: "row",
473
+ className: g("rmd-weekday-grid", r?.weekdayGrid),
474
+ children: ne.map((e) => /* @__PURE__ */ p("div", {
475
+ role: "columnheader",
476
+ "aria-label": e,
477
+ className: g("rmd-weekday", r?.weekday),
289
478
  children: e
290
479
  }, e))
291
480
  }),
292
- /* @__PURE__ */ f("div", {
293
- className: `${_.daysGrid} ${w === "left" ? "animate-slide-in-left" : w === "right" ? "animate-slide-in-right" : ""}`,
294
- children: e.weeks.map((e, t) => e.map((e, n) => /* @__PURE__ */ f(m, {
295
- dateObj: e,
296
- getDateProps: M,
297
- dayProps: e ? u?.(e) : void 0,
298
- classNames: _
299
- }, `${t}-${n}`)))
300
- })
481
+ /* @__PURE__ */ p("div", {
482
+ role: "row",
483
+ className: g("rmd-days-grid", k === "left" && "rmd-slide-left", k === "right" && "rmd-slide-right", r?.daysGrid),
484
+ children: e.weeks.map((e, t) => e.map((e, n) => {
485
+ if (!e) return /* @__PURE__ */ p(S, {
486
+ dateObj: null,
487
+ getDateProps: K,
488
+ classNames: r
489
+ }, `${t}-${n}`);
490
+ let a = T(e.date), s = o.isSame(o.date(e.date), o.date(J), "day");
491
+ return /* @__PURE__ */ p(S, {
492
+ dateObj: e,
493
+ getDateProps: K,
494
+ dayProps: _?.(e),
495
+ classNames: r,
496
+ tabIndex: s ? 0 : -1,
497
+ adapter: o,
498
+ locale: i,
499
+ onKeyDown: ae,
500
+ onFocus: (e) => {
501
+ P(e.date);
502
+ },
503
+ buttonRef: (e) => {
504
+ e ? z.current.set(a, e) : z.current.delete(a);
505
+ }
506
+ }, `${t}-${n}`);
507
+ }))
508
+ }, `daysGrid-${e.month}-${e.year}`)
301
509
  ]
302
510
  }, `${e.month}-${e.year}`))
303
511
  ]
304
512
  }),
305
- l && /* @__PURE__ */ f("div", {
306
- className: _.footer,
307
- children: l
513
+ h && /* @__PURE__ */ p("div", {
514
+ className: g("rmd-footer", r?.footer),
515
+ children: h
308
516
  })
309
517
  ]
310
518
  });
311
519
  };
312
520
  //#endregion
313
- export { w as Calendar, y as CalendarHeader, _ as ChevronLeftIcon, v as ChevronRightIcon, m as Day, e as DayjsAdapter, S as MonthSelection, C as YearSelection, r as addMonth, i as composeEventHandlers, t as defaultAdapter, b as defaultClassNames, a as getCalendars, h as getDefaults, g as getTranslations, o as isBackDisabled, s as isForwardDisabled, x as mergeClassNames, c as subtractMonth, n as useDates };
521
+ export { E as Calendar, x as CalendarHeader, y as ChevronLeftIcon, b as ChevronRightIcon, S as Day, e as DayjsAdapter, C as MonthSelection, w as YearSelection, r as addMonth, i as composeEventHandlers, t as defaultAdapter, a as getCalendars, _ as getDefaults, v as getTranslations, o as isBackDisabled, s as isForwardDisabled, c as subtractMonth, n as useDates };
314
522
 
315
523
  //# sourceMappingURL=index.js.map