@starasia/date 7.0.1 → 7.0.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
@@ -1521,7 +1521,7 @@ const sn = (n) => {
1521
1521
  {
1522
1522
  className: `${u.currentMonth ? "sa-calendar-days-current" : "sa-calendar-days"} ${u.selected ? "sa-calendar-days-active" : ""} ${u.isToday && !u.selected ? "sa-calendar-days-today" : ""}`,
1523
1523
  style: {
1524
- color: T ? "#ccc" : void 0,
1524
+ color: T ? "var(--sa-text-disable, #181a198f)" : void 0,
1525
1525
  pointerEvents: T ? "none" : void 0,
1526
1526
  cursor: T ? "not-allowed" : "pointer",
1527
1527
  ...p ? {} : { width: "100%" }
@@ -1558,7 +1558,7 @@ const sn = (n) => {
1558
1558
  {
1559
1559
  className: c && g === w && E === M ? "sa-calendar-months-active" : "",
1560
1560
  style: {
1561
- color: u ? "#ccc" : void 0,
1561
+ color: u ? "var(--sa-text-disable, #181a198f)" : void 0,
1562
1562
  pointerEvents: u ? "none" : void 0,
1563
1563
  cursor: u ? "not-allowed" : "pointer",
1564
1564
  ...l ? {} : { width: "100%" }
@@ -1605,7 +1605,7 @@ const sn = (n) => {
1605
1605
  {
1606
1606
  className: u.active ? "sa-calendar-months-active" : "",
1607
1607
  style: {
1608
- color: u.isDisabled ? "#ccc" : void 0,
1608
+ color: u.isDisabled ? "var(--sa-text-disable, #181a198f)" : void 0,
1609
1609
  pointerEvents: u.isDisabled ? "none" : void 0,
1610
1610
  cursor: u.isDisabled ? "not-allowed" : "pointer",
1611
1611
  ...l ? {} : { width: "100%" }
package/dist/date.umd.js CHANGED
@@ -597,7 +597,7 @@
597
597
  width: 32px;
598
598
  height: 32px;
599
599
  }
600
- `,$n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],_=["January","February","March","April","May","June","July","August","September","October","November","December"],Bn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function vn(n){const[a,r]=g.useState(n),o=g.useRef(null),s=d=>{o.current&&!o.current.contains(d.target)&&r(!1)};return g.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:r}}const Cn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Cn)){const a=document.createElement("style");a.id=Cn,a.textContent=n,document.head.appendChild(a)}})(sn);const an=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},Vn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,$=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:$,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})})]})},Pn=({date:n,setDate:a,dateRange:r,setDateRange:o,onChange:s,minDate:d,maxDate:i,input:p})=>{var T,w,M;const[h,l]=g.useState(null);let c=new Date(n.getFullYear(),n.getMonth(),1),x=c.getDay(),$=[];const E=n.getMonth(),k=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let m=0;m<42;m++){m===0&&x===0?c.setDate(c.getDate()-7):m===0?c.setDate(c.getDate()+(m-x)):c.setDate(c.getDate()+1);let N={currentMonth:c.getMonth()===E,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((T=r.from)==null?void 0:T.toDateString())||c.toDateString()===(((w=r.to)==null?void 0:w.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};$.push(N)}const u=m=>{a(m)},C=m=>{let N={...r};if(N.from&&N.to)N={from:m,to:null};else if(!N.from)N={from:m,to:null};else{const B=N.from.getTime();m.getTime()>B?N={from:N.from,to:m}:N={from:m,to:N.from}}o(N),s(N)};return e.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>l(null),children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:$n.map((m,N)=>e.jsx("p",{children:m},N))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:$.map((m,N)=>{const B=r.from&&r.to&&m.date.getTime()>r.from.getTime()&&m.date.getTime()<r.to.getTime(),H=(()=>{if(!v||!r.from)return!1;const S=m.date.getTime(),Y=r.from.getTime(),L=v.getTime();return L>Y?S>Y&&S<L:S<Y&&S>L})(),V=y&&h&&m.date.toDateString()===h.toDateString(),F=m.isDisabled,D=()=>B||H?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",b=()=>F?"var(--sa-color-gray-400, #b7b9be)":B||H?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${m.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${m.selected||V?"sa-calendar-days-active":""} ${m.isToday&&!m.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:D(),pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",color:b(),opacity:V&&!m.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{F||(u(m.date),C(m.date))},onMouseEnter:()=>{F||l(m.date)},children:m.number},N)})})]})},jn=({date:n,setDate:a,filter:r,setViews:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var k;const c=(k=s.from)==null?void 0:k.getFullYear(),x=n.getFullYear(),$=y=>{r?(E(y),a(y)):(o("days"),a(y))},E=y=>{let v={...s};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const u=v.from.getTime();y.getTime()>u?v={from:v.from,to:y}:v={from:y,to:v.from}}d(v),i(v)};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{var T,w,M;const u=s.from!=null&&new Date(x,v).getTime()>s.from.getTime()&&new Date(x,v).getTime()<(((T=s.to)==null?void 0:T.getTime())||s.from.getTime()),C=p&&new Date(x,v)<p||h&&new Date(x,v)>h;return e.jsx("p",{className:c===x&&(v===((w=s.from)==null?void 0:w.getMonth())||v===((M=s.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:u?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:C?"none":void 0,cursor:C?"not-allowed":"pointer",color:C?"var(--sa-color-gray-400, #b7b9be)":u?"var(--sa-color-gray-500, #8c8f97)":"",...l?{}:{width:"100%"}},onClick:()=>{C||$(new Date(x,v))},children:y.slice(0,3)},v)})})},bn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},On=({date:n,filter:a,setViews:r,setDate:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var C,T;let c=[];const x=n.getFullYear(),{start:$,end:E}=bn(x),k=(C=s.from)==null?void 0:C.getFullYear(),y=(T=s.to)==null?void 0:T.getFullYear();for(let w=$;w<E;w++){const M=new Date(w,0),m=(!p||M>=p)&&(!h||M<=h),N=k!=null&&w===k||y!=null&&w===y,B=s.from!=null&&s.to!=null&&M>s.from&&M<s.to;c.push({year:w,active:N&&m,highlight:B&&m,disabled:!m})}const v=w=>{a?(u(w),o(w)):(o(w),r("months"))},u=w=>{let M={...s};if(M.from&&M.to)M={from:w,to:null};else if(!M.from)M={from:w,to:null};else{const m=M.from.getTime();w.getTime()>m?M={from:M.from,to:w}:M={from:w,to:M.from}}d(M),i(M)};return e.jsx("div",{className:"sa-calendar-years-preview",children:c.map((w,M)=>e.jsx("p",{className:`${w.active?"sa-calendar-months-active":""} ${w.highlight?"sa-calendar-months-highlight":""} ${w.disabled?"sa-calendar-disabled":""}`,onClick:()=>{w.disabled||v(new Date(w.year,0))},style:{backgroundColor:w.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:w.highlight?"var(--sa-color-gray-500, #8c8f97)":w.active?"":w.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:w.disabled?"not-allowed":"pointer",pointerEvents:w.disbled?"none":"all",...l?{}:{width:"100%"}},children:w.year},M))})},Dn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.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"})}),zn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.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"})}),An=({setViews:n,views:a,filter:r,date:o,setDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${bn(o.getFullYear()).start} ~ ${bn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})};function rn(n){const a=new Date(n),r=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${Bn[o]} ${r}`}const En=(()=>{const n={};return _.forEach((a,r)=>{n[a.toLowerCase()]=r,n[a.slice(0,3).toLowerCase()]=r}),n})(),mn=n=>n<100?2e3+n:n;function yn(n,a){const r=String(n.getDate()).padStart(2,"0"),o=String(n.getMonth()+1).padStart(2,"0"),s=n.getFullYear();return a==="years"?`${s}`:a==="months"?`${o}/${s}`:`${r}/${o}/${s}`}function Hn(n,a){const r=n.from?yn(n.from,a):"",o=n.to?yn(n.to,a):"";return r?o?`${r} ~ ${o}`:r:""}function fn(n,a){const r=n.trim().toLowerCase().split(/[\s/.\-,]+/).filter(Boolean);if(!r.length)return null;let o=null;const s=[];for(const c of r)c in En?o=En[c]:/^\d+$/.test(c)&&s.push(parseInt(c,10));if(a==="years"){const c=s[0];return c==null?null:new Date(mn(c),0,1)}if(a==="months"){const c=o??s[0]-1,x=o!=null?s[0]:s[1];return c==null||isNaN(c)||c<0||c>11||x==null?null:new Date(mn(x),c,1)}let d,i,p;if(o!=null?(d=s[0],p=s[1],i=o):(d=s[0],i=s[1]!=null?s[1]-1:void 0,p=s[2]),d==null||i==null||p==null)return null;const h=mn(p),l=new Date(h,i,d);return l.getFullYear()!==h||l.getMonth()!==i||l.getDate()!==d?null:l}function Wn(n,a){const r=n.indexOf("~");if(r===-1){const d=fn(n,a);return d?{from:d,to:null}:null}const o=fn(n.slice(0,r),a);if(!o)return null;const s=fn(n.slice(r+1),a);return{from:o,to:s??null}}function wn(n,a,r){const o=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate()).getTime(),s=o(n);return!(a&&s<o(a)||r&&s>o(r))}const xn=({label:n,labelPosition:a="outside-top",required:r,optional:o,description:s,helperText:d,errorText:i,fullWidth:p,size:h="sm",children:l})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),x=n?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:n}),o&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,$=e.jsxs(e.Fragment,{children:[d&&!i&&e.jsx("p",{className:"sa-date-field-helper",children:d}),i&&e.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return n?a==="outside-left"?e.jsxs("div",{className:`${c} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[l,$]})]}):e.jsxs("div",{className:c,children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,$]}):e.jsxs("div",{className:c,children:[s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,$]})},Sn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Sn)){const a=document.createElement("style");a.id=Sn,a.textContent=n,document.head.appendChild(a)}})(sn);const Jn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:$=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),W=typeof v=="function"||y!=null,O=!o&&!W,J=!O,[z,q]=g.useState({from:(n==null?void 0:n.from)??null,to:(n==null?void 0:n.to)??null}),[K,U]=g.useState(null);g.useEffect(()=>{if(n){const t=n;t.from&&I(t.from),q(t)}else I(new Date),q({from:null,to:null});U(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{O&&D(!0)},[O]);const Q=()=>{var t,f;if(!n)return"";if(r){if(S==="days")return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`;if(S==="months")return`${_[z.from.getMonth()]} ~ ${z.to?_[z.to.getMonth()]:"-"}`;if(S==="years")return`${(t=z.from)==null?void 0:t.getFullYear()} ~ ${((f=z.to)==null?void 0:f.getFullYear())||"-"}`}else return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`},j=()=>{if(b.current&&V.current&&J){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&J&&j()},[b,V,F]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&U(Hn(z,r))},R=()=>{if(K===null)return;const t=K.trim();if(!t){a(void 0),U(null);return}const f=Wn(t,r),P=f&&wn(f.from,d,i)&&(!f.to||wn(f.to,d,i));f&&P&&(a(f),q(f),I(f.from)),U(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(U(null),D(!1))},un={isOpen:F,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${W?" sa-calendar-wrapper-custom":""}`,style:{height:O?"100%":"auto"},ref:t=>{V.current=J?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[W?nn():o?e.jsx(Vn,{value:k&&K!==null?K:Q(),inputMode:k?"text":"none",readOnly:!k,onClick:()=>{D(!0)},onChange:k?t=>U(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,disabled:s,placeholder:p,size:h,variant:l,status:H,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${O?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(An,{setViews:Y,views:S,filter:r,date:L,setDate:I}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Pn,{date:L,setDate:I,setIsComponentVisible:D,dateRange:z,setDateRange:q,input:o,onChange:a,minDate:d,maxDate:i}):S==="months"?e.jsx(jn,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i}):e.jsx(On,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i})})]}):null]});return e.jsx(xn,{label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:$,size:h,children:pn})}),Yn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Yn)){const a=document.createElement("style");a.id=Yn,a.textContent=n,document.head.appendChild(a)}})(sn);const tn=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},qn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,$=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:$,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})})]})},Kn=({date:n,setDate:a,previewDate:r,setPreviewDate:o,setIsComponentVisible:s,minDate:d,maxDate:i,input:p,onChange:h,hasValue:l})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),x=c.getDay(),$=[];const E=n.toDateString(),k=new Date().toDateString(),y=r.getMonth();for(let u=0;u<42;u++){u===0&&x===0?c.setDate(c.getDate()-7):u===0?c.setDate(c.getDate()+(u-x)):c.setDate(c.getDate()+1);let C={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:l&&c.toDateString()===E,isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};$.push(C)}const v=u=>{(!d||u>=d)&&(!i||u<=i)&&(a(u),h(u),o(u),p&&s(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:$n.map((u,C)=>e.jsx("p",{children:u},C))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:$.map((u,C)=>{const T=u.isDisabled;return e.jsx("p",{className:`${u.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${u.selected?"sa-calendar-days-active":""} ${u.isToday&&!u.selected?"sa-calendar-days-today":""}`,style:{color:T?"#ccc":void 0,pointerEvents:T?"none":void 0,cursor:T?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{T||v(u.date)},children:u.number},C)})})]})},Un=({date:n,setDate:a,filter:r,setViews:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{const x=n.getMonth(),$=n.getFullYear(),E=d.getFullYear(),k=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(s(y),a(y),i(y)):(o("days"),i(y)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{const u=p&&new Date(E,v,1)<p||h&&new Date(E,v+1,0)>h;return e.jsx("p",{className:c&&v===x&&E===$?"sa-calendar-months-active":"",style:{color:u?"#ccc":void 0,pointerEvents:u?"none":void 0,cursor:u?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u||k(new Date(E,v))},children:y.slice(0,3)},v)})})},kn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},Gn=({date:n,filter:a,setViews:r,setDate:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{let x=[];const $=d.getFullYear(),{start:E,end:k}=kn($),y=n.getFullYear();for(let u=E;u<k;u++){let C=p&&new Date(u,0,1)<p||h&&new Date(u,11,31)>h;x.push({year:u,active:!!c&&u===y,isDisabled:C})}const v=u=>{(!p||u>=p)&&(!h||u<=h)&&(a?(s(u),o(u),i(u)):(r("months"),i(u)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((u,C)=>e.jsx("p",{className:u.active?"sa-calendar-months-active":"",style:{color:u.isDisabled?"#ccc":void 0,pointerEvents:u.isDisabled?"none":void 0,cursor:u.isDisabled?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u.isDisabled||v(new Date(u.year,0))},children:u.year},C))})},Zn=({setViews:n,views:a,filter:r,previewDate:o,setPreviewDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${kn(o.getFullYear()).start} ~ ${kn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})},Fn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Fn)){const a=document.createElement("style");a.id=Fn,a.textContent=n,document.head.appendChild(a)}})(sn);const _n=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:$=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),[W,O]=g.useState(new Date),[J,z]=g.useState(null),q=typeof v=="function"||y!=null,K=!o&&!q,U=!K;g.useEffect(()=>{n?(I(n),O(n)):(I(new Date),O(new Date)),z(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{K&&D(!0)},[K]);const Q=()=>n?r==="days"?rn(L):r==="months"?`${_[L.getMonth()]} ${L.getFullYear()}`:r==="years"?L.getFullYear():rn(L):"",j=()=>{if(b.current&&V.current&&U){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&U&&j()},[b,V,F]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&z(n?yn(n,r):"")},R=()=>{if(J===null)return;const t=J.trim();if(!t){a(void 0),z(null);return}const f=fn(t,r);f&&wn(f,d,i)&&(a(f),I(f),O(f)),z(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(z(null),D(!1))},un={isOpen:F,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${q?" sa-calendar-wrapper-custom":""}`,style:{height:K?"100%":"auto"},ref:t=>{V.current=U?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[q?nn():o?e.jsx(qn,{value:k&&J!==null?J:Q(),onClick:()=>D(!0),onChange:k?t=>z(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,placeholder:p,disabled:s,size:h,variant:l,status:H,inputMode:k?"text":"none",readOnly:!k,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${K?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(Zn,{setViews:Y,views:S,filter:r,previewDate:W,setPreviewDate:O,isComponentVisible:F}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Kn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,setIsComponentVisible:D,input:o,minDate:d,maxDate:i,onChange:a,hasValue:n!=null}):S==="months"?e.jsx(Un,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null}):e.jsx(Gn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null})})]}):null]});return e.jsx(xn,{label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:$,size:h,children:pn})}),Qn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,rangedDate:s,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:$,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:C,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B},H)=>{const V={onChange:a,value:n,input:o,filter:r,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:$,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:C,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B};return e.jsx(e.Fragment,{children:s?e.jsx(Jn,{...V,ref:H}):e.jsx(_n,{...V,ref:H})})}),Xn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
600
+ `,$n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],_=["January","February","March","April","May","June","July","August","September","October","November","December"],Bn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function vn(n){const[a,r]=g.useState(n),o=g.useRef(null),s=d=>{o.current&&!o.current.contains(d.target)&&r(!1)};return g.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:r}}const Cn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Cn)){const a=document.createElement("style");a.id=Cn,a.textContent=n,document.head.appendChild(a)}})(sn);const an=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},Vn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,$=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:$,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})})]})},Pn=({date:n,setDate:a,dateRange:r,setDateRange:o,onChange:s,minDate:d,maxDate:i,input:p})=>{var T,w,M;const[h,l]=g.useState(null);let c=new Date(n.getFullYear(),n.getMonth(),1),x=c.getDay(),$=[];const E=n.getMonth(),k=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let m=0;m<42;m++){m===0&&x===0?c.setDate(c.getDate()-7):m===0?c.setDate(c.getDate()+(m-x)):c.setDate(c.getDate()+1);let N={currentMonth:c.getMonth()===E,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((T=r.from)==null?void 0:T.toDateString())||c.toDateString()===(((w=r.to)==null?void 0:w.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};$.push(N)}const u=m=>{a(m)},C=m=>{let N={...r};if(N.from&&N.to)N={from:m,to:null};else if(!N.from)N={from:m,to:null};else{const B=N.from.getTime();m.getTime()>B?N={from:N.from,to:m}:N={from:m,to:N.from}}o(N),s(N)};return e.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>l(null),children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:$n.map((m,N)=>e.jsx("p",{children:m},N))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:$.map((m,N)=>{const B=r.from&&r.to&&m.date.getTime()>r.from.getTime()&&m.date.getTime()<r.to.getTime(),H=(()=>{if(!v||!r.from)return!1;const S=m.date.getTime(),Y=r.from.getTime(),L=v.getTime();return L>Y?S>Y&&S<L:S<Y&&S>L})(),V=y&&h&&m.date.toDateString()===h.toDateString(),F=m.isDisabled,D=()=>B||H?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",b=()=>F?"var(--sa-color-gray-400, #b7b9be)":B||H?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${m.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${m.selected||V?"sa-calendar-days-active":""} ${m.isToday&&!m.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:D(),pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",color:b(),opacity:V&&!m.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{F||(u(m.date),C(m.date))},onMouseEnter:()=>{F||l(m.date)},children:m.number},N)})})]})},jn=({date:n,setDate:a,filter:r,setViews:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var k;const c=(k=s.from)==null?void 0:k.getFullYear(),x=n.getFullYear(),$=y=>{r?(E(y),a(y)):(o("days"),a(y))},E=y=>{let v={...s};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const u=v.from.getTime();y.getTime()>u?v={from:v.from,to:y}:v={from:y,to:v.from}}d(v),i(v)};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{var T,w,M;const u=s.from!=null&&new Date(x,v).getTime()>s.from.getTime()&&new Date(x,v).getTime()<(((T=s.to)==null?void 0:T.getTime())||s.from.getTime()),C=p&&new Date(x,v)<p||h&&new Date(x,v)>h;return e.jsx("p",{className:c===x&&(v===((w=s.from)==null?void 0:w.getMonth())||v===((M=s.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:u?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:C?"none":void 0,cursor:C?"not-allowed":"pointer",color:C?"var(--sa-color-gray-400, #b7b9be)":u?"var(--sa-color-gray-500, #8c8f97)":"",...l?{}:{width:"100%"}},onClick:()=>{C||$(new Date(x,v))},children:y.slice(0,3)},v)})})},bn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},On=({date:n,filter:a,setViews:r,setDate:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var C,T;let c=[];const x=n.getFullYear(),{start:$,end:E}=bn(x),k=(C=s.from)==null?void 0:C.getFullYear(),y=(T=s.to)==null?void 0:T.getFullYear();for(let w=$;w<E;w++){const M=new Date(w,0),m=(!p||M>=p)&&(!h||M<=h),N=k!=null&&w===k||y!=null&&w===y,B=s.from!=null&&s.to!=null&&M>s.from&&M<s.to;c.push({year:w,active:N&&m,highlight:B&&m,disabled:!m})}const v=w=>{a?(u(w),o(w)):(o(w),r("months"))},u=w=>{let M={...s};if(M.from&&M.to)M={from:w,to:null};else if(!M.from)M={from:w,to:null};else{const m=M.from.getTime();w.getTime()>m?M={from:M.from,to:w}:M={from:w,to:M.from}}d(M),i(M)};return e.jsx("div",{className:"sa-calendar-years-preview",children:c.map((w,M)=>e.jsx("p",{className:`${w.active?"sa-calendar-months-active":""} ${w.highlight?"sa-calendar-months-highlight":""} ${w.disabled?"sa-calendar-disabled":""}`,onClick:()=>{w.disabled||v(new Date(w.year,0))},style:{backgroundColor:w.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:w.highlight?"var(--sa-color-gray-500, #8c8f97)":w.active?"":w.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:w.disabled?"not-allowed":"pointer",pointerEvents:w.disbled?"none":"all",...l?{}:{width:"100%"}},children:w.year},M))})},Dn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.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"})}),zn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.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"})}),An=({setViews:n,views:a,filter:r,date:o,setDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${bn(o.getFullYear()).start} ~ ${bn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})};function rn(n){const a=new Date(n),r=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${Bn[o]} ${r}`}const En=(()=>{const n={};return _.forEach((a,r)=>{n[a.toLowerCase()]=r,n[a.slice(0,3).toLowerCase()]=r}),n})(),mn=n=>n<100?2e3+n:n;function yn(n,a){const r=String(n.getDate()).padStart(2,"0"),o=String(n.getMonth()+1).padStart(2,"0"),s=n.getFullYear();return a==="years"?`${s}`:a==="months"?`${o}/${s}`:`${r}/${o}/${s}`}function Hn(n,a){const r=n.from?yn(n.from,a):"",o=n.to?yn(n.to,a):"";return r?o?`${r} ~ ${o}`:r:""}function fn(n,a){const r=n.trim().toLowerCase().split(/[\s/.\-,]+/).filter(Boolean);if(!r.length)return null;let o=null;const s=[];for(const c of r)c in En?o=En[c]:/^\d+$/.test(c)&&s.push(parseInt(c,10));if(a==="years"){const c=s[0];return c==null?null:new Date(mn(c),0,1)}if(a==="months"){const c=o??s[0]-1,x=o!=null?s[0]:s[1];return c==null||isNaN(c)||c<0||c>11||x==null?null:new Date(mn(x),c,1)}let d,i,p;if(o!=null?(d=s[0],p=s[1],i=o):(d=s[0],i=s[1]!=null?s[1]-1:void 0,p=s[2]),d==null||i==null||p==null)return null;const h=mn(p),l=new Date(h,i,d);return l.getFullYear()!==h||l.getMonth()!==i||l.getDate()!==d?null:l}function Wn(n,a){const r=n.indexOf("~");if(r===-1){const d=fn(n,a);return d?{from:d,to:null}:null}const o=fn(n.slice(0,r),a);if(!o)return null;const s=fn(n.slice(r+1),a);return{from:o,to:s??null}}function wn(n,a,r){const o=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate()).getTime(),s=o(n);return!(a&&s<o(a)||r&&s>o(r))}const xn=({label:n,labelPosition:a="outside-top",required:r,optional:o,description:s,helperText:d,errorText:i,fullWidth:p,size:h="sm",children:l})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),x=n?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:n}),o&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,$=e.jsxs(e.Fragment,{children:[d&&!i&&e.jsx("p",{className:"sa-date-field-helper",children:d}),i&&e.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return n?a==="outside-left"?e.jsxs("div",{className:`${c} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[l,$]})]}):e.jsxs("div",{className:c,children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,$]}):e.jsxs("div",{className:c,children:[s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,$]})},Sn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Sn)){const a=document.createElement("style");a.id=Sn,a.textContent=n,document.head.appendChild(a)}})(sn);const Jn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:$=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),W=typeof v=="function"||y!=null,O=!o&&!W,J=!O,[z,q]=g.useState({from:(n==null?void 0:n.from)??null,to:(n==null?void 0:n.to)??null}),[K,U]=g.useState(null);g.useEffect(()=>{if(n){const t=n;t.from&&I(t.from),q(t)}else I(new Date),q({from:null,to:null});U(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{O&&D(!0)},[O]);const Q=()=>{var t,f;if(!n)return"";if(r){if(S==="days")return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`;if(S==="months")return`${_[z.from.getMonth()]} ~ ${z.to?_[z.to.getMonth()]:"-"}`;if(S==="years")return`${(t=z.from)==null?void 0:t.getFullYear()} ~ ${((f=z.to)==null?void 0:f.getFullYear())||"-"}`}else return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`},j=()=>{if(b.current&&V.current&&J){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&J&&j()},[b,V,F]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&U(Hn(z,r))},R=()=>{if(K===null)return;const t=K.trim();if(!t){a(void 0),U(null);return}const f=Wn(t,r),P=f&&wn(f.from,d,i)&&(!f.to||wn(f.to,d,i));f&&P&&(a(f),q(f),I(f.from)),U(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(U(null),D(!1))},un={isOpen:F,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${W?" sa-calendar-wrapper-custom":""}`,style:{height:O?"100%":"auto"},ref:t=>{V.current=J?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[W?nn():o?e.jsx(Vn,{value:k&&K!==null?K:Q(),inputMode:k?"text":"none",readOnly:!k,onClick:()=>{D(!0)},onChange:k?t=>U(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,disabled:s,placeholder:p,size:h,variant:l,status:H,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${O?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(An,{setViews:Y,views:S,filter:r,date:L,setDate:I}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Pn,{date:L,setDate:I,setIsComponentVisible:D,dateRange:z,setDateRange:q,input:o,onChange:a,minDate:d,maxDate:i}):S==="months"?e.jsx(jn,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i}):e.jsx(On,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i})})]}):null]});return e.jsx(xn,{label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:$,size:h,children:pn})}),Yn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Yn)){const a=document.createElement("style");a.id=Yn,a.textContent=n,document.head.appendChild(a)}})(sn);const tn=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},qn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,$=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:$,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.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"})})})]})},Kn=({date:n,setDate:a,previewDate:r,setPreviewDate:o,setIsComponentVisible:s,minDate:d,maxDate:i,input:p,onChange:h,hasValue:l})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),x=c.getDay(),$=[];const E=n.toDateString(),k=new Date().toDateString(),y=r.getMonth();for(let u=0;u<42;u++){u===0&&x===0?c.setDate(c.getDate()-7):u===0?c.setDate(c.getDate()+(u-x)):c.setDate(c.getDate()+1);let C={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:l&&c.toDateString()===E,isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};$.push(C)}const v=u=>{(!d||u>=d)&&(!i||u<=i)&&(a(u),h(u),o(u),p&&s(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:$n.map((u,C)=>e.jsx("p",{children:u},C))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:$.map((u,C)=>{const T=u.isDisabled;return e.jsx("p",{className:`${u.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${u.selected?"sa-calendar-days-active":""} ${u.isToday&&!u.selected?"sa-calendar-days-today":""}`,style:{color:T?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:T?"none":void 0,cursor:T?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{T||v(u.date)},children:u.number},C)})})]})},Un=({date:n,setDate:a,filter:r,setViews:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{const x=n.getMonth(),$=n.getFullYear(),E=d.getFullYear(),k=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(s(y),a(y),i(y)):(o("days"),i(y)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{const u=p&&new Date(E,v,1)<p||h&&new Date(E,v+1,0)>h;return e.jsx("p",{className:c&&v===x&&E===$?"sa-calendar-months-active":"",style:{color:u?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:u?"none":void 0,cursor:u?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u||k(new Date(E,v))},children:y.slice(0,3)},v)})})},kn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},Gn=({date:n,filter:a,setViews:r,setDate:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{let x=[];const $=d.getFullYear(),{start:E,end:k}=kn($),y=n.getFullYear();for(let u=E;u<k;u++){let C=p&&new Date(u,0,1)<p||h&&new Date(u,11,31)>h;x.push({year:u,active:!!c&&u===y,isDisabled:C})}const v=u=>{(!p||u>=p)&&(!h||u<=h)&&(a?(s(u),o(u),i(u)):(r("months"),i(u)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((u,C)=>e.jsx("p",{className:u.active?"sa-calendar-months-active":"",style:{color:u.isDisabled?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:u.isDisabled?"none":void 0,cursor:u.isDisabled?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u.isDisabled||v(new Date(u.year,0))},children:u.year},C))})},Zn=({setViews:n,views:a,filter:r,previewDate:o,setPreviewDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${kn(o.getFullYear()).start} ~ ${kn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})},Fn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Fn)){const a=document.createElement("style");a.id=Fn,a.textContent=n,document.head.appendChild(a)}})(sn);const _n=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:$=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),[W,O]=g.useState(new Date),[J,z]=g.useState(null),q=typeof v=="function"||y!=null,K=!o&&!q,U=!K;g.useEffect(()=>{n?(I(n),O(n)):(I(new Date),O(new Date)),z(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{K&&D(!0)},[K]);const Q=()=>n?r==="days"?rn(L):r==="months"?`${_[L.getMonth()]} ${L.getFullYear()}`:r==="years"?L.getFullYear():rn(L):"",j=()=>{if(b.current&&V.current&&U){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&U&&j()},[b,V,F]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&z(n?yn(n,r):"")},R=()=>{if(J===null)return;const t=J.trim();if(!t){a(void 0),z(null);return}const f=fn(t,r);f&&wn(f,d,i)&&(a(f),I(f),O(f)),z(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(z(null),D(!1))},un={isOpen:F,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${q?" sa-calendar-wrapper-custom":""}`,style:{height:K?"100%":"auto"},ref:t=>{V.current=U?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[q?nn():o?e.jsx(qn,{value:k&&J!==null?J:Q(),onClick:()=>D(!0),onChange:k?t=>z(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,placeholder:p,disabled:s,size:h,variant:l,status:H,inputMode:k?"text":"none",readOnly:!k,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${K?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(Zn,{setViews:Y,views:S,filter:r,previewDate:W,setPreviewDate:O,isComponentVisible:F}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Kn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,setIsComponentVisible:D,input:o,minDate:d,maxDate:i,onChange:a,hasValue:n!=null}):S==="months"?e.jsx(Un,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null}):e.jsx(Gn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null})})]}):null]});return e.jsx(xn,{label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:$,size:h,children:pn})}),Qn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,rangedDate:s,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:$,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:C,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B},H)=>{const V={onChange:a,value:n,input:o,filter:r,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:$,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:C,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B};return e.jsx(e.Fragment,{children:s?e.jsx(Jn,{...V,ref:H}):e.jsx(_n,{...V,ref:H})})}),Xn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
601
601
  date.module.css, injected alongside this sheet) and the .sa-calendar /
602
602
  .sa-calendar-input-* shells for the box + masked input. */
603
603
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "7.0.1",
3
+ "version": "7.0.2",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",