@starasia/date 3.1.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/date.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(Y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(Y=typeof globalThis<"u"?globalThis:Y||self,a(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,a,x){"use strict";const T=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
1
+ (function(F,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(F=typeof globalThis<"u"?globalThis:F||self,a(F.Date={},F.jsxRuntime,F.React))})(this,function(F,a,k){"use strict";const I=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
2
2
 
3
3
  * {
4
4
  margin: 0;
@@ -27,6 +27,9 @@
27
27
  }
28
28
  .sa-calendar-wrapper {
29
29
  position: relative;
30
+ width: max-content;
31
+ }
32
+ .sa-calendar-wrapper-fullwidth {
30
33
  width: 100%;
31
34
  }
32
35
 
@@ -277,4 +280,4 @@
277
280
  outline: 2px solid var(--sa-date-brand);
278
281
  outline-offset: 1px;
279
282
  }
280
- `,B=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function V(t){const[e,s]=x.useState(t),o=x.useRef(null),i=f=>{o.current&&!o.current.contains(f.target)&&s(!1)};return x.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const W="sa-calendar-input-styles";(t=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=t,document.head.appendChild(e)}})(T);const L=t=>{if(t==="sm")return 16;if(t==="md")return 16;if(t==="lg")return 20},U=t=>{const{size:e="md",status:s="default",variant:o="outline",clearable:i,onClear:f,...g}=t,p=x.useRef(null),h=()=>{p.current&&g.onClick&&(p.current.focus(),g.onClick(""))},n=s==="disable"||g.disabled,k=!!g.value,w=i&&k&&!n,b=M=>{M.stopPropagation(),f==null||f()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:h,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...g,disabled:n,value:g.value,ref:p})}),w?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:b,children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},q=({date:t,setDate:e,dateRange:s,setDateRange:o,onChange:i,minDate:f,maxDate:g,input:p})=>{var y,r,l;let h=new Date(t.getFullYear(),t.getMonth(),1),n=h.getDay(),k=[];const w=t.getMonth();for(let d=0;d<42;d++){d===0&&n===0?h.setDate(h.getDate()-7):d===0?h.setDate(h.getDate()+(d-n)):h.setDate(h.getDate()+1);let v={currentMonth:h.getMonth()===w,date:new Date(h),month:h.getMonth(),number:h.getDate(),selected:h.toDateString()===((y=s.from)==null?void 0:y.toDateString())||h.toDateString()===(((r=s.to)==null?void 0:r.toDateString())||((l=s.from)==null?void 0:l.toDateString())),year:h.getFullYear(),isDisabled:f&&h<f||g&&h>g};k.push(v)}const b=d=>{e(d)},M=d=>{var c;let v={...s};if(v.from&&v.to)v={from:d,to:null};else{const u=((c=v.from)==null?void 0:c.getTime())||0;d.getTime()>u?v={from:v.from,to:d}:v={from:d,to:v.from}}o(v),i(v)};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:B.map((d,v)=>a.jsx("p",{children:d},v))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:k.map((d,v)=>{var C;const c=d.date.getTime()>s.from.getTime()&&d.date.getTime()<(((C=s.to)==null?void 0:C.getTime())||s.from.getTime()),u=d.isDisabled;return a.jsx("p",{className:`${d.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${d.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:u?"none":void 0,cursor:u?"not-allowed":"pointer",color:u?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...p?{}:{width:"100%"}},onClick:()=>{u||(b(d.date),M(d.date))},children:d.number},v)})})]})},G=({date:t,setDate:e,filter:s,setViews:o,dateRange:i,setDateRange:f,onChange:g,minDate:p,maxDate:h,input:n})=>{const k=i.from.getFullYear(),w=t.getFullYear(),b=y=>{s?(M(y),e(y)):(o("days"),e(y))},M=y=>{var l;let r={...i};if(r.from&&r.to)r={from:y,to:null};else{const d=((l=r.from)==null?void 0:l.getTime())||0;y.getTime()>d?r={from:r.from,to:y}:r={from:y,to:r.from}}f(r),g(r)};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((y,r)=>{var v,c,u;const l=new Date(w,r).getTime()>i.from.getTime()&&new Date(w,r).getTime()<(((v=i.to)==null?void 0:v.getTime())||i.from.getTime()),d=p&&new Date(w,r)<p||h&&new Date(w,r)>h;return a.jsx("p",{className:k===w&&(r===((c=i.from)==null?void 0:c.getMonth())||r===((u=i.to)==null?void 0:u.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:l?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",color:d?"var(--sa-color-gray-400, #b7b9be)":l?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{d||b(new Date(w,r))},children:y.slice(0,3)},r)})})},I=t=>{const e=Math.floor(t/10)*10,s=e+10;return{start:e,end:s}},K=({date:t,filter:e,setViews:s,setDate:o,dateRange:i,setDateRange:f,onChange:g,minDate:p,maxDate:h,input:n})=>{var v;let k=[];const w=t.getFullYear(),{start:b,end:M}=I(w),y=i.from.getFullYear(),r=(v=i.to)==null?void 0:v.getFullYear();for(let c=b;c<M;c++){const u=new Date(c,0),C=(!p||u>=p)&&(!h||u<=h),N=c===y||c===r,D=u>i.from&&u<i.to;k.push({year:c,active:N&&C,highlight:D&&C,disabled:!C})}const l=c=>{e?(d(c),o(c)):(o(c),s("months"))},d=c=>{var C;let u={...i};if(u.from&&u.to)u={from:c,to:null};else{const N=((C=u.from)==null?void 0:C.getTime())||0;c.getTime()>N?u={from:u.from,to:c}:u={from:c,to:u.from}}f(u),g(u)};return a.jsx("div",{className:"sa-calendar-years-preview",children:k.map((c,u)=>a.jsx("p",{className:`${c.active?"sa-calendar-months-active":""} ${c.highlight?"sa-calendar-months-highlight":""} ${c.disabled?"sa-calendar-disabled":""}`,onClick:()=>{c.disabled||l(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",...n?{}:{width:"100%"}},children:c.year},u))})},z=({...t})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...t,children:a.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"})}),O=({...t})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...t,children:a.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"})}),Q=({setViews:t,views:e,filter:s,date:o,setDate:i})=>{const f=()=>{s||t(n=>n==="days"?"months":n==="months"?"years":"days")},g=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},h=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:f,children:h()}),a.jsx(O,{onClick:()=>g()})]})};function E(t){const e=new Date(t),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${P[o]} ${s}`}const H="sa-calendar-styles";(t=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=t,document.head.appendChild(e)}})(T);const X=x.forwardRef(({value:t,onChange:e,filter:s,input:o=!0,disabled:i,minDate:f,maxDate:g,placeholder:p,size:h,status:n,clearable:k},w)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:y}=V(!1),r=x.useRef(null),[l,d]=x.useState("days"),[v,c]=x.useState(new Date),[u,C]=x.useState({from:(t==null?void 0:t.from)||new Date,to:(t==null?void 0:t.to)||new Date});x.useEffect(()=>{t?(c(t.from),C(t)):(c(new Date),C({from:new Date,to:new Date}))},[t]),x.useEffect(()=>{s&&d(s)},[s]),x.useEffect(()=>{s||d("days")},[M]),x.useEffect(()=>{o||y(!0)},[o]);const N=()=>{var m,$;if(!t)return"";if(s){if(l==="days")return`${E(u.from)} ~ ${E(u.to||u.from)||"-"}`;if(l==="months")return`${F[u.from.getMonth()]} ~ ${u.to?F[u.to.getMonth()]:"-"}`;if(l==="years")return`${(m=u.from)==null?void 0:m.getFullYear()} ~ ${(($=u.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(u.from)} ~ ${E(u.to||u.from)||"-"}`},D=()=>{if(r.current&&b.current&&o){const m=b.current.getBoundingClientRect(),$=r.current.getBoundingClientRect();window.innerWidth<m.left+$.width?r.current.style.left=`${m.left-$.width+m.width}px`:r.current.style.left=`${m.left}px`,m.top+$.height>window.innerHeight?r.current.style.top=`${m.y-(m.height+$.height-28)}px`:r.current.style.top=`${m.y+m.height}px`}};return x.useEffect(()=>{r.current&&b.current&&o&&D()},[r,b,M]),x.useEffect(()=>{const m=w==null?void 0:w.current;return m&&m.addEventListener("scroll",D),window.addEventListener("scroll",D),()=>{m&&m.removeEventListener("scroll",D),window.removeEventListener("scroll",D)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(U,{value:N(),inputMode:"none",onClick:()=>{y(!0)},onChange:()=>{},disabled:i,placeholder:p,size:h,status:n,clearable:k,onClear:()=>e(void 0)}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:r,children:[a.jsx(Q,{setViews:d,views:l,filter:s,date:v,setDate:c}),a.jsx("div",{className:"sa-calendar-body",children:l==="days"?a.jsx(q,{date:v,setDate:c,setIsComponentVisible:y,dateRange:u,setDateRange:C,input:o,onChange:e,minDate:f,maxDate:g}):l==="months"?a.jsx(G,{date:v,setDate:c,filter:s,setViews:d,dateRange:u,setDateRange:C,setIsComponentVisible:y,input:o,onChange:e,minDate:f,maxDate:g}):a.jsx(K,{date:v,setDate:c,filter:s,setViews:d,dateRange:u,setDateRange:C,setIsComponentVisible:y,input:o,onChange:e,minDate:f,maxDate:g})})]}):null]})}),A="sa-calendar-input-styles";(t=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=t,document.head.appendChild(e)}})(T);const S=t=>{if(t==="sm")return 16;if(t==="md")return 16;if(t==="lg")return 20},Z=t=>{const{size:e="md",status:s="default",variant:o="outline",clearable:i,onClear:f,...g}=t,p=x.useRef(null),h=()=>{p.current&&g.onClick&&(p.current.focus(),g.onClick(""))},n=s==="disable"||g.disabled,k=!!g.value,w=i&&k&&!n,b=M=>{M.stopPropagation(),f==null||f()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:h,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...g,disabled:n,value:g.value,ref:p})}),w?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:b,children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},_=({date:t,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:i,minDate:f,maxDate:g,input:p,onChange:h})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),k=n.getDay(),w=[];const b=t.toDateString(),M=s.getMonth();for(let r=0;r<42;r++){r===0&&k===0?n.setDate(n.getDate()-7):r===0?n.setDate(n.getDate()+(r-k)):n.setDate(n.getDate()+1);let l={currentMonth:n.getMonth()===M,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===b,year:n.getFullYear(),isDisabled:f&&n<f||g&&n>g};w.push(l)}const y=r=>{(!f||r>=f)&&(!g||r<=g)&&(e(r),h(r),o(r),p&&i(!1))};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:B.map((r,l)=>a.jsx("p",{children:r},l))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:w.map((r,l)=>{const d=r.isDisabled;return a.jsx("p",{className:`${r.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${r.selected?"sa-calendar-days-active":""}`,style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{d||y(r.date)},children:r.number},l)})})]})},R=({date:t,setDate:e,filter:s,setViews:o,onChange:i,previewDate:f,setPreviewDate:g,minDate:p,maxDate:h,input:n})=>{const k=t.getMonth(),w=t.getFullYear(),b=f.getFullYear(),M=y=>{(!p||y>=p)&&(!h||y<=h)&&(s?(i(y),e(y),g(y)):(o("days"),g(y)))};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((y,r)=>{const l=p&&new Date(b,r,1)<p||h&&new Date(b,r+1,0)>h;return a.jsx("p",{className:r===k&&b===w?"sa-calendar-months-active":"",style:{color:l?"#ccc":void 0,pointerEvents:l?"none":void 0,cursor:l?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{l||M(new Date(b,r))},children:y.slice(0,3)},r)})})},j=t=>{const e=Math.floor(t/10)*10,s=e+10;return{start:e,end:s}},ee=({date:t,filter:e,setViews:s,setDate:o,onChange:i,previewDate:f,setPreviewDate:g,minDate:p,maxDate:h,input:n})=>{let k=[];const w=f.getFullYear(),{start:b,end:M}=j(w),y=t.getFullYear();for(let l=b;l<M;l++){let d=p&&new Date(l,0,1)<p||h&&new Date(l,11,31)>h;k.push({year:l,active:l===y,isDisabled:d})}const r=l=>{(!p||l>=p)&&(!h||l<=h)&&(e?(i(l),o(l),g(l)):(s("months"),g(l)))};return a.jsx("div",{className:"sa-calendar-years-preview",children:k.map((l,d)=>a.jsx("p",{className:l.active?"sa-calendar-months-active":"",style:{color:l.isDisabled?"#ccc":void 0,pointerEvents:l.isDisabled?"none":void 0,cursor:l.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{l.isDisabled||r(new Date(l.year,0))},children:l.year},d))})},ne=({setViews:t,views:e,filter:s,previewDate:o,setPreviewDate:i})=>{const f=()=>{s||t(n=>n==="days"?"months":n==="months"?"years":"days")},g=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},h=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${j(o.getFullYear()).start} ~ ${j(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:f,children:h()}),a.jsx(O,{onClick:()=>g()})]})},J="sa-calendar-styles";(t=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=t,document.head.appendChild(e)}})(T);const ae=x.forwardRef(({value:t,onChange:e,filter:s,input:o=!0,disabled:i,minDate:f,maxDate:g,placeholder:p,size:h,status:n,clearable:k},w)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:y}=V(!1),r=x.useRef(null),[l,d]=x.useState("days"),[v,c]=x.useState(new Date),[u,C]=x.useState(new Date);x.useEffect(()=>{t?(c(t),C(t)):(c(new Date),C(new Date))},[t]),x.useEffect(()=>{s&&d(s)},[s]),x.useEffect(()=>{s||d("days")},[M]),x.useEffect(()=>{o||y(!0)},[o]);const N=()=>t?s==="days"?E(v):s==="months"?`${F[v.getMonth()]} ${v.getFullYear()}`:s==="years"?v.getFullYear():E(v):"",D=()=>{if(r.current&&b.current&&o){const m=b.current.getBoundingClientRect(),$=r.current.getBoundingClientRect();window.innerWidth<m.left+$.width?r.current.style.left=`${m.left-$.width+m.width}px`:r.current.style.left=`${m.left}px`,m.top+$.height>window.innerHeight?r.current.style.top=`${m.y-(m.height+$.height-28)}px`:r.current.style.top=`${m.y+m.height}px`}};return x.useEffect(()=>{r.current&&b.current&&o&&D()},[r,b,M]),x.useEffect(()=>{const m=w==null?void 0:w.current;return m&&m.addEventListener("scroll",D),window.addEventListener("scroll",D),()=>{m&&m.removeEventListener("scroll",D),window.removeEventListener("scroll",D)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(Z,{value:N(),onClick:()=>y(!0),onChange:()=>{},placeholder:p,disabled:i,size:h,status:n,inputMode:"none",clearable:k,onClear:()=>e(void 0)}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:r,children:[a.jsx(ne,{setViews:d,views:l,filter:s,previewDate:u,setPreviewDate:C,isComponentVisible:M}),a.jsx("div",{className:"sa-calendar-body",children:l==="days"?a.jsx(_,{date:v,setDate:c,previewDate:u,setPreviewDate:C,setIsComponentVisible:y,input:o,minDate:f,maxDate:g,onChange:e}):l==="months"?a.jsx(R,{date:v,setDate:c,previewDate:u,setPreviewDate:C,filter:s,setViews:d,onChange:e,minDate:f,maxDate:g,input:o}):a.jsx(ee,{date:v,setDate:c,previewDate:u,setPreviewDate:C,filter:s,setViews:d,onChange:e,minDate:f,maxDate:g,input:o})})]}):null]})}),re=x.forwardRef(({value:t,onChange:e,filter:s,input:o=!0,rangedDate:i,disabled:f,minDate:g,maxDate:p,placeholder:h,size:n,status:k,clearable:w},b)=>a.jsx(a.Fragment,{children:i?a.jsx(X,{onChange:e,value:t,input:o,filter:s,disabled:f,ref:b,minDate:g,maxDate:p,placeholder:h,size:n,status:k,clearable:w}):a.jsx(ae,{onChange:e,value:t,input:o,filter:s,disabled:f,ref:b,minDate:g,maxDate:p,placeholder:h,size:n,status:k,clearable:w})}));Y.StarasiaDate=re,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
283
+ `,V=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],N=["January","February","March","April","May","June","July","August","September","October","November","December"],U=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function z(r){const[e,o]=k.useState(r),l=k.useRef(null),i=g=>{l.current&&!l.current.contains(g.target)&&o(!1)};return k.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:o}}const O="sa-calendar-input-styles";(r=>{if(!document.getElementById(O)){const e=document.createElement("style");e.id=O,e.textContent=r,document.head.appendChild(e)}})(I);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},q=r=>{const{size:e="md",status:o="default",variant:l="outline",clearable:i,onClear:g,...u}=r,p=k.useRef(null),h=()=>{p.current&&u.onClick&&(p.current.focus(),u.onClick(""))},n=o==="disable"||u.disabled,C=!!u.value,M=i&&C&&!n,x=w=>{w.stopPropagation(),g==null||g()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${l} sa-calendar-input-container-${o} ${e} `,onClick:h,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...u,disabled:n,value:u.value,ref:p})}),M?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:x,children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},G=({date:r,setDate:e,dateRange:o,setDateRange:l,onChange:i,minDate:g,maxDate:u,input:p})=>{var y,s,t;let h=new Date(r.getFullYear(),r.getMonth(),1),n=h.getDay(),C=[];const M=r.getMonth();for(let d=0;d<42;d++){d===0&&n===0?h.setDate(h.getDate()-7):d===0?h.setDate(h.getDate()+(d-n)):h.setDate(h.getDate()+1);let v={currentMonth:h.getMonth()===M,date:new Date(h),month:h.getMonth(),number:h.getDate(),selected:h.toDateString()===((y=o.from)==null?void 0:y.toDateString())||h.toDateString()===(((s=o.to)==null?void 0:s.toDateString())||((t=o.from)==null?void 0:t.toDateString())),year:h.getFullYear(),isDisabled:g&&h<g||u&&h>u};C.push(v)}const x=d=>{e(d)},w=d=>{var c;let v={...o};if(v.from&&v.to)v={from:d,to:null};else{const f=((c=v.from)==null?void 0:c.getTime())||0;d.getTime()>f?v={from:v.from,to:d}:v={from:d,to:v.from}}l(v),i(v)};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:V.map((d,v)=>a.jsx("p",{children:d},v))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((d,v)=>{var m;const c=d.date.getTime()>o.from.getTime()&&d.date.getTime()<(((m=o.to)==null?void 0:m.getTime())||o.from.getTime()),f=d.isDisabled;return a.jsx("p",{className:`${d.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${d.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...p?{}:{width:"100%"}},onClick:()=>{f||(x(d.date),w(d.date))},children:d.number},v)})})]})},K=({date:r,setDate:e,filter:o,setViews:l,dateRange:i,setDateRange:g,onChange:u,minDate:p,maxDate:h,input:n})=>{const C=i.from.getFullYear(),M=r.getFullYear(),x=y=>{o?(w(y),e(y)):(l("days"),e(y))},w=y=>{var t;let s={...i};if(s.from&&s.to)s={from:y,to:null};else{const d=((t=s.from)==null?void 0:t.getTime())||0;y.getTime()>d?s={from:s.from,to:y}:s={from:y,to:s.from}}g(s),u(s)};return a.jsx("div",{className:"sa-calendar-months-preview",children:N.map((y,s)=>{var v,c,f;const t=new Date(M,s).getTime()>i.from.getTime()&&new Date(M,s).getTime()<(((v=i.to)==null?void 0:v.getTime())||i.from.getTime()),d=p&&new Date(M,s)<p||h&&new Date(M,s)>h;return a.jsx("p",{className:C===M&&(s===((c=i.from)==null?void 0:c.getMonth())||s===((f=i.to)==null?void 0:f.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:t?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",color:d?"var(--sa-color-gray-400, #b7b9be)":t?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{d||x(new Date(M,s))},children:y.slice(0,3)},s)})})},j=r=>{const e=Math.floor(r/10)*10,o=e+10;return{start:e,end:o}},Q=({date:r,filter:e,setViews:o,setDate:l,dateRange:i,setDateRange:g,onChange:u,minDate:p,maxDate:h,input:n})=>{var v;let C=[];const M=r.getFullYear(),{start:x,end:w}=j(M),y=i.from.getFullYear(),s=(v=i.to)==null?void 0:v.getFullYear();for(let c=x;c<w;c++){const f=new Date(c,0),m=(!p||f>=p)&&(!h||f<=h),D=c===y||c===s,T=f>i.from&&f<i.to;C.push({year:c,active:D&&m,highlight:T&&m,disabled:!m})}const t=c=>{e?(d(c),l(c)):(l(c),o("months"))},d=c=>{var m;let f={...i};if(f.from&&f.to)f={from:c,to:null};else{const D=((m=f.from)==null?void 0:m.getTime())||0;c.getTime()>D?f={from:f.from,to:c}:f={from:c,to:f.from}}g(f),u(f)};return a.jsx("div",{className:"sa-calendar-years-preview",children:C.map((c,f)=>a.jsx("p",{className:`${c.active?"sa-calendar-months-active":""} ${c.highlight?"sa-calendar-months-highlight":""} ${c.disabled?"sa-calendar-disabled":""}`,onClick:()=>{c.disabled||t(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",...n?{}:{width:"100%"}},children:c.year},f))})},W=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.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"})}),H=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.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"})}),X=({setViews:r,views:e,filter:o,date:l,setDate:i})=>{const g=()=>{o||r(n=>n==="days"?"months":n==="months"?"years":"days")},u=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},h=()=>{if(e==="days")return`${N[l.getMonth()]} ${l.getFullYear()}`;if(e==="months")return`${l.getFullYear()}`;if(e==="years")return`${j(l.getFullYear()).start} ~ ${j(l.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(W,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:h()}),a.jsx(H,{onClick:()=>u()})]})};function E(r){const e=new Date(r),o=e.getFullYear(),l=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${U[l]} ${o}`}const A="sa-calendar-styles";(r=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=r,document.head.appendChild(e)}})(I);const Z=k.forwardRef(({value:r,onChange:e,filter:o,input:l=!0,disabled:i,minDate:g,maxDate:u,placeholder:p,size:h,status:n,clearable:C,fullWidth:M=!1},x)=>{const{ref:w,isComponentVisible:y,setIsComponentVisible:s}=z(!1),t=k.useRef(null),[d,v]=k.useState("days"),[c,f]=k.useState(new Date),[m,D]=k.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});k.useEffect(()=>{r?(f(r.from),D(r)):(f(new Date),D({from:new Date,to:new Date}))},[r]),k.useEffect(()=>{o&&v(o)},[o]),k.useEffect(()=>{o||v("days")},[y]),k.useEffect(()=>{l||s(!0)},[l]);const T=()=>{var b,$;if(!r)return"";if(o){if(d==="days")return`${E(m.from)} ~ ${E(m.to||m.from)||"-"}`;if(d==="months")return`${N[m.from.getMonth()]} ~ ${m.to?N[m.to.getMonth()]:"-"}`;if(d==="years")return`${(b=m.from)==null?void 0:b.getFullYear()} ~ ${(($=m.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(m.from)} ~ ${E(m.to||m.from)||"-"}`},Y=()=>{if(t.current&&w.current&&l){const b=w.current.getBoundingClientRect(),$=t.current.getBoundingClientRect();window.innerWidth<b.left+$.width?t.current.style.left=`${b.left-$.width+b.width}px`:t.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?t.current.style.top=`${b.y-(b.height+$.height-28)}px`:t.current.style.top=`${b.y+b.height}px`}};return k.useEffect(()=>{t.current&&w.current&&l&&Y()},[t,w,y]),k.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",Y),window.addEventListener("scroll",Y),()=>{b&&b.removeEventListener("scroll",Y),window.removeEventListener("scroll",Y)}},[]),a.jsxs("div",{className:`sa-calendar-wrapper${M?" sa-calendar-wrapper-fullwidth":""}`,style:{height:l?"auto":"100%"},ref:l?w:null,children:[l?a.jsx(q,{value:T(),inputMode:"none",onClick:()=>{s(!0)},onChange:()=>{},disabled:i,placeholder:p,size:h,status:n,clearable:C,onClear:()=>e(void 0)}):null,y?a.jsxs("div",{className:`sa-calendar ${l?"":"sa-calendar-no-input"}`,ref:t,children:[a.jsx(X,{setViews:v,views:d,filter:o,date:c,setDate:f}),a.jsx("div",{className:"sa-calendar-body",children:d==="days"?a.jsx(G,{date:c,setDate:f,setIsComponentVisible:s,dateRange:m,setDateRange:D,input:l,onChange:e,minDate:g,maxDate:u}):d==="months"?a.jsx(K,{date:c,setDate:f,filter:o,setViews:v,dateRange:m,setDateRange:D,setIsComponentVisible:s,input:l,onChange:e,minDate:g,maxDate:u}):a.jsx(Q,{date:c,setDate:f,filter:o,setViews:v,dateRange:m,setDateRange:D,setIsComponentVisible:s,input:l,onChange:e,minDate:g,maxDate:u})})]}):null]})}),J="sa-calendar-input-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(I);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},_=r=>{const{size:e="md",status:o="default",variant:l="outline",clearable:i,onClear:g,...u}=r,p=k.useRef(null),h=()=>{p.current&&u.onClick&&(p.current.focus(),u.onClick(""))},n=o==="disable"||u.disabled,C=!!u.value,M=i&&C&&!n,x=w=>{w.stopPropagation(),g==null||g()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${l} sa-calendar-input-container-${o} ${e} `,onClick:h,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...u,disabled:n,value:u.value,ref:p})}),M?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:x,children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},R=({date:r,setDate:e,previewDate:o,setPreviewDate:l,setIsComponentVisible:i,minDate:g,maxDate:u,input:p,onChange:h})=>{let n=new Date(o.getFullYear(),o.getMonth(),1),C=n.getDay(),M=[];const x=r.toDateString(),w=o.getMonth();for(let s=0;s<42;s++){s===0&&C===0?n.setDate(n.getDate()-7):s===0?n.setDate(n.getDate()+(s-C)):n.setDate(n.getDate()+1);let t={currentMonth:n.getMonth()===w,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===x,year:n.getFullYear(),isDisabled:g&&n<g||u&&n>u};M.push(t)}const y=s=>{(!g||s>=g)&&(!u||s<=u)&&(e(s),h(s),l(s),p&&i(!1))};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:V.map((s,t)=>a.jsx("p",{children:s},t))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:M.map((s,t)=>{const d=s.isDisabled;return a.jsx("p",{className:`${s.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${s.selected?"sa-calendar-days-active":""}`,style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{d||y(s.date)},children:s.number},t)})})]})},ee=({date:r,setDate:e,filter:o,setViews:l,onChange:i,previewDate:g,setPreviewDate:u,minDate:p,maxDate:h,input:n})=>{const C=r.getMonth(),M=r.getFullYear(),x=g.getFullYear(),w=y=>{(!p||y>=p)&&(!h||y<=h)&&(o?(i(y),e(y),u(y)):(l("days"),u(y)))};return a.jsx("div",{className:"sa-calendar-months-preview",children:N.map((y,s)=>{const t=p&&new Date(x,s,1)<p||h&&new Date(x,s+1,0)>h;return a.jsx("p",{className:s===C&&x===M?"sa-calendar-months-active":"",style:{color:t?"#ccc":void 0,pointerEvents:t?"none":void 0,cursor:t?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{t||w(new Date(x,s))},children:y.slice(0,3)},s)})})},B=r=>{const e=Math.floor(r/10)*10,o=e+10;return{start:e,end:o}},ne=({date:r,filter:e,setViews:o,setDate:l,onChange:i,previewDate:g,setPreviewDate:u,minDate:p,maxDate:h,input:n})=>{let C=[];const M=g.getFullYear(),{start:x,end:w}=B(M),y=r.getFullYear();for(let t=x;t<w;t++){let d=p&&new Date(t,0,1)<p||h&&new Date(t,11,31)>h;C.push({year:t,active:t===y,isDisabled:d})}const s=t=>{(!p||t>=p)&&(!h||t<=h)&&(e?(i(t),l(t),u(t)):(o("months"),u(t)))};return a.jsx("div",{className:"sa-calendar-years-preview",children:C.map((t,d)=>a.jsx("p",{className:t.active?"sa-calendar-months-active":"",style:{color:t.isDisabled?"#ccc":void 0,pointerEvents:t.isDisabled?"none":void 0,cursor:t.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{t.isDisabled||s(new Date(t.year,0))},children:t.year},d))})},ae=({setViews:r,views:e,filter:o,previewDate:l,setPreviewDate:i})=>{const g=()=>{o||r(n=>n==="days"?"months":n==="months"?"years":"days")},u=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},h=()=>{if(e==="days")return`${N[l.getMonth()]} ${l.getFullYear()}`;if(e==="months")return`${l.getFullYear()}`;if(e==="years")return`${B(l.getFullYear()).start} ~ ${B(l.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(W,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:h()}),a.jsx(H,{onClick:()=>u()})]})},P="sa-calendar-styles";(r=>{if(!document.getElementById(P)){const e=document.createElement("style");e.id=P,e.textContent=r,document.head.appendChild(e)}})(I);const re=k.forwardRef(({value:r,onChange:e,filter:o,input:l=!0,disabled:i,minDate:g,maxDate:u,placeholder:p,size:h,status:n,clearable:C,fullWidth:M=!1},x)=>{const{ref:w,isComponentVisible:y,setIsComponentVisible:s}=z(!1),t=k.useRef(null),[d,v]=k.useState("days"),[c,f]=k.useState(new Date),[m,D]=k.useState(new Date);k.useEffect(()=>{r?(f(r),D(r)):(f(new Date),D(new Date))},[r]),k.useEffect(()=>{o&&v(o)},[o]),k.useEffect(()=>{o||v("days")},[y]),k.useEffect(()=>{l||s(!0)},[l]);const T=()=>r?o==="days"?E(c):o==="months"?`${N[c.getMonth()]} ${c.getFullYear()}`:o==="years"?c.getFullYear():E(c):"",Y=()=>{if(t.current&&w.current&&l){const b=w.current.getBoundingClientRect(),$=t.current.getBoundingClientRect();window.innerWidth<b.left+$.width?t.current.style.left=`${b.left-$.width+b.width}px`:t.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?t.current.style.top=`${b.y-(b.height+$.height-28)}px`:t.current.style.top=`${b.y+b.height}px`}};return k.useEffect(()=>{t.current&&w.current&&l&&Y()},[t,w,y]),k.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",Y),window.addEventListener("scroll",Y),()=>{b&&b.removeEventListener("scroll",Y),window.removeEventListener("scroll",Y)}},[]),a.jsxs("div",{className:`sa-calendar-wrapper${M?" sa-calendar-wrapper-fullwidth":""}`,style:{height:l?"auto":"100%"},ref:l?w:null,children:[l?a.jsx(_,{value:T(),onClick:()=>s(!0),onChange:()=>{},placeholder:p,disabled:i,size:h,status:n,inputMode:"none",clearable:C,onClear:()=>e(void 0)}):null,y?a.jsxs("div",{className:`sa-calendar ${l?"":"sa-calendar-no-input"}`,ref:t,children:[a.jsx(ae,{setViews:v,views:d,filter:o,previewDate:m,setPreviewDate:D,isComponentVisible:y}),a.jsx("div",{className:"sa-calendar-body",children:d==="days"?a.jsx(R,{date:c,setDate:f,previewDate:m,setPreviewDate:D,setIsComponentVisible:s,input:l,minDate:g,maxDate:u,onChange:e}):d==="months"?a.jsx(ee,{date:c,setDate:f,previewDate:m,setPreviewDate:D,filter:o,setViews:v,onChange:e,minDate:g,maxDate:u,input:l}):a.jsx(ne,{date:c,setDate:f,previewDate:m,setPreviewDate:D,filter:o,setViews:v,onChange:e,minDate:g,maxDate:u,input:l})})]}):null]})}),te=k.forwardRef(({value:r,onChange:e,filter:o,input:l=!0,rangedDate:i,disabled:g,minDate:u,maxDate:p,placeholder:h,size:n,status:C,clearable:M,fullWidth:x},w)=>a.jsx(a.Fragment,{children:i?a.jsx(Z,{onChange:e,value:r,input:l,filter:o,disabled:g,ref:w,minDate:u,maxDate:p,placeholder:h,size:n,status:C,clearable:M,fullWidth:x}):a.jsx(re,{onChange:e,value:r,input:l,filter:o,disabled:g,ref:w,minDate:u,maxDate:p,placeholder:h,size:n,status:C,clearable:M,fullWidth:x})}));F.StarasiaDate=te,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
@@ -11,6 +11,7 @@ export interface IDateProps {
11
11
  size?: "sm" | "md" | "lg";
12
12
  status?: "error" | "warning";
13
13
  clearable?: boolean;
14
+ fullWidth?: boolean;
14
15
  }
15
16
  export interface IDateRange {
16
17
  from: Date | null;
@@ -0,0 +1,3 @@
1
+ export declare const DAYS: string[];
2
+ export declare const MONTHS: string[];
3
+ export declare const MonthThreeLetters: string[];
@@ -0,0 +1 @@
1
+ export declare function formatDateByDDMMYYYY(inputDate: Date): string;
@@ -0,0 +1,5 @@
1
+ export declare function useComponentVisible(initialIsVisible: boolean): {
2
+ ref: import("react").MutableRefObject<any>;
3
+ isComponentVisible: boolean;
4
+ setIsComponentVisible: import("react").Dispatch<import("react").SetStateAction<boolean>>;
5
+ };
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "3.1.1",
3
+ "version": "4.0.0",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",
7
7
  "module": "dist/date.es.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "files": [
10
- "dist/*.js",
11
- "dist/*.d.ts",
12
- "dist/*.map",
13
- "dist/*.css"
10
+ "dist"
14
11
  ],
15
12
  "keywords": [],
16
13
  "license": "ISC",