@rnwonder/react-date-picker
Version:
A lightweight, customizable, and accessible date picker component for React applications.
264 lines (263 loc) • 6.64 kB
JavaScript
import { k as c, S as h, g, L as f } from "./format-CMbjATj9-B6oamtiF.js";
const b = (t, e, a) => {
const o = h(
e,
t,
1 - ((a == null ? void 0 : a.weekStartDay) || 0)
).getDay(), r = h(e, t + 1, 0).getDate(), n = [], y = t === 0 ? 11 : t - 1, s = y === 11 ? e - 1 : e, l = h(
s,
y + 1,
0
).getDate();
let i = l - o + 1;
i === l + 1 && (i = 1);
const v = (m) => g(m, a == null ? void 0 : a.locale);
for (let m = 0; m < o; m++)
n.push({ value: v(i + m), month: "prev" });
for (let m = 1; m <= r; m++)
n.push({ value: v(m), month: "current" });
const D = 35 - n.length >= 0 ? 35 - n.length : 42 - n.length;
for (let m = 1; m <= D; m++)
n.push({ value: v(m), month: "next" });
return n;
}, p = () => {
const t = /* @__PURE__ */ new Date();
return {
day: t.getDate(),
month: t.getMonth(),
year: t.getFullYear()
};
};
function M(t, e) {
const a = [];
for (let o = e; o >= t; o--)
a.push(o);
return a;
}
const w = /* @__PURE__ */ new Date(), T = w.getFullYear(), u = (t, e) => e === "prev" ? t === 0 ? 11 : t - 1 : e === "next" ? t === 11 ? 0 : t + 1 : t, d = (t, e, a) => a === "prev" ? e === 0 ? t - 1 : t : a === "next" && e === 11 ? t + 1 : t, $ = (t, e) => ({
year: e === 0 ? t - 1 : t,
month: e === 0 ? 11 : e - 1
}), E = (t, e) => ({
year: e === 11 ? t + 1 : t,
month: e === 11 ? 0 : e + 1
});
function R(t, e) {
const a = [];
for (let o = 0; o < t.length; o += e)
a.push(t.slice(o, o + e));
return a;
}
const W = ({
startDay: t,
month: e,
year: a,
type: o,
setStartDay: r
}) => {
if (o === "single") {
const n = {
...t || p(),
...e !== void 0 && { month: e },
...a !== void 0 && { year: a }
};
return r == null || r(n), {
selectedDate: n,
type: o
};
}
return null;
}, x = () => {
const t = /* @__PURE__ */ new Date();
return {
day: t.getDate(),
month: t.getMonth(),
year: t.getFullYear()
};
}, j = (t) => {
const e = x();
return t instanceof Date ? t.getDate() === e.day && t.getMonth() === e.month && t.getFullYear() === e.year : t.day === e.day && t.month === e.month && t.year === e.year;
}, q = (t, e) => {
const a = t instanceof Date ? t : c(t), o = e instanceof Date ? e : c(e);
return a.getTime() < o.getTime();
}, A = (t, e = "long", a) => new Date(2e3, t, 1).toLocaleString(a ?? "en", { month: e }), B = (t, e) => {
const a = (o) => {
t && !t.contains(o.target) && e(o);
};
return document.addEventListener("click", a), () => {
document.removeEventListener("click", a);
};
}, C = ({
day: t,
endDate: e,
startDate: a,
year: o,
month: r,
monthStatus: n
}) => {
if (!a || !e)
return !1;
const y = h(
d(o, r, n),
u(r, n),
t
), s = h(a.year, a.month, a.day), l = h(e.year, e.month, e.day);
return y > s && y < l;
}, G = ({
dateRange: t,
day: e,
year: a,
month: o,
monthStatus: r
}) => {
if (!t)
return !1;
const n = h(
d(a, o, r),
u(o, r),
e
), y = h(t.year, t.month, t.day);
return n.getTime() === y.getTime();
}, H = ({
maxDate: t,
minDate: e,
day: a,
year: o,
month: r
}) => {
if (!e && !t)
return !1;
const n = h(
d(
f(o),
f(r),
a.month
),
u(f(r), a.month),
a.value
);
if (e && t) {
const y = h(e.year, e.month, e.day), s = h(t.year, t.month, t.day);
return n < y || n > s;
} else if (e) {
const y = h(e.year, e.month, e.day);
return n < y;
} else if (t) {
const y = h(t.year, t.month, t.day);
return n > y;
}
return !1;
}, S = ({
disabledDays: t,
month: e,
day: a,
year: o
}) => t ? !!t.find((r) => {
if ("start" in r && "end" in r) {
const n = c(r.start), y = c(r.end), s = c({
day: a.value,
month: u(e, a.month),
year: d(o, e, a.month)
});
return s >= n && s <= y;
} else
return r.day === a.value && r.month === u(e, a.month) && r.year === d(o, e, a.month);
}) : !1, k = ({
enabledDays: t,
day: e,
year: a,
month: o,
next: r,
prev: n
}) => t ? t.every((y) => {
const s = e ? {
day: e.value,
month: u(o, e.month),
year: d(a, o, e.month)
} : {
year: a,
month: o
};
if ("start" in y && "end" in y) {
const l = y.start, i = y.end;
if (Y(s, l, i, { next: r, prev: n }))
return !1;
} else if (F(s, y))
return !1;
return !0;
}) : !1;
function F(t, e) {
return t.day ? t.year === e.year && t.month === e.month && t.day === e.day : t.year === e.year && t.month === e.month;
}
function Y(t, e, a, o) {
if (o != null && o.next)
return e.year === void 0 || t.year === void 0 || e.year > t.year || t.year === e.year && (t.month === void 0 || e.month === void 0 || e.month >= t.month);
if (o != null && o.prev)
return a.year === void 0 || t.year === void 0 || a.year < t.year || t.year === a.year && (t.month === void 0 || a.month === void 0 || a.month <= t.month);
const r = e.year === void 0 || t.year === void 0 || t.year > e.year || t.year === e.year && (t.month === void 0 || e.month === void 0 || t.month > e.month || t.month === e.month && (t.day ? e.day === void 0 || t.day >= e.day : !0)), n = a.year === void 0 || t.year === void 0 || t.year < a.year || t.year === a.year && (t.month === void 0 || a.month === void 0 || t.month < a.month || t.month === a.month && (t.day ? a.day === void 0 || t.day <= a.day : !0));
return r && n;
}
const J = (t, e, a) => {
const o = new Date(t), r = new Date(e);
for (let n = new Date(o); n <= r; n.setDate(n.getDate() + 1))
if (S({
day: {
month: "current",
value: n.getDate()
},
month: n.getMonth(),
year: n.getFullYear(),
disabledDays: a
}))
return !0;
return !1;
}, K = (t, e, a) => {
const o = new Date(t), r = new Date(e);
for (let n = new Date(o); n <= r; n.setDate(n.getDate() + 1))
if (k({
day: {
month: "current",
value: n.getDate()
},
month: n.getMonth(),
year: n.getFullYear(),
enabledDays: a
}))
return !0;
return !1;
}, N = ({
year: t,
month: e,
day: a
}) => {
const o = u(e, a.month), r = d(t, e, a.month), n = h(r, o, a.value).getDay();
return {
isWeekend: n === 0 || n === 6,
isSaturday: n === 6,
isSunday: n === 0
};
}, O = (t, e) => t.day === e.day && t.month === e.month && t.year === e.year;
export {
H as $,
j as B,
B as C,
b as E,
J as G,
K as H,
N as J,
O as K,
W as L,
q as N,
x as O,
M as P,
T as R,
k as T,
G as V,
$ as W,
S as Y,
E as b,
u as f,
R as j,
d as l,
A as q,
C as x
};