@starasia/date 5.2.2 → 5.2.4
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.umd.js
CHANGED
|
@@ -242,6 +242,7 @@
|
|
|
242
242
|
|
|
243
243
|
.sa-calendar-days-today {
|
|
244
244
|
position: relative;
|
|
245
|
+
isolation: isolate;
|
|
245
246
|
color: var(--sa-date-brand);
|
|
246
247
|
font-weight: 700;
|
|
247
248
|
background: transparent;
|
|
@@ -253,13 +254,18 @@
|
|
|
253
254
|
top: 50%;
|
|
254
255
|
left: 50%;
|
|
255
256
|
transform: translate(-50%, -50%);
|
|
256
|
-
width:
|
|
257
|
-
height:
|
|
257
|
+
width: 26px;
|
|
258
|
+
height: 26px;
|
|
258
259
|
background: var(--sa-date-brand-secondary);
|
|
259
260
|
border-radius: 50%;
|
|
260
261
|
z-index: -1;
|
|
261
262
|
}
|
|
262
263
|
|
|
264
|
+
.sa-calendar-days-number-preivew p.sa-calendar-days-today:hover {
|
|
265
|
+
background: transparent;
|
|
266
|
+
color: var(--sa-date-brand);
|
|
267
|
+
}
|
|
268
|
+
|
|
263
269
|
/* MONTH STYLING */
|
|
264
270
|
.sa-calendar-months-preview {
|
|
265
271
|
display: grid;
|
|
@@ -483,8 +489,8 @@
|
|
|
483
489
|
height: 26px;
|
|
484
490
|
}
|
|
485
491
|
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-today::before {
|
|
486
|
-
width:
|
|
487
|
-
height:
|
|
492
|
+
width: 22px;
|
|
493
|
+
height: 22px;
|
|
488
494
|
}
|
|
489
495
|
.sa-calendar.sa-calendar-size-sm .sa-calendar-months-preview p,
|
|
490
496
|
.sa-calendar.sa-calendar-size-sm .sa-calendar-years-preview p {
|
|
@@ -512,8 +518,8 @@
|
|
|
512
518
|
height: 36px;
|
|
513
519
|
}
|
|
514
520
|
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-today::before {
|
|
515
|
-
width:
|
|
516
|
-
height:
|
|
521
|
+
width: 30px;
|
|
522
|
+
height: 30px;
|
|
517
523
|
}
|
|
518
524
|
.sa-calendar.sa-calendar-size-lg .sa-calendar-months-preview p,
|
|
519
525
|
.sa-calendar.sa-calendar-size-lg .sa-calendar-years-preview p {
|
|
@@ -536,4 +542,4 @@
|
|
|
536
542
|
width: 32px;
|
|
537
543
|
height: 32px;
|
|
538
544
|
}
|
|
539
|
-
`,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(r){const[a,t]=x.useState(r),o=x.useRef(null),l=c=>{o.current&&!o.current.contains(c.target)&&t(!1)};return x.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:t}}const Q="sa-calendar-input-styles";(r=>{if(!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,a.textContent=r,document.head.appendChild(a)}})(P);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},tn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,h=x.useRef(null),p=()=>{h.current&&d.onClick&&(h.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:p,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),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",...d,disabled:e,value:d.value,ref:h})}),y?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(a),height:O(a),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(a),height:O(a),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:r,setDate:a,dateRange:t,setDateRange:o,onChange:l,minDate:c,maxDate:d,input:h})=>{var u,m,Y;const[p,e]=x.useState(null);let i=new Date(r.getFullYear(),r.getMonth(),1),y=i.getDay(),D=[];const N=r.getMonth(),v=new Date().toDateString(),f=!!(t.from&&!t.to),s=f&&p?p:null;for(let g=0;g<42;g++){g===0&&y===0?i.setDate(i.getDate()-7):g===0?i.setDate(i.getDate()+(g-y)):i.setDate(i.getDate()+1);let b={currentMonth:i.getMonth()===N,date:new Date(i),month:i.getMonth(),number:i.getDate(),selected:i.toDateString()===((u=t.from)==null?void 0:u.toDateString())||i.toDateString()===(((m=t.to)==null?void 0:m.toDateString())||((Y=t.from)==null?void 0:Y.toDateString())),isToday:i.toDateString()===v,year:i.getFullYear(),isDisabled:c&&i<c||d&&i>d};D.push(b)}const k=g=>{a(g)},$=g=>{var L;let b={...t};if(b.from&&b.to)b={from:g,to:null};else{const T=((L=b.from)==null?void 0:L.getTime())||0;g.getTime()>T?b={from:b.from,to:g}:b={from:g,to:b.from}}o(b),l(b)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>e(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((g,b)=>n.jsx("p",{children:g},b))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((g,b)=>{const L=t.from&&t.to&&g.date.getTime()>t.from.getTime()&&g.date.getTime()<t.to.getTime(),T=(()=>{if(!s||!t.from)return!1;const z=g.date.getTime(),C=t.from.getTime(),F=s.getTime();return F>C?z>C&&z<F:z<C&&z>F})(),M=f&&p&&g.date.toDateString()===p.toDateString(),E=g.isDisabled,I=()=>L||T?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",S=()=>E?"var(--sa-color-gray-400, #b7b9be)":L||T?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${g.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${g.selected||M?"sa-calendar-days-active":""} ${g.isToday&&!g.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:I(),pointerEvents:E?"none":void 0,cursor:E?"not-allowed":"pointer",color:S(),opacity:M&&!g.selected?.75:1,...h?{}:{width:"100%"}},onClick:()=>{E||(k(g.date),$(g.date))},onMouseEnter:()=>{E||e(g.date)},children:g.number},b)})})]})},on=({date:r,setDate:a,filter:t,setViews:o,dateRange:l,setDateRange:c,onChange:d,minDate:h,maxDate:p,input:e})=>{const i=l.from.getFullYear(),y=r.getFullYear(),D=v=>{t?(N(v),a(v)):(o("days"),a(v))},N=v=>{var s;let f={...l};if(f.from&&f.to)f={from:v,to:null};else{const k=((s=f.from)==null?void 0:s.getTime())||0;v.getTime()>k?f={from:f.from,to:v}:f={from:v,to:f.from}}c(f),d(f)};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{var $,u,m;const s=new Date(y,f).getTime()>l.from.getTime()&&new Date(y,f).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=h&&new Date(y,f)<h||p&&new Date(y,f)>p;return n.jsx("p",{className:i===y&&(f===((u=l.from)==null?void 0:u.getMonth())||f===((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)":"",...e?{}:{width:"100%"}},onClick:()=>{k||D(new Date(y,f))},children:v.slice(0,3)},f)})})},J=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},ln=({date:r,filter:a,setViews:t,setDate:o,dateRange:l,setDateRange:c,onChange:d,minDate:h,maxDate:p,input:e})=>{var $;let i=[];const y=r.getFullYear(),{start:D,end:N}=J(y),v=l.from.getFullYear(),f=($=l.to)==null?void 0:$.getFullYear();for(let u=D;u<N;u++){const m=new Date(u,0),Y=(!h||m>=h)&&(!p||m<=p),g=u===v||u===f,b=m>l.from&&m<l.to;i.push({year:u,active:g&&Y,highlight:b&&Y,disabled:!Y})}const s=u=>{a?(k(u),o(u)):(o(u),t("months"))},k=u=>{var Y;let m={...l};if(m.from&&m.to)m={from:u,to:null};else{const g=((Y=m.from)==null?void 0:Y.getTime())||0;u.getTime()>g?m={from:m.from,to:u}:m={from:u,to:m.from}}c(m),d(m)};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.map((u,m)=>n.jsx("p",{className:`${u.active?"sa-calendar-months-active":""} ${u.highlight?"sa-calendar-months-highlight":""} ${u.disabled?"sa-calendar-disabled":""}`,onClick:()=>{u.disabled||s(new Date(u.year,0))},style:{backgroundColor:u.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:u.highlight?"var(--sa-color-gray-500, #8c8f97)":u.active?"":u.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:u.disabled?"not-allowed":"pointer",pointerEvents:u.disbled?"none":"all",...e?{}:{width:"100%"}},children:u.year},m))})},X=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,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"})}),_=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,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:r,views:a,filter:t,date:o,setDate:l})=>{const c=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},h=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},p=()=>{if(a==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="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:c,children:p()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:h,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})};function W(r){const a=new Date(r),t=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${rn[o]} ${t}`}const R=({label:r,labelPosition:a="outside-top",required:t,optional:o,description:l,helperText:c,errorText:d,fullWidth:h,children:p})=>{const e=["sa-date-field",h?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),i=r?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:r}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,y=n.jsxs(n.Fragment,{children:[c&&!d&&n.jsx("p",{className:"sa-date-field-helper",children:c}),d&&n.jsx("p",{className:"sa-date-field-error-msg",children:d})]});return r?a==="outside-left"?n.jsxs("div",{className:`${e} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[p,y]})]}):n.jsxs("div",{className:e,children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),p,y]}):n.jsxs("div",{className:e,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),p,y]})},nn="sa-calendar-styles";(r=>{if(!document.getElementById(nn)){const a=document.createElement("style");a.id=nn,a.textContent=r,document.head.appendChild(a)}})(P);const cn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:h,size:p,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});x.useEffect(()=>{r?(z(r.from),F(r)):(z(new Date),F({from:new Date,to:new Date}))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var w,j;if(!r)return"";if(t){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`${(w=C.from)==null?void 0:w.getFullYear()} ~ ${((j=C.to)==null?void 0:j.getFullYear())||"-"}`}else return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`},B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(tn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:h,size:p,variant:e,status:g,clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${p||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:M,children:[n.jsx(dn,{setViews:I,views:E,filter:t,date:S,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(sn,{date:S,setDate:z,setIsComponentVisible:T,dateRange:C,setDateRange:F,input:o,onChange:a,minDate:c,maxDate:d}):E==="months"?n.jsx(on,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d}):n.jsx(ln,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),en="sa-calendar-input-styles";(r=>{if(!document.getElementById(en)){const a=document.createElement("style");a.id=en,a.textContent=r,document.head.appendChild(a)}})(P);const H=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},pn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,h=x.useRef(null),p=()=>{h.current&&d.onClick&&(h.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:p,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),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",...d,disabled:e,value:d.value,ref:h})}),y?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(a),height:H(a),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(a),height:H(a),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:r,setDate:a,previewDate:t,setPreviewDate:o,setIsComponentVisible:l,minDate:c,maxDate:d,input:h,onChange:p})=>{let e=new Date(t.getFullYear(),t.getMonth(),1),i=e.getDay(),y=[];const D=r.toDateString(),N=new Date().toDateString(),v=t.getMonth();for(let s=0;s<42;s++){s===0&&i===0?e.setDate(e.getDate()-7):s===0?e.setDate(e.getDate()+(s-i)):e.setDate(e.getDate()+1);let k={currentMonth:e.getMonth()===v,date:new Date(e),month:e.getMonth(),number:e.getDate(),selected:e.toDateString()===D,isToday:e.toDateString()===N,year:e.getFullYear(),isDisabled:c&&e<c||d&&e>d};y.push(k)}const f=s=>{(!c||s>=c)&&(!d||s<=d)&&(a(s),p(s),o(s),h&&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:y.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",...h?{}:{width:"100%"}},onClick:()=>{$||f(s.date)},children:s.number},k)})})]})},fn=({date:r,setDate:a,filter:t,setViews:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:h,maxDate:p,input:e})=>{const i=r.getMonth(),y=r.getFullYear(),D=c.getFullYear(),N=v=>{(!h||v>=h)&&(!p||v<=p)&&(t?(l(v),a(v),d(v)):(o("days"),d(v)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{const s=h&&new Date(D,f,1)<h||p&&new Date(D,f+1,0)>p;return n.jsx("p",{className:f===i&&D===y?"sa-calendar-months-active":"",style:{color:s?"#ccc":void 0,pointerEvents:s?"none":void 0,cursor:s?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s||N(new Date(D,f))},children:v.slice(0,3)},f)})})},q=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},un=({date:r,filter:a,setViews:t,setDate:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:h,maxDate:p,input:e})=>{let i=[];const y=c.getFullYear(),{start:D,end:N}=q(y),v=r.getFullYear();for(let s=D;s<N;s++){let k=h&&new Date(s,0,1)<h||p&&new Date(s,11,31)>p;i.push({year:s,active:s===v,isDisabled:k})}const f=s=>{(!h||s>=h)&&(!p||s<=p)&&(a?(l(s),o(s),d(s)):(t("months"),d(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.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",...e?{}:{width:"100%"}},onClick:()=>{s.isDisabled||f(new Date(s.year,0))},children:s.year},k))})},gn=({setViews:r,views:a,filter:t,previewDate:o,setPreviewDate:l})=>{const c=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},h=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},p=()=>{if(a==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="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:c,children:p()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:h,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})},an="sa-calendar-styles";(r=>{if(!document.getElementById(an)){const a=document.createElement("style");a.id=an,a.textContent=r,document.head.appendChild(a)}})(P);const bn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:h,size:p,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState(new Date);x.useEffect(()=>{r?(z(r),F(r)):(z(new Date),F(new Date))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>r?t==="days"?W(S):t==="months"?`${A[S.getMonth()]} ${S.getFullYear()}`:t==="years"?S.getFullYear():W(S):"",B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(pn,{value:G(),onClick:()=>T(!0),onChange:()=>{},placeholder:h,disabled:l,size:p,variant:e,status:g,inputMode:"none",clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${p||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:M,children:[n.jsx(gn,{setViews:I,views:E,filter:t,previewDate:C,setPreviewDate:F,isComponentVisible:L}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(hn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,setIsComponentVisible:T,input:o,minDate:c,maxDate:d,onChange:a}):E==="months"?n.jsx(fn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o}):n.jsx(un,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),vn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,rangedDate:l,disabled:c,minDate:d,maxDate:h,placeholder:p,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y},g)=>{const b={onChange:a,value:r,input:o,filter:t,disabled:c,minDate:d,maxDate:h,placeholder:p,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y};return n.jsx(n.Fragment,{children:l?n.jsx(cn,{...b,ref:g}):n.jsx(bn,{...b,ref:g})})});V.StarasiaDate=vn,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
|
|
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"})});
|