@sonygrg/nepali-datepicker 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -22,7 +22,14 @@ npm install react react-dom @mui/material @mui/x-date-pickers @emotion/react @em
|
|
|
22
22
|
import { InputCalendar } from "@sonygrg/nepali-datepicker";
|
|
23
23
|
|
|
24
24
|
function App() {
|
|
25
|
-
|
|
25
|
+
const [date, setDate] = useState<ParsedBSDate | null>(null);
|
|
26
|
+
return (
|
|
27
|
+
<InputCalendar
|
|
28
|
+
value={date}
|
|
29
|
+
onChange={(value) => setDate(value)}
|
|
30
|
+
className=""
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
export default App;
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { ParsedBSDate } from '../converter/bsDateParser';
|
|
2
|
+
type Props = {
|
|
3
|
+
value?: ParsedBSDate | null;
|
|
4
|
+
onChange?: (date: ParsedBSDate | null) => void;
|
|
5
|
+
className?: string;
|
|
6
|
+
};
|
|
7
|
+
export default function InputCalendar({ value, onChange, className }: Props): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
+
import { ParsedBSDate } from '../converter/bsDateParser';
|
|
1
2
|
type Props = {
|
|
2
|
-
onSelectDate: (date:
|
|
3
|
-
|
|
4
|
-
month: number;
|
|
5
|
-
day: number;
|
|
6
|
-
}) => void;
|
|
7
|
-
selectDate: {
|
|
8
|
-
year: number;
|
|
9
|
-
month: number;
|
|
10
|
-
day: number;
|
|
11
|
-
} | null;
|
|
3
|
+
onSelectDate: (date: ParsedBSDate) => void;
|
|
4
|
+
selectDate: ParsedBSDate | null;
|
|
12
5
|
};
|
|
13
6
|
export default function NepaliCalendar({ onSelectDate, selectDate }: Props): import("react").JSX.Element;
|
|
14
7
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t)=>
|
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require("react"),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),x=e(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=y():t.exports=b()}))(),S=[`Baisakh`,`Jestha`,`Asar`,`Shrawan`,`Bhadra`,`Aswin`,`Kartik`,`Mangsir`,`Poush`,`Magh`,`Falgun`,`Chaitra`];function C({onSelectDate:e,selectDate:n}){let[o,s]=(0,r.useState)(()=>n?.year??2083),[c,l]=(0,r.useState)(()=>n?.month??1);(0,r.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>{s(n.year),l(n.month)},0);return()=>clearTimeout(e)},[n]);let u=Object.keys(i).map(Number),d=i[String(o)]?.[S[c-1]]??30,p=f(o,c),m=()=>{c===1?(l(12),s(e=>e-1)):l(e=>e-1)},g=()=>{c===12?(l(1),s(e=>e+1)):l(e=>e+1)},_=o===2e3&&c===1,v=o===2090&&c===12,y=[...Array(p).fill(null),...Array.from({length:d},(e,t)=>t+1)];return(0,x.jsxs)(t.Card,{sx:{p:`20px`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,x.jsxs)(t.Box,{sx:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`4px`,mb:`8px`},children:[(0,x.jsx)(t.IconButton,{onClick:m,disabled:_,children:`‹`}),(0,x.jsx)(t.Select,{value:o,onChange:e=>{s(Number(e.target.value))},size:`small`,MenuProps:{slotProps:{paper:{sx:{maxHeight:250}}}},sx:{minWidth:90},children:u.map(e=>(0,x.jsx)(t.MenuItem,{value:e,children:h(e)},e))}),(0,x.jsx)(t.Select,{value:c,onChange:e=>l(Number(e.target.value)),MenuProps:{slotProps:{paper:{sx:{maxHeight:250}}}},sx:{minWidth:90},size:`small`,children:a.month.long.map((e,n)=>(0,x.jsx)(t.MenuItem,{value:n+1,children:e},e))}),(0,x.jsx)(t.IconButton,{onClick:g,disabled:v,children:`›`})]}),(0,x.jsxs)(t.Box,{sx:{display:`grid`,gridTemplateColumns:`repeat(7, 1fr)`,textAlign:`center`,gap:2},children:[a.day.short.map(e=>(0,x.jsx)(t.Box,{children:(0,x.jsx)(t.Typography,{variant:`caption`,sx:{fontSize:`14px`},children:e})},e)),y.map((r,i)=>{let a=n&&n.day===r&&n.month===c&&n.year===o;return(0,x.jsx)(t.Box,{children:r&&(0,x.jsx)(t.Box,{onClick:()=>{e({year:o,month:c,day:r})},sx:{cursor:`pointer`,bgcolor:a?`primary.main`:`transparent`,color:a?`#fff`:`text.primary`,borderRadius:`50%`,height:`32px`,width:`32px`,display:`flex`,justifyContent:`center`,alignItems:`center`},children:h(r)})},i)})]})]})}var w=[`Baisakh`,`Jestha`,`Asar`,`Shrawan`,`Bhadra`,`Aswin`,`Kartik`,`Mangsir`,`Poush`,`Magh`,`Falgun`,`Chaitra`];function T(e){let t=_(e).split(`/`);if(t.length!==3||t[0].length!==4)return null;let n=parseInt(t[0],10),r=parseInt(t[1],10),a=parseInt(t[2],10);if(isNaN(n)||isNaN(r)||isNaN(a))return null;let o=i[String(n)]?.[w[r-1]];return!o||r<1||r>12||a<1||a>o?null:{year:n,month:r,day:a}}function E(){let[
|
|
6
|
+
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require("react"),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),x=e(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=y():t.exports=b()}))(),S=[`Baisakh`,`Jestha`,`Asar`,`Shrawan`,`Bhadra`,`Aswin`,`Kartik`,`Mangsir`,`Poush`,`Magh`,`Falgun`,`Chaitra`];function C({onSelectDate:e,selectDate:n}){let[o,s]=(0,r.useState)(()=>n?.year??2083),[c,l]=(0,r.useState)(()=>n?.month??1);(0,r.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>{s(n.year),l(n.month)},0);return()=>clearTimeout(e)},[n]);let u=Object.keys(i).map(Number),d=i[String(o)]?.[S[c-1]]??30,p=f(o,c),m=()=>{c===1?(l(12),s(e=>e-1)):l(e=>e-1)},g=()=>{c===12?(l(1),s(e=>e+1)):l(e=>e+1)},_=o===2e3&&c===1,v=o===2090&&c===12,y=[...Array(p).fill(null),...Array.from({length:d},(e,t)=>t+1)];return(0,x.jsxs)(t.Card,{sx:{p:`20px`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,x.jsxs)(t.Box,{sx:{display:`flex`,alignItems:`center`,justifyContent:`center`,gap:`4px`,mb:`8px`},children:[(0,x.jsx)(t.IconButton,{onClick:m,disabled:_,children:`‹`}),(0,x.jsx)(t.Select,{value:o,onChange:e=>{s(Number(e.target.value))},size:`small`,MenuProps:{slotProps:{paper:{sx:{maxHeight:250}}}},sx:{minWidth:90},children:u.map(e=>(0,x.jsx)(t.MenuItem,{value:e,children:h(e)},e))}),(0,x.jsx)(t.Select,{value:c,onChange:e=>l(Number(e.target.value)),MenuProps:{slotProps:{paper:{sx:{maxHeight:250}}}},sx:{minWidth:90},size:`small`,children:a.month.long.map((e,n)=>(0,x.jsx)(t.MenuItem,{value:n+1,children:e},e))}),(0,x.jsx)(t.IconButton,{onClick:g,disabled:v,children:`›`})]}),(0,x.jsxs)(t.Box,{sx:{display:`grid`,gridTemplateColumns:`repeat(7, 1fr)`,textAlign:`center`,gap:2},children:[a.day.short.map(e=>(0,x.jsx)(t.Box,{children:(0,x.jsx)(t.Typography,{variant:`caption`,sx:{fontSize:`14px`},children:e})},e)),y.map((r,i)=>{let a=n&&n.day===r&&n.month===c&&n.year===o;return(0,x.jsx)(t.Box,{children:r&&(0,x.jsx)(t.Box,{onClick:()=>{e({year:o,month:c,day:r})},sx:{cursor:`pointer`,bgcolor:a?`primary.main`:`transparent`,color:a?`#fff`:`text.primary`,borderRadius:`50%`,height:`32px`,width:`32px`,display:`flex`,justifyContent:`center`,alignItems:`center`},children:h(r)})},i)})]})]})}var w=[`Baisakh`,`Jestha`,`Asar`,`Shrawan`,`Bhadra`,`Aswin`,`Kartik`,`Mangsir`,`Poush`,`Magh`,`Falgun`,`Chaitra`];function T(e){let t=_(e).split(`/`);if(t.length!==3||t[0].length!==4)return null;let n=parseInt(t[0],10),r=parseInt(t[1],10),a=parseInt(t[2],10);if(isNaN(n)||isNaN(r)||isNaN(a))return null;let o=i[String(n)]?.[w[r-1]];return!o||r<1||r>12||a<1||a>o?null:{year:n,month:r,day:a}}function E({value:e,onChange:i,className:a}){let[o,s]=(0,r.useState)(null),[c,l]=(0,r.useState)(``),[u,d]=(0,r.useState)(null),f=e===void 0?u:e,p=(0,r.useRef)(null),m=(0,r.useRef)(null),h=(0,r.useRef)(null),y=e=>{d(e),i?.(e)},b=()=>{let e=T(c);e?(y(e),console.log(`Selected Date:`,g(e))):c&&y(null),l(``)};return(0,r.useLayoutEffect)(()=>{m.current&&h.current!==null&&m.current.setSelectionRange(h.current,h.current)},[c]),(0,x.jsx)(`div`,{className:a,children:(0,x.jsxs)(t.Box,{sx:{m:`0px`},children:[(0,x.jsx)(t.Box,{ref:p,children:(0,x.jsx)(t.TextField,{label:f?``:`मिति छान्नुहोस् `,size:`small`,sx:{" .MuiInputBase-input":{height:`20px`}},value:c?v(c):f?g(f):``,placeholder:` YYYY/MM/DD`,onChange:e=>{let t=e.target,n=t.selectionStart??0,r=_(t.value);r=r.split(``).filter(e=>e>=`0`&&e<=`9`||e===`/`).join(``);let i=r.length;(r.length===4&&!r.includes(`/`)||r.length===7&&r.split(`/`).length===2)&&(r+=`/`),r.length>i&&n===i&&(n+=1),h.current=n,l(r.slice(0,10))},onFocus:()=>{if(f&&!c){let e=f.year;l(`${e}/${String(f.month).padStart(2,`0`)}/${String(f.day).padStart(2,`0`)}`)}},onBlur:b,onKeyDown:e=>{e.key===`Enter`&&b()},slotProps:{input:{inputRef:m,sx:{pl:`8px`,fontSize:`18px`},endAdornment:(0,x.jsx)(t.InputAdornment,{position:`end`,children:(0,x.jsx)(t.IconButton,{onClick:()=>s(p.current),children:(0,x.jsx)(n.CalendarIcon,{})})})}}})}),(0,x.jsx)(t.Popover,{open:!!o,anchorEl:o,onClose:()=>s(null),anchorOrigin:{vertical:`bottom`,horizontal:`left`},children:(0,x.jsx)(C,{selectDate:f,onSelectDate:e=>{y(e),l(``),s(null),console.log(`Selected Date:`,g(e))}})})]})})}exports.InputCalendar=E;
|
|
@@ -1745,70 +1745,75 @@ function R(e) {
|
|
|
1745
1745
|
}
|
|
1746
1746
|
//#endregion
|
|
1747
1747
|
//#region src/components/InputCalendar.tsx
|
|
1748
|
-
function z() {
|
|
1749
|
-
let [
|
|
1750
|
-
|
|
1751
|
-
|
|
1748
|
+
function z({ value: t, onChange: i, className: o }) {
|
|
1749
|
+
let [c, u] = m(null), [d, h] = m(""), [g, _] = m(null), v = t === void 0 ? g : t, y = p(null), b = p(null), x = p(null), S = (e) => {
|
|
1750
|
+
_(e), i?.(e);
|
|
1751
|
+
}, C = () => {
|
|
1752
|
+
let e = R(d);
|
|
1753
|
+
e ? (S(e), console.log("Selected Date:", O(e))) : d && S(null), h("");
|
|
1752
1754
|
};
|
|
1753
1755
|
return f(() => {
|
|
1754
|
-
|
|
1755
|
-
}, [
|
|
1756
|
-
|
|
1757
|
-
children:
|
|
1758
|
-
|
|
1759
|
-
children: /* @__PURE__ */ (0, P.jsx)(
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
d
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
inputRef: g,
|
|
1783
|
-
sx: {
|
|
1784
|
-
pl: "8px",
|
|
1785
|
-
fontSize: "18px"
|
|
1756
|
+
b.current && x.current !== null && b.current.setSelectionRange(x.current, x.current);
|
|
1757
|
+
}, [d]), /* @__PURE__ */ (0, P.jsx)("div", {
|
|
1758
|
+
className: o,
|
|
1759
|
+
children: /* @__PURE__ */ (0, P.jsxs)(e, {
|
|
1760
|
+
sx: { m: "0px" },
|
|
1761
|
+
children: [/* @__PURE__ */ (0, P.jsx)(e, {
|
|
1762
|
+
ref: y,
|
|
1763
|
+
children: /* @__PURE__ */ (0, P.jsx)(s, {
|
|
1764
|
+
label: v ? "" : "मिति छान्नुहोस् ",
|
|
1765
|
+
size: "small",
|
|
1766
|
+
sx: { " .MuiInputBase-input": { height: "20px" } },
|
|
1767
|
+
value: d ? A(d) : v ? O(v) : "",
|
|
1768
|
+
placeholder: " YYYY/MM/DD",
|
|
1769
|
+
onChange: (e) => {
|
|
1770
|
+
let t = e.target, n = t.selectionStart ?? 0, r = k(t.value);
|
|
1771
|
+
r = r.split("").filter((e) => e >= "0" && e <= "9" || e === "/").join("");
|
|
1772
|
+
let i = r.length;
|
|
1773
|
+
(r.length === 4 && !r.includes("/") || r.length === 7 && r.split("/").length === 2) && (r += "/"), r.length > i && n === i && (n += 1), x.current = n, h(r.slice(0, 10));
|
|
1774
|
+
},
|
|
1775
|
+
onFocus: () => {
|
|
1776
|
+
if (v && !d) {
|
|
1777
|
+
let e = v.year;
|
|
1778
|
+
h(`${e}/${String(v.month).padStart(2, "0")}/${String(v.day).padStart(2, "0")}`);
|
|
1779
|
+
}
|
|
1780
|
+
},
|
|
1781
|
+
onBlur: C,
|
|
1782
|
+
onKeyDown: (e) => {
|
|
1783
|
+
e.key === "Enter" && C();
|
|
1786
1784
|
},
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1785
|
+
slotProps: { input: {
|
|
1786
|
+
inputRef: b,
|
|
1787
|
+
sx: {
|
|
1788
|
+
pl: "8px",
|
|
1789
|
+
fontSize: "18px"
|
|
1790
|
+
},
|
|
1791
|
+
endAdornment: /* @__PURE__ */ (0, P.jsx)(r, {
|
|
1792
|
+
position: "end",
|
|
1793
|
+
children: /* @__PURE__ */ (0, P.jsx)(n, {
|
|
1794
|
+
onClick: () => u(y.current),
|
|
1795
|
+
children: /* @__PURE__ */ (0, P.jsx)(l, {})
|
|
1796
|
+
})
|
|
1792
1797
|
})
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
})
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
}
|
|
1809
|
-
})
|
|
1810
|
-
})
|
|
1811
|
-
})
|
|
1798
|
+
} }
|
|
1799
|
+
})
|
|
1800
|
+
}), /* @__PURE__ */ (0, P.jsx)(a, {
|
|
1801
|
+
open: !!c,
|
|
1802
|
+
anchorEl: c,
|
|
1803
|
+
onClose: () => u(null),
|
|
1804
|
+
anchorOrigin: {
|
|
1805
|
+
vertical: "bottom",
|
|
1806
|
+
horizontal: "left"
|
|
1807
|
+
},
|
|
1808
|
+
children: /* @__PURE__ */ (0, P.jsx)(I, {
|
|
1809
|
+
selectDate: v,
|
|
1810
|
+
onSelectDate: (e) => {
|
|
1811
|
+
S(e), h(""), u(null), console.log("Selected Date:", O(e));
|
|
1812
|
+
}
|
|
1813
|
+
})
|
|
1814
|
+
})]
|
|
1815
|
+
})
|
|
1816
|
+
});
|
|
1812
1817
|
}
|
|
1813
1818
|
//#endregion
|
|
1814
1819
|
export { z as InputCalendar };
|