@starasia/date 5.2.3 → 5.2.5

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
@@ -542,4 +542,4 @@
542
542
  width: 32px;
543
543
  height: 32px;
544
544
  }
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(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=h=>{o.current&&!o.current.contains(h.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:h,...i}=a,g=x.useRef(null),f=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))},r=t==="disable"||i.disabled,d=!!i.value,m=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-${t} ${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})}),m?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:h,maxDate:i,input:g})=>{var Y,c,w;const[f,r]=x.useState(null);let d=new Date(a.getFullYear(),a.getMonth(),1),m=d.getDay(),D=[];const M=a.getMonth(),$=new Date().toDateString(),b=!!(t.from&&!t.to),u=b&&f?f:null;for(let p=0;p<42;p++){p===0&&m===0?d.setDate(d.getDate()-7):p===0?d.setDate(d.getDate()+(p-m)):d.setDate(d.getDate()+1);let v={currentMonth:d.getMonth()===M,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:d.toDateString()===((Y=t.from)==null?void 0:Y.toDateString())||d.toDateString()===(((c=t.to)==null?void 0:c.toDateString())||((w=t.from)==null?void 0:w.toDateString())),isToday:d.toDateString()===$,year:d.getFullYear(),isDisabled:h&&d<h||i&&d>i};D.push(v)}const s=p=>{e(p)},k=p=>{let v={...t};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=t.from&&t.to&&p.date.getTime()>t.from.getTime()&&p.date.getTime()<t.to.getTime(),T=(()=>{if(!u||!t.from)return!1;const z=p.date.getTime(),C=t.from.getTime(),F=u.getTime();return F>C?z>C&&z<F:z<C&&z>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||(s(p.date),k(p.date))},onMouseEnter:()=>{E||r(p.date)},children:p.number},v)})})]})},on=({date:a,setDate:e,filter:t,setViews:o,dateRange:l,setDateRange:h,onChange:i,minDate:g,maxDate:f,input:r})=>{var $;const d=($=l.from)==null?void 0:$.getFullYear(),m=a.getFullYear(),D=b=>{t?(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 s=u.from.getTime();b.getTime()>s?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 Y,c,w;const s=l.from!=null&&new Date(m,u).getTime()>l.from.getTime()&&new Date(m,u).getTime()<(((Y=l.to)==null?void 0:Y.getTime())||l.from.getTime()),k=g&&new Date(m,u)<g||f&&new Date(m,u)>f;return n.jsx("p",{className:d===m&&(u===((c=l.from)==null?void 0:c.getMonth())||u===((w=l.to)==null?void 0:w.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(m,u))},children:b.slice(0,3)},u)})})},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:h,onChange:i,minDate:g,maxDate:f,input:r})=>{var k,Y;let d=[];const m=a.getFullYear(),{start:D,end:M}=J(m),$=(k=l.from)==null?void 0:k.getFullYear(),b=(Y=l.to)==null?void 0:Y.getFullYear();for(let c=D;c<M;c++){const w=new Date(c,0),p=(!g||w>=g)&&(!f||w<=f),v=$!=null&&c===$||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?(s(c),o(c)):(o(c),t("months"))},s=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:t,date:o,setDate:l})=>{const h=()=>{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))},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),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: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"}),t&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,m=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,m]})]}):n.jsxs("div",{className:r,children:[d,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),f,m]}):n.jsxs("div",{className:r,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),f,m]})},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:h,maxDate:i,placeholder:g,size:f,variant:r,status:d,clearable:m,fullWidth:D=!0,withPadding:M=!0,label:$,labelPosition:b,required:u,optional:s,description:k,helperText:Y,errorText:c},w)=>{const p=c?"error":d,{ref:v,isComponentVisible:S,setIsComponentVisible:T}=K(!1),N=x.useRef(null),[E,I]=x.useState("days"),[L,z]=x.useState(new Date),[C,F]=x.useState({from:(a==null?void 0:a.from)??null,to:(a==null?void 0:a.to)??null});x.useEffect(()=>{if(a){const y=a;y.from&&z(y.from),F(y)}else z(new Date),F({from:null,to:null})},[a]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[S]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var y,j;if(!a)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`${(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`}};x.useEffect(()=>{N.current&&v.current&&o&&B()},[N,v,S]),x.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(tn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:g,size:f,variant:r,status:p,clearable:m,onClear:()=>e(void 0)}):null,S?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${f||"md"} ${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:t,date:L,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(sn,{date:L,setDate:z,setIsComponentVisible:T,dateRange:C,setDateRange:F,input:o,onChange:e,minDate:h,maxDate:i}):E==="months"?n.jsx(on,{date:L,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:e,minDate:h,maxDate:i}):n.jsx(ln,{date:L,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:e,minDate:h,maxDate:i})})]}):null]});return n.jsx(R,{label:$,labelPosition:b,required:u,optional:s,description:k,helperText:Y,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==="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:h,...i}=a,g=x.useRef(null),f=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))},r=t==="disable"||i.disabled,d=!!i.value,m=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-${t} ${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})}),m?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:h,maxDate:i,input:g,onChange:f,hasValue:r})=>{let d=new Date(t.getFullYear(),t.getMonth(),1),m=d.getDay(),D=[];const M=a.toDateString(),$=new Date().toDateString(),b=t.getMonth();for(let s=0;s<42;s++){s===0&&m===0?d.setDate(d.getDate()-7):s===0?d.setDate(d.getDate()+(s-m)):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()===$,year:d.getFullYear(),isDisabled:h&&d<h||i&&d>i};D.push(k)}const u=s=>{(!h||s>=h)&&(!i||s<=i)&&(e(s),f(s),o(s),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((s,k)=>n.jsx("p",{children:s},k))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((s,k)=>{const Y=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:Y?"#ccc":void 0,pointerEvents:Y?"none":void 0,cursor:Y?"not-allowed":"pointer",...g?{}:{width:"100%"}},onClick:()=>{Y||u(s.date)},children:s.number},k)})})]})},fn=({date:a,setDate:e,filter:t,setViews:o,onChange:l,previewDate:h,setPreviewDate:i,minDate:g,maxDate:f,input:r,hasValue:d})=>{const m=a.getMonth(),D=a.getFullYear(),M=h.getFullYear(),$=b=>{(!g||b>=g)&&(!f||b<=f)&&(t?(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 s=g&&new Date(M,u,1)<g||f&&new Date(M,u+1,0)>f;return n.jsx("p",{className:d&&u===m&&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||$(new Date(M,u))},children:b.slice(0,3)},u)})})},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:h,setPreviewDate:i,minDate:g,maxDate:f,input:r,hasValue:d})=>{let m=[];const D=h.getFullYear(),{start:M,end:$}=q(D),b=a.getFullYear();for(let s=M;s<$;s++){let k=g&&new Date(s,0,1)<g||f&&new Date(s,11,31)>f;m.push({year:s,active:!!d&&s===b,isDisabled:k})}const u=s=>{(!g||s>=g)&&(!f||s<=f)&&(e?(l(s),o(s),i(s)):(t("months"),i(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:m.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||u(new Date(s.year,0))},children:s.year},k))})},gn=({setViews:a,views:e,filter:t,previewDate:o,setPreviewDate:l})=>{const h=()=>{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))},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=x.forwardRef(({value:a,onChange:e,filter:t,input:o=!0,disabled:l,minDate:h,maxDate:i,placeholder:g,size:f,variant:r,status:d,clearable:m,fullWidth:D=!0,withPadding:M=!0,label:$,labelPosition:b,required:u,optional:s,description:k,helperText:Y,errorText:c},w)=>{const p=c?"error":d,{ref:v,isComponentVisible:S,setIsComponentVisible:T}=K(!1),N=x.useRef(null),[E,I]=x.useState("days"),[L,z]=x.useState(new Date),[C,F]=x.useState(new Date);x.useEffect(()=>{a?(z(a),F(a)):(z(new Date),F(new Date))},[a]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[S]),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(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`}};x.useEffect(()=>{N.current&&v.current&&o&&B()},[N,v,S]),x.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:m,onClear:()=>e(void 0)}):null,S?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${f||"md"} ${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:t,previewDate:C,setPreviewDate:F,isComponentVisible:S}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(hn,{date:L,setDate:z,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:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:e,minDate:h,maxDate:i,input:o,hasValue:a!=null}):n.jsx(un,{date:L,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:e,minDate:h,maxDate:i,input:o,hasValue:a!=null})})]}):null]});return n.jsx(R,{label:$,labelPosition:b,required:u,optional:s,description:k,helperText:Y,errorText:c,fullWidth:D,children:U})}),vn=x.forwardRef(({value:a,onChange:e,filter:t,input:o=!0,rangedDate:l,disabled:h,minDate:i,maxDate:g,placeholder:f,size:r,variant:d,status:m,clearable:D,fullWidth:M,withPadding:$,label:b,labelPosition:u,required:s,optional:k,description:Y,helperText:c,errorText:w},p)=>{const v={onChange:e,value:a,input:o,filter:t,disabled:h,minDate:i,maxDate:g,placeholder:f,size:r,variant:d,status:m,clearable:D,fullWidth:M,withPadding:$,label:b,labelPosition:u,required:s,optional:k,description:Y,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "5.2.3",
3
+ "version": "5.2.5",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",