@starasia/date 5.4.2 → 5.5.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 +722 -668
- package/dist/date.umd.js +3 -3
- package/dist/interfaces.d.ts +39 -0
- package/package.json +1 -1
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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");
|
|
2
2
|
|
|
3
3
|
* {
|
|
4
4
|
margin: 0;
|
|
@@ -588,7 +588,7 @@
|
|
|
588
588
|
width: 32px;
|
|
589
589
|
height: 32px;
|
|
590
590
|
}
|
|
591
|
-
`,ln=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],J=["January","February","March","April","May","June","July","August","September","October","November","December"],yn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function nn(e){const[a,r]=b.useState(e),s=b.useRef(null),o=i=>{s.current&&!s.current.contains(i.target)&&r(!1)};return b.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:r}}const dn="sa-calendar-input-styles";(e=>{if(!(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
|
|
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
|
|
592
592
|
date.module.css, injected alongside this sheet) and the .sa-calendar /
|
|
593
593
|
.sa-calendar-input-* shells for the box + masked input. */
|
|
594
594
|
|
|
@@ -719,4 +719,4 @@
|
|
|
719
719
|
.sa-time-input-wrap {
|
|
720
720
|
width: 100%;
|
|
721
721
|
}
|
|
722
|
-
`,
|
|
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"})});
|
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,20 @@ export interface IDateProps {
|
|
|
16
41
|
clearable?: boolean;
|
|
17
42
|
fullWidth?: boolean;
|
|
18
43
|
withPadding?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Custom trigger element rendered in place of the built-in input. It is
|
|
46
|
+
* cloned with an injected `onClick` that toggles the calendar (popup mode);
|
|
47
|
+
* any existing `onClick` on the element is preserved and called first.
|
|
48
|
+
* Ignored when `renderTrigger` is also provided.
|
|
49
|
+
*/
|
|
50
|
+
trigger?: React.ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Render-prop trigger. Receives calendar controls + the formatted value and
|
|
53
|
+
* returns the element to render. Takes precedence over `trigger`. Providing
|
|
54
|
+
* either implies popup mode (an `input={false}` is ignored — the inline,
|
|
55
|
+
* always-open calendar only applies when no custom trigger is set).
|
|
56
|
+
*/
|
|
57
|
+
renderTrigger?: (state: IDateTriggerState) => React.ReactNode;
|
|
19
58
|
label?: React.ReactNode;
|
|
20
59
|
labelPosition?: DateLabelPosition;
|
|
21
60
|
required?: boolean;
|