UNPKG

@brightsoftware/date-np

Version:

Simple & minimal Nepali date picker that just works.

102 lines (101 loc) 4.29 kB
import { jsx as t, jsxs as M } from "react/jsx-runtime"; import "react"; import { MAX_AD_YEAR as N, MAX_BS_YEAR as Y, MIN_AD_YEAR as A, MIN_BS_YEAR as R } from "../../../data/constants.js"; import { CALENDAR as b } from "../../../data/locale.js"; import { getTotalDaysInMonth as x, getStartingDayOfMonth as k, getEndingDayOfMonth as B } from "../../../utils/helpers.js"; import { useRangePicker as C } from "../hooks/useRangePicker.js"; import j from "./range-day.js"; import I from "./range-month.js"; import O from "./range-year.js"; import { RangeWeekRow as X } from "./range-week-row.js"; import { NepaliDate as L } from "../../NepaliDate.js"; import P from "./empty-range-day.js"; const at = ({ panel: l }) => { const { rangePickerState: d, resetToOriginalState: _ } = C(), { locale: e } = d, S = l === "left" ? d.leftPanel : d.rightPanel, i = l === "left" ? d.rightPanel : d.leftPanel, { activeYear: a, activeMonth: m, mode: g } = S, E = e === "en" && a === A || e === "ne" && a === R || e === "en" && a === N || e === "ne" && a === Y, w = () => { _(); }; if (g === "date" && E) return /* @__PURE__ */ t("div", { className: "flex items-center justify-center w-full h-72 text-center", children: /* @__PURE__ */ M("div", { className: "text-gray-600", children: [ /* @__PURE__ */ t("div", { className: "text-lg font-medium mb-2", children: "Date not supported" }), /* @__PURE__ */ t("div", { className: "text-sm text-gray-500 mb-4", children: e === "en" ? "Dates before 1945 are not supported" : "Dates before 2001 are not supported" }), /* @__PURE__ */ t( "button", { onClick: w, className: "px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50", children: "Pick another" } ) ] }) }); const h = (n, s, r) => e === "ne" ? new L(n, s, r || 1) : new Date(n, s, r || 1); if (g === "date") { const n = h(a, m, 1), s = x({ date: n, locale: e }), r = k({ date: n, locale: e }), o = h(a, m, s), p = h(a, m - 1, 1), c = B({ date: o, locale: e }), T = x({ date: p, locale: e }), v = r; return /* @__PURE__ */ M("div", { className: "w-full", children: [ /* @__PURE__ */ t("div", { className: "grid grid-cols-7 gap-1 mb-2", children: /* @__PURE__ */ t(X, { locale: e }) }), /* @__PURE__ */ M("div", { className: "grid grid-cols-7 gap-1", children: [ /* @__PURE__ */ t(() => [...Array(v)].map((D, f) => { const u = T - (v - (f + 1)); return h(a, m - 1, u), /* @__PURE__ */ t( P, {} ); }), {}), /* @__PURE__ */ t(() => [...Array(s)].map((D, f) => { const u = f + 1, y = h(a, m, u); return /* @__PURE__ */ t( j, { date: y, panel: l }, f ); }), {}), /* @__PURE__ */ t(() => { const D = 6 - c; return [...Array(D)].map((f, u) => { const y = u + 1; return h(a, m + 1, y), /* @__PURE__ */ t( P, {} ); }); }, {}) ] }) ] }); } if (g === "month") { const n = e === "en" ? b.AD.months : b.BS.months; return /* @__PURE__ */ t("div", { className: "grid grid-cols-3 gap-2 p-2", children: n.map((s, r) => { let o = !0; return l === "left" ? (a === i.activeYear && r >= i.activeMonth && (o = !1), a > i.activeYear && (o = !1)) : (a === i.activeYear && r <= i.activeMonth && (o = !1), a < i.activeYear && (o = !1)), o ? /* @__PURE__ */ t( I, { month: r, panel: l }, r ) : null; }) }); } if (g === "year") { const n = e === "en" ? A : R, s = e === "en" ? N : Y; let r = n, o = s; l === "left" ? o = Math.min(s, i.activeYear) : r = Math.max(n, i.activeYear); const p = []; for (let c = r; c <= o; c++) p.push(c); return /* @__PURE__ */ t("div", { className: "grid grid-cols-4 gap-2 p-2 max-h-60 overflow-y-auto", children: p.map((c) => /* @__PURE__ */ t( O, { year: c, panel: l }, c )) }); } return null; }; export { at as default };