react-nepali-datetime
Version:
React components for a Nepali DateTime picker, built on top of nepali-datetime.
1,059 lines (1,056 loc) • 36 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('._selector_dblms_1{background-color:#fff;color:#000;padding:8px 10px;border:1px solid #ccc;border-radius:4px;scrollbar-width:thin;scrollbar-color:#2096f5}._selector_dblms_1:focus{outline:none}._selector_dblms_1::-webkit-scrollbar{width:6px}._selector_dblms_1::-webkit-scrollbar-thumb{background-color:#2096f5;border-radius:4px}._selector_dblms_1::-webkit-scrollbar-track{border-radius:4px}._calendarContainer_1osiy_1{margin-top:16px;color:#666;font-family:sans-serif;font-size:14px;font-weight:300;font-style:normal}._calendarGrid_1osiy_10{display:grid;grid-template-columns:repeat(7,1fr)}._calendarCell_1osiy_15{display:inline-flex;align-items:center;justify-content:center;width:45px;height:40px;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}._calendarCellInactive_1osiy_28{opacity:.5}._calendarCell_1osiy_15:not(._calendarCellInactive_1osiy_28,._calendarCellHeader_1osiy_32){cursor:pointer}._calendarCellCurrent_1osiy_36{color:#2096f5;font-weight:700}._calendarCellSelected_1osiy_41{position:relative;color:#fff;z-index:1}._calendarCellSelected_1osiy_41:after{content:"";background-color:#2096f5;border-radius:50%;width:40px;height:40px;position:absolute;z-index:-1}._prevNext_1osiy_56{width:22px;height:22px}._prevNext_1osiy_56 span{cursor:pointer}._calendarControls_1osiy_64{display:flex;justify-content:space-between;align-items:center}._popoverContent_qysd3_1{position:absolute;left:0;padding:16px;background-color:#fff;color:#444;box-shadow:0 4px 6px #0000001a;z-index:101}._nepaliDateInput_1xgfv_1{width:100%;padding:4px 8px;line-height:22px;border-radius:5px;border-width:1px;border-style:solid;outline:0;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}._nepaliDateInputError_1xgfv_14{color:#fb4141}._nepaliDateInputError_1xgfv_14 input{color:inherit}')),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
import Ke, { useState as V, useEffect as Ge, useRef as ve, useCallback as ce, useLayoutEffect as kr, cloneElement as Sr } from "react";
import L from "nepali-datetime";
var Q = { exports: {} }, G = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var $e;
function Nr() {
if ($e) return G;
$e = 1;
var t = Ke, a = Symbol.for("react.element"), c = Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, v = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, E = { key: !0, ref: !0, __self: !0, __source: !0 };
function m(h, d, x) {
var p, j = {}, _ = null, C = null;
x !== void 0 && (_ = "" + x), d.key !== void 0 && (_ = "" + d.key), d.ref !== void 0 && (C = d.ref);
for (p in d) o.call(d, p) && !E.hasOwnProperty(p) && (j[p] = d[p]);
if (h && h.defaultProps) for (p in d = h.defaultProps, d) j[p] === void 0 && (j[p] = d[p]);
return { $$typeof: a, type: h, key: _, ref: C, props: j, _owner: v.current };
}
return G.Fragment = c, G.jsx = m, G.jsxs = m, G;
}
var J = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var De;
function Ir() {
return De || (De = 1, process.env.NODE_ENV !== "production" && function() {
var t = Ke, a = Symbol.for("react.element"), c = Symbol.for("react.portal"), o = Symbol.for("react.fragment"), v = Symbol.for("react.strict_mode"), E = Symbol.for("react.profiler"), m = Symbol.for("react.provider"), h = Symbol.for("react.context"), d = Symbol.for("react.forward_ref"), x = Symbol.for("react.suspense"), p = Symbol.for("react.suspense_list"), j = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), C = Symbol.for("react.offscreen"), R = Symbol.iterator, P = "@@iterator";
function i(e) {
if (e === null || typeof e != "object")
return null;
var r = R && e[R] || e[P];
return typeof r == "function" ? r : null;
}
var N = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function b(e) {
{
for (var r = arguments.length, n = new Array(r > 1 ? r - 1 : 0), s = 1; s < r; s++)
n[s - 1] = arguments[s];
M("error", e, n);
}
}
function M(e, r, n) {
{
var s = N.ReactDebugCurrentFrame, g = s.getStackAddendum();
g !== "" && (r += "%s", n = n.concat([g]));
var y = n.map(function(f) {
return String(f);
});
y.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, y);
}
}
var U = !1, ze = !1, Ze = !1, Qe = !1, er = !1, pe;
pe = Symbol.for("react.module.reference");
function rr(e) {
return !!(typeof e == "string" || typeof e == "function" || e === o || e === E || er || e === v || e === x || e === p || Qe || e === C || U || ze || Ze || typeof e == "object" && e !== null && (e.$$typeof === _ || e.$$typeof === j || e.$$typeof === m || e.$$typeof === h || e.$$typeof === d || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === pe || e.getModuleId !== void 0));
}
function nr(e, r, n) {
var s = e.displayName;
if (s)
return s;
var g = r.displayName || r.name || "";
return g !== "" ? n + "(" + g + ")" : n;
}
function he(e) {
return e.displayName || "Context";
}
function Y(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case o:
return "Fragment";
case c:
return "Portal";
case E:
return "Profiler";
case v:
return "StrictMode";
case x:
return "Suspense";
case p:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case h:
var r = e;
return he(r) + ".Consumer";
case m:
var n = e;
return he(n._context) + ".Provider";
case d:
return nr(e, e.render, "ForwardRef");
case j:
var s = e.displayName || null;
return s !== null ? s : Y(e.type) || "Memo";
case _: {
var g = e, y = g._payload, f = g._init;
try {
return Y(f(y));
} catch {
return null;
}
}
}
return null;
}
var F = Object.assign, H = 0, _e, ge, Ee, ye, me, be, xe;
function Ce() {
}
Ce.__reactDisabledLog = !0;
function tr() {
{
if (H === 0) {
_e = console.log, ge = console.info, Ee = console.warn, ye = console.error, me = console.group, be = console.groupCollapsed, xe = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: Ce,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
H++;
}
}
function ar() {
{
if (H--, H === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: F({}, e, {
value: _e
}),
info: F({}, e, {
value: ge
}),
warn: F({}, e, {
value: Ee
}),
error: F({}, e, {
value: ye
}),
group: F({}, e, {
value: me
}),
groupCollapsed: F({}, e, {
value: be
}),
groupEnd: F({}, e, {
value: xe
})
});
}
H < 0 && b("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var re = N.ReactCurrentDispatcher, ne;
function q(e, r, n) {
{
if (ne === void 0)
try {
throw Error();
} catch (g) {
var s = g.stack.trim().match(/\n( *(at )?)/);
ne = s && s[1] || "";
}
return `
` + ne + e;
}
}
var te = !1, X;
{
var or = typeof WeakMap == "function" ? WeakMap : Map;
X = new or();
}
function Re(e, r) {
if (!e || te)
return "";
{
var n = X.get(e);
if (n !== void 0)
return n;
}
var s;
te = !0;
var g = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var y;
y = re.current, re.current = null, tr();
try {
if (r) {
var f = function() {
throw Error();
};
if (Object.defineProperty(f.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(f, []);
} catch (k) {
s = k;
}
Reflect.construct(e, [], f);
} else {
try {
f.call();
} catch (k) {
s = k;
}
e.call(f.prototype);
}
} else {
try {
throw Error();
} catch (k) {
s = k;
}
e();
}
} catch (k) {
if (k && s && typeof k.stack == "string") {
for (var l = k.stack.split(`
`), O = s.stack.split(`
`), w = l.length - 1, T = O.length - 1; w >= 1 && T >= 0 && l[w] !== O[T]; )
T--;
for (; w >= 1 && T >= 0; w--, T--)
if (l[w] !== O[T]) {
if (w !== 1 || T !== 1)
do
if (w--, T--, T < 0 || l[w] !== O[T]) {
var I = `
` + l[w].replace(" at new ", " at ");
return e.displayName && I.includes("<anonymous>") && (I = I.replace("<anonymous>", e.displayName)), typeof e == "function" && X.set(e, I), I;
}
while (w >= 1 && T >= 0);
break;
}
}
} finally {
te = !1, re.current = y, ar(), Error.prepareStackTrace = g;
}
var W = e ? e.displayName || e.name : "", $ = W ? q(W) : "";
return typeof e == "function" && X.set(e, $), $;
}
function sr(e, r, n) {
return Re(e, !1);
}
function ir(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function z(e, r, n) {
if (e == null)
return "";
if (typeof e == "function")
return Re(e, ir(e));
if (typeof e == "string")
return q(e);
switch (e) {
case x:
return q("Suspense");
case p:
return q("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case d:
return sr(e.render);
case j:
return z(e.type, r, n);
case _: {
var s = e, g = s._payload, y = s._init;
try {
return z(y(g), r, n);
} catch {
}
}
}
return "";
}
var K = Object.prototype.hasOwnProperty, we = {}, je = N.ReactDebugCurrentFrame;
function Z(e) {
if (e) {
var r = e._owner, n = z(e.type, e._source, r ? r.type : null);
je.setExtraStackFrame(n);
} else
je.setExtraStackFrame(null);
}
function lr(e, r, n, s, g) {
{
var y = Function.call.bind(K);
for (var f in e)
if (y(e, f)) {
var l = void 0;
try {
if (typeof e[f] != "function") {
var O = Error((s || "React class") + ": " + n + " type `" + f + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[f] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw O.name = "Invariant Violation", O;
}
l = e[f](r, f, s, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (w) {
l = w;
}
l && !(l instanceof Error) && (Z(g), b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", s || "React class", n, f, typeof l), Z(null)), l instanceof Error && !(l.message in we) && (we[l.message] = !0, Z(g), b("Failed %s type: %s", n, l.message), Z(null));
}
}
}
var ur = Array.isArray;
function ae(e) {
return ur(e);
}
function cr(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, n = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return n;
}
}
function fr(e) {
try {
return Te(e), !1;
} catch {
return !0;
}
}
function Te(e) {
return "" + e;
}
function Pe(e) {
if (fr(e))
return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", cr(e)), Te(e);
}
var Oe = N.ReactCurrentOwner, dr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, ke, Se;
function vr(e) {
if (K.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function pr(e) {
if (K.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function hr(e, r) {
typeof e.ref == "string" && Oe.current;
}
function _r(e, r) {
{
var n = function() {
ke || (ke = !0, b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
n.isReactWarning = !0, Object.defineProperty(e, "key", {
get: n,
configurable: !0
});
}
}
function gr(e, r) {
{
var n = function() {
Se || (Se = !0, b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
n.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: n,
configurable: !0
});
}
}
var Er = function(e, r, n, s, g, y, f) {
var l = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: a,
// Built-in properties that belong on the element
type: e,
key: r,
ref: n,
props: f,
// Record the component responsible for creating this element.
_owner: y
};
return l._store = {}, Object.defineProperty(l._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(l, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: s
}), Object.defineProperty(l, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: g
}), Object.freeze && (Object.freeze(l.props), Object.freeze(l)), l;
};
function yr(e, r, n, s, g) {
{
var y, f = {}, l = null, O = null;
n !== void 0 && (Pe(n), l = "" + n), pr(r) && (Pe(r.key), l = "" + r.key), vr(r) && (O = r.ref, hr(r, g));
for (y in r)
K.call(r, y) && !dr.hasOwnProperty(y) && (f[y] = r[y]);
if (e && e.defaultProps) {
var w = e.defaultProps;
for (y in w)
f[y] === void 0 && (f[y] = w[y]);
}
if (l || O) {
var T = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
l && _r(f, T), O && gr(f, T);
}
return Er(e, l, O, g, s, Oe.current, f);
}
}
var oe = N.ReactCurrentOwner, Ne = N.ReactDebugCurrentFrame;
function D(e) {
if (e) {
var r = e._owner, n = z(e.type, e._source, r ? r.type : null);
Ne.setExtraStackFrame(n);
} else
Ne.setExtraStackFrame(null);
}
var se;
se = !1;
function ie(e) {
return typeof e == "object" && e !== null && e.$$typeof === a;
}
function Ie() {
{
if (oe.current) {
var e = Y(oe.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function mr(e) {
return "";
}
var Ae = {};
function br(e) {
{
var r = Ie();
if (!r) {
var n = typeof e == "string" ? e : e.displayName || e.name;
n && (r = `
Check the top-level render call using <` + n + ">.");
}
return r;
}
}
function Me(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var n = br(r);
if (Ae[n])
return;
Ae[n] = !0;
var s = "";
e && e._owner && e._owner !== oe.current && (s = " It was passed a child from " + Y(e._owner.type) + "."), D(e), b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, s), D(null);
}
}
function Ye(e, r) {
{
if (typeof e != "object")
return;
if (ae(e))
for (var n = 0; n < e.length; n++) {
var s = e[n];
ie(s) && Me(s, r);
}
else if (ie(e))
e._store && (e._store.validated = !0);
else if (e) {
var g = i(e);
if (typeof g == "function" && g !== e.entries)
for (var y = g.call(e), f; !(f = y.next()).done; )
ie(f.value) && Me(f.value, r);
}
}
}
function xr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var n;
if (typeof r == "function")
n = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === d || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === j))
n = r.propTypes;
else
return;
if (n) {
var s = Y(r);
lr(n, e.props, "prop", s, e);
} else if (r.PropTypes !== void 0 && !se) {
se = !0;
var g = Y(r);
b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", g || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function Cr(e) {
{
for (var r = Object.keys(e.props), n = 0; n < r.length; n++) {
var s = r[n];
if (s !== "children" && s !== "key") {
D(e), b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", s), D(null);
break;
}
}
e.ref !== null && (D(e), b("Invalid attribute `ref` supplied to `React.Fragment`."), D(null));
}
}
var Le = {};
function Fe(e, r, n, s, g, y) {
{
var f = rr(e);
if (!f) {
var l = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (l += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var O = mr();
O ? l += O : l += Ie();
var w;
e === null ? w = "null" : ae(e) ? w = "array" : e !== void 0 && e.$$typeof === a ? (w = "<" + (Y(e.type) || "Unknown") + " />", l = " Did you accidentally export a JSX literal instead of a component?") : w = typeof e, b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", w, l);
}
var T = yr(e, r, n, g, y);
if (T == null)
return T;
if (f) {
var I = r.children;
if (I !== void 0)
if (s)
if (ae(I)) {
for (var W = 0; W < I.length; W++)
Ye(I[W], e);
Object.freeze && Object.freeze(I);
} else
b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Ye(I, e);
}
if (K.call(r, "key")) {
var $ = Y(e), k = Object.keys(r).filter(function(Or) {
return Or !== "key";
}), le = k.length > 0 ? "{key: someKey, " + k.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!Le[$ + le]) {
var Pr = k.length > 0 ? "{" + k.join(": ..., ") + ": ...}" : "{}";
b(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, le, $, Pr, $), Le[$ + le] = !0;
}
}
return e === o ? Cr(T) : xr(T), T;
}
}
function Rr(e, r, n) {
return Fe(e, r, n, !0);
}
function wr(e, r, n) {
return Fe(e, r, n, !1);
}
var jr = wr, Tr = Rr;
J.Fragment = o, J.jsx = jr, J.jsxs = Tr;
}()), J;
}
var We;
function Ar() {
return We || (We = 1, process.env.NODE_ENV === "production" ? Q.exports = Nr() : Q.exports = Ir()), Q.exports;
}
var u = Ar();
const Mr = "_selector_dblms_1", Je = {
selector: Mr
}, fe = ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"], Yr = "en", B = "ne", ee = Yr, de = L.minSupportedNepaliDate().getYear(), qe = L.maxSupportedNepaliDate().getYear(), Lr = [
"Baisakh",
"Jestha",
"Asar",
"Shrawan",
"Bhadra",
"Aswin",
"Kartik",
"Mangsir",
"Poush",
"Magh",
"Falgun",
"Chaitra"
], Fr = [
"बैशाख",
"जेठ",
"असार",
"श्रावण",
"भाद्र",
"आश्विन",
"कार्तिक",
"मंसिर",
"पौष",
"माघ",
"फाल्गुण",
"चैत्र"
], $r = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], Dr = ["आइत", "सोम", "मंगल", "बुध", "बिहि", "शुक्र", "शनि"], Xe = (t) => t.toString().split("").map((a) => isNaN(Number(a)) ? a : fe[Number(a)]).join(""), Wr = (t) => t.toString().split("").map((a) => fe.includes(a) ? fe.indexOf(a) : a).join(""), Vr = Array.from(
{ length: qe - de + 1 },
(t, a) => a + de
), Br = ({
selectedYear: t,
onChange: a,
locale: c = ee
}) => /* @__PURE__ */ u.jsx(
"select",
{
value: t,
onChange: (o) => a && a(Number(o.target.value)),
className: Je.selector,
tabIndex: -1,
children: Vr.map((o) => /* @__PURE__ */ u.jsx("option", { value: o, children: c === B ? Xe(o) : o }, o))
}
), Ur = (t) => t === B ? Fr : Lr, Hr = ({
selectedMonth: t,
onChange: a,
locale: c = ee
}) => /* @__PURE__ */ u.jsx(
"select",
{
value: t,
onChange: (o) => a && a(Number(o.target.value)),
className: Je.selector,
tabIndex: -1,
children: Ur(c).map((o, v) => /* @__PURE__ */ u.jsx("option", { value: v, children: o }, o))
}
), Ve = 7, Be = (t, a) => {
try {
return L.getDaysOfMonth(t, a);
} catch {
return null;
}
}, Kr = (t, a) => {
const c = Be(t, a);
if (!c)
return [];
const o = new L(t, a, 1).getDay(), [v, E] = a === 0 ? [t - 1, 11] : [t, a - 1], m = Be(v, E), [h, d] = a === 11 ? [t + 1, 0] : [t, a + 1], x = Math.ceil((o + c) / Ve) * Ve;
return Array(x).fill(null).map((j, _) => {
let C, R, P, i;
return _ < o ? (C = m ? m - (o - _ - 1) : null, R = E, P = v, i = !1) : _ < o + c ? (C = _ - o + 1, R = a, P = t, i = !0) : (C = _ - (o + c) + 1, R = d, P = h, i = !1), {
index: _,
active: i,
year: P,
month: R,
date: C
};
});
}, A = (...t) => t.filter(Boolean).join(" "), Gr = "_calendarContainer_1osiy_1", Jr = "_calendarGrid_1osiy_10", qr = "_calendarCell_1osiy_15", Xr = "_calendarCellInactive_1osiy_28", zr = "_calendarCellHeader_1osiy_32", Zr = "_calendarCellCurrent_1osiy_36", Qr = "_calendarCellSelected_1osiy_41", en = "_prevNext_1osiy_56", rn = "_calendarControls_1osiy_64", S = {
calendarContainer: Gr,
calendarGrid: Jr,
calendarCell: qr,
calendarCellInactive: Xr,
calendarCellHeader: zr,
calendarCellCurrent: Zr,
calendarCellSelected: Qr,
prevNext: en,
calendarControls: rn
}, nn = ({
selectedNepaliDate: t,
onDateSelect: a = null,
locale: c = ee
}) => {
const o = new L(), v = c === B ? Dr : $r, [E, m] = V(o.getYear()), [h, d] = V(o.getMonth());
Ge(() => {
t && (m(t == null ? void 0 : t.getYear()), d(t == null ? void 0 : t.getMonth()));
}, [t]);
const x = (i) => i.year === o.getYear() && i.month === o.getMonth() && i.date === o.getDate(), p = (i) => t && i.year === t.getYear() && i.month === t.getMonth() && i.date === t.getDate(), j = (i) => {
!i.active || !i.date || !a || a(new L(E, h, i.date));
}, _ = () => {
if (E === de && h === 0)
return;
const [i, N] = h === 0 ? [E - 1, 11] : [E, h - 1];
m(i), d(N);
}, C = () => {
if (E === qe && h === 11)
return;
const [i, N] = h === 11 ? [E + 1, 0] : [E, h + 1];
m(i), d(N);
}, R = () => {
const i = new L();
m(i.getYear()), d(i.getMonth()), a && a(i);
}, P = Kr(E, h);
return /* @__PURE__ */ u.jsxs("div", { className: "ndt-calendar", children: [
/* @__PURE__ */ u.jsxs("div", { className: `ndt-calendar-controls ${S.calendarControls}`, children: [
/* @__PURE__ */ u.jsx("div", { className: `ndt-prev ${S.prevNext}`, children: /* @__PURE__ */ u.jsx("span", { onClick: _, children: /* @__PURE__ */ u.jsx(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
viewBox: "0 0 24 24",
children: /* @__PURE__ */ u.jsx(
"path",
{
fill: "none",
fillRule: "evenodd",
stroke: "currentcolor",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: "2.4",
d: "M16.283 18.907L9.6 12l6.683-5.438"
}
)
}
) }) }),
/* @__PURE__ */ u.jsx("div", { className: `ndt-prev ${S.prevNext}`, children: /* @__PURE__ */ u.jsx("span", { onClick: _, children: /* @__PURE__ */ u.jsx("div", { className: `ndt-prev ${S.prevNext}`, children: /* @__PURE__ */ u.jsx("span", { onClick: R, children: /* @__PURE__ */ u.jsx(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
x: "0px",
y: "0px",
width: "20",
height: "20",
viewBox: "0 0 1024 1024",
children: /* @__PURE__ */ u.jsx("path", { d: "M946.5 505L534.6 93.4a31.93 31.93 0 0 0-45.2 0L77.5 505c-12 12-18.8 28.3-18.8 45.3 0 35.3 28.7 64 64 64h43.4V908c0 17.7 14.3 32 32 32H448V716h112v224h265.9c17.7 0 32-14.3 32-32V614.3h43.4c17 0 33.3-6.7 45.3-18.8 24.9-25 24.9-65.5-.1-90.5z" })
}
) }) }) }) }),
/* @__PURE__ */ u.jsxs("div", { children: [
/* @__PURE__ */ u.jsx(
Br,
{
selectedYear: E,
onChange: (i) => m(i),
locale: c
}
),
/* @__PURE__ */ u.jsx(
Hr,
{
selectedMonth: h,
onChange: (i) => d(i),
locale: c
}
)
] }),
/* @__PURE__ */ u.jsx("div", { className: `ndt-next ${S.prevNext}`, children: /* @__PURE__ */ u.jsx("span", { onClick: C, children: /* @__PURE__ */ u.jsx(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
viewBox: "0 0 24 24",
children: /* @__PURE__ */ u.jsx(
"path",
{
transform: "rotate(180 12 12)",
fill: "none",
fillRule: "evenodd",
stroke: "currentcolor",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: "2.4",
d: "M16.283 18.907L9.6 12l6.683-5.438"
}
)
}
) }) })
] }),
/* @__PURE__ */ u.jsxs("div", { className: `ndt-calendar-container ${S.calendarContainer}`, children: [
/* @__PURE__ */ u.jsx("div", { className: `ndt-calendar-grid ${S.calendarGrid}`, children: v.map((i) => /* @__PURE__ */ u.jsx(
"div",
{
className: A(
"ndt-calendar-cell-header",
S.calendarCellHeader,
S.calendarCell
),
children: i
},
i
)) }),
/* @__PURE__ */ u.jsx("div", { className: `ndt-calendar-grid ${S.calendarGrid}`, children: P.map((i) => /* @__PURE__ */ u.jsx(
"div",
{
onClick: () => j(i),
className: A(
"ndt-calendar-cell",
S.calendarCell,
p(i) && A("ndt-calendar-cell-selected", S.calendarCellSelected),
x(i) && A("ndt-calendar-cell-current", S.calendarCellCurrent),
!i.active && S.calendarCellInactive
),
children: i.date && c === B ? Xe(i.date) : i.date
},
i.index
)) })
] })
] });
}, tn = "_popoverContent_qysd3_1", an = {
popoverContent: tn
}, on = 150, sn = ({
popoverChildRef: t,
children: a,
onOutsideClick: c,
onMouseDown: o,
onMouseEnter: v,
onBlur: E
}) => {
const m = ve(null), [h, d] = V(), x = ce(() => {
const _ = t == null ? void 0 : t.current;
if (!_) {
d({});
return;
}
const { bottom: C, height: R } = _.getBoundingClientRect(), P = C + on > window.innerHeight;
d(P ? { bottom: R } : { top: R });
}, [t]), p = ce(
// Handle if user clicks outside the Popover elements (Popover Children and Popover Content).
(_) => {
var R, P;
if (!c)
return;
const C = _.target;
!((R = t == null ? void 0 : t.current) != null && R.contains(C)) && !((P = m.current) != null && P.contains(C)) && c();
},
[t, c]
), j = (_) => {
var R, P;
if (E == null || E(_), !c)
return;
const C = _.relatedTarget;
!((R = m == null ? void 0 : m.current) != null && R.contains(C)) && !((P = t == null ? void 0 : t.current) != null && P.contains(C)) && c();
};
return kr(() => (x(), document.addEventListener("mousedown", p), () => document.removeEventListener("mousedown", p)), [p, x]), h ? /* @__PURE__ */ u.jsx(
"div",
{
className: A("ndt-popover-content", an.popoverContent),
ref: m,
style: h,
onMouseDown: o,
onMouseEnter: v,
onBlur: j,
tabIndex: -1,
children: a
}
) : null;
}, ln = ({
children: t,
content: a,
open: c = !1,
className: o,
onOpenChange: v,
onContentMouseDown: E,
onContentMouseEnter: m,
onContentBlur: h
}) => {
const d = ve(null), x = (p) => v == null ? void 0 : v(p);
return /* @__PURE__ */ u.jsxs(
"div",
{
className: A("ndt-popover", o),
style: { position: "relative" },
children: [
/* @__PURE__ */ u.jsx(
"div",
{
className: "ndt-popover-child",
style: { display: "flex" },
ref: d,
onClick: () => x(!0),
children: t
}
),
c && /* @__PURE__ */ u.jsx(
sn,
{
onOutsideClick: () => x(!1),
popoverChildRef: d,
onMouseDown: E,
onMouseEnter: m,
onBlur: h,
children: a
}
)
]
}
);
}, un = "_nepaliDateInput_1xgfv_1", cn = "_nepaliDateInputError_1xgfv_14", ue = {
nepaliDateInput: un,
nepaliDateInputError: cn
}, fn = "Enter", dn = ({
value: t,
inputElement: a,
className: c,
hasError: o,
onComplete: v,
onChange: E,
...m
}) => {
const x = {
...m,
value: t,
onChange: E,
autoComplete: "off",
onKeyDown: (j) => j.key === fn && (v == null ? void 0 : v()),
onBlur: () => v == null ? void 0 : v(),
className: A(
"ndt-date-input",
o && ue.nepaliDateInputError,
c
)
};
if (a)
return Sr(a, x);
const p = {
...x,
className: A(
"ndt-date-input",
o && ue.nepaliDateInputError,
c,
ue.nepaliDateInput
)
};
return /* @__PURE__ */ u.jsx("input", { type: "text", ...p });
}, Ue = (t, a, c) => c === B ? t.formatNepali(a) : t.format(a), He = (t, a, c) => {
if (t.trim() === "")
return null;
const o = c === B ? Wr(t) : t;
try {
return new L(o, a);
} catch {
return null;
}
}, hn = ({
value: t = "",
format: a = "YYYY-MM-DD",
inputElement: c,
onDateSelect: o,
locale: v = ee,
...E
}) => {
const [m, h] = V(!1), [d, x] = V(t), [p, j] = V(), _ = ve(!1), C = !!(d && !p), R = ce(() => {
if (C) {
x(""), o == null || o("", null);
return;
}
if (p) {
const b = Ue(p, a, v);
x(b), o == null || o(b, p);
}
}, [a, C, v, p, o]);
Ge(() => {
x(t), j(He(t, a, v));
}, [t, v, a]);
const P = (b) => {
const M = Ue(b, a, v);
x(M), j(b), o == null || o(M, b), h(!1);
}, i = (b) => {
const M = b.target.value, U = He(M, a, v);
x(M), j(U), U && (o == null || o(M, U));
}, N = () => {
if (_.current) {
_.current = !1;
return;
}
R(), h(!1);
};
return /* @__PURE__ */ u.jsx(
ln,
{
className: A("ndt-date-picker"),
open: m,
onOpenChange: (b) => h(b),
onContentMouseDown: () => {
_.current = !0;
},
onContentBlur: () => {
_.current = !1;
},
onContentMouseEnter: () => R(),
content: /* @__PURE__ */ u.jsx(
nn,
{
locale: v,
selectedNepaliDate: p,
onDateSelect: P
}
),
children: /* @__PURE__ */ u.jsx(
dn,
{
value: d,
inputElement: c,
hasError: C,
onChange: i,
onComplete: N,
onFocus: () => h(!0),
...E
}
)
}
);
};
export {
nn as NepaliCalendar,
hn as NepaliDatePicker
};