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