@starasia/date 5.5.0 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/date.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(U,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(U=typeof globalThis<"u"?globalThis:U||self,n(U.Date={},U.jsxRuntime,U.React))})(this,function(U,n,h){"use strict";const an=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
1
+ (function(G,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(G=typeof globalThis<"u"?globalThis:G||self,e(G.Date={},G.jsxRuntime,G.React))})(this,function(G,e,g){"use strict";const sn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
2
2
 
3
3
  * {
4
4
  margin: 0;
@@ -31,6 +31,12 @@
31
31
  position: relative;
32
32
  width: 100%;
33
33
  }
34
+ /* Custom trigger: hug the trigger so the fixed calendar anchors to the actual
35
+ element (not a full-width container) — fixes right-edge flip misalignment. */
36
+ .sa-calendar-wrapper-custom {
37
+ width: max-content;
38
+ max-width: 100%;
39
+ }
34
40
 
35
41
  /* === DATE FIELD WRAPPER === */
36
42
  .sa-date-field {
@@ -588,7 +594,7 @@
588
594
  width: 32px;
589
595
  height: 32px;
590
596
  }
591
- `,yn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Q=["January","February","March","April","May","June","July","August","September","October","November","December"],En=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function un(e){const[a,r]=h.useState(e),o=h.useRef(null),s=d=>{o.current&&!o.current.contains(d.target)&&r(!1)};return h.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:r}}const wn="sa-calendar-input-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(wn)){const a=document.createElement("style");a.id=wn,a.textContent=e,document.head.appendChild(a)}})(an);const R=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},Sn=e=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...l}=e,p=h.useRef(null),f=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=s&&c&&!t,M=S=>{S.stopPropagation(),d==null||d()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:f,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:R(a),height:R(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:M,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:R(a),height:R(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:R(a),height:R(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"})})})]})},Yn=({date:e,setDate:a,dateRange:r,setDateRange:o,onChange:s,minDate:d,maxDate:l,input:p})=>{var T,v,k;const[f,t]=h.useState(null);let c=new Date(e.getFullYear(),e.getMonth(),1),w=c.getDay(),M=[];const S=e.getMonth(),$=new Date().toDateString(),m=!!(r.from&&!r.to),b=m&&f?f:null;for(let g=0;g<42;g++){g===0&&w===0?c.setDate(c.getDate()-7):g===0?c.setDate(c.getDate()+(g-w)):c.setDate(c.getDate()+1);let Y={currentMonth:c.getMonth()===S,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((T=r.from)==null?void 0:T.toDateString())||c.toDateString()===(((v=r.to)==null?void 0:v.toDateString())||((k=r.from)==null?void 0:k.toDateString())),isToday:c.toDateString()===$,year:c.getFullYear(),isDisabled:d&&c<d||l&&c>l};M.push(Y)}const i=g=>{a(g)},N=g=>{let Y={...r};if(Y.from&&Y.to)Y={from:g,to:null};else if(!Y.from)Y={from:g,to:null};else{const A=Y.from.getTime();g.getTime()>A?Y={from:Y.from,to:g}:Y={from:g,to:Y.from}}o(Y),s(Y)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>t(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:yn.map((g,Y)=>n.jsx("p",{children:g},Y))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:M.map((g,Y)=>{const A=r.from&&r.to&&g.date.getTime()>r.from.getTime()&&g.date.getTime()<r.to.getTime(),I=(()=>{if(!b||!r.from)return!1;const E=g.date.getTime(),C=r.from.getTime(),V=b.getTime();return V>C?E>C&&E<V:E<C&&E>V})(),j=m&&f&&g.date.toDateString()===f.toDateString(),z=g.isDisabled,D=()=>A||I?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",x=()=>z?"var(--sa-color-gray-400, #b7b9be)":A||I?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${g.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${g.selected||j?"sa-calendar-days-active":""} ${g.isToday&&!g.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:D(),pointerEvents:z?"none":void 0,cursor:z?"not-allowed":"pointer",color:x(),opacity:j&&!g.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{z||(i(g.date),N(g.date))},onMouseEnter:()=>{z||t(g.date)},children:g.number},Y)})})]})},Ln=({date:e,setDate:a,filter:r,setViews:o,dateRange:s,setDateRange:d,onChange:l,minDate:p,maxDate:f,input:t})=>{var $;const c=($=s.from)==null?void 0:$.getFullYear(),w=e.getFullYear(),M=m=>{r?(S(m),a(m)):(o("days"),a(m))},S=m=>{let b={...s};if(b.from&&b.to)b={from:m,to:null};else if(!b.from)b={from:m,to:null};else{const i=b.from.getTime();m.getTime()>i?b={from:b.from,to:m}:b={from:m,to:b.from}}d(b),l(b)};return n.jsx("div",{className:"sa-calendar-months-preview",children:Q.map((m,b)=>{var T,v,k;const i=s.from!=null&&new Date(w,b).getTime()>s.from.getTime()&&new Date(w,b).getTime()<(((T=s.to)==null?void 0:T.getTime())||s.from.getTime()),N=p&&new Date(w,b)<p||f&&new Date(w,b)>f;return n.jsx("p",{className:c===w&&(b===((v=s.from)==null?void 0:v.getMonth())||b===((k=s.to)==null?void 0:k.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:i?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:N?"none":void 0,cursor:N?"not-allowed":"pointer",color:N?"var(--sa-color-gray-400, #b7b9be)":i?"var(--sa-color-gray-500, #8c8f97)":"",...t?{}:{width:"100%"}},onClick:()=>{N||M(new Date(w,b))},children:m.slice(0,3)},b)})})},fn=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},Fn=({date:e,filter:a,setViews:r,setDate:o,dateRange:s,setDateRange:d,onChange:l,minDate:p,maxDate:f,input:t})=>{var N,T;let c=[];const w=e.getFullYear(),{start:M,end:S}=fn(w),$=(N=s.from)==null?void 0:N.getFullYear(),m=(T=s.to)==null?void 0:T.getFullYear();for(let v=M;v<S;v++){const k=new Date(v,0),g=(!p||k>=p)&&(!f||k<=f),Y=$!=null&&v===$||m!=null&&v===m,A=s.from!=null&&s.to!=null&&k>s.from&&k<s.to;c.push({year:v,active:Y&&g,highlight:A&&g,disabled:!g})}const b=v=>{a?(i(v),o(v)):(o(v),r("months"))},i=v=>{let k={...s};if(k.from&&k.to)k={from:v,to:null};else if(!k.from)k={from:v,to:null};else{const g=k.from.getTime();v.getTime()>g?k={from:k.from,to:v}:k={from:v,to:k.from}}d(k),l(k)};return n.jsx("div",{className:"sa-calendar-years-preview",children:c.map((v,k)=>n.jsx("p",{className:`${v.active?"sa-calendar-months-active":""} ${v.highlight?"sa-calendar-months-highlight":""} ${v.disabled?"sa-calendar-disabled":""}`,onClick:()=>{v.disabled||b(new Date(v.year,0))},style:{backgroundColor:v.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:v.highlight?"var(--sa-color-gray-500, #8c8f97)":v.active?"":v.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:v.disabled?"not-allowed":"pointer",pointerEvents:v.disbled?"none":"all",...t?{}:{width:"100%"}},children:v.year},k))})},xn=({...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"})}),kn=({...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"})}),In=({setViews:e,views:a,filter:r,date:o,setDate:s})=>{const d=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){s(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){s(t=>new Date(t.getFullYear()+1,t.getMonth()));return}s(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){s(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){s(t=>new Date(t.getFullYear()-1,t.getMonth()));return}s(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},f=()=>{if(a==="days")return`${Q[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${fn(o.getFullYear()).start} ~ ${fn(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:f()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(xn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(kn,{})})]})]})};function nn(e){const a=new Date(e),r=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${En[o]} ${r}`}const hn=({label:e,labelPosition:a="outside-top",required:r,optional:o,description:s,helperText:d,errorText:l,fullWidth:p,size:f="sm",children:t})=>{const c=["sa-date-field",`sa-date-field-size-${f}`,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}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,M=n.jsxs(n.Fragment,{children:[d&&!l&&n.jsx("p",{className:"sa-date-field-helper",children:d}),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,s&&n.jsx("p",{className:"sa-date-field-helper-top",children:s})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[t,M]})]}):n.jsxs("div",{className:c,children:[w,s&&n.jsx("p",{className:"sa-date-field-helper-top",children:s}),t,M]}):n.jsxs("div",{className:c,children:[s&&n.jsx("p",{className:"sa-date-field-helper-top",children:s}),t,M]})},Mn="sa-calendar-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(Mn)){const a=document.createElement("style");a.id=Mn,a.textContent=e,document.head.appendChild(a)}})(an);const Tn=h.forwardRef(({value:e,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:l,placeholder:p,size:f="sm",variant:t,status:c,clearable:w,fullWidth:M=!0,withPadding:S=!0,trigger:$,renderTrigger:m,label:b,labelPosition:i,required:N,optional:T,description:v,helperText:k,errorText:g},Y)=>{const A=g?"error":c,{ref:I,isComponentVisible:j,setIsComponentVisible:z}=un(!1),D=h.useRef(null),[x,E]=h.useState("days"),[C,V]=h.useState(new Date),O=typeof m=="function"||$!=null,B=!o&&!O,K=!B,[F,W]=h.useState({from:(e==null?void 0:e.from)??null,to:(e==null?void 0:e.to)??null});h.useEffect(()=>{if(e){const y=e;y.from&&V(y.from),W(y)}else V(new Date),W({from:null,to:null})},[e]),h.useEffect(()=>{r&&E(r)},[r]),h.useEffect(()=>{r||E("days")},[j]),h.useEffect(()=>{B&&z(!0)},[B]);const _=()=>{var y,P;if(!e)return"";if(r){if(x==="days")return`${nn(F.from)} ~ ${nn(F.to||F.from)||"-"}`;if(x==="months")return`${Q[F.from.getMonth()]} ~ ${F.to?Q[F.to.getMonth()]:"-"}`;if(x==="years")return`${(y=F.from)==null?void 0:y.getFullYear()} ~ ${((P=F.to)==null?void 0:P.getFullYear())||"-"}`}else return`${nn(F.from)} ~ ${nn(F.to||F.from)||"-"}`},J=()=>{if(D.current&&I.current&&K){const y=I.current.getBoundingClientRect(),P=D.current.getBoundingClientRect();window.innerWidth<y.left+P.width?D.current.style.left=`${y.left-P.width+y.width}px`:D.current.style.left=`${y.left}px`,y.top+P.height>window.innerHeight?D.current.style.top=`${y.y-(y.height+P.height-28)}px`:D.current.style.top=`${y.y+y.height}px`}};h.useEffect(()=>{D.current&&I.current&&K&&J()},[D,I,j]),h.useEffect(()=>(window.addEventListener("scroll",J,!0),window.addEventListener("resize",J),()=>{window.removeEventListener("scroll",J,!0),window.removeEventListener("resize",J)}),[]);const rn=()=>z(!0),tn=()=>z(!1),G=()=>z(y=>!y),sn={isOpen:j,open:rn,close:tn,toggle:G,value:e,formattedValue:String(_()??""),clear:()=>a(void 0),disabled:s,placeholder:p},on=()=>{if(typeof m=="function")return m(sn);if(h.isValidElement($)){const y=$;return h.cloneElement(y,{onClick:P=>{var q,X;(X=(q=y.props)==null?void 0:q.onClick)==null||X.call(q,P),s||G()}})}return $},ln=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:B?"100%":"auto"},ref:K?I:null,children:[O?on():o?n.jsx(Sn,{value:_(),inputMode:"none",onClick:()=>{z(!0)},onChange:()=>{},disabled:s,placeholder:p,size:f,variant:t,status:A,clearable:w,onClear:()=>a(void 0)}):null,j?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${f||"sm"} ${B?"sa-calendar-no-input":""} ${S?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:D,children:[n.jsx(In,{setViews:E,views:x,filter:r,date:C,setDate:V}),n.jsx("div",{className:"sa-calendar-body",children:x==="days"?n.jsx(Yn,{date:C,setDate:V,setIsComponentVisible:z,dateRange:F,setDateRange:W,input:o,onChange:a,minDate:d,maxDate:l}):x==="months"?n.jsx(Ln,{date:C,setDate:V,filter:r,setViews:E,dateRange:F,setDateRange:W,setIsComponentVisible:z,input:o,onChange:a,minDate:d,maxDate:l}):n.jsx(Fn,{date:C,setDate:V,filter:r,setViews:E,dateRange:F,setDateRange:W,setIsComponentVisible:z,input:o,onChange:a,minDate:d,maxDate:l})})]}):null]});return n.jsx(hn,{label:b,labelPosition:i,required:N,optional:T,description:v,helperText:k,errorText:g,fullWidth:M,size:f,children:ln})}),Nn="sa-calendar-input-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(Nn)){const a=document.createElement("style");a.id=Nn,a.textContent=e,document.head.appendChild(a)}})(an);const en=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},Vn=e=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...l}=e,p=h.useRef(null),f=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=s&&c&&!t,M=S=>{S.stopPropagation(),d==null||d()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:f,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:en(a),height:en(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:M,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:en(a),height:en(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:en(a),height:en(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"})})})]})},Bn=({date:e,setDate:a,previewDate:r,setPreviewDate:o,setIsComponentVisible:s,minDate:d,maxDate:l,input:p,onChange:f,hasValue:t})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),w=c.getDay(),M=[];const S=e.toDateString(),$=new Date().toDateString(),m=r.getMonth();for(let i=0;i<42;i++){i===0&&w===0?c.setDate(c.getDate()-7):i===0?c.setDate(c.getDate()+(i-w)):c.setDate(c.getDate()+1);let N={currentMonth:c.getMonth()===m,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:t&&c.toDateString()===S,isToday:c.toDateString()===$,year:c.getFullYear(),isDisabled:d&&c<d||l&&c>l};M.push(N)}const b=i=>{(!d||i>=d)&&(!l||i<=l)&&(a(i),f(i),o(i),p&&s(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:yn.map((i,N)=>n.jsx("p",{children:i},N))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:M.map((i,N)=>{const T=i.isDisabled;return n.jsx("p",{className:`${i.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${i.selected?"sa-calendar-days-active":""} ${i.isToday&&!i.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||b(i.date)},children:i.number},N)})})]})},Pn=({date:e,setDate:a,filter:r,setViews:o,onChange:s,previewDate:d,setPreviewDate:l,minDate:p,maxDate:f,input:t,hasValue:c})=>{const w=e.getMonth(),M=e.getFullYear(),S=d.getFullYear(),$=m=>{(!p||m>=p)&&(!f||m<=f)&&(r?(s(m),a(m),l(m)):(o("days"),l(m)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:Q.map((m,b)=>{const i=p&&new Date(S,b,1)<p||f&&new Date(S,b+1,0)>f;return n.jsx("p",{className:c&&b===w&&S===M?"sa-calendar-months-active":"",style:{color:i?"#ccc":void 0,pointerEvents:i?"none":void 0,cursor:i?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{i||$(new Date(S,b))},children:m.slice(0,3)},b)})})},gn=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},jn=({date:e,filter:a,setViews:r,setDate:o,onChange:s,previewDate:d,setPreviewDate:l,minDate:p,maxDate:f,input:t,hasValue:c})=>{let w=[];const M=d.getFullYear(),{start:S,end:$}=gn(M),m=e.getFullYear();for(let i=S;i<$;i++){let N=p&&new Date(i,0,1)<p||f&&new Date(i,11,31)>f;w.push({year:i,active:!!c&&i===m,isDisabled:N})}const b=i=>{(!p||i>=p)&&(!f||i<=f)&&(a?(s(i),o(i),l(i)):(r("months"),l(i)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:w.map((i,N)=>n.jsx("p",{className:i.active?"sa-calendar-months-active":"",style:{color:i.isDisabled?"#ccc":void 0,pointerEvents:i.isDisabled?"none":void 0,cursor:i.isDisabled?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{i.isDisabled||b(new Date(i.year,0))},children:i.year},N))})},An=({setViews:e,views:a,filter:r,previewDate:o,setPreviewDate:s})=>{const d=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){s(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){s(t=>new Date(t.getFullYear()+1,t.getMonth()));return}s(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){s(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){s(t=>new Date(t.getFullYear()-1,t.getMonth()));return}s(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},f=()=>{if(a==="days")return`${Q[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${gn(o.getFullYear()).start} ~ ${gn(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:f()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(xn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(kn,{})})]})]})},Cn="sa-calendar-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(Cn)){const a=document.createElement("style");a.id=Cn,a.textContent=e,document.head.appendChild(a)}})(an);const On=h.forwardRef(({value:e,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:l,placeholder:p,size:f="sm",variant:t,status:c,clearable:w,fullWidth:M=!0,withPadding:S=!0,trigger:$,renderTrigger:m,label:b,labelPosition:i,required:N,optional:T,description:v,helperText:k,errorText:g},Y)=>{const A=g?"error":c,{ref:I,isComponentVisible:j,setIsComponentVisible:z}=un(!1),D=h.useRef(null),[x,E]=h.useState("days"),[C,V]=h.useState(new Date),[O,B]=h.useState(new Date),K=typeof m=="function"||$!=null,F=!o&&!K,W=!F;h.useEffect(()=>{e?(V(e),B(e)):(V(new Date),B(new Date))},[e]),h.useEffect(()=>{r&&E(r)},[r]),h.useEffect(()=>{r||E("days")},[j]),h.useEffect(()=>{F&&z(!0)},[F]);const _=()=>e?r==="days"?nn(C):r==="months"?`${Q[C.getMonth()]} ${C.getFullYear()}`:r==="years"?C.getFullYear():nn(C):"",J=()=>{if(D.current&&I.current&&W){const y=I.current.getBoundingClientRect(),P=D.current.getBoundingClientRect();window.innerWidth<y.left+P.width?D.current.style.left=`${y.left-P.width+y.width}px`:D.current.style.left=`${y.left}px`,y.top+P.height>window.innerHeight?D.current.style.top=`${y.y-(y.height+P.height-28)}px`:D.current.style.top=`${y.y+y.height}px`}};h.useEffect(()=>{D.current&&I.current&&W&&J()},[D,I,j]),h.useEffect(()=>(window.addEventListener("scroll",J,!0),window.addEventListener("resize",J),()=>{window.removeEventListener("scroll",J,!0),window.removeEventListener("resize",J)}),[]);const rn=()=>z(!0),tn=()=>z(!1),G=()=>z(y=>!y),sn={isOpen:j,open:rn,close:tn,toggle:G,value:e,formattedValue:String(_()??""),clear:()=>a(void 0),disabled:s,placeholder:p},on=()=>{if(typeof m=="function")return m(sn);if(h.isValidElement($)){const y=$;return h.cloneElement(y,{onClick:P=>{var q,X;(X=(q=y.props)==null?void 0:q.onClick)==null||X.call(q,P),s||G()}})}return $},ln=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:F?"100%":"auto"},ref:W?I:null,children:[K?on():o?n.jsx(Vn,{value:_(),onClick:()=>z(!0),onChange:()=>{},placeholder:p,disabled:s,size:f,variant:t,status:A,inputMode:"none",clearable:w,onClear:()=>a(void 0)}):null,j?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${f||"sm"} ${F?"sa-calendar-no-input":""} ${S?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:D,children:[n.jsx(An,{setViews:E,views:x,filter:r,previewDate:O,setPreviewDate:B,isComponentVisible:j}),n.jsx("div",{className:"sa-calendar-body",children:x==="days"?n.jsx(Bn,{date:C,setDate:V,previewDate:O,setPreviewDate:B,setIsComponentVisible:z,input:o,minDate:d,maxDate:l,onChange:a,hasValue:e!=null}):x==="months"?n.jsx(Pn,{date:C,setDate:V,previewDate:O,setPreviewDate:B,filter:r,setViews:E,onChange:a,minDate:d,maxDate:l,input:o,hasValue:e!=null}):n.jsx(jn,{date:C,setDate:V,previewDate:O,setPreviewDate:B,filter:r,setViews:E,onChange:a,minDate:d,maxDate:l,input:o,hasValue:e!=null})})]}):null]});return n.jsx(hn,{label:b,labelPosition:i,required:N,optional:T,description:v,helperText:k,errorText:g,fullWidth:M,size:f,children:ln})}),Hn=h.forwardRef(({value:e,onChange:a,filter:r,input:o=!0,rangedDate:s,disabled:d,minDate:l,maxDate:p,placeholder:f,size:t,variant:c,status:w,clearable:M,fullWidth:S,withPadding:$,trigger:m,renderTrigger:b,label:i,labelPosition:N,required:T,optional:v,description:k,helperText:g,errorText:Y},A)=>{const I={onChange:a,value:e,input:o,filter:r,disabled:d,minDate:l,maxDate:p,placeholder:f,size:t,variant:c,status:w,clearable:M,fullWidth:S,withPadding:$,trigger:m,renderTrigger:b,label:i,labelPosition:N,required:T,optional:v,description:k,helperText:g,errorText:Y};return n.jsx(n.Fragment,{children:s?n.jsx(Tn,{...I,ref:A}):n.jsx(On,{...I,ref:A})})}),Wn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
597
+ `,$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 q=N.from.getTime();m.getTime()>q?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 q=r.from&&r.to&&m.date.getTime()>r.from.getTime()&&m.date.getTime()<r.to.getTime(),A=(()=>{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})(),B=y&&h&&m.date.toDateString()===h.toDateString(),F=m.isDisabled,D=()=>q||A?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",b=()=>F?"var(--sa-color-gray-400, #b7b9be)":q||A?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${m.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${m.selected||B?"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:B&&!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,q=s.from!=null&&s.to!=null&&M>s.from&&M<s.to;c.push({year:w,active:N&&m,highlight:q&&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},q)=>{const A=N?"error":c,{ref:B,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),H=typeof v=="function"||y!=null,j=!o&&!H,W=!j,[z,J]=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),J(t)}else I(new Date),J({from:null,to:null});U(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{j&&D(!0)},[j]);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)||"-"}`},P=()=>{if(b.current&&B.current&&W){const t=B.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&&B.current&&W&&P()},[b,B,F]),g.useEffect(()=>(window.addEventListener("scroll",P,!0),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,!0),window.removeEventListener("resize",P)}),[]);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),V=f&&wn(f.from,d,i)&&(!f.to||wn(f.to,d,i));f&&V&&(a(f),J(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 V,en;(en=(V=t.props)==null?void 0:V.onClick)==null||en.call(V,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${H?" sa-calendar-wrapper-custom":""}`,style:{height:j?"100%":"auto"},ref:W?B:null,children:[H?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:A,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${j?"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:J,input:o,onChange:a,minDate:d,maxDate:i}):S==="months"?e.jsx(jn,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:J,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i}):e.jsx(On,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:J,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},q)=>{const A=N?"error":c,{ref:B,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),[H,j]=g.useState(new Date),[W,z]=g.useState(null),J=typeof v=="function"||y!=null,K=!o&&!J,U=!K;g.useEffect(()=>{n?(I(n),j(n)):(I(new Date),j(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):"",P=()=>{if(b.current&&B.current&&U){const t=B.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&&B.current&&U&&P()},[b,B,F]),g.useEffect(()=>(window.addEventListener("scroll",P,!0),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,!0),window.removeEventListener("resize",P)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&z(n?yn(n,r):"")},R=()=>{if(W===null)return;const t=W.trim();if(!t){a(void 0),z(null);return}const f=fn(t,r);f&&wn(f,d,i)&&(a(f),I(f),j(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 V,en;(en=(V=t.props)==null?void 0:V.onClick)==null||en.call(V,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${J?" sa-calendar-wrapper-custom":""}`,style:{height:K?"100%":"auto"},ref:U?B:null,children:[J?nn():o?e.jsx(qn,{value:k&&W!==null?W: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:A,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:H,setPreviewDate:j,isComponentVisible:F}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Kn,{date:L,setDate:I,previewDate:H,setPreviewDate:j,setIsComponentVisible:D,input:o,minDate:d,maxDate:i,onChange:a,hasValue:n!=null}):S==="months"?e.jsx(Un,{date:L,setDate:I,previewDate:H,setPreviewDate:j,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null}):e.jsx(Gn,{date:L,setDate:I,previewDate:H,setPreviewDate:j,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:q},A)=>{const B={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:q};return e.jsx(e.Fragment,{children:s?e.jsx(Jn,{...B,ref:A}):e.jsx(_n,{...B,ref:A})})}),Xn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
592
598
  date.module.css, injected alongside this sheet) and the .sa-calendar /
593
599
  .sa-calendar-input-* shells for the box + masked input. */
594
600
 
@@ -719,4 +725,4 @@
719
725
  .sa-time-input-wrap {
720
726
  width: 100%;
721
727
  }
722
- `,bn=(e,a,r)=>Math.min(r,Math.max(a,e)),H=e=>String(e).padStart(2,"0"),vn=e=>{if(!e)return null;const a=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(e.trim());if(!a)return null;const r=Number(a[1]),o=Number(a[2]),s=a[3]!=null?Number(a[3]):0;return r>23||o>59||s>59?null:{h:r,m:o,s}},Jn=(e,a)=>a?`${H(e.h)}:${H(e.m)}:${H(e.s)}`:`${H(e.h)}:${H(e.m)}`,Z=e=>e.h*60+e.m,qn=(e,a,r)=>{const o=r?`:${H(e.s)}`:"";if(a==="12h"){const s=e.h>=12?"PM":"AM",d=e.h%12===0?12:e.h%12;return`${H(d)}:${H(e.m)}${o} ${s}`}return`${H(e.h)}:${H(e.m)}${o}`},Gn=(e,a,r)=>{const o=e.toLowerCase(),s=/p/.test(o)?"pm":/a/.test(o)?"am":null,d=o.replace(/[^\d]/g,"");if(!d)return null;let l=0,p=0,f=0;if(e.includes(":")){const t=e.split(":").map(c=>c.replace(/[^\d]/g,""));l=Number(t[0]||0),p=Number(t[1]||0),f=r?Number(t[2]||0):0}else d.length<=2?l=Number(d):d.length<=4?(l=Number(d.slice(0,d.length-2)),p=Number(d.slice(-2))):(l=Number(d.slice(0,d.length-4)),p=Number(d.slice(-4,-2)),f=r?Number(d.slice(-2)):0);return s&&(s==="pm"&&l<12&&(l+=12),s==="am"&&l===12&&(l=0)),l>23||p>59||f>59?null:{h:bn(l,0,23),m:bn(p,0,59),s:bn(f,0,59)}},cn=(e,a=1)=>{const r=[];for(let o=0;o<e;o+=a)r.push(o);return r},$n=(e,a)=>{if(typeof document>"u"||document.getElementById(e))return;const r=document.createElement("style");r.id=e,r.textContent=a,document.head.appendChild(r)};$n("sa-calendar-styles",an),$n("sa-time-styles",Wn);const Un=e=>e==="xs"?14:e==="lg"?20:16,zn=({s:e})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M10 5v5l3 2M17.5 10a7.5 7.5 0 1 1-15 0 7.5 7.5 0 0 1 15 0Z",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Zn=({s:e})=>n.jsx("svg",{width:e,height:e,viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round"})}),pn=({label:e,options:a,active:r,onPick:o})=>{const s=h.useRef(null),d=h.useRef(null);return h.useEffect(()=>{var l;(l=d.current)==null||l.scrollIntoView({block:"nearest"})},[r]),n.jsxs("div",{className:"sa-time-col",children:[n.jsx("div",{className:"sa-time-col-head",children:e}),n.jsx("div",{className:"sa-time-col-list",ref:s,children:a.map(l=>{const p=l.value===r;return n.jsx("button",{type:"button",ref:p?d:null,disabled:l.disabled,className:`sa-time-opt${p?" sa-time-opt-active":""}`,onClick:()=>o(l.value),children:l.label},l.value)})})]})},Dn=h.forwardRef(({value:e,onChange:a,format:r="24h",withSeconds:o=!1,step:s=1,minTime:d,maxTime:l,input:p=!0,placeholder:f="--:--",disabled:t,clearable:c,size:w="sm",variant:M="outline",status:S,fullWidth:$=!0,withPadding:m=!0,label:b,labelPosition:i,required:N,optional:T,description:v,helperText:k,errorText:g},Y)=>{const A=g?"error":S,{ref:I,isComponentVisible:j,setIsComponentVisible:z}=un(!1),D=h.useRef(null),x=h.useMemo(()=>vn(e),[e]),E=h.useMemo(()=>vn(d),[d]),C=h.useMemo(()=>vn(l),[l]),[V,O]=h.useState(null);h.useEffect(()=>{p||z(!0)},[p]);const B=()=>{if(!D.current||!I.current||!p)return;const u=I.current.getBoundingClientRect(),L=D.current.getBoundingClientRect();D.current.style.left=window.innerWidth<u.left+L.width?`${u.left-L.width+u.width}px`:`${u.left}px`,D.current.style.top=u.top+L.height>window.innerHeight?`${u.y-(u.height+L.height-28)}px`:`${u.y+u.height}px`};h.useEffect(()=>{B()},[j]),h.useEffect(()=>(window.addEventListener("scroll",B,!0),window.addEventListener("resize",B),()=>{window.removeEventListener("scroll",B,!0),window.removeEventListener("resize",B)}),[]);const K=u=>{const L=Z(u);return!(E&&L<Z(E)||C&&L>Z(C))},F=u=>{a(Jn(u,o)),O(null)},W=u=>{F({...x??{h:0,m:0,s:0},...u})},_=()=>{if(V==null)return;if(V.trim()===""){a(null),O(null);return}const u=Gn(V,r,o);u&&K(u)?F(u):O(null)},J=x?qn(x,r,o):"",rn=V??J,tn=c&&!!x&&!t,G=x&&x.h>=12?"PM":"AM",sn=h.useMemo(()=>r==="12h"?cn(12).map(u=>{const L=u===0?12:u,dn=G==="PM"?L%12+12:L%12;return{value:L,label:H(L),disabled:E&&dn*60+59<Z(E)||C&&dn*60>Z(C)||!1}}):cn(24).map(u=>({value:u,label:H(u),disabled:E&&u*60+59<Z(E)||C&&u*60>Z(C)||!1})),[r,G,E,C]),on=h.useMemo(()=>{const u=(x==null?void 0:x.h)??0;return cn(60,s).map(L=>({value:L,label:H(L),disabled:E&&u*60+L<Z(E)||C&&u*60+L>Z(C)||!1}))},[s,x==null?void 0:x.h,E,C]),ln=h.useMemo(()=>cn(60).map(u=>({value:u,label:H(u)})),[]),y=x==null?null:r==="12h"?x.h%12===0?12:x.h%12:x.h,P=u=>{if(r==="12h"){const L=G==="PM"?u%12+12:u%12;W({h:L})}else W({h:u})},q=u=>{const L=x??{h:0,m:0,s:0},dn=L.h%12===0?12:L.h%12,_n=u==="PM"?dn%12+12:dn%12;F({...L,h:_n})},X=()=>{const u=new Date,L=Math.floor(u.getMinutes()/s)*s;F({h:u.getHours(),m:L,s:o?u.getSeconds():0})},mn=Un(w),Kn=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:p?"auto":"100%"},ref:p?I:null,children:[p?n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${M} sa-calendar-input-container-${A||"default"} ${w}`,onClick:()=>!t&&z(!0),children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx(zn,{s:mn})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",value:rn,placeholder:f,disabled:t,onChange:u=>O(u.target.value),onFocus:()=>z(!0),onBlur:_,onKeyDown:u=>{u.key==="Enter"&&(_(),z(!1)),u.key==="Escape"&&(O(null),z(!1))}})}),tn?n.jsx("button",{type:"button","aria-label":"Clear time",className:"sa-calendar-input-clear",onClick:u=>{u.stopPropagation(),a(null),O(null)},children:n.jsx(Zn,{s:mn})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx(zn,{s:mn})})]}):null,j?n.jsxs("div",{ref:D,className:`sa-calendar sa-calendar-size-${w} ${p?"":"sa-calendar-no-input"} ${m?"":"sa-calendar-no-padding"}`,style:t?{pointerEvents:"none"}:void 0,children:[n.jsxs("div",{className:"sa-time-columns",children:[n.jsx(pn,{label:"Jam",options:sn,active:y,onPick:P}),n.jsx("div",{className:"sa-time-divider"}),n.jsx(pn,{label:"Menit",options:on,active:(x==null?void 0:x.m)??null,onPick:u=>W({m:u})}),o&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"sa-time-divider"}),n.jsx(pn,{label:"Detik",options:ln,active:(x==null?void 0:x.s)??null,onPick:u=>W({s:u})})]}),r==="12h"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"sa-time-divider"}),n.jsx(pn,{label:"",options:[{value:0,label:"AM"},{value:1,label:"PM"}],active:x==null?null:G==="PM"?1:0,onPick:u=>q(u===1?"PM":"AM")})]})]}),n.jsxs("div",{className:"sa-time-footer",children:[n.jsx("button",{type:"button",className:"sa-time-footer-btn",onClick:X,children:"Sekarang"}),n.jsx("button",{type:"button",className:"sa-time-footer-btn sa-time-footer-btn-muted",onClick:()=>{a(null),O(null)},children:"Hapus"})]})]}):null]});return n.jsx(hn,{label:b,labelPosition:i,required:N,optional:T,description:v,helperText:k,errorText:g,fullWidth:$,size:w,children:Kn})});Dn.displayName="StarasiaTime",U.StarasiaDate=Hn,U.StarasiaTime=Dn,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
728
+ `,Mn=(n,a,r)=>Math.min(r,Math.max(a,n)),O=n=>String(n).padStart(2,"0"),Nn=n=>{if(!n)return null;const a=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(n.trim());if(!a)return null;const r=Number(a[1]),o=Number(a[2]),s=a[3]!=null?Number(a[3]):0;return r>23||o>59||s>59?null:{h:r,m:o,s}},Rn=(n,a)=>a?`${O(n.h)}:${O(n.m)}:${O(n.s)}`:`${O(n.h)}:${O(n.m)}`,Z=n=>n.h*60+n.m,ne=(n,a,r)=>{const o=r?`:${O(n.s)}`:"";if(a==="12h"){const s=n.h>=12?"PM":"AM",d=n.h%12===0?12:n.h%12;return`${O(d)}:${O(n.m)}${o} ${s}`}return`${O(n.h)}:${O(n.m)}${o}`},ee=(n,a,r)=>{const o=n.toLowerCase(),s=/p/.test(o)?"pm":/a/.test(o)?"am":null,d=o.replace(/[^\d]/g,"");if(!d)return null;let i=0,p=0,h=0;if(n.includes(":")){const l=n.split(":").map(c=>c.replace(/[^\d]/g,""));i=Number(l[0]||0),p=Number(l[1]||0),h=r?Number(l[2]||0):0}else d.length<=2?i=Number(d):d.length<=4?(i=Number(d.slice(0,d.length-2)),p=Number(d.slice(-2))):(i=Number(d.slice(0,d.length-4)),p=Number(d.slice(-4,-2)),h=r?Number(d.slice(-2)):0);return s&&(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0)),i>23||p>59||h>59?null:{h:Mn(i,0,23),m:Mn(p,0,59),s:Mn(h,0,59)}},hn=(n,a=1)=>{const r=[];for(let o=0;o<n;o+=a)r.push(o);return r},Ln=(n,a)=>{if(typeof document>"u"||document.getElementById(n))return;const r=document.createElement("style");r.id=n,r.textContent=a,document.head.appendChild(r)};Ln("sa-calendar-styles",sn),Ln("sa-time-styles",Xn);const ae=n=>n==="xs"?14:n==="lg"?20:16,In=({s:n})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M10 5v5l3 2M17.5 10a7.5 7.5 0 1 1-15 0 7.5 7.5 0 0 1 15 0Z",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),re=({s:n})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round"})}),gn=({label:n,options:a,active:r,onPick:o})=>{const s=g.useRef(null),d=g.useRef(null);return g.useEffect(()=>{var i;(i=d.current)==null||i.scrollIntoView({block:"nearest"})},[r]),e.jsxs("div",{className:"sa-time-col",children:[e.jsx("div",{className:"sa-time-col-head",children:n}),e.jsx("div",{className:"sa-time-col-list",ref:s,children:a.map(i=>{const p=i.value===r;return e.jsx("button",{type:"button",ref:p?d:null,disabled:i.disabled,className:`sa-time-opt${p?" sa-time-opt-active":""}`,onClick:()=>o(i.value),children:i.label},i.value)})})]})},Tn=g.forwardRef(({value:n,onChange:a,format:r="24h",withSeconds:o=!1,step:s=1,minTime:d,maxTime:i,input:p=!0,placeholder:h="--:--",disabled:l,clearable:c,size:x="sm",variant:$="outline",status:E,fullWidth:k=!0,withPadding:y=!0,label:v,labelPosition:u,required:C,optional:T,description:w,helperText:M,errorText:m},N)=>{const q=m?"error":E,{ref:A,isComponentVisible:B,setIsComponentVisible:F}=vn(!1),D=g.useRef(null),b=g.useMemo(()=>Nn(n),[n]),S=g.useMemo(()=>Nn(d),[d]),Y=g.useMemo(()=>Nn(i),[i]),[L,I]=g.useState(null);g.useEffect(()=>{p||F(!0)},[p]);const H=()=>{if(!D.current||!A.current||!p)return;const t=A.current.getBoundingClientRect(),f=D.current.getBoundingClientRect();D.current.style.left=window.innerWidth<t.left+f.width?`${t.left-f.width+t.width}px`:`${t.left}px`,D.current.style.top=t.top+f.height>window.innerHeight?`${t.y-(t.height+f.height-28)}px`:`${t.y+t.height}px`};g.useEffect(()=>{H()},[B]),g.useEffect(()=>(window.addEventListener("scroll",H,!0),window.addEventListener("resize",H),()=>{window.removeEventListener("scroll",H,!0),window.removeEventListener("resize",H)}),[]);const j=t=>{const f=Z(t);return!(S&&f<Z(S)||Y&&f>Z(Y))},W=t=>{a(Rn(t,o)),I(null)},z=t=>{W({...b??{h:0,m:0,s:0},...t})},J=()=>{if(L==null)return;if(L.trim()===""){a(null),I(null);return}const t=ee(L,r,o);t&&j(t)?W(t):I(null)},K=b?ne(b,r,o):"",U=L??K,Q=c&&!!b&&!l,P=b&&b.h>=12?"PM":"AM",on=g.useMemo(()=>r==="12h"?hn(12).map(t=>{const f=t===0?12:t,V=P==="PM"?f%12+12:f%12;return{value:f,label:O(f),disabled:S&&V*60+59<Z(S)||Y&&V*60>Z(Y)||!1}}):hn(24).map(t=>({value:t,label:O(t),disabled:S&&t*60+59<Z(S)||Y&&t*60>Z(Y)||!1})),[r,P,S,Y]),ln=g.useMemo(()=>{const t=(b==null?void 0:b.h)??0;return hn(60,s).map(f=>({value:f,label:O(f),disabled:S&&t*60+f<Z(S)||Y&&t*60+f>Z(Y)||!1}))},[s,b==null?void 0:b.h,S,Y]),X=g.useMemo(()=>hn(60).map(t=>({value:t,label:O(t)})),[]),dn=b==null?null:r==="12h"?b.h%12===0?12:b.h%12:b.h,R=t=>{if(r==="12h"){const f=P==="PM"?t%12+12:t%12;z({h:f})}else z({h:t})},cn=t=>{const f=b??{h:0,m:0,s:0},V=f.h%12===0?12:f.h%12,en=t==="PM"?V%12+12:V%12;W({...f,h:en})},un=()=>{const t=new Date,f=Math.floor(t.getMinutes()/s)*s;W({h:t.getHours(),m:f,s:o?t.getSeconds():0})},nn=ae(x),pn=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:p?"auto":"100%"},ref:p?A:null,children:[p?e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${$} sa-calendar-input-container-${q||"default"} ${x}`,onClick:()=>!l&&F(!0),children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx(In,{s:nn})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",value:U,placeholder:h,disabled:l,onChange:t=>I(t.target.value),onFocus:()=>F(!0),onBlur:J,onKeyDown:t=>{t.key==="Enter"&&(J(),F(!1)),t.key==="Escape"&&(I(null),F(!1))}})}),Q?e.jsx("button",{type:"button","aria-label":"Clear time",className:"sa-calendar-input-clear",onClick:t=>{t.stopPropagation(),a(null),I(null)},children:e.jsx(re,{s:nn})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx(In,{s:nn})})]}):null,B?e.jsxs("div",{ref:D,className:`sa-calendar sa-calendar-size-${x} ${p?"":"sa-calendar-no-input"} ${y?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,children:[e.jsxs("div",{className:"sa-time-columns",children:[e.jsx(gn,{label:"Jam",options:on,active:dn,onPick:R}),e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"Menit",options:ln,active:(b==null?void 0:b.m)??null,onPick:t=>z({m:t})}),o&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"Detik",options:X,active:(b==null?void 0:b.s)??null,onPick:t=>z({s:t})})]}),r==="12h"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"",options:[{value:0,label:"AM"},{value:1,label:"PM"}],active:b==null?null:P==="PM"?1:0,onPick:t=>cn(t===1?"PM":"AM")})]})]}),e.jsxs("div",{className:"sa-time-footer",children:[e.jsx("button",{type:"button",className:"sa-time-footer-btn",onClick:un,children:"Sekarang"}),e.jsx("button",{type:"button",className:"sa-time-footer-btn sa-time-footer-btn-muted",onClick:()=>{a(null),I(null)},children:"Hapus"})]})]}):null]});return e.jsx(xn,{label:v,labelPosition:u,required:C,optional:T,description:w,helperText:M,errorText:m,fullWidth:k,size:x,children:pn})});Tn.displayName="StarasiaTime",G.StarasiaDate=Qn,G.StarasiaTime=Tn,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})});
@@ -41,6 +41,15 @@ export interface IDateProps {
41
41
  clearable?: boolean;
42
42
  fullWidth?: boolean;
43
43
  withPadding?: boolean;
44
+ /**
45
+ * Allow typing the date directly in the field (hybrid). On focus the field
46
+ * switches to a numeric editable form (`DD/MM/YYYY`, `MM/YYYY`, or `YYYY`
47
+ * per `filter`; `from ~ to` when ranged) and re-formats to the pretty form
48
+ * on blur. Parsing is lenient (accepts `/ . -` separators and month names).
49
+ * Invalid input reverts to the last committed value. Default `false`.
50
+ * Ignored when a custom `trigger`/`renderTrigger` is used.
51
+ */
52
+ editable?: boolean;
44
53
  /**
45
54
  * Custom trigger element rendered in place of the built-in input. It is
46
55
  * cloned with an injected `onClick` that toggles the calendar (popup mode);
@@ -1 +1,27 @@
1
1
  export declare function formatDateByDDMMYYYY(inputDate: Date): string;
2
+ type Filter = "days" | "months" | "years";
3
+ /** Numeric editable form shown on focus. */
4
+ export declare function formatEditableDate(date: Date, filter?: Filter): string;
5
+ export declare function formatEditableRange(range: {
6
+ from: Date | null;
7
+ to: Date | null;
8
+ }, filter?: Filter): string;
9
+ /**
10
+ * Lenient single-date parser. Accepts numeric ("13/07/2026", "13-7-26",
11
+ * "13.07.2026", "13 07 2026") and month-name ("13 Jul 2026", "13 july 26")
12
+ * forms. Respects `filter` granularity. Returns a Date at local midnight, or
13
+ * `null` when the text can't be parsed / is an impossible calendar date.
14
+ */
15
+ export declare function parseLooseDate(text: string, filter?: Filter): Date | null;
16
+ /**
17
+ * Lenient range parser. Splits on "~" (the display separator). A single date
18
+ * with no separator becomes `{from, to: null}`. Returns `null` when `from`
19
+ * can't be parsed.
20
+ */
21
+ export declare function parseLooseRange(text: string, filter?: Filter): {
22
+ from: Date;
23
+ to: Date | null;
24
+ } | null;
25
+ /** Inclusive day-level bounds check. */
26
+ export declare function isWithinBounds(date: Date, minDate?: Date, maxDate?: Date): boolean;
27
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",