@starasia/date 5.2.4 → 5.3.0
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/dist/date.es.js +432 -388
- package/dist/date.umd.js +39 -2
- package/dist/interfaces.d.ts +2 -2
- package/package.json +1 -1
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(V,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(V=typeof globalThis<"u"?globalThis:V||self,n(V.Date={},V.jsxRuntime,V.React))})(this,function(V,n,
|
|
1
|
+
(function(V,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(V=typeof globalThis<"u"?globalThis:V||self,n(V.Date={},V.jsxRuntime,V.React))})(this,function(V,n,m){"use strict";const P=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
|
|
2
2
|
|
|
3
3
|
* {
|
|
4
4
|
margin: 0;
|
|
@@ -346,6 +346,12 @@
|
|
|
346
346
|
border-style: solid;
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
+
.sa-calendar-input-container.xs {
|
|
350
|
+
height: var(--sa-h-7, 28px);
|
|
351
|
+
border-radius: var(--sa-radii-sm, 6px);
|
|
352
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
353
|
+
padding-inline: var(--sa-spacing-2, 8px);
|
|
354
|
+
}
|
|
349
355
|
.sa-calendar-input-container.sm {
|
|
350
356
|
height: var(--sa-h-8, 32px);
|
|
351
357
|
border-radius: var(--sa-radii-sm, 6px);
|
|
@@ -499,6 +505,37 @@
|
|
|
499
505
|
height: 38px;
|
|
500
506
|
}
|
|
501
507
|
|
|
508
|
+
/* xs trigger → reuse the compact (sm) calendar panel */
|
|
509
|
+
.sa-calendar.sa-calendar-size-xs {
|
|
510
|
+
padding: 16px 12px;
|
|
511
|
+
gap: 8px;
|
|
512
|
+
}
|
|
513
|
+
.sa-calendar.sa-calendar-size-xs.sa-calendar-no-padding {
|
|
514
|
+
padding: 0;
|
|
515
|
+
}
|
|
516
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-days-name-preivew,
|
|
517
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-days-number-preivew {
|
|
518
|
+
gap: 4px;
|
|
519
|
+
}
|
|
520
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-days-name-preivew p,
|
|
521
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-days-number-preivew p {
|
|
522
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
523
|
+
}
|
|
524
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-days-number-preivew p {
|
|
525
|
+
width: 28px;
|
|
526
|
+
height: 26px;
|
|
527
|
+
}
|
|
528
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-days-today::before {
|
|
529
|
+
width: 22px;
|
|
530
|
+
height: 22px;
|
|
531
|
+
}
|
|
532
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-months-preview p,
|
|
533
|
+
.sa-calendar.sa-calendar-size-xs .sa-calendar-years-preview p {
|
|
534
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
535
|
+
width: 76px;
|
|
536
|
+
height: 38px;
|
|
537
|
+
}
|
|
538
|
+
|
|
502
539
|
.sa-calendar.sa-calendar-size-lg {
|
|
503
540
|
padding: 28px 20px;
|
|
504
541
|
gap: 16px;
|
|
@@ -542,4 +579,4 @@
|
|
|
542
579
|
width: 32px;
|
|
543
580
|
height: 32px;
|
|
544
581
|
}
|
|
545
|
-
`,Z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A=["January","February","March","April","May","June","July","August","September","October","November","December"],rn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function K(a){const[e,t]=x.useState(a),o=x.useRef(null),l=p=>{o.current&&!o.current.contains(p.target)&&t(!1)};return x.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:t}}const Q="sa-calendar-input-styles";(a=>{if(!document.getElementById(Q)){const e=document.createElement("style");e.id=Q,e.textContent=a,document.head.appendChild(e)}})(P);const O=a=>{if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},tn=a=>{const{size:e="md",status:t="default",variant:o="outline",clearable:l,onClear:p,...i}=a,u=x.useRef(null),h=()=>{u.current&&i.onClick&&(u.current.focus(),i.onClick(""))},r=t==="disable"||i.disabled,d=!!i.value,w=l&&d&&!r,D=M=>{M.stopPropagation(),p==null||p()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${e} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(e),height:O(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...i,disabled:r,value:i.value,ref:u})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(e),height:O(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(e),height:O(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},sn=({date:a,setDate:e,dateRange:t,setDateRange:o,onChange:l,minDate:p,maxDate:i,input:u})=>{var $,f,m;const[h,r]=x.useState(null);let d=new Date(a.getFullYear(),a.getMonth(),1),w=d.getDay(),D=[];const M=a.getMonth(),Y=new Date().toDateString(),v=!!(t.from&&!t.to),g=v&&h?h:null;for(let c=0;c<42;c++){c===0&&w===0?d.setDate(d.getDate()-7):c===0?d.setDate(d.getDate()+(c-w)):d.setDate(d.getDate()+1);let y={currentMonth:d.getMonth()===M,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:d.toDateString()===(($=t.from)==null?void 0:$.toDateString())||d.toDateString()===(((f=t.to)==null?void 0:f.toDateString())||((m=t.from)==null?void 0:m.toDateString())),isToday:d.toDateString()===Y,year:d.getFullYear(),isDisabled:p&&d<p||i&&d>i};D.push(y)}const s=c=>{e(c)},k=c=>{var z;let y={...t};if(y.from&&y.to)y={from:c,to:null};else{const T=((z=y.from)==null?void 0:z.getTime())||0;c.getTime()>T?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),l(y)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>r(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((c,y)=>n.jsx("p",{children:c},y))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((c,y)=>{const z=t.from&&t.to&&c.date.getTime()>t.from.getTime()&&c.date.getTime()<t.to.getTime(),T=(()=>{if(!g||!t.from)return!1;const E=c.date.getTime(),N=t.from.getTime(),S=g.getTime();return S>N?E>N&&E<S:E<N&&E>S})(),C=v&&h&&c.date.toDateString()===h.toDateString(),F=c.isDisabled,I=()=>z||T?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",L=()=>F?"var(--sa-color-gray-400, #b7b9be)":z||T?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${c.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${c.selected||C?"sa-calendar-days-active":""} ${c.isToday&&!c.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:I(),pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",color:L(),opacity:C&&!c.selected?.75:1,...u?{}:{width:"100%"}},onClick:()=>{F||(s(c.date),k(c.date))},onMouseEnter:()=>{F||r(c.date)},children:c.number},y)})})]})},on=({date:a,setDate:e,filter:t,setViews:o,dateRange:l,setDateRange:p,onChange:i,minDate:u,maxDate:h,input:r})=>{var Y;const d=(Y=l.from)==null?void 0:Y.getFullYear(),w=a.getFullYear(),D=v=>{t?(M(v),e(v)):(o("days"),e(v))},M=v=>{var s;let g={...l};if(g.from&&g.to)g={from:v,to:null};else{const k=((s=g.from)==null?void 0:s.getTime())||0;v.getTime()>k?g={from:g.from,to:v}:g={from:v,to:g.from}}p(g),i(g)};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,g)=>{var $,f,m;const s=l.from!=null&&new Date(w,g).getTime()>l.from.getTime()&&new Date(w,g).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=u&&new Date(w,g)<u||h&&new Date(w,g)>h;return n.jsx("p",{className:d===w&&(g===((f=l.from)==null?void 0:f.getMonth())||g===((m=l.to)==null?void 0:m.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:s?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:k?"none":void 0,cursor:k?"not-allowed":"pointer",color:k?"var(--sa-color-gray-400, #b7b9be)":s?"var(--sa-color-gray-500, #8c8f97)":"",...r?{}:{width:"100%"}},onClick:()=>{k||D(new Date(w,g))},children:v.slice(0,3)},g)})})},J=a=>{const e=Math.floor(a/10)*10,t=e+10;return{start:e,end:t}},ln=({date:a,filter:e,setViews:t,setDate:o,dateRange:l,setDateRange:p,onChange:i,minDate:u,maxDate:h,input:r})=>{var k,$;let d=[];const w=a.getFullYear(),{start:D,end:M}=J(w),Y=(k=l.from)==null?void 0:k.getFullYear(),v=($=l.to)==null?void 0:$.getFullYear();for(let f=D;f<M;f++){const m=new Date(f,0),c=(!u||m>=u)&&(!h||m<=h),y=Y!=null&&f===Y||v!=null&&f===v,z=l.from!=null&&l.to!=null&&m>l.from&&m<l.to;d.push({year:f,active:y&&c,highlight:z&&c,disabled:!c})}const g=f=>{e?(s(f),o(f)):(o(f),t("months"))},s=f=>{var c;let m={...l};if(m.from&&m.to)m={from:f,to:null};else{const y=((c=m.from)==null?void 0:c.getTime())||0;f.getTime()>y?m={from:m.from,to:f}:m={from:f,to:m.from}}p(m),i(m)};return n.jsx("div",{className:"sa-calendar-years-preview",children:d.map((f,m)=>n.jsx("p",{className:`${f.active?"sa-calendar-months-active":""} ${f.highlight?"sa-calendar-months-highlight":""} ${f.disabled?"sa-calendar-disabled":""}`,onClick:()=>{f.disabled||g(new Date(f.year,0))},style:{backgroundColor:f.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:f.highlight?"var(--sa-color-gray-500, #8c8f97)":f.active?"":f.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:f.disabled?"not-allowed":"pointer",pointerEvents:f.disbled?"none":"all",...r?{}:{width:"100%"}},children:f.year},m))})},X=({...a})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...a,children:n.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),_=({...a})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...a,children:n.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),dn=({setViews:a,views:e,filter:t,date:o,setDate:l})=>{const p=()=>{t||a(r=>r==="days"?"months":r==="months"?"years":"days")},i=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()+10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()+1,r.getMonth()));return}l(r=>new Date(r.getFullYear(),r.getMonth()+1))},u=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()-10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()-1,r.getMonth()));return}l(r=>new Date(r.getMonth()===0?r.getFullYear()-1:r.getFullYear(),r.getMonth()===0?11:r.getMonth()-1))},h=()=>{if(e==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${J(o.getFullYear()).start} ~ ${J(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:p,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:u,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:n.jsx(_,{})})]})]})};function W(a){const e=new Date(a),t=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${rn[o]} ${t}`}const R=({label:a,labelPosition:e="outside-top",required:t,optional:o,description:l,helperText:p,errorText:i,fullWidth:u,children:h})=>{const r=["sa-date-field",u?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),d=a?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:a}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,w=n.jsxs(n.Fragment,{children:[p&&!i&&n.jsx("p",{className:"sa-date-field-helper",children:p}),i&&n.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return a?e==="outside-left"?n.jsxs("div",{className:`${r} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[d,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[h,w]})]}):n.jsxs("div",{className:r,children:[d,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,w]}):n.jsxs("div",{className:r,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,w]})},nn="sa-calendar-styles";(a=>{if(!document.getElementById(nn)){const e=document.createElement("style");e.id=nn,e.textContent=a,document.head.appendChild(e)}})(P);const cn=x.forwardRef(({value:a,onChange:e,filter:t,input:o=!0,disabled:l,minDate:p,maxDate:i,placeholder:u,size:h,variant:r,status:d,clearable:w,fullWidth:D=!0,withPadding:M=!0,label:Y,labelPosition:v,required:g,optional:s,description:k,helperText:$,errorText:f},m)=>{const c=f?"error":d,{ref:y,isComponentVisible:z,setIsComponentVisible:T}=K(!1),C=x.useRef(null),[F,I]=x.useState("days"),[L,E]=x.useState(new Date),[N,S]=x.useState({from:(a==null?void 0:a.from)??null,to:(a==null?void 0:a.to)??null});x.useEffect(()=>{if(a){const b=a;b.from&&E(b.from),S(b)}else E(new Date),S({from:null,to:null})},[a]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[z]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var b,j;if(!a)return"";if(t){if(F==="days")return`${W(N.from)} ~ ${W(N.to||N.from)||"-"}`;if(F==="months")return`${A[N.from.getMonth()]} ~ ${N.to?A[N.to.getMonth()]:"-"}`;if(F==="years")return`${(b=N.from)==null?void 0:b.getFullYear()} ~ ${((j=N.to)==null?void 0:j.getFullYear())||"-"}`}else return`${W(N.from)} ~ ${W(N.to||N.from)||"-"}`},B=()=>{if(C.current&&y.current&&o){const b=y.current.getBoundingClientRect(),j=C.current.getBoundingClientRect();window.innerWidth<b.left+j.width?C.current.style.left=`${b.left-j.width+b.width}px`:C.current.style.left=`${b.left}px`,b.top+j.height>window.innerHeight?C.current.style.top=`${b.y-(b.height+j.height-28)}px`:C.current.style.top=`${b.y+b.height}px`}};x.useEffect(()=>{C.current&&y.current&&o&&B()},[C,y,z]),x.useEffect(()=>{const b=m==null?void 0:m.current;return b&&b.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{b&&b.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?y:null,children:[o?n.jsx(tn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:u,size:h,variant:r,status:c,clearable:w,onClear:()=>e(void 0)}):null,z?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${o?"":"sa-calendar-no-input"} ${M?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:C,children:[n.jsx(dn,{setViews:I,views:F,filter:t,date:L,setDate:E}),n.jsx("div",{className:"sa-calendar-body",children:F==="days"?n.jsx(sn,{date:L,setDate:E,setIsComponentVisible:T,dateRange:N,setDateRange:S,input:o,onChange:e,minDate:p,maxDate:i}):F==="months"?n.jsx(on,{date:L,setDate:E,filter:t,setViews:I,dateRange:N,setDateRange:S,setIsComponentVisible:T,input:o,onChange:e,minDate:p,maxDate:i}):n.jsx(ln,{date:L,setDate:E,filter:t,setViews:I,dateRange:N,setDateRange:S,setIsComponentVisible:T,input:o,onChange:e,minDate:p,maxDate:i})})]}):null]});return n.jsx(R,{label:Y,labelPosition:v,required:g,optional:s,description:k,helperText:$,errorText:f,fullWidth:D,children:U})}),en="sa-calendar-input-styles";(a=>{if(!document.getElementById(en)){const e=document.createElement("style");e.id=en,e.textContent=a,document.head.appendChild(e)}})(P);const H=a=>{if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},pn=a=>{const{size:e="md",status:t="default",variant:o="outline",clearable:l,onClear:p,...i}=a,u=x.useRef(null),h=()=>{u.current&&i.onClick&&(u.current.focus(),i.onClick(""))},r=t==="disable"||i.disabled,d=!!i.value,w=l&&d&&!r,D=M=>{M.stopPropagation(),p==null||p()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${e} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(e),height:H(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...i,disabled:r,value:i.value,ref:u})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(e),height:H(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(e),height:H(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},hn=({date:a,setDate:e,previewDate:t,setPreviewDate:o,setIsComponentVisible:l,minDate:p,maxDate:i,input:u,onChange:h,hasValue:r})=>{let d=new Date(t.getFullYear(),t.getMonth(),1),w=d.getDay(),D=[];const M=a.toDateString(),Y=new Date().toDateString(),v=t.getMonth();for(let s=0;s<42;s++){s===0&&w===0?d.setDate(d.getDate()-7):s===0?d.setDate(d.getDate()+(s-w)):d.setDate(d.getDate()+1);let k={currentMonth:d.getMonth()===v,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:r&&d.toDateString()===M,isToday:d.toDateString()===Y,year:d.getFullYear(),isDisabled:p&&d<p||i&&d>i};D.push(k)}const g=s=>{(!p||s>=p)&&(!i||s<=i)&&(e(s),h(s),o(s),u&&l(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((s,k)=>n.jsx("p",{children:s},k))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((s,k)=>{const $=s.isDisabled;return n.jsx("p",{className:`${s.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${s.selected?"sa-calendar-days-active":""} ${s.isToday&&!s.selected?"sa-calendar-days-today":""}`,style:{color:$?"#ccc":void 0,pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",...u?{}:{width:"100%"}},onClick:()=>{$||g(s.date)},children:s.number},k)})})]})},fn=({date:a,setDate:e,filter:t,setViews:o,onChange:l,previewDate:p,setPreviewDate:i,minDate:u,maxDate:h,input:r,hasValue:d})=>{const w=a.getMonth(),D=a.getFullYear(),M=p.getFullYear(),Y=v=>{(!u||v>=u)&&(!h||v<=h)&&(t?(l(v),e(v),i(v)):(o("days"),i(v)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,g)=>{const s=u&&new Date(M,g,1)<u||h&&new Date(M,g+1,0)>h;return n.jsx("p",{className:d&&g===w&&M===D?"sa-calendar-months-active":"",style:{color:s?"#ccc":void 0,pointerEvents:s?"none":void 0,cursor:s?"not-allowed":"pointer",...r?{}:{width:"100%"}},onClick:()=>{s||Y(new Date(M,g))},children:v.slice(0,3)},g)})})},q=a=>{const e=Math.floor(a/10)*10,t=e+10;return{start:e,end:t}},un=({date:a,filter:e,setViews:t,setDate:o,onChange:l,previewDate:p,setPreviewDate:i,minDate:u,maxDate:h,input:r,hasValue:d})=>{let w=[];const D=p.getFullYear(),{start:M,end:Y}=q(D),v=a.getFullYear();for(let s=M;s<Y;s++){let k=u&&new Date(s,0,1)<u||h&&new Date(s,11,31)>h;w.push({year:s,active:!!d&&s===v,isDisabled:k})}const g=s=>{(!u||s>=u)&&(!h||s<=h)&&(e?(l(s),o(s),i(s)):(t("months"),i(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:w.map((s,k)=>n.jsx("p",{className:s.active?"sa-calendar-months-active":"",style:{color:s.isDisabled?"#ccc":void 0,pointerEvents:s.isDisabled?"none":void 0,cursor:s.isDisabled?"not-allowed":"pointer",...r?{}:{width:"100%"}},onClick:()=>{s.isDisabled||g(new Date(s.year,0))},children:s.year},k))})},gn=({setViews:a,views:e,filter:t,previewDate:o,setPreviewDate:l})=>{const p=()=>{t||a(r=>r==="days"?"months":r==="months"?"years":"days")},i=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()+10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()+1,r.getMonth()));return}l(r=>new Date(r.getFullYear(),r.getMonth()+1))},u=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()-10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()-1,r.getMonth()));return}l(r=>new Date(r.getMonth()===0?r.getFullYear()-1:r.getFullYear(),r.getMonth()===0?11:r.getMonth()-1))},h=()=>{if(e==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${q(o.getFullYear()).start} ~ ${q(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:p,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:u,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:n.jsx(_,{})})]})]})},an="sa-calendar-styles";(a=>{if(!document.getElementById(an)){const e=document.createElement("style");e.id=an,e.textContent=a,document.head.appendChild(e)}})(P);const bn=x.forwardRef(({value:a,onChange:e,filter:t,input:o=!0,disabled:l,minDate:p,maxDate:i,placeholder:u,size:h,variant:r,status:d,clearable:w,fullWidth:D=!0,withPadding:M=!0,label:Y,labelPosition:v,required:g,optional:s,description:k,helperText:$,errorText:f},m)=>{const c=f?"error":d,{ref:y,isComponentVisible:z,setIsComponentVisible:T}=K(!1),C=x.useRef(null),[F,I]=x.useState("days"),[L,E]=x.useState(new Date),[N,S]=x.useState(new Date);x.useEffect(()=>{a?(E(a),S(a)):(E(new Date),S(new Date))},[a]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[z]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>a?t==="days"?W(L):t==="months"?`${A[L.getMonth()]} ${L.getFullYear()}`:t==="years"?L.getFullYear():W(L):"",B=()=>{if(C.current&&y.current&&o){const b=y.current.getBoundingClientRect(),j=C.current.getBoundingClientRect();window.innerWidth<b.left+j.width?C.current.style.left=`${b.left-j.width+b.width}px`:C.current.style.left=`${b.left}px`,b.top+j.height>window.innerHeight?C.current.style.top=`${b.y-(b.height+j.height-28)}px`:C.current.style.top=`${b.y+b.height}px`}};x.useEffect(()=>{C.current&&y.current&&o&&B()},[C,y,z]),x.useEffect(()=>{const b=m==null?void 0:m.current;return b&&b.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{b&&b.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?y:null,children:[o?n.jsx(pn,{value:G(),onClick:()=>T(!0),onChange:()=>{},placeholder:u,disabled:l,size:h,variant:r,status:c,inputMode:"none",clearable:w,onClear:()=>e(void 0)}):null,z?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${o?"":"sa-calendar-no-input"} ${M?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:C,children:[n.jsx(gn,{setViews:I,views:F,filter:t,previewDate:N,setPreviewDate:S,isComponentVisible:z}),n.jsx("div",{className:"sa-calendar-body",children:F==="days"?n.jsx(hn,{date:L,setDate:E,previewDate:N,setPreviewDate:S,setIsComponentVisible:T,input:o,minDate:p,maxDate:i,onChange:e,hasValue:a!=null}):F==="months"?n.jsx(fn,{date:L,setDate:E,previewDate:N,setPreviewDate:S,filter:t,setViews:I,onChange:e,minDate:p,maxDate:i,input:o,hasValue:a!=null}):n.jsx(un,{date:L,setDate:E,previewDate:N,setPreviewDate:S,filter:t,setViews:I,onChange:e,minDate:p,maxDate:i,input:o,hasValue:a!=null})})]}):null]});return n.jsx(R,{label:Y,labelPosition:v,required:g,optional:s,description:k,helperText:$,errorText:f,fullWidth:D,children:U})}),vn=x.forwardRef(({value:a,onChange:e,filter:t,input:o=!0,rangedDate:l,disabled:p,minDate:i,maxDate:u,placeholder:h,size:r,variant:d,status:w,clearable:D,fullWidth:M,withPadding:Y,label:v,labelPosition:g,required:s,optional:k,description:$,helperText:f,errorText:m},c)=>{const y={onChange:e,value:a,input:o,filter:t,disabled:p,minDate:i,maxDate:u,placeholder:h,size:r,variant:d,status:w,clearable:D,fullWidth:M,withPadding:Y,label:v,labelPosition:g,required:s,optional:k,description:$,helperText:f,errorText:m};return n.jsx(n.Fragment,{children:l?n.jsx(cn,{...y,ref:c}):n.jsx(bn,{...y,ref:c})})});V.StarasiaDate=vn,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
|
|
582
|
+
`,Z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A=["January","February","March","April","May","June","July","August","September","October","November","December"],rn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function K(a){const[e,s]=m.useState(a),o=m.useRef(null),l=h=>{o.current&&!o.current.contains(h.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const Q="sa-calendar-input-styles";(a=>{if(!document.getElementById(Q)){const e=document.createElement("style");e.id=Q,e.textContent=a,document.head.appendChild(e)}})(P);const O=a=>{if(a==="xs")return 14;if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},sn=a=>{const{size:e="sm",status:s="default",variant:o="outline",clearable:l,onClear:h,...i}=a,g=m.useRef(null),f=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))},r=s==="disable"||i.disabled,d=!!i.value,x=l&&d&&!r,D=M=>{M.stopPropagation(),h==null||h()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:f,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(e),height:O(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...i,disabled:r,value:i.value,ref:g})}),x?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(e),height:O(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(e),height:O(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},tn=({date:a,setDate:e,dateRange:s,setDateRange:o,onChange:l,minDate:h,maxDate:i,input:g})=>{var $,c,w;const[f,r]=m.useState(null);let d=new Date(a.getFullYear(),a.getMonth(),1),x=d.getDay(),D=[];const M=a.getMonth(),z=new Date().toDateString(),b=!!(s.from&&!s.to),u=b&&f?f:null;for(let p=0;p<42;p++){p===0&&x===0?d.setDate(d.getDate()-7):p===0?d.setDate(d.getDate()+(p-x)):d.setDate(d.getDate()+1);let v={currentMonth:d.getMonth()===M,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:d.toDateString()===(($=s.from)==null?void 0:$.toDateString())||d.toDateString()===(((c=s.to)==null?void 0:c.toDateString())||((w=s.from)==null?void 0:w.toDateString())),isToday:d.toDateString()===z,year:d.getFullYear(),isDisabled:h&&d<h||i&&d>i};D.push(v)}const t=p=>{e(p)},k=p=>{let v={...s};if(v.from&&v.to)v={from:p,to:null};else if(!v.from)v={from:p,to:null};else{const S=v.from.getTime();p.getTime()>S?v={from:v.from,to:p}:v={from:p,to:v.from}}o(v),l(v)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>r(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((p,v)=>n.jsx("p",{children:p},v))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((p,v)=>{const S=s.from&&s.to&&p.date.getTime()>s.from.getTime()&&p.date.getTime()<s.to.getTime(),T=(()=>{if(!u||!s.from)return!1;const Y=p.date.getTime(),C=s.from.getTime(),F=u.getTime();return F>C?Y>C&&Y<F:Y<C&&Y>F})(),N=b&&f&&p.date.toDateString()===f.toDateString(),E=p.isDisabled,I=()=>S||T?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",L=()=>E?"var(--sa-color-gray-400, #b7b9be)":S||T?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${p.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${p.selected||N?"sa-calendar-days-active":""} ${p.isToday&&!p.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:I(),pointerEvents:E?"none":void 0,cursor:E?"not-allowed":"pointer",color:L(),opacity:N&&!p.selected?.75:1,...g?{}:{width:"100%"}},onClick:()=>{E||(t(p.date),k(p.date))},onMouseEnter:()=>{E||r(p.date)},children:p.number},v)})})]})},on=({date:a,setDate:e,filter:s,setViews:o,dateRange:l,setDateRange:h,onChange:i,minDate:g,maxDate:f,input:r})=>{var z;const d=(z=l.from)==null?void 0:z.getFullYear(),x=a.getFullYear(),D=b=>{s?(M(b),e(b)):(o("days"),e(b))},M=b=>{let u={...l};if(u.from&&u.to)u={from:b,to:null};else if(!u.from)u={from:b,to:null};else{const t=u.from.getTime();b.getTime()>t?u={from:u.from,to:b}:u={from:b,to:u.from}}h(u),i(u)};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((b,u)=>{var $,c,w;const t=l.from!=null&&new Date(x,u).getTime()>l.from.getTime()&&new Date(x,u).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=g&&new Date(x,u)<g||f&&new Date(x,u)>f;return n.jsx("p",{className:d===x&&(u===((c=l.from)==null?void 0:c.getMonth())||u===((w=l.to)==null?void 0:w.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:t?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:k?"none":void 0,cursor:k?"not-allowed":"pointer",color:k?"var(--sa-color-gray-400, #b7b9be)":t?"var(--sa-color-gray-500, #8c8f97)":"",...r?{}:{width:"100%"}},onClick:()=>{k||D(new Date(x,u))},children:b.slice(0,3)},u)})})},J=a=>{const e=Math.floor(a/10)*10,s=e+10;return{start:e,end:s}},ln=({date:a,filter:e,setViews:s,setDate:o,dateRange:l,setDateRange:h,onChange:i,minDate:g,maxDate:f,input:r})=>{var k,$;let d=[];const x=a.getFullYear(),{start:D,end:M}=J(x),z=(k=l.from)==null?void 0:k.getFullYear(),b=($=l.to)==null?void 0:$.getFullYear();for(let c=D;c<M;c++){const w=new Date(c,0),p=(!g||w>=g)&&(!f||w<=f),v=z!=null&&c===z||b!=null&&c===b,S=l.from!=null&&l.to!=null&&w>l.from&&w<l.to;d.push({year:c,active:v&&p,highlight:S&&p,disabled:!p})}const u=c=>{e?(t(c),o(c)):(o(c),s("months"))},t=c=>{let w={...l};if(w.from&&w.to)w={from:c,to:null};else if(!w.from)w={from:c,to:null};else{const p=w.from.getTime();c.getTime()>p?w={from:w.from,to:c}:w={from:c,to:w.from}}h(w),i(w)};return n.jsx("div",{className:"sa-calendar-years-preview",children:d.map((c,w)=>n.jsx("p",{className:`${c.active?"sa-calendar-months-active":""} ${c.highlight?"sa-calendar-months-highlight":""} ${c.disabled?"sa-calendar-disabled":""}`,onClick:()=>{c.disabled||u(new Date(c.year,0))},style:{backgroundColor:c.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:c.highlight?"var(--sa-color-gray-500, #8c8f97)":c.active?"":c.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:c.disabled?"not-allowed":"pointer",pointerEvents:c.disbled?"none":"all",...r?{}:{width:"100%"}},children:c.year},w))})},X=({...a})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...a,children:n.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),_=({...a})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...a,children:n.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),dn=({setViews:a,views:e,filter:s,date:o,setDate:l})=>{const h=()=>{s||a(r=>r==="days"?"months":r==="months"?"years":"days")},i=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()+10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()+1,r.getMonth()));return}l(r=>new Date(r.getFullYear(),r.getMonth()+1))},g=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()-10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()-1,r.getMonth()));return}l(r=>new Date(r.getMonth()===0?r.getFullYear()-1:r.getFullYear(),r.getMonth()===0?11:r.getMonth()-1))},f=()=>{if(e==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${J(o.getFullYear()).start} ~ ${J(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:h,children:f()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:g,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:n.jsx(_,{})})]})]})};function W(a){const e=new Date(a),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${rn[o]} ${s}`}const R=({label:a,labelPosition:e="outside-top",required:s,optional:o,description:l,helperText:h,errorText:i,fullWidth:g,children:f})=>{const r=["sa-date-field",g?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),d=a?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:a}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),s&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,x=n.jsxs(n.Fragment,{children:[h&&!i&&n.jsx("p",{className:"sa-date-field-helper",children:h}),i&&n.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return a?e==="outside-left"?n.jsxs("div",{className:`${r} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[d,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[f,x]})]}):n.jsxs("div",{className:r,children:[d,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),f,x]}):n.jsxs("div",{className:r,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),f,x]})},nn="sa-calendar-styles";(a=>{if(!document.getElementById(nn)){const e=document.createElement("style");e.id=nn,e.textContent=a,document.head.appendChild(e)}})(P);const cn=m.forwardRef(({value:a,onChange:e,filter:s,input:o=!0,disabled:l,minDate:h,maxDate:i,placeholder:g,size:f="sm",variant:r,status:d,clearable:x,fullWidth:D=!0,withPadding:M=!0,label:z,labelPosition:b,required:u,optional:t,description:k,helperText:$,errorText:c},w)=>{const p=c?"error":d,{ref:v,isComponentVisible:S,setIsComponentVisible:T}=K(!1),N=m.useRef(null),[E,I]=m.useState("days"),[L,Y]=m.useState(new Date),[C,F]=m.useState({from:(a==null?void 0:a.from)??null,to:(a==null?void 0:a.to)??null});m.useEffect(()=>{if(a){const y=a;y.from&&Y(y.from),F(y)}else Y(new Date),F({from:null,to:null})},[a]),m.useEffect(()=>{s&&I(s)},[s]),m.useEffect(()=>{s||I("days")},[S]),m.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var y,j;if(!a)return"";if(s){if(E==="days")return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`;if(E==="months")return`${A[C.from.getMonth()]} ~ ${C.to?A[C.to.getMonth()]:"-"}`;if(E==="years")return`${(y=C.from)==null?void 0:y.getFullYear()} ~ ${((j=C.to)==null?void 0:j.getFullYear())||"-"}`}else return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`},B=()=>{if(N.current&&v.current&&o){const y=v.current.getBoundingClientRect(),j=N.current.getBoundingClientRect();window.innerWidth<y.left+j.width?N.current.style.left=`${y.left-j.width+y.width}px`:N.current.style.left=`${y.left}px`,y.top+j.height>window.innerHeight?N.current.style.top=`${y.y-(y.height+j.height-28)}px`:N.current.style.top=`${y.y+y.height}px`}};m.useEffect(()=>{N.current&&v.current&&o&&B()},[N,v,S]),m.useEffect(()=>{const y=w==null?void 0:w.current;return y&&y.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{y&&y.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?v:null,children:[o?n.jsx(sn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:g,size:f,variant:r,status:p,clearable:x,onClear:()=>e(void 0)}):null,S?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${f||"sm"} ${o?"":"sa-calendar-no-input"} ${M?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:N,children:[n.jsx(dn,{setViews:I,views:E,filter:s,date:L,setDate:Y}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(tn,{date:L,setDate:Y,setIsComponentVisible:T,dateRange:C,setDateRange:F,input:o,onChange:e,minDate:h,maxDate:i}):E==="months"?n.jsx(on,{date:L,setDate:Y,filter:s,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:e,minDate:h,maxDate:i}):n.jsx(ln,{date:L,setDate:Y,filter:s,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:e,minDate:h,maxDate:i})})]}):null]});return n.jsx(R,{label:z,labelPosition:b,required:u,optional:t,description:k,helperText:$,errorText:c,fullWidth:D,children:U})}),en="sa-calendar-input-styles";(a=>{if(!document.getElementById(en)){const e=document.createElement("style");e.id=en,e.textContent=a,document.head.appendChild(e)}})(P);const H=a=>{if(a==="xs")return 14;if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},pn=a=>{const{size:e="sm",status:s="default",variant:o="outline",clearable:l,onClear:h,...i}=a,g=m.useRef(null),f=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))},r=s==="disable"||i.disabled,d=!!i.value,x=l&&d&&!r,D=M=>{M.stopPropagation(),h==null||h()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:f,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(e),height:H(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...i,disabled:r,value:i.value,ref:g})}),x?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(e),height:H(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(e),height:H(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},hn=({date:a,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:h,maxDate:i,input:g,onChange:f,hasValue:r})=>{let d=new Date(s.getFullYear(),s.getMonth(),1),x=d.getDay(),D=[];const M=a.toDateString(),z=new Date().toDateString(),b=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?d.setDate(d.getDate()-7):t===0?d.setDate(d.getDate()+(t-x)):d.setDate(d.getDate()+1);let k={currentMonth:d.getMonth()===b,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:r&&d.toDateString()===M,isToday:d.toDateString()===z,year:d.getFullYear(),isDisabled:h&&d<h||i&&d>i};D.push(k)}const u=t=>{(!h||t>=h)&&(!i||t<=i)&&(e(t),f(t),o(t),g&&l(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((t,k)=>n.jsx("p",{children:t},k))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((t,k)=>{const $=t.isDisabled;return n.jsx("p",{className:`${t.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${t.selected?"sa-calendar-days-active":""} ${t.isToday&&!t.selected?"sa-calendar-days-today":""}`,style:{color:$?"#ccc":void 0,pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",...g?{}:{width:"100%"}},onClick:()=>{$||u(t.date)},children:t.number},k)})})]})},fn=({date:a,setDate:e,filter:s,setViews:o,onChange:l,previewDate:h,setPreviewDate:i,minDate:g,maxDate:f,input:r,hasValue:d})=>{const x=a.getMonth(),D=a.getFullYear(),M=h.getFullYear(),z=b=>{(!g||b>=g)&&(!f||b<=f)&&(s?(l(b),e(b),i(b)):(o("days"),i(b)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((b,u)=>{const t=g&&new Date(M,u,1)<g||f&&new Date(M,u+1,0)>f;return n.jsx("p",{className:d&&u===x&&M===D?"sa-calendar-months-active":"",style:{color:t?"#ccc":void 0,pointerEvents:t?"none":void 0,cursor:t?"not-allowed":"pointer",...r?{}:{width:"100%"}},onClick:()=>{t||z(new Date(M,u))},children:b.slice(0,3)},u)})})},q=a=>{const e=Math.floor(a/10)*10,s=e+10;return{start:e,end:s}},un=({date:a,filter:e,setViews:s,setDate:o,onChange:l,previewDate:h,setPreviewDate:i,minDate:g,maxDate:f,input:r,hasValue:d})=>{let x=[];const D=h.getFullYear(),{start:M,end:z}=q(D),b=a.getFullYear();for(let t=M;t<z;t++){let k=g&&new Date(t,0,1)<g||f&&new Date(t,11,31)>f;x.push({year:t,active:!!d&&t===b,isDisabled:k})}const u=t=>{(!g||t>=g)&&(!f||t<=f)&&(e?(l(t),o(t),i(t)):(s("months"),i(t)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:x.map((t,k)=>n.jsx("p",{className:t.active?"sa-calendar-months-active":"",style:{color:t.isDisabled?"#ccc":void 0,pointerEvents:t.isDisabled?"none":void 0,cursor:t.isDisabled?"not-allowed":"pointer",...r?{}:{width:"100%"}},onClick:()=>{t.isDisabled||u(new Date(t.year,0))},children:t.year},k))})},gn=({setViews:a,views:e,filter:s,previewDate:o,setPreviewDate:l})=>{const h=()=>{s||a(r=>r==="days"?"months":r==="months"?"years":"days")},i=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()+10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()+1,r.getMonth()));return}l(r=>new Date(r.getFullYear(),r.getMonth()+1))},g=()=>{if(e==="years"){l(r=>new Date(r.getFullYear()-10,0));return}if(e==="months"){l(r=>new Date(r.getFullYear()-1,r.getMonth()));return}l(r=>new Date(r.getMonth()===0?r.getFullYear()-1:r.getFullYear(),r.getMonth()===0?11:r.getMonth()-1))},f=()=>{if(e==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${q(o.getFullYear()).start} ~ ${q(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:h,children:f()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:g,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:n.jsx(_,{})})]})]})},an="sa-calendar-styles";(a=>{if(!document.getElementById(an)){const e=document.createElement("style");e.id=an,e.textContent=a,document.head.appendChild(e)}})(P);const bn=m.forwardRef(({value:a,onChange:e,filter:s,input:o=!0,disabled:l,minDate:h,maxDate:i,placeholder:g,size:f="sm",variant:r,status:d,clearable:x,fullWidth:D=!0,withPadding:M=!0,label:z,labelPosition:b,required:u,optional:t,description:k,helperText:$,errorText:c},w)=>{const p=c?"error":d,{ref:v,isComponentVisible:S,setIsComponentVisible:T}=K(!1),N=m.useRef(null),[E,I]=m.useState("days"),[L,Y]=m.useState(new Date),[C,F]=m.useState(new Date);m.useEffect(()=>{a?(Y(a),F(a)):(Y(new Date),F(new Date))},[a]),m.useEffect(()=>{s&&I(s)},[s]),m.useEffect(()=>{s||I("days")},[S]),m.useEffect(()=>{o||T(!0)},[o]);const G=()=>a?s==="days"?W(L):s==="months"?`${A[L.getMonth()]} ${L.getFullYear()}`:s==="years"?L.getFullYear():W(L):"",B=()=>{if(N.current&&v.current&&o){const y=v.current.getBoundingClientRect(),j=N.current.getBoundingClientRect();window.innerWidth<y.left+j.width?N.current.style.left=`${y.left-j.width+y.width}px`:N.current.style.left=`${y.left}px`,y.top+j.height>window.innerHeight?N.current.style.top=`${y.y-(y.height+j.height-28)}px`:N.current.style.top=`${y.y+y.height}px`}};m.useEffect(()=>{N.current&&v.current&&o&&B()},[N,v,S]),m.useEffect(()=>{const y=w==null?void 0:w.current;return y&&y.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{y&&y.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?v:null,children:[o?n.jsx(pn,{value:G(),onClick:()=>T(!0),onChange:()=>{},placeholder:g,disabled:l,size:f,variant:r,status:p,inputMode:"none",clearable:x,onClear:()=>e(void 0)}):null,S?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${f||"sm"} ${o?"":"sa-calendar-no-input"} ${M?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:N,children:[n.jsx(gn,{setViews:I,views:E,filter:s,previewDate:C,setPreviewDate:F,isComponentVisible:S}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(hn,{date:L,setDate:Y,previewDate:C,setPreviewDate:F,setIsComponentVisible:T,input:o,minDate:h,maxDate:i,onChange:e,hasValue:a!=null}):E==="months"?n.jsx(fn,{date:L,setDate:Y,previewDate:C,setPreviewDate:F,filter:s,setViews:I,onChange:e,minDate:h,maxDate:i,input:o,hasValue:a!=null}):n.jsx(un,{date:L,setDate:Y,previewDate:C,setPreviewDate:F,filter:s,setViews:I,onChange:e,minDate:h,maxDate:i,input:o,hasValue:a!=null})})]}):null]});return n.jsx(R,{label:z,labelPosition:b,required:u,optional:t,description:k,helperText:$,errorText:c,fullWidth:D,children:U})}),vn=m.forwardRef(({value:a,onChange:e,filter:s,input:o=!0,rangedDate:l,disabled:h,minDate:i,maxDate:g,placeholder:f,size:r,variant:d,status:x,clearable:D,fullWidth:M,withPadding:z,label:b,labelPosition:u,required:t,optional:k,description:$,helperText:c,errorText:w},p)=>{const v={onChange:e,value:a,input:o,filter:s,disabled:h,minDate:i,maxDate:g,placeholder:f,size:r,variant:d,status:x,clearable:D,fullWidth:M,withPadding:z,label:b,labelPosition:u,required:t,optional:k,description:$,helperText:c,errorText:w};return n.jsx(n.Fragment,{children:l?n.jsx(cn,{...v,ref:p}):n.jsx(bn,{...v,ref:p})})});V.StarasiaDate=vn,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface IDateProps {
|
|
|
10
10
|
minDate?: Date;
|
|
11
11
|
maxDate?: Date;
|
|
12
12
|
placeholder?: string;
|
|
13
|
-
size?: "sm" | "md" | "lg";
|
|
13
|
+
size?: "xs" | "sm" | "md" | "lg";
|
|
14
14
|
variant?: "outline" | "filled" | "flushed";
|
|
15
15
|
status?: "error" | "warning";
|
|
16
16
|
clearable?: boolean;
|
|
@@ -29,7 +29,7 @@ export interface IDateRange {
|
|
|
29
29
|
to: Date | null;
|
|
30
30
|
}
|
|
31
31
|
export interface IInputDateProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
32
|
-
size?: "sm" | "md" | "lg";
|
|
32
|
+
size?: "xs" | "sm" | "md" | "lg";
|
|
33
33
|
status?: "error" | "warning" | "disable" | "default";
|
|
34
34
|
variant?: "outline" | "filled" | "flushed";
|
|
35
35
|
clearable?: boolean;
|