@starasia/date 5.4.2 → 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.es.js +935 -782
- package/dist/date.umd.js +9 -3
- package/dist/interfaces.d.ts +48 -0
- package/dist/utils/functions.d.ts +26 -0
- package/package.json +1 -1
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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
|
-
`,ln=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],J=["January","February","March","April","May","June","July","August","September","October","November","December"],yn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function nn(e){const[a,r]=b.useState(e),s=b.useRef(null),o=i=>{s.current&&!s.current.contains(i.target)&&r(!1)};return b.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:r}}const dn="sa-calendar-input-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(dn)){const a=document.createElement("style");a.id=dn,a.textContent=e,document.head.appendChild(a)}})(Z);const q=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},wn=e=>{const{size:a="sm",status:r="default",variant:s="outline",clearable:o,onClear:i,...l}=e,p=b.useRef(null),h=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=o&&c&&!t,C=D=>{D.stopPropagation(),i==null||i()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:q(a),height:q(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...l,disabled:t,value:l.value,ref:p})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:q(a),height:q(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:q(a),height:q(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},xn=({date:e,setDate:a,dateRange:r,setDateRange:s,onChange:o,minDate:i,maxDate:l,input:p})=>{var F,g,M;const[h,t]=b.useState(null);let c=new Date(e.getFullYear(),e.getMonth(),1),w=c.getDay(),C=[];const D=e.getMonth(),L=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let f=0;f<42;f++){f===0&&w===0?c.setDate(c.getDate()-7):f===0?c.setDate(c.getDate()+(f-w)):c.setDate(c.getDate()+1);let x={currentMonth:c.getMonth()===D,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((F=r.from)==null?void 0:F.toDateString())||c.toDateString()===(((g=r.to)==null?void 0:g.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===L,year:c.getFullYear(),isDisabled:i&&c<i||l&&c>l};C.push(x)}const d=f=>{a(f)},$=f=>{let x={...r};if(x.from&&x.to)x={from:f,to:null};else if(!x.from)x={from:f,to:null};else{const B=x.from.getTime();f.getTime()>B?x={from:x.from,to:f}:x={from:f,to:x.from}}s(x),o(x)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>t(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:ln.map((f,x)=>n.jsx("p",{children:f},x))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((f,x)=>{const B=r.from&&r.to&&f.date.getTime()>r.from.getTime()&&f.date.getTime()<r.to.getTime(),P=(()=>{if(!v||!r.from)return!1;const z=f.date.getTime(),k=r.from.getTime(),I=v.getTime();return I>k?z>k&&z<I:z<k&&z>I})(),Y=y&&h&&f.date.toDateString()===h.toDateString(),S=f.isDisabled,T=()=>B||P?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",m=()=>S?"var(--sa-color-gray-400, #b7b9be)":B||P?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${f.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${f.selected||Y?"sa-calendar-days-active":""} ${f.isToday&&!f.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:T(),pointerEvents:S?"none":void 0,cursor:S?"not-allowed":"pointer",color:m(),opacity:Y&&!f.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{S||(d(f.date),$(f.date))},onMouseEnter:()=>{S||t(f.date)},children:f.number},x)})})]})},kn=({date:e,setDate:a,filter:r,setViews:s,dateRange:o,setDateRange:i,onChange:l,minDate:p,maxDate:h,input:t})=>{var L;const c=(L=o.from)==null?void 0:L.getFullYear(),w=e.getFullYear(),C=y=>{r?(D(y),a(y)):(s("days"),a(y))},D=y=>{let v={...o};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const d=v.from.getTime();y.getTime()>d?v={from:v.from,to:y}:v={from:y,to:v.from}}i(v),l(v)};return n.jsx("div",{className:"sa-calendar-months-preview",children:J.map((y,v)=>{var F,g,M;const d=o.from!=null&&new Date(w,v).getTime()>o.from.getTime()&&new Date(w,v).getTime()<(((F=o.to)==null?void 0:F.getTime())||o.from.getTime()),$=p&&new Date(w,v)<p||h&&new Date(w,v)>h;return n.jsx("p",{className:c===w&&(v===((g=o.from)==null?void 0:g.getMonth())||v===((M=o.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",color:$?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...t?{}:{width:"100%"}},onClick:()=>{$||C(new Date(w,v))},children:y.slice(0,3)},v)})})},en=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},Mn=({date:e,filter:a,setViews:r,setDate:s,dateRange:o,setDateRange:i,onChange:l,minDate:p,maxDate:h,input:t})=>{var $,F;let c=[];const w=e.getFullYear(),{start:C,end:D}=en(w),L=($=o.from)==null?void 0:$.getFullYear(),y=(F=o.to)==null?void 0:F.getFullYear();for(let g=C;g<D;g++){const M=new Date(g,0),f=(!p||M>=p)&&(!h||M<=h),x=L!=null&&g===L||y!=null&&g===y,B=o.from!=null&&o.to!=null&&M>o.from&&M<o.to;c.push({year:g,active:x&&f,highlight:B&&f,disabled:!f})}const v=g=>{a?(d(g),s(g)):(s(g),r("months"))},d=g=>{let M={...o};if(M.from&&M.to)M={from:g,to:null};else if(!M.from)M={from:g,to:null};else{const f=M.from.getTime();g.getTime()>f?M={from:M.from,to:g}:M={from:g,to:M.from}}i(M),l(M)};return n.jsx("div",{className:"sa-calendar-years-preview",children:c.map((g,M)=>n.jsx("p",{className:`${g.active?"sa-calendar-months-active":""} ${g.highlight?"sa-calendar-months-highlight":""} ${g.disabled?"sa-calendar-disabled":""}`,onClick:()=>{g.disabled||v(new Date(g.year,0))},style:{backgroundColor:g.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:g.highlight?"var(--sa-color-gray-500, #8c8f97)":g.active?"":g.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:g.disabled?"not-allowed":"pointer",pointerEvents:g.disbled?"none":"all",...t?{}:{width:"100%"}},children:g.year},M))})},cn=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...e,children:n.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),pn=({...e})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...e,children:n.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Nn=({setViews:e,views:a,filter:r,date:s,setDate:o})=>{const i=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()+1,t.getMonth()));return}o(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()-1,t.getMonth()));return}o(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},h=()=>{if(a==="days")return`${J[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${en(s.getFullYear()).start} ~ ${en(s.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:i,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(cn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(pn,{})})]})]})};function G(e){const a=new Date(e),r=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${yn[s]} ${r}`}const an=({label:e,labelPosition:a="outside-top",required:r,optional:s,description:o,helperText:i,errorText:l,fullWidth:p,size:h="sm",children:t})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),w=e?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:e}),s&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,C=n.jsxs(n.Fragment,{children:[i&&!l&&n.jsx("p",{className:"sa-date-field-helper",children:i}),l&&n.jsx("p",{className:"sa-date-field-error-msg",children:l})]});return e?a==="outside-left"?n.jsxs("div",{className:`${c} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[w,o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[t,C]})]}):n.jsxs("div",{className:c,children:[w,o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o}),t,C]}):n.jsxs("div",{className:c,children:[o&&n.jsx("p",{className:"sa-date-field-helper-top",children:o}),t,C]})},un="sa-calendar-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(un)){const a=document.createElement("style");a.id=un,a.textContent=e,document.head.appendChild(a)}})(Z);const Cn=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,disabled:o,minDate:i,maxDate:l,placeholder:p,size:h="sm",variant:t,status:c,clearable:w,fullWidth:C=!0,withPadding:D=!0,label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g},M)=>{const f=g?"error":c,{ref:x,isComponentVisible:B,setIsComponentVisible:P}=nn(!1),Y=b.useRef(null),[S,T]=b.useState("days"),[m,z]=b.useState(new Date),[k,I]=b.useState({from:(e==null?void 0:e.from)??null,to:(e==null?void 0:e.to)??null});b.useEffect(()=>{if(e){const N=e;N.from&&z(N.from),I(N)}else z(new Date),I({from:null,to:null})},[e]),b.useEffect(()=>{r&&T(r)},[r]),b.useEffect(()=>{r||T("days")},[B]),b.useEffect(()=>{s||P(!0)},[s]);const H=()=>{var N,j;if(!e)return"";if(r){if(S==="days")return`${G(k.from)} ~ ${G(k.to||k.from)||"-"}`;if(S==="months")return`${J[k.from.getMonth()]} ~ ${k.to?J[k.to.getMonth()]:"-"}`;if(S==="years")return`${(N=k.from)==null?void 0:N.getFullYear()} ~ ${((j=k.to)==null?void 0:j.getFullYear())||"-"}`}else return`${G(k.from)} ~ ${G(k.to||k.from)||"-"}`},V=()=>{if(Y.current&&x.current&&s){const N=x.current.getBoundingClientRect(),j=Y.current.getBoundingClientRect();window.innerWidth<N.left+j.width?Y.current.style.left=`${N.left-j.width+N.width}px`:Y.current.style.left=`${N.left}px`,N.top+j.height>window.innerHeight?Y.current.style.top=`${N.y-(N.height+j.height-28)}px`:Y.current.style.top=`${N.y+N.height}px`}};b.useEffect(()=>{Y.current&&x.current&&s&&V()},[Y,x,B]),b.useEffect(()=>(window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}),[]);const K=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?x:null,children:[s?n.jsx(wn,{value:H(),inputMode:"none",onClick:()=>{P(!0)},onChange:()=>{},disabled:o,placeholder:p,size:h,variant:t,status:f,clearable:w,onClear:()=>a(void 0)}):null,B?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${s?"":"sa-calendar-no-input"} ${D?"":"sa-calendar-no-padding"}`,style:o?{pointerEvents:"none"}:void 0,ref:Y,children:[n.jsx(Nn,{setViews:T,views:S,filter:r,date:m,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:S==="days"?n.jsx(xn,{date:m,setDate:z,setIsComponentVisible:P,dateRange:k,setDateRange:I,input:s,onChange:a,minDate:i,maxDate:l}):S==="months"?n.jsx(kn,{date:m,setDate:z,filter:r,setViews:T,dateRange:k,setDateRange:I,setIsComponentVisible:P,input:s,onChange:a,minDate:i,maxDate:l}):n.jsx(Mn,{date:m,setDate:z,filter:r,setViews:T,dateRange:k,setDateRange:I,setIsComponentVisible:P,input:s,onChange:a,minDate:i,maxDate:l})})]}):null]});return n.jsx(an,{label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g,fullWidth:C,size:h,children:K})}),hn="sa-calendar-input-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(hn)){const a=document.createElement("style");a.id=hn,a.textContent=e,document.head.appendChild(a)}})(Z);const U=e=>{if(e==="xs")return 14;if(e==="sm")return 16;if(e==="md")return 16;if(e==="lg")return 20},$n=e=>{const{size:a="sm",status:r="default",variant:s="outline",clearable:o,onClear:i,...l}=e,p=b.useRef(null),h=()=>{p.current&&l.onClick&&(p.current.focus(),l.onClick(""))},t=r==="disable"||l.disabled,c=!!l.value,w=o&&c&&!t,C=D=>{D.stopPropagation(),i==null||i()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:U(a),height:U(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...l,disabled:t,value:l.value,ref:p})}),w?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:U(a),height:U(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:U(a),height:U(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},zn=({date:e,setDate:a,previewDate:r,setPreviewDate:s,setIsComponentVisible:o,minDate:i,maxDate:l,input:p,onChange:h,hasValue:t})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),w=c.getDay(),C=[];const D=e.toDateString(),L=new Date().toDateString(),y=r.getMonth();for(let d=0;d<42;d++){d===0&&w===0?c.setDate(c.getDate()-7):d===0?c.setDate(c.getDate()+(d-w)):c.setDate(c.getDate()+1);let $={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:t&&c.toDateString()===D,isToday:c.toDateString()===L,year:c.getFullYear(),isDisabled:i&&c<i||l&&c>l};C.push($)}const v=d=>{(!i||d>=i)&&(!l||d<=l)&&(a(d),h(d),s(d),p&&o(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:ln.map((d,$)=>n.jsx("p",{children:d},$))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((d,$)=>{const F=d.isDisabled;return n.jsx("p",{className:`${d.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${d.selected?"sa-calendar-days-active":""} ${d.isToday&&!d.selected?"sa-calendar-days-today":""}`,style:{color:F?"#ccc":void 0,pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{F||v(d.date)},children:d.number},$)})})]})},Dn=({date:e,setDate:a,filter:r,setViews:s,onChange:o,previewDate:i,setPreviewDate:l,minDate:p,maxDate:h,input:t,hasValue:c})=>{const w=e.getMonth(),C=e.getFullYear(),D=i.getFullYear(),L=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(o(y),a(y),l(y)):(s("days"),l(y)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:J.map((y,v)=>{const d=p&&new Date(D,v,1)<p||h&&new Date(D,v+1,0)>h;return n.jsx("p",{className:c&&v===w&&D===C?"sa-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{d||L(new Date(D,v))},children:y.slice(0,3)},v)})})},rn=e=>{const a=Math.floor(e/10)*10,r=a+10;return{start:a,end:r}},En=({date:e,filter:a,setViews:r,setDate:s,onChange:o,previewDate:i,setPreviewDate:l,minDate:p,maxDate:h,input:t,hasValue:c})=>{let w=[];const C=i.getFullYear(),{start:D,end:L}=rn(C),y=e.getFullYear();for(let d=D;d<L;d++){let $=p&&new Date(d,0,1)<p||h&&new Date(d,11,31)>h;w.push({year:d,active:!!c&&d===y,isDisabled:$})}const v=d=>{(!p||d>=p)&&(!h||d<=h)&&(a?(o(d),s(d),l(d)):(r("months"),l(d)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:w.map((d,$)=>n.jsx("p",{className:d.active?"sa-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...t?{}:{width:"100%"}},onClick:()=>{d.isDisabled||v(new Date(d.year,0))},children:d.year},$))})},Yn=({setViews:e,views:a,filter:r,previewDate:s,setPreviewDate:o})=>{const i=()=>{r||e(t=>t==="days"?"months":t==="months"?"years":"days")},l=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()+10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()+1,t.getMonth()));return}o(t=>new Date(t.getFullYear(),t.getMonth()+1))},p=()=>{if(a==="years"){o(t=>new Date(t.getFullYear()-10,0));return}if(a==="months"){o(t=>new Date(t.getFullYear()-1,t.getMonth()));return}o(t=>new Date(t.getMonth()===0?t.getFullYear()-1:t.getFullYear(),t.getMonth()===0?11:t.getMonth()-1))},h=()=>{if(a==="days")return`${J[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${rn(s.getFullYear()).start} ~ ${rn(s.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:i,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(cn,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:l,children:n.jsx(pn,{})})]})]})},fn="sa-calendar-styles";(e=>{if(!(typeof document>"u")&&!document.getElementById(fn)){const a=document.createElement("style");a.id=fn,a.textContent=e,document.head.appendChild(a)}})(Z);const Sn=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,disabled:o,minDate:i,maxDate:l,placeholder:p,size:h="sm",variant:t,status:c,clearable:w,fullWidth:C=!0,withPadding:D=!0,label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g},M)=>{const f=g?"error":c,{ref:x,isComponentVisible:B,setIsComponentVisible:P}=nn(!1),Y=b.useRef(null),[S,T]=b.useState("days"),[m,z]=b.useState(new Date),[k,I]=b.useState(new Date);b.useEffect(()=>{e?(z(e),I(e)):(z(new Date),I(new Date))},[e]),b.useEffect(()=>{r&&T(r)},[r]),b.useEffect(()=>{r||T("days")},[B]),b.useEffect(()=>{s||P(!0)},[s]);const H=()=>e?r==="days"?G(m):r==="months"?`${J[m.getMonth()]} ${m.getFullYear()}`:r==="years"?m.getFullYear():G(m):"",V=()=>{if(Y.current&&x.current&&s){const N=x.current.getBoundingClientRect(),j=Y.current.getBoundingClientRect();window.innerWidth<N.left+j.width?Y.current.style.left=`${N.left-j.width+N.width}px`:Y.current.style.left=`${N.left}px`,N.top+j.height>window.innerHeight?Y.current.style.top=`${N.y-(N.height+j.height-28)}px`:Y.current.style.top=`${N.y+N.height}px`}};b.useEffect(()=>{Y.current&&x.current&&s&&V()},[Y,x,B]),b.useEffect(()=>(window.addEventListener("scroll",V,!0),window.addEventListener("resize",V),()=>{window.removeEventListener("scroll",V,!0),window.removeEventListener("resize",V)}),[]);const K=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?x:null,children:[s?n.jsx($n,{value:H(),onClick:()=>P(!0),onChange:()=>{},placeholder:p,disabled:o,size:h,variant:t,status:f,inputMode:"none",clearable:w,onClear:()=>a(void 0)}):null,B?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${s?"":"sa-calendar-no-input"} ${D?"":"sa-calendar-no-padding"}`,style:o?{pointerEvents:"none"}:void 0,ref:Y,children:[n.jsx(Yn,{setViews:T,views:S,filter:r,previewDate:k,setPreviewDate:I,isComponentVisible:B}),n.jsx("div",{className:"sa-calendar-body",children:S==="days"?n.jsx(zn,{date:m,setDate:z,previewDate:k,setPreviewDate:I,setIsComponentVisible:P,input:s,minDate:i,maxDate:l,onChange:a,hasValue:e!=null}):S==="months"?n.jsx(Dn,{date:m,setDate:z,previewDate:k,setPreviewDate:I,filter:r,setViews:T,onChange:a,minDate:i,maxDate:l,input:s,hasValue:e!=null}):n.jsx(En,{date:m,setDate:z,previewDate:k,setPreviewDate:I,filter:r,setViews:T,onChange:a,minDate:i,maxDate:l,input:s,hasValue:e!=null})})]}):null]});return n.jsx(an,{label:L,labelPosition:y,required:v,optional:d,description:$,helperText:F,errorText:g,fullWidth:C,size:h,children:K})}),Ln=b.forwardRef(({value:e,onChange:a,filter:r,input:s=!0,rangedDate:o,disabled:i,minDate:l,maxDate:p,placeholder:h,size:t,variant:c,status:w,clearable:C,fullWidth:D,withPadding:L,label:y,labelPosition:v,required:d,optional:$,description:F,helperText:g,errorText:M},f)=>{const x={onChange:a,value:e,input:s,filter:r,disabled:i,minDate:l,maxDate:p,placeholder:h,size:t,variant:c,status:w,clearable:C,fullWidth:D,withPadding:L,label:y,labelPosition:v,required:d,optional:$,description:F,helperText:g,errorText:M};return n.jsx(n.Fragment,{children:o?n.jsx(Cn,{...x,ref:f}):n.jsx(Sn,{...x,ref:f})})}),Fn=`/* StarasiaTime — popover columns. Reuses --sa-date-* tokens (defined in
|
|
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
|
-
`,
|
|
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"})});
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export type DateLabelPosition = "outside-top" | "outside-left";
|
|
3
|
+
/**
|
|
4
|
+
* Controls handed to a custom trigger (`trigger` / `renderTrigger`) so the
|
|
5
|
+
* consumer can open/close the calendar and reflect the current value without
|
|
6
|
+
* owning any of the picker's internal state.
|
|
7
|
+
*/
|
|
8
|
+
export interface IDateTriggerState {
|
|
9
|
+
/** Whether the calendar popup is currently open. */
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
/** Open the calendar popup. */
|
|
12
|
+
open: () => void;
|
|
13
|
+
/** Close the calendar popup. */
|
|
14
|
+
close: () => void;
|
|
15
|
+
/** Toggle the calendar popup. */
|
|
16
|
+
toggle: () => void;
|
|
17
|
+
/** Raw selected value (single `Date`, or `{from,to}` when ranged). */
|
|
18
|
+
value?: Date | IDateRange;
|
|
19
|
+
/** Human-readable value string (same formatting as the built-in input). */
|
|
20
|
+
formattedValue: string;
|
|
21
|
+
/** Clear the selection (`onChange(undefined)`). */
|
|
22
|
+
clear: () => void;
|
|
23
|
+
/** Mirrors the `disabled` prop. */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Mirrors the `placeholder` prop. */
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
}
|
|
3
28
|
export interface IDateProps {
|
|
4
29
|
value?: Date | IDateRange;
|
|
5
30
|
onChange: (props: any) => void;
|
|
@@ -16,6 +41,29 @@ export interface IDateProps {
|
|
|
16
41
|
clearable?: boolean;
|
|
17
42
|
fullWidth?: boolean;
|
|
18
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;
|
|
53
|
+
/**
|
|
54
|
+
* Custom trigger element rendered in place of the built-in input. It is
|
|
55
|
+
* cloned with an injected `onClick` that toggles the calendar (popup mode);
|
|
56
|
+
* any existing `onClick` on the element is preserved and called first.
|
|
57
|
+
* Ignored when `renderTrigger` is also provided.
|
|
58
|
+
*/
|
|
59
|
+
trigger?: React.ReactNode;
|
|
60
|
+
/**
|
|
61
|
+
* Render-prop trigger. Receives calendar controls + the formatted value and
|
|
62
|
+
* returns the element to render. Takes precedence over `trigger`. Providing
|
|
63
|
+
* either implies popup mode (an `input={false}` is ignored — the inline,
|
|
64
|
+
* always-open calendar only applies when no custom trigger is set).
|
|
65
|
+
*/
|
|
66
|
+
renderTrigger?: (state: IDateTriggerState) => React.ReactNode;
|
|
19
67
|
label?: React.ReactNode;
|
|
20
68
|
labelPosition?: DateLabelPosition;
|
|
21
69
|
required?: boolean;
|
|
@@ -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 {};
|