@brightsoftware/date-np
Version:
Simple & minimal Nepali date picker that just works.
55 lines (54 loc) • 1.82 kB
JavaScript
import { jsx as k } from "react/jsx-runtime";
import { CALENDAR as u } from "../../../data/locale.js";
import { cn as T } from "../../../utils/clsx.js";
import { useRangePicker as N } from "../hooks/useRangePicker.js";
import { NepaliDate as g } from "../../NepaliDate.js";
const F = ({ month: t, panel: a, className: d }) => {
const {
rangePickerState: s,
updatePanelMonth: m,
updatePanelMode: D,
getEffectiveMinDate: p,
getEffectiveMaxDate: b
} = N(), { locale: l } = s, M = a === "left" ? s.leftPanel : s.rightPanel, { activeMonth: h, activeYear: o } = M, y = l === "en" ? u.AD.months[t] : u.BS.months[t], i = t === h, x = (() => {
const n = /* @__PURE__ */ new Date();
return t === n.getMonth() && o === n.getFullYear();
})(), e = (() => {
const n = p(), P = b();
let r, c;
if (l === "ne")
try {
const f = new g(o, t, 1), v = f.getDaysInMonth(), A = new g(o, t, v);
r = f.toADDate(), c = A.toADDate();
} catch {
return !0;
}
else
r = new Date(o, t, 1), c = new Date(o, t + 1, 0);
return c.getTime() < n.getTime() || r.getTime() > P.getTime();
})(), w = () => {
e || (m(t, a), D(a, "date"));
};
return /* @__PURE__ */ k(
"button",
{
disabled: e,
onClick: (n) => {
n.stopPropagation(), w();
},
className: T(
"w-full h-10 flex items-center justify-center text-sm rounded-md",
"focus:outline-none focus:ring-2 focus:ring-blue-500",
!e && !i && "hover:bg-gray-300 transition-colors cursor-pointer",
e && "text-gray-300 cursor-not-allowed",
i && !e && "bg-black text-white font-semibold",
x && !i && !e && "bg-blue-50 text-blue-600 font-semibold",
d
),
children: y
}
);
};
export {
F as default
};