@sonygrg/nepali-datepicker 1.0.11 → 1.0.12
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
|
@@ -24,18 +24,26 @@ import { InputCalendar, type ParsedBSDate } from "@sonygrg/nepali-datepicker";
|
|
|
24
24
|
|
|
25
25
|
function App() {
|
|
26
26
|
const [date, setDate] = useState<ParsedBSDate | null>(null);
|
|
27
|
-
return (
|
|
28
|
-
<InputCalendar
|
|
29
|
-
value={date}
|
|
30
|
-
onChange={(value) => setDate(value)}
|
|
31
|
-
className=""
|
|
32
|
-
/>
|
|
33
|
-
);
|
|
27
|
+
return <InputCalendar value={date} onChange={(value) => setDate(value)} />;
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
export default App;
|
|
37
31
|
```
|
|
38
32
|
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
35
|
+
### Props
|
|
36
|
+
|
|
37
|
+
| Prop | Type | Description |
|
|
38
|
+
| ---------- | -------------------------------------- | --------------------------------------------- |
|
|
39
|
+
| `value` | `ParsedBSDate \| null` | The currently selected date (controlled mode) |
|
|
40
|
+
| `onChange` | `(date: ParsedBSDate \| null) => void` | Called whenever the date changes |
|
|
41
|
+
|
|
42
|
+
`ParsedBSDate` is shaped like:
|
|
43
|
+
\`\`\`ts
|
|
44
|
+
{ year: number; month: number; day: number }
|
|
45
|
+
\`\`\`
|
|
46
|
+
|
|
39
47
|
## Features
|
|
40
48
|
|
|
41
49
|
- Type a Nepali date manually (e.g. `२०८३/०१/०१`), or pick it from a calendar grid
|
|
@@ -2,7 +2,6 @@ import { ParsedBSDate } from '../converter/bsDateParser';
|
|
|
2
2
|
type Props = {
|
|
3
3
|
value?: ParsedBSDate | null;
|
|
4
4
|
onChange?: (date: ParsedBSDate | null) => void;
|
|
5
|
-
className?: string;
|
|
6
5
|
};
|
|
7
|
-
export default function InputCalendar({ value, onChange
|
|
6
|
+
export default function InputCalendar({ value, onChange }: Props): import("react").JSX.Element;
|
|
8
7
|
export {};
|
|
@@ -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({value:e,onChange:i
|
|
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}){let[a,o]=(0,r.useState)(null),[s,c]=(0,r.useState)(``),[l,u]=(0,r.useState)(null),d=e===void 0?l:e,f=(0,r.useRef)(null),p=(0,r.useRef)(null),m=(0,r.useRef)(null),h=e=>{u(e),i?.(e)},y=()=>{let e=T(s);e?(h(e),console.log(`Selected Date:`,g(e))):s&&h(null),c(``)};return(0,r.useLayoutEffect)(()=>{p.current&&m.current!==null&&p.current.setSelectionRange(m.current,m.current)},[s]),(0,x.jsx)(`div`,{children:(0,x.jsxs)(t.Box,{sx:{m:`0px`},children:[(0,x.jsx)(t.Box,{ref:f,children:(0,x.jsx)(t.TextField,{label:d?``:`मिति छान्नुहोस् `,size:`small`,sx:{" .MuiInputBase-input":{height:`20px`}},value:s?v(s):d?g(d):``,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),m.current=n,c(r.slice(0,10))},onFocus:()=>{if(d&&!s){let e=d.year;c(`${e}/${String(d.month).padStart(2,`0`)}/${String(d.day).padStart(2,`0`)}`)}},onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y()},slotProps:{input:{inputRef:p,sx:{pl:`8px`,fontSize:`18px`},endAdornment:(0,x.jsx)(t.InputAdornment,{position:`end`,children:(0,x.jsx)(t.IconButton,{onClick:()=>o(f.current),children:(0,x.jsx)(n.CalendarIcon,{})})})}}})}),(0,x.jsx)(t.Popover,{open:!!a,anchorEl:a,onClose:()=>o(null),anchorOrigin:{vertical:`bottom`,horizontal:`left`},children:(0,x.jsx)(C,{selectDate:d,onSelectDate:e=>{h(e),c(``),o(null),console.log(`Selected Date:`,g(e))}})})]})})}exports.InputCalendar=E;
|
|
@@ -1745,75 +1745,72 @@ function R(e) {
|
|
|
1745
1745
|
}
|
|
1746
1746
|
//#endregion
|
|
1747
1747
|
//#region src/components/InputCalendar.tsx
|
|
1748
|
-
function z({ value: t, onChange: i
|
|
1749
|
-
let [
|
|
1750
|
-
|
|
1751
|
-
},
|
|
1752
|
-
let e = R(
|
|
1753
|
-
e ? (
|
|
1748
|
+
function z({ value: t, onChange: i }) {
|
|
1749
|
+
let [o, c] = m(null), [u, d] = m(""), [h, g] = m(null), _ = t === void 0 ? h : t, v = p(null), y = p(null), b = p(null), x = (e) => {
|
|
1750
|
+
g(e), i?.(e);
|
|
1751
|
+
}, S = () => {
|
|
1752
|
+
let e = R(u);
|
|
1753
|
+
e ? (x(e), console.log("Selected Date:", O(e))) : u && x(null), d("");
|
|
1754
1754
|
};
|
|
1755
1755
|
return f(() => {
|
|
1756
|
-
|
|
1757
|
-
}, [
|
|
1758
|
-
|
|
1759
|
-
children: /* @__PURE__ */ (0, P.
|
|
1760
|
-
|
|
1761
|
-
children:
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
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();
|
|
1784
|
-
},
|
|
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
|
-
})
|
|
1797
|
-
})
|
|
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"
|
|
1756
|
+
y.current && b.current !== null && y.current.setSelectionRange(b.current, b.current);
|
|
1757
|
+
}, [u]), /* @__PURE__ */ (0, P.jsx)("div", { children: /* @__PURE__ */ (0, P.jsxs)(e, {
|
|
1758
|
+
sx: { m: "0px" },
|
|
1759
|
+
children: [/* @__PURE__ */ (0, P.jsx)(e, {
|
|
1760
|
+
ref: v,
|
|
1761
|
+
children: /* @__PURE__ */ (0, P.jsx)(s, {
|
|
1762
|
+
label: _ ? "" : "मिति छान्नुहोस् ",
|
|
1763
|
+
size: "small",
|
|
1764
|
+
sx: { " .MuiInputBase-input": { height: "20px" } },
|
|
1765
|
+
value: u ? A(u) : _ ? O(_) : "",
|
|
1766
|
+
placeholder: " YYYY/MM/DD",
|
|
1767
|
+
onChange: (e) => {
|
|
1768
|
+
let t = e.target, n = t.selectionStart ?? 0, r = k(t.value);
|
|
1769
|
+
r = r.split("").filter((e) => e >= "0" && e <= "9" || e === "/").join("");
|
|
1770
|
+
let i = r.length;
|
|
1771
|
+
(r.length === 4 && !r.includes("/") || r.length === 7 && r.split("/").length === 2) && (r += "/"), r.length > i && n === i && (n += 1), b.current = n, d(r.slice(0, 10));
|
|
1807
1772
|
},
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1773
|
+
onFocus: () => {
|
|
1774
|
+
if (_ && !u) {
|
|
1775
|
+
let e = _.year;
|
|
1776
|
+
d(`${e}/${String(_.month).padStart(2, "0")}/${String(_.day).padStart(2, "0")}`);
|
|
1812
1777
|
}
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1778
|
+
},
|
|
1779
|
+
onBlur: S,
|
|
1780
|
+
onKeyDown: (e) => {
|
|
1781
|
+
e.key === "Enter" && S();
|
|
1782
|
+
},
|
|
1783
|
+
slotProps: { input: {
|
|
1784
|
+
inputRef: y,
|
|
1785
|
+
sx: {
|
|
1786
|
+
pl: "8px",
|
|
1787
|
+
fontSize: "18px"
|
|
1788
|
+
},
|
|
1789
|
+
endAdornment: /* @__PURE__ */ (0, P.jsx)(r, {
|
|
1790
|
+
position: "end",
|
|
1791
|
+
children: /* @__PURE__ */ (0, P.jsx)(n, {
|
|
1792
|
+
onClick: () => c(v.current),
|
|
1793
|
+
children: /* @__PURE__ */ (0, P.jsx)(l, {})
|
|
1794
|
+
})
|
|
1795
|
+
})
|
|
1796
|
+
} }
|
|
1797
|
+
})
|
|
1798
|
+
}), /* @__PURE__ */ (0, P.jsx)(a, {
|
|
1799
|
+
open: !!o,
|
|
1800
|
+
anchorEl: o,
|
|
1801
|
+
onClose: () => c(null),
|
|
1802
|
+
anchorOrigin: {
|
|
1803
|
+
vertical: "bottom",
|
|
1804
|
+
horizontal: "left"
|
|
1805
|
+
},
|
|
1806
|
+
children: /* @__PURE__ */ (0, P.jsx)(I, {
|
|
1807
|
+
selectDate: _,
|
|
1808
|
+
onSelectDate: (e) => {
|
|
1809
|
+
x(e), d(""), c(null), console.log("Selected Date:", O(e));
|
|
1810
|
+
}
|
|
1811
|
+
})
|
|
1812
|
+
})]
|
|
1813
|
+
}) });
|
|
1817
1814
|
}
|
|
1818
1815
|
//#endregion
|
|
1819
1816
|
export { z as InputCalendar };
|