@brightsoftware/date-np
Version:
Simple & minimal Nepali date picker that just works.
55 lines (54 loc) • 1.8 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: b,
getEffectiveMaxDate: p
} = N(), { locale: c } = s, M = a === "left" ? s.leftPanel : s.rightPanel, { activeMonth: h, activeYear: o } = M, y = c === "en" ? u.AD.months[t] : u.BS.months[t], l = t === h, x = (() => {
const n = /* @__PURE__ */ new Date();
return t === n.getMonth() && o === n.getFullYear();
})(), e = (() => {
const n = b(), P = p();
let i, r;
if (c === "ne")
try {
const f = new g(o, t, 1), v = f.getDaysInMonth(), A = new g(o, t, v);
i = f.toADDate(), r = A.toADDate();
} catch {
return !0;
}
else
i = new Date(o, t, 1), r = new Date(o, t + 1, 0);
return r.getTime() < n.getTime() || i.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 && "hover:bg-gray-100 transition-colors",
e && "text-gray-300 cursor-not-allowed",
l && !e && "bg-black text-white font-semibold",
x && !l && !e && "bg-blue-50 text-blue-600 font-semibold",
d
),
children: y
}
);
};
export {
F as default
};