@starasia/date 5.4.0 → 5.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/date.es.js CHANGED
@@ -131,7 +131,7 @@ const X = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
131
131
  gap: var(--sa-spacing-3, 12px);
132
132
  flex-direction: column;
133
133
  position: fixed;
134
- z-index: 999;
134
+ z-index: var(--sa-z-popover, 1200);
135
135
  }
136
136
 
137
137
  .sa-calendar.sa-calendar-no-input {
@@ -626,7 +626,7 @@ function un(n) {
626
626
  }), []), { ref: t, isComponentVisible: e, setIsComponentVisible: r };
627
627
  }
628
628
  const fn = "sa-calendar-input-styles", Bn = (n) => {
629
- if (!document.getElementById(fn)) {
629
+ if (!(typeof document > "u") && !document.getElementById(fn)) {
630
630
  const e = document.createElement("style");
631
631
  e.id = fn, e.textContent = n, document.head.appendChild(e);
632
632
  }
@@ -1071,7 +1071,7 @@ const pn = ({
1071
1071
  M
1072
1072
  ] });
1073
1073
  }, gn = "sa-calendar-styles", Hn = (n) => {
1074
- if (!document.getElementById(gn)) {
1074
+ if (!(typeof document > "u") && !document.getElementById(gn)) {
1075
1075
  const e = document.createElement("style");
1076
1076
  e.id = gn, e.textContent = n, document.head.appendChild(e);
1077
1077
  }
@@ -1252,7 +1252,7 @@ const Wn = tn(
1252
1252
  );
1253
1253
  }
1254
1254
  ), mn = "sa-calendar-input-styles", On = (n) => {
1255
- if (!document.getElementById(mn)) {
1255
+ if (!(typeof document > "u") && !document.getElementById(mn)) {
1256
1256
  const e = document.createElement("style");
1257
1257
  e.id = mn, e.textContent = n, document.head.appendChild(e);
1258
1258
  }
@@ -1563,7 +1563,7 @@ const Z = (n) => {
1563
1563
  ] })
1564
1564
  ] });
1565
1565
  }, bn = "sa-calendar-styles", Kn = (n) => {
1566
- if (!document.getElementById(bn)) {
1566
+ if (!(typeof document > "u") && !document.getElementById(bn)) {
1567
1567
  const e = document.createElement("style");
1568
1568
  e.id = bn, e.textContent = n, document.head.appendChild(e);
1569
1569
  }
package/dist/date.umd.js CHANGED
@@ -129,7 +129,7 @@
129
129
  gap: var(--sa-spacing-3, 12px);
130
130
  flex-direction: column;
131
131
  position: fixed;
132
- z-index: 999;
132
+ z-index: var(--sa-z-popover, 1200);
133
133
  }
134
134
 
135
135
  .sa-calendar.sa-calendar-no-input {
@@ -588,7 +588,7 @@
588
588
  width: 32px;
589
589
  height: 32px;
590
590
  }
591
- `,ln=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],J=["January","February","March","April","May","June","July","August","September","October","November","December"],yn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function nn(e){const[a,r]=b.useState(e),s=b.useRef(null),o=i=>{s.current&&!s.current.contains(i.target)&&r(!1)};return b.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:r}}const dn="sa-calendar-input-styles";(e=>{if(!document.getElementById(dn)){const a=document.createElement("style");a.id=dn,a.textContent=e,document.head.appendChild(a)}})(Z);const q=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},wn=e=>{const{size:a="sm",status:r="default",variant:s="outline",clearable:o,onClear:i,...l}=e,p=b.useRef(null),h=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=o&&c&&!t,C=D=>{D.stopPropagation(),i==null||i()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${r} ${a} `,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:q(a),height:q(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",...l,disabled:t,value:l.value,ref:p})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:q(a),height:q(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:q(a),height:q(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"})})})]})},xn=({date:e,setDate:a,dateRange:r,setDateRange:s,onChange:o,minDate:i,maxDate:l,input:p})=>{var F,g,M;const[h,t]=b.useState(null);let c=new Date(e.getFullYear(),e.getMonth(),1),w=c.getDay(),C=[];const D=e.getMonth(),L=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let f=0;f<42;f++){f===0&&w===0?c.setDate(c.getDate()-7):f===0?c.setDate(c.getDate()+(f-w)):c.setDate(c.getDate()+1);let x={currentMonth:c.getMonth()===D,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((F=r.from)==null?void 0:F.toDateString())||c.toDateString()===(((g=r.to)==null?void 0:g.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===L,year:c.getFullYear(),isDisabled:i&&c<i||l&&c>l};C.push(x)}const d=f=>{a(f)},$=f=>{let x={...r};if(x.from&&x.to)x={from:f,to:null};else if(!x.from)x={from:f,to:null};else{const B=x.from.getTime();f.getTime()>B?x={from:x.from,to:f}:x={from:f,to:x.from}}s(x),o(x)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>t(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:ln.map((f,x)=>n.jsx("p",{children:f},x))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((f,x)=>{const B=r.from&&r.to&&f.date.getTime()>r.from.getTime()&&f.date.getTime()<r.to.getTime(),P=(()=>{if(!v||!r.from)return!1;const z=f.date.getTime(),k=r.from.getTime(),I=v.getTime();return I>k?z>k&&z<I:z<k&&z>I})(),Y=y&&h&&f.date.toDateString()===h.toDateString(),S=f.isDisabled,T=()=>B||P?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",m=()=>S?"var(--sa-color-gray-400, #b7b9be)":B||P?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${f.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${f.selected||Y?"sa-calendar-days-active":""} ${f.isToday&&!f.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:T(),pointerEvents:S?"none":void 0,cursor:S?"not-allowed":"pointer",color:m(),opacity:Y&&!f.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{S||(d(f.date),$(f.date))},onMouseEnter:()=>{S||t(f.date)},children:f.number},x)})})]})},kn=({date:e,setDate:a,filter:r,setViews:s,dateRange:o,setDateRange:i,onChange:l,minDate:p,maxDate:h,input:t})=>{var L;const c=(L=o.from)==null?void 0:L.getFullYear(),w=e.getFullYear(),C=y=>{r?(D(y),a(y)):(s("days"),a(y))},D=y=>{let v={...o};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const d=v.from.getTime();y.getTime()>d?v={from:v.from,to:y}:v={from:y,to:v.from}}i(v),l(v)};return n.jsx("div",{className:"sa-calendar-months-preview",children:J.map((y,v)=>{var F,g,M;const d=o.from!=null&&new Date(w,v).getTime()>o.from.getTime()&&new Date(w,v).getTime()<(((F=o.to)==null?void 0:F.getTime())||o.from.getTime()),$=p&&new Date(w,v)<p||h&&new Date(w,v)>h;return n.jsx("p",{className:c===w&&(v===((g=o.from)==null?void 0:g.getMonth())||v===((M=o.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",color:$?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...t?{}:{width:"100%"}},onClick:()=>{$||C(new Date(w,v))},children:y.slice(0,3)},v)})})},en=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},Mn=({date:e,filter:a,setViews:r,setDate:s,dateRange:o,setDateRange:i,onChange:l,minDate:p,maxDate:h,input:t})=>{var $,F;let c=[];const w=e.getFullYear(),{start:C,end:D}=en(w),L=($=o.from)==null?void 0:$.getFullYear(),y=(F=o.to)==null?void 0:F.getFullYear();for(let g=C;g<D;g++){const M=new Date(g,0),f=(!p||M>=p)&&(!h||M<=h),x=L!=null&&g===L||y!=null&&g===y,B=o.from!=null&&o.to!=null&&M>o.from&&M<o.to;c.push({year:g,active:x&&f,highlight:B&&f,disabled:!f})}const v=g=>{a?(d(g),s(g)):(s(g),r("months"))},d=g=>{let M={...o};if(M.from&&M.to)M={from:g,to:null};else if(!M.from)M={from:g,to:null};else{const f=M.from.getTime();g.getTime()>f?M={from:M.from,to:g}:M={from:g,to:M.from}}i(M),l(M)};return n.jsx("div",{className:"sa-calendar-years-preview",children:c.map((g,M)=>n.jsx("p",{className:`${g.active?"sa-calendar-months-active":""} ${g.highlight?"sa-calendar-months-highlight":""} ${g.disabled?"sa-calendar-disabled":""}`,onClick:()=>{g.disabled||v(new Date(g.year,0))},style:{backgroundColor:g.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:g.highlight?"var(--sa-color-gray-500, #8c8f97)":g.active?"":g.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:g.disabled?"not-allowed":"pointer",pointerEvents:g.disbled?"none":"all",...t?{}:{width:"100%"}},children:g.year},M))})},cn=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...e,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"})}),pn=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...e,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"})}),Nn=({setViews:e,views:a,filter:r,date:s,setDate:o})=>{const i=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()+1,t.getMonth()));return}o(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()-1,t.getMonth()));return}o(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},h=()=>{if(a==="days")return`${J[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${en(s.getFullYear()).start} ~ ${en(s.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:i,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(cn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(pn,{})})]})]})};function G(e){const a=new Date(e),r=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${yn[s]} ${r}`}const an=({label:e,labelPosition:a="outside-top",required:r,optional:s,description:o,helperText:i,errorText:l,fullWidth:p,size:h="sm",children:t})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),w=e?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:e}),s&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,C=n.jsxs(n.Fragment,{children:[i&&!l&&n.jsx("p",{className:"sa-date-field-helper",children:i}),l&&n.jsx("p",{className:"sa-date-field-error-msg",children:l})]});return e?a==="outside-left"?n.jsxs("div",{className:`${c} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[w,o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[t,C]})]}):n.jsxs("div",{className:c,children:[w,o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o}),t,C]}):n.jsxs("div",{className:c,children:[o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o}),t,C]})},un="sa-calendar-styles";(e=>{if(!document.getElementById(un)){const a=document.createElement("style");a.id=un,a.textContent=e,document.head.appendChild(a)}})(Z);const Cn=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,disabled:o,minDate:i,maxDate:l,placeholder:p,size:h="sm",variant:t,status:c,clearable:w,fullWidth:C=!0,withPadding:D=!0,label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g},M)=>{const f=g?"error":c,{ref:x,isComponentVisible:B,setIsComponentVisible:P}=nn(!1),Y=b.useRef(null),[S,T]=b.useState("days"),[m,z]=b.useState(new Date),[k,I]=b.useState({from:(e==null?void 0:e.from)??null,to:(e==null?void 0:e.to)??null});b.useEffect(()=>{if(e){const N=e;N.from&&z(N.from),I(N)}else z(new Date),I({from:null,to:null})},[e]),b.useEffect(()=>{r&&T(r)},[r]),b.useEffect(()=>{r||T("days")},[B]),b.useEffect(()=>{s||P(!0)},[s]);const H=()=>{var N,j;if(!e)return"";if(r){if(S==="days")return`${G(k.from)} ~ ${G(k.to||k.from)||"-"}`;if(S==="months")return`${J[k.from.getMonth()]} ~ ${k.to?J[k.to.getMonth()]:"-"}`;if(S==="years")return`${(N=k.from)==null?void 0:N.getFullYear()} ~ ${((j=k.to)==null?void 0:j.getFullYear())||"-"}`}else return`${G(k.from)} ~ ${G(k.to||k.from)||"-"}`},V=()=>{if(Y.current&&x.current&&s){const N=x.current.getBoundingClientRect(),j=Y.current.getBoundingClientRect();window.innerWidth<N.left+j.width?Y.current.style.left=`${N.left-j.width+N.width}px`:Y.current.style.left=`${N.left}px`,N.top+j.height>window.innerHeight?Y.current.style.top=`${N.y-(N.height+j.height-28)}px`:Y.current.style.top=`${N.y+N.height}px`}};b.useEffect(()=>{Y.current&&x.current&&s&&V()},[Y,x,B]),b.useEffect(()=>(window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}),[]);const K=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?x:null,children:[s?n.jsx(wn,{value:H(),inputMode:"none",onClick:()=>{P(!0)},onChange:()=>{},disabled:o,placeholder:p,size:h,variant:t,status:f,clearable:w,onClear:()=>a(void 0)}):null,B?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${s?"":"sa-calendar-no-input"} ${D?"":"sa-calendar-no-padding"}`,style:o?{pointerEvents:"none"}:void 0,ref:Y,children:[n.jsx(Nn,{setViews:T,views:S,filter:r,date:m,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:S==="days"?n.jsx(xn,{date:m,setDate:z,setIsComponentVisible:P,dateRange:k,setDateRange:I,input:s,onChange:a,minDate:i,maxDate:l}):S==="months"?n.jsx(kn,{date:m,setDate:z,filter:r,setViews:T,dateRange:k,setDateRange:I,setIsComponentVisible:P,input:s,onChange:a,minDate:i,maxDate:l}):n.jsx(Mn,{date:m,setDate:z,filter:r,setViews:T,dateRange:k,setDateRange:I,setIsComponentVisible:P,input:s,onChange:a,minDate:i,maxDate:l})})]}):null]});return n.jsx(an,{label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g,fullWidth:C,size:h,children:K})}),hn="sa-calendar-input-styles";(e=>{if(!document.getElementById(hn)){const a=document.createElement("style");a.id=hn,a.textContent=e,document.head.appendChild(a)}})(Z);const U=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},$n=e=>{const{size:a="sm",status:r="default",variant:s="outline",clearable:o,onClear:i,...l}=e,p=b.useRef(null),h=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=o&&c&&!t,C=D=>{D.stopPropagation(),i==null||i()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${r} ${a} `,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:U(a),height:U(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",...l,disabled:t,value:l.value,ref:p})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:U(a),height:U(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:U(a),height:U(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"})})})]})},zn=({date:e,setDate:a,previewDate:r,setPreviewDate:s,setIsComponentVisible:o,minDate:i,maxDate:l,input:p,onChange:h,hasValue:t})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),w=c.getDay(),C=[];const D=e.toDateString(),L=new Date().toDateString(),y=r.getMonth();for(let d=0;d<42;d++){d===0&&w===0?c.setDate(c.getDate()-7):d===0?c.setDate(c.getDate()+(d-w)):c.setDate(c.getDate()+1);let $={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:t&&c.toDateString()===D,isToday:c.toDateString()===L,year:c.getFullYear(),isDisabled:i&&c<i||l&&c>l};C.push($)}const v=d=>{(!i||d>=i)&&(!l||d<=l)&&(a(d),h(d),s(d),p&&o(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:ln.map((d,$)=>n.jsx("p",{children:d},$))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((d,$)=>{const F=d.isDisabled;return n.jsx("p",{className:`${d.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${d.selected?"sa-calendar-days-active":""} ${d.isToday&&!d.selected?"sa-calendar-days-today":""}`,style:{color:F?"#ccc":void 0,pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{F||v(d.date)},children:d.number},$)})})]})},Dn=({date:e,setDate:a,filter:r,setViews:s,onChange:o,previewDate:i,setPreviewDate:l,minDate:p,maxDate:h,input:t,hasValue:c})=>{const w=e.getMonth(),C=e.getFullYear(),D=i.getFullYear(),L=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(o(y),a(y),l(y)):(s("days"),l(y)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:J.map((y,v)=>{const d=p&&new Date(D,v,1)<p||h&&new Date(D,v+1,0)>h;return n.jsx("p",{className:c&&v===w&&D===C?"sa-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{d||L(new Date(D,v))},children:y.slice(0,3)},v)})})},rn=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},En=({date:e,filter:a,setViews:r,setDate:s,onChange:o,previewDate:i,setPreviewDate:l,minDate:p,maxDate:h,input:t,hasValue:c})=>{let w=[];const C=i.getFullYear(),{start:D,end:L}=rn(C),y=e.getFullYear();for(let d=D;d<L;d++){let $=p&&new Date(d,0,1)<p||h&&new Date(d,11,31)>h;w.push({year:d,active:!!c&&d===y,isDisabled:$})}const v=d=>{(!p||d>=p)&&(!h||d<=h)&&(a?(o(d),s(d),l(d)):(r("months"),l(d)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:w.map((d,$)=>n.jsx("p",{className:d.active?"sa-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{d.isDisabled||v(new Date(d.year,0))},children:d.year},$))})},Yn=({setViews:e,views:a,filter:r,previewDate:s,setPreviewDate:o})=>{const i=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()+1,t.getMonth()));return}o(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()-1,t.getMonth()));return}o(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},h=()=>{if(a==="days")return`${J[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${rn(s.getFullYear()).start} ~ ${rn(s.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:i,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(cn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(pn,{})})]})]})},fn="sa-calendar-styles";(e=>{if(!document.getElementById(fn)){const a=document.createElement("style");a.id=fn,a.textContent=e,document.head.appendChild(a)}})(Z);const Sn=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,disabled:o,minDate:i,maxDate:l,placeholder:p,size:h="sm",variant:t,status:c,clearable:w,fullWidth:C=!0,withPadding:D=!0,label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g},M)=>{const f=g?"error":c,{ref:x,isComponentVisible:B,setIsComponentVisible:P}=nn(!1),Y=b.useRef(null),[S,T]=b.useState("days"),[m,z]=b.useState(new Date),[k,I]=b.useState(new Date);b.useEffect(()=>{e?(z(e),I(e)):(z(new Date),I(new Date))},[e]),b.useEffect(()=>{r&&T(r)},[r]),b.useEffect(()=>{r||T("days")},[B]),b.useEffect(()=>{s||P(!0)},[s]);const H=()=>e?r==="days"?G(m):r==="months"?`${J[m.getMonth()]} ${m.getFullYear()}`:r==="years"?m.getFullYear():G(m):"",V=()=>{if(Y.current&&x.current&&s){const N=x.current.getBoundingClientRect(),j=Y.current.getBoundingClientRect();window.innerWidth<N.left+j.width?Y.current.style.left=`${N.left-j.width+N.width}px`:Y.current.style.left=`${N.left}px`,N.top+j.height>window.innerHeight?Y.current.style.top=`${N.y-(N.height+j.height-28)}px`:Y.current.style.top=`${N.y+N.height}px`}};b.useEffect(()=>{Y.current&&x.current&&s&&V()},[Y,x,B]),b.useEffect(()=>(window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}),[]);const K=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?x:null,children:[s?n.jsx($n,{value:H(),onClick:()=>P(!0),onChange:()=>{},placeholder:p,disabled:o,size:h,variant:t,status:f,inputMode:"none",clearable:w,onClear:()=>a(void 0)}):null,B?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${s?"":"sa-calendar-no-input"} ${D?"":"sa-calendar-no-padding"}`,style:o?{pointerEvents:"none"}:void 0,ref:Y,children:[n.jsx(Yn,{setViews:T,views:S,filter:r,previewDate:k,setPreviewDate:I,isComponentVisible:B}),n.jsx("div",{className:"sa-calendar-body",children:S==="days"?n.jsx(zn,{date:m,setDate:z,previewDate:k,setPreviewDate:I,setIsComponentVisible:P,input:s,minDate:i,maxDate:l,onChange:a,hasValue:e!=null}):S==="months"?n.jsx(Dn,{date:m,setDate:z,previewDate:k,setPreviewDate:I,filter:r,setViews:T,onChange:a,minDate:i,maxDate:l,input:s,hasValue:e!=null}):n.jsx(En,{date:m,setDate:z,previewDate:k,setPreviewDate:I,filter:r,setViews:T,onChange:a,minDate:i,maxDate:l,input:s,hasValue:e!=null})})]}):null]});return n.jsx(an,{label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g,fullWidth:C,size:h,children:K})}),Ln=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,rangedDate:o,disabled:i,minDate:l,maxDate:p,placeholder:h,size:t,variant:c,status:w,clearable:C,fullWidth:D,withPadding:L,label:y,labelPosition:v,required:d,optional:$,description:F,helperText:g,errorText:M},f)=>{const x={onChange:a,value:e,input:s,filter:r,disabled:i,minDate:l,maxDate:p,placeholder:h,size:t,variant:c,status:w,clearable:C,fullWidth:D,withPadding:L,label:y,labelPosition:v,required:d,optional:$,description:F,helperText:g,errorText:M};return n.jsx(n.Fragment,{children:o?n.jsx(Cn,{...x,ref:f}):n.jsx(Sn,{...x,ref:f})})}),Fn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
591
+ `,ln=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],J=["January","February","March","April","May","June","July","August","September","October","November","December"],yn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function nn(e){const[a,r]=b.useState(e),s=b.useRef(null),o=i=>{s.current&&!s.current.contains(i.target)&&r(!1)};return b.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:r}}const dn="sa-calendar-input-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(dn)){const a=document.createElement("style");a.id=dn,a.textContent=e,document.head.appendChild(a)}})(Z);const q=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},wn=e=>{const{size:a="sm",status:r="default",variant:s="outline",clearable:o,onClear:i,...l}=e,p=b.useRef(null),h=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=o&&c&&!t,C=D=>{D.stopPropagation(),i==null||i()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${r} ${a} `,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:q(a),height:q(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",...l,disabled:t,value:l.value,ref:p})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:q(a),height:q(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:q(a),height:q(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"})})})]})},xn=({date:e,setDate:a,dateRange:r,setDateRange:s,onChange:o,minDate:i,maxDate:l,input:p})=>{var F,g,M;const[h,t]=b.useState(null);let c=new Date(e.getFullYear(),e.getMonth(),1),w=c.getDay(),C=[];const D=e.getMonth(),L=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let f=0;f<42;f++){f===0&&w===0?c.setDate(c.getDate()-7):f===0?c.setDate(c.getDate()+(f-w)):c.setDate(c.getDate()+1);let x={currentMonth:c.getMonth()===D,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((F=r.from)==null?void 0:F.toDateString())||c.toDateString()===(((g=r.to)==null?void 0:g.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===L,year:c.getFullYear(),isDisabled:i&&c<i||l&&c>l};C.push(x)}const d=f=>{a(f)},$=f=>{let x={...r};if(x.from&&x.to)x={from:f,to:null};else if(!x.from)x={from:f,to:null};else{const B=x.from.getTime();f.getTime()>B?x={from:x.from,to:f}:x={from:f,to:x.from}}s(x),o(x)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>t(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:ln.map((f,x)=>n.jsx("p",{children:f},x))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((f,x)=>{const B=r.from&&r.to&&f.date.getTime()>r.from.getTime()&&f.date.getTime()<r.to.getTime(),P=(()=>{if(!v||!r.from)return!1;const z=f.date.getTime(),k=r.from.getTime(),I=v.getTime();return I>k?z>k&&z<I:z<k&&z>I})(),Y=y&&h&&f.date.toDateString()===h.toDateString(),S=f.isDisabled,T=()=>B||P?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",m=()=>S?"var(--sa-color-gray-400, #b7b9be)":B||P?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${f.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${f.selected||Y?"sa-calendar-days-active":""} ${f.isToday&&!f.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:T(),pointerEvents:S?"none":void 0,cursor:S?"not-allowed":"pointer",color:m(),opacity:Y&&!f.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{S||(d(f.date),$(f.date))},onMouseEnter:()=>{S||t(f.date)},children:f.number},x)})})]})},kn=({date:e,setDate:a,filter:r,setViews:s,dateRange:o,setDateRange:i,onChange:l,minDate:p,maxDate:h,input:t})=>{var L;const c=(L=o.from)==null?void 0:L.getFullYear(),w=e.getFullYear(),C=y=>{r?(D(y),a(y)):(s("days"),a(y))},D=y=>{let v={...o};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const d=v.from.getTime();y.getTime()>d?v={from:v.from,to:y}:v={from:y,to:v.from}}i(v),l(v)};return n.jsx("div",{className:"sa-calendar-months-preview",children:J.map((y,v)=>{var F,g,M;const d=o.from!=null&&new Date(w,v).getTime()>o.from.getTime()&&new Date(w,v).getTime()<(((F=o.to)==null?void 0:F.getTime())||o.from.getTime()),$=p&&new Date(w,v)<p||h&&new Date(w,v)>h;return n.jsx("p",{className:c===w&&(v===((g=o.from)==null?void 0:g.getMonth())||v===((M=o.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",color:$?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...t?{}:{width:"100%"}},onClick:()=>{$||C(new Date(w,v))},children:y.slice(0,3)},v)})})},en=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},Mn=({date:e,filter:a,setViews:r,setDate:s,dateRange:o,setDateRange:i,onChange:l,minDate:p,maxDate:h,input:t})=>{var $,F;let c=[];const w=e.getFullYear(),{start:C,end:D}=en(w),L=($=o.from)==null?void 0:$.getFullYear(),y=(F=o.to)==null?void 0:F.getFullYear();for(let g=C;g<D;g++){const M=new Date(g,0),f=(!p||M>=p)&&(!h||M<=h),x=L!=null&&g===L||y!=null&&g===y,B=o.from!=null&&o.to!=null&&M>o.from&&M<o.to;c.push({year:g,active:x&&f,highlight:B&&f,disabled:!f})}const v=g=>{a?(d(g),s(g)):(s(g),r("months"))},d=g=>{let M={...o};if(M.from&&M.to)M={from:g,to:null};else if(!M.from)M={from:g,to:null};else{const f=M.from.getTime();g.getTime()>f?M={from:M.from,to:g}:M={from:g,to:M.from}}i(M),l(M)};return n.jsx("div",{className:"sa-calendar-years-preview",children:c.map((g,M)=>n.jsx("p",{className:`${g.active?"sa-calendar-months-active":""} ${g.highlight?"sa-calendar-months-highlight":""} ${g.disabled?"sa-calendar-disabled":""}`,onClick:()=>{g.disabled||v(new Date(g.year,0))},style:{backgroundColor:g.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:g.highlight?"var(--sa-color-gray-500, #8c8f97)":g.active?"":g.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:g.disabled?"not-allowed":"pointer",pointerEvents:g.disbled?"none":"all",...t?{}:{width:"100%"}},children:g.year},M))})},cn=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...e,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"})}),pn=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...e,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"})}),Nn=({setViews:e,views:a,filter:r,date:s,setDate:o})=>{const i=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()+1,t.getMonth()));return}o(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()-1,t.getMonth()));return}o(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},h=()=>{if(a==="days")return`${J[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${en(s.getFullYear()).start} ~ ${en(s.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:i,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(cn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(pn,{})})]})]})};function G(e){const a=new Date(e),r=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${yn[s]} ${r}`}const an=({label:e,labelPosition:a="outside-top",required:r,optional:s,description:o,helperText:i,errorText:l,fullWidth:p,size:h="sm",children:t})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),w=e?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:e}),s&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,C=n.jsxs(n.Fragment,{children:[i&&!l&&n.jsx("p",{className:"sa-date-field-helper",children:i}),l&&n.jsx("p",{className:"sa-date-field-error-msg",children:l})]});return e?a==="outside-left"?n.jsxs("div",{className:`${c} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[w,o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[t,C]})]}):n.jsxs("div",{className:c,children:[w,o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o}),t,C]}):n.jsxs("div",{className:c,children:[o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o}),t,C]})},un="sa-calendar-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(un)){const a=document.createElement("style");a.id=un,a.textContent=e,document.head.appendChild(a)}})(Z);const Cn=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,disabled:o,minDate:i,maxDate:l,placeholder:p,size:h="sm",variant:t,status:c,clearable:w,fullWidth:C=!0,withPadding:D=!0,label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g},M)=>{const f=g?"error":c,{ref:x,isComponentVisible:B,setIsComponentVisible:P}=nn(!1),Y=b.useRef(null),[S,T]=b.useState("days"),[m,z]=b.useState(new Date),[k,I]=b.useState({from:(e==null?void 0:e.from)??null,to:(e==null?void 0:e.to)??null});b.useEffect(()=>{if(e){const N=e;N.from&&z(N.from),I(N)}else z(new Date),I({from:null,to:null})},[e]),b.useEffect(()=>{r&&T(r)},[r]),b.useEffect(()=>{r||T("days")},[B]),b.useEffect(()=>{s||P(!0)},[s]);const H=()=>{var N,j;if(!e)return"";if(r){if(S==="days")return`${G(k.from)} ~ ${G(k.to||k.from)||"-"}`;if(S==="months")return`${J[k.from.getMonth()]} ~ ${k.to?J[k.to.getMonth()]:"-"}`;if(S==="years")return`${(N=k.from)==null?void 0:N.getFullYear()} ~ ${((j=k.to)==null?void 0:j.getFullYear())||"-"}`}else return`${G(k.from)} ~ ${G(k.to||k.from)||"-"}`},V=()=>{if(Y.current&&x.current&&s){const N=x.current.getBoundingClientRect(),j=Y.current.getBoundingClientRect();window.innerWidth<N.left+j.width?Y.current.style.left=`${N.left-j.width+N.width}px`:Y.current.style.left=`${N.left}px`,N.top+j.height>window.innerHeight?Y.current.style.top=`${N.y-(N.height+j.height-28)}px`:Y.current.style.top=`${N.y+N.height}px`}};b.useEffect(()=>{Y.current&&x.current&&s&&V()},[Y,x,B]),b.useEffect(()=>(window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}),[]);const K=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?x:null,children:[s?n.jsx(wn,{value:H(),inputMode:"none",onClick:()=>{P(!0)},onChange:()=>{},disabled:o,placeholder:p,size:h,variant:t,status:f,clearable:w,onClear:()=>a(void 0)}):null,B?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${s?"":"sa-calendar-no-input"} ${D?"":"sa-calendar-no-padding"}`,style:o?{pointerEvents:"none"}:void 0,ref:Y,children:[n.jsx(Nn,{setViews:T,views:S,filter:r,date:m,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:S==="days"?n.jsx(xn,{date:m,setDate:z,setIsComponentVisible:P,dateRange:k,setDateRange:I,input:s,onChange:a,minDate:i,maxDate:l}):S==="months"?n.jsx(kn,{date:m,setDate:z,filter:r,setViews:T,dateRange:k,setDateRange:I,setIsComponentVisible:P,input:s,onChange:a,minDate:i,maxDate:l}):n.jsx(Mn,{date:m,setDate:z,filter:r,setViews:T,dateRange:k,setDateRange:I,setIsComponentVisible:P,input:s,onChange:a,minDate:i,maxDate:l})})]}):null]});return n.jsx(an,{label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g,fullWidth:C,size:h,children:K})}),hn="sa-calendar-input-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(hn)){const a=document.createElement("style");a.id=hn,a.textContent=e,document.head.appendChild(a)}})(Z);const U=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},$n=e=>{const{size:a="sm",status:r="default",variant:s="outline",clearable:o,onClear:i,...l}=e,p=b.useRef(null),h=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=o&&c&&!t,C=D=>{D.stopPropagation(),i==null||i()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${r} ${a} `,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:U(a),height:U(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",...l,disabled:t,value:l.value,ref:p})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:U(a),height:U(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:U(a),height:U(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"})})})]})},zn=({date:e,setDate:a,previewDate:r,setPreviewDate:s,setIsComponentVisible:o,minDate:i,maxDate:l,input:p,onChange:h,hasValue:t})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),w=c.getDay(),C=[];const D=e.toDateString(),L=new Date().toDateString(),y=r.getMonth();for(let d=0;d<42;d++){d===0&&w===0?c.setDate(c.getDate()-7):d===0?c.setDate(c.getDate()+(d-w)):c.setDate(c.getDate()+1);let $={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:t&&c.toDateString()===D,isToday:c.toDateString()===L,year:c.getFullYear(),isDisabled:i&&c<i||l&&c>l};C.push($)}const v=d=>{(!i||d>=i)&&(!l||d<=l)&&(a(d),h(d),s(d),p&&o(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:ln.map((d,$)=>n.jsx("p",{children:d},$))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((d,$)=>{const F=d.isDisabled;return n.jsx("p",{className:`${d.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${d.selected?"sa-calendar-days-active":""} ${d.isToday&&!d.selected?"sa-calendar-days-today":""}`,style:{color:F?"#ccc":void 0,pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{F||v(d.date)},children:d.number},$)})})]})},Dn=({date:e,setDate:a,filter:r,setViews:s,onChange:o,previewDate:i,setPreviewDate:l,minDate:p,maxDate:h,input:t,hasValue:c})=>{const w=e.getMonth(),C=e.getFullYear(),D=i.getFullYear(),L=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(o(y),a(y),l(y)):(s("days"),l(y)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:J.map((y,v)=>{const d=p&&new Date(D,v,1)<p||h&&new Date(D,v+1,0)>h;return n.jsx("p",{className:c&&v===w&&D===C?"sa-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{d||L(new Date(D,v))},children:y.slice(0,3)},v)})})},rn=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},En=({date:e,filter:a,setViews:r,setDate:s,onChange:o,previewDate:i,setPreviewDate:l,minDate:p,maxDate:h,input:t,hasValue:c})=>{let w=[];const C=i.getFullYear(),{start:D,end:L}=rn(C),y=e.getFullYear();for(let d=D;d<L;d++){let $=p&&new Date(d,0,1)<p||h&&new Date(d,11,31)>h;w.push({year:d,active:!!c&&d===y,isDisabled:$})}const v=d=>{(!p||d>=p)&&(!h||d<=h)&&(a?(o(d),s(d),l(d)):(r("months"),l(d)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:w.map((d,$)=>n.jsx("p",{className:d.active?"sa-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{d.isDisabled||v(new Date(d.year,0))},children:d.year},$))})},Yn=({setViews:e,views:a,filter:r,previewDate:s,setPreviewDate:o})=>{const i=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()+1,t.getMonth()));return}o(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()-1,t.getMonth()));return}o(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},h=()=>{if(a==="days")return`${J[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${rn(s.getFullYear()).start} ~ ${rn(s.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:i,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(cn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(pn,{})})]})]})},fn="sa-calendar-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(fn)){const a=document.createElement("style");a.id=fn,a.textContent=e,document.head.appendChild(a)}})(Z);const Sn=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,disabled:o,minDate:i,maxDate:l,placeholder:p,size:h="sm",variant:t,status:c,clearable:w,fullWidth:C=!0,withPadding:D=!0,label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g},M)=>{const f=g?"error":c,{ref:x,isComponentVisible:B,setIsComponentVisible:P}=nn(!1),Y=b.useRef(null),[S,T]=b.useState("days"),[m,z]=b.useState(new Date),[k,I]=b.useState(new Date);b.useEffect(()=>{e?(z(e),I(e)):(z(new Date),I(new Date))},[e]),b.useEffect(()=>{r&&T(r)},[r]),b.useEffect(()=>{r||T("days")},[B]),b.useEffect(()=>{s||P(!0)},[s]);const H=()=>e?r==="days"?G(m):r==="months"?`${J[m.getMonth()]} ${m.getFullYear()}`:r==="years"?m.getFullYear():G(m):"",V=()=>{if(Y.current&&x.current&&s){const N=x.current.getBoundingClientRect(),j=Y.current.getBoundingClientRect();window.innerWidth<N.left+j.width?Y.current.style.left=`${N.left-j.width+N.width}px`:Y.current.style.left=`${N.left}px`,N.top+j.height>window.innerHeight?Y.current.style.top=`${N.y-(N.height+j.height-28)}px`:Y.current.style.top=`${N.y+N.height}px`}};b.useEffect(()=>{Y.current&&x.current&&s&&V()},[Y,x,B]),b.useEffect(()=>(window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}),[]);const K=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?x:null,children:[s?n.jsx($n,{value:H(),onClick:()=>P(!0),onChange:()=>{},placeholder:p,disabled:o,size:h,variant:t,status:f,inputMode:"none",clearable:w,onClear:()=>a(void 0)}):null,B?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${s?"":"sa-calendar-no-input"} ${D?"":"sa-calendar-no-padding"}`,style:o?{pointerEvents:"none"}:void 0,ref:Y,children:[n.jsx(Yn,{setViews:T,views:S,filter:r,previewDate:k,setPreviewDate:I,isComponentVisible:B}),n.jsx("div",{className:"sa-calendar-body",children:S==="days"?n.jsx(zn,{date:m,setDate:z,previewDate:k,setPreviewDate:I,setIsComponentVisible:P,input:s,minDate:i,maxDate:l,onChange:a,hasValue:e!=null}):S==="months"?n.jsx(Dn,{date:m,setDate:z,previewDate:k,setPreviewDate:I,filter:r,setViews:T,onChange:a,minDate:i,maxDate:l,input:s,hasValue:e!=null}):n.jsx(En,{date:m,setDate:z,previewDate:k,setPreviewDate:I,filter:r,setViews:T,onChange:a,minDate:i,maxDate:l,input:s,hasValue:e!=null})})]}):null]});return n.jsx(an,{label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g,fullWidth:C,size:h,children:K})}),Ln=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,rangedDate:o,disabled:i,minDate:l,maxDate:p,placeholder:h,size:t,variant:c,status:w,clearable:C,fullWidth:D,withPadding:L,label:y,labelPosition:v,required:d,optional:$,description:F,helperText:g,errorText:M},f)=>{const x={onChange:a,value:e,input:s,filter:r,disabled:i,minDate:l,maxDate:p,placeholder:h,size:t,variant:c,status:w,clearable:C,fullWidth:D,withPadding:L,label:y,labelPosition:v,required:d,optional:$,description:F,helperText:g,errorText:M};return n.jsx(n.Fragment,{children:o?n.jsx(Cn,{...x,ref:f}):n.jsx(Sn,{...x,ref:f})})}),Fn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
592
592
  date.module.css, injected alongside this sheet) and the .sa-calendar /
593
593
  .sa-calendar-input-* shells for the box + masked input. */
594
594
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "5.4.0",
3
+ "version": "5.4.2",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",