@starasia/date 3.0.0 → 3.1.1
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 +647 -539
- package/dist/date.umd.js +33 -8
- package/dist/interfaces.d.ts +3 -0
- package/package.json +1 -1
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(Y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(Y=typeof globalThis<"u"?globalThis:Y||self,a(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,a,
|
|
1
|
+
(function(Y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(Y=typeof globalThis<"u"?globalThis:Y||self,a(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,a,x){"use strict";const T=`@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;
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
.sa-calendar-wrapper {
|
|
29
29
|
position: relative;
|
|
30
|
+
width: 100%;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
.sa-calendar {
|
|
@@ -173,6 +174,7 @@
|
|
|
173
174
|
align-items: center;
|
|
174
175
|
gap: var(--sa-spacing-sm, 8px);
|
|
175
176
|
cursor: pointer;
|
|
177
|
+
width: 100%;
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
.sa-calendar-input-container:has(input:focus) {
|
|
@@ -198,20 +200,20 @@
|
|
|
198
200
|
|
|
199
201
|
.sa-calendar-input-container.sm {
|
|
200
202
|
height: var(--sa-h-8, 32px);
|
|
201
|
-
border-radius: var(--sa-
|
|
203
|
+
border-radius: var(--sa-radii-sm, 6px);
|
|
202
204
|
font-size: var(--sa-font-size-sm, 12px);
|
|
203
|
-
padding-inline: var(--sa-spacing-
|
|
205
|
+
padding-inline: var(--sa-spacing-3, 12px);
|
|
204
206
|
}
|
|
205
207
|
.sa-calendar-input-container.md {
|
|
206
|
-
height:
|
|
207
|
-
border-radius: var(--sa-
|
|
208
|
+
height: var(--sa-h-10, 40px);
|
|
209
|
+
border-radius: var(--sa-radii-sm, 6px);
|
|
208
210
|
font-size: var(--sa-font-size-md, 14px);
|
|
209
211
|
padding-inline: var(--sa-spacing-3, 12px);
|
|
210
212
|
}
|
|
211
213
|
.sa-calendar-input-container.lg {
|
|
212
214
|
height: var(--sa-h-12, 48px);
|
|
213
|
-
border-radius: var(--sa-
|
|
214
|
-
font-size: var(--sa-font-size-
|
|
215
|
+
border-radius: var(--sa-radii-sm, 6px);
|
|
216
|
+
font-size: var(--sa-font-size-md, 14px);
|
|
215
217
|
padding-inline: var(--sa-spacing-3, 12px);
|
|
216
218
|
}
|
|
217
219
|
|
|
@@ -252,4 +254,27 @@
|
|
|
252
254
|
.sa-calendar-input-container-warning {
|
|
253
255
|
border-color: var(--sa-date-border-warning) !important;
|
|
254
256
|
}
|
|
255
|
-
`,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(r){const[e,s]=m.useState(r),o=m.useRef(null),l=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const V="sa-calendar-input-styles";(r=>{if(!document.getElementById(V)){const e=document.createElement("style");e.id=V,e.textContent=r,document.head.appendChild(e)}})(E);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},P=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:l,minDate:g,maxDate:p,input:w})=>{var h,t,c;let u=new Date(r.getFullYear(),r.getMonth(),1),n=u.getDay(),x=[];const b=r.getMonth();for(let i=0;i<42;i++){i===0&&n===0?u.setDate(u.getDate()-7):i===0?u.setDate(u.getDate()+(i-n)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===b,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((h=s.from)==null?void 0:h.toDateString())||u.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((c=s.from)==null?void 0:c.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=i=>{e(i)},k=i=>{var d;let y={...s};if(y.from&&y.to)y={from:i,to:null};else{const f=((d=y.from)==null?void 0:d.getTime())||0;i.getTime()>f?y={from:y.from,to:i}:y={from:i,to:y.from}}o(y),l(y)};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:j.map((i,y)=>a.jsx("p",{children:i},y))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:x.map((i,y)=>{var D;const d=i.date.getTime()>s.from.getTime()&&i.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=i.isDisabled;return a.jsx("p",{className:`${i.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${i.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...w?{}:{width:"100%"}},onClick:()=>{f||(M(i.date),k(i.date))},children:i.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{const x=l.from.getFullYear(),b=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var c;let t={...l};if(t.from&&t.to)t={from:h,to:null};else{const i=((c=t.from)==null?void 0:c.getTime())||0;h.getTime()>i?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((h,t)=>{var y,d,f;const c=new Date(b,t).getTime()>l.from.getTime()&&new Date(b,t).getTime()<(((y=l.to)==null?void 0:y.getTime())||l.from.getTime()),i=w&&new Date(b,t)<w||u&&new Date(b,t)>u;return a.jsx("p",{className:x===b&&(t===((d=l.from)==null?void 0:d.getMonth())||t===((f=l.to)==null?void 0:f.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:i?"none":void 0,cursor:i?"not-allowed":"pointer",color:i?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{i||M(new Date(b,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{var y;let x=[];const b=r.getFullYear(),{start:M,end:k}=T(b),h=l.from.getFullYear(),t=(y=l.to)==null?void 0:y.getFullYear();for(let d=M;d<k;d++){const f=new Date(d,0),D=(!w||f>=w)&&(!u||f<=u),C=d===h||d===t,v=f>l.from&&f<l.to;x.push({year:d,active:C&&D,highlight:v&&D,disabled:!D})}const c=d=>{e?(i(d),o(d)):(o(d),s("months"))},i=d=>{var D;let f={...l};if(f.from&&f.to)f={from:d,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;d.getTime()>C?f={from:f.from,to:d}:f={from:d,to:f.from}}g(f),p(f)};return a.jsx("div",{className:"sa-calendar-years-preview",children:x.map((d,f)=>a.jsx("p",{className:`${d.active?"sa-calendar-months-active":""} ${d.highlight?"sa-calendar-months-highlight":""} ${d.disabled?"sa-calendar-disabled":""}`,onClick:()=>{d.disabled||c(new Date(d.year,0))},style:{backgroundColor:d.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:d.highlight?"var(--sa-color-gray-500, #8c8f97)":d.active?"":d.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:d.disabled?"not-allowed":"pointer",pointerEvents:d.disbled?"none":"all",...n?{}:{width:"100%"}},children:d.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.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"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.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"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function N(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${A[o]} ${s}`}const W="sa-calendar-styles";(r=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=r,document.head.appendChild(e)}})(E);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,c]=m.useState("days"),[i,y]=m.useState(new Date),[d,f]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(y(r.from),f(r)):(y(new Date),f({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{s&&c(s)},[s]),m.useEffect(()=>{s||c("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var v,$;if(!r)return"";if(s){if(t==="days")return`${N(d.from)} ~ ${N(d.to||d.from)||"-"}`;if(t==="months")return`${F[d.from.getMonth()]} ~ ${d.to?F[d.to.getMonth()]:"-"}`;if(t==="years")return`${(v=d.from)==null?void 0:v.getFullYear()} ~ ${(($=d.to)==null?void 0:$.getFullYear())||"-"}`}else return`${N(d.from)} ~ ${N(d.to||d.from)||"-"}`},C=()=>{if(h.current&&b.current&&o){const v=b.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<v.left+$.width?h.current.style.left=`${v.left-$.width+v.width}px`:h.current.style.left=`${v.left}px`,v.top+$.height>window.innerHeight?h.current.style.top=`${v.y-(v.height+$.height-28)}px`:h.current.style.top=`${v.y+v.height}px`}};return m.useEffect(()=>{h.current&&b.current&&o&&C()},[h,b,M]),m.useEffect(()=>{const v=x==null?void 0:x.current;return v&&v.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{v&&v.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:l,placeholder:w,size:u,status:n}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:h,children:[a.jsx(K,{setViews:c,views:t,filter:s,date:i,setDate:y}),a.jsx("div",{className:"sa-calendar-body",children:t==="days"?a.jsx(q,{date:i,setDate:y,setIsComponentVisible:k,dateRange:d,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:i,setDate:y,filter:s,setViews:c,dateRange:d,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.jsx(U,{date:i,setDate:y,filter:s,setViews:c,dateRange:d,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="sa-calendar-input-styles";(r=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=r,document.head.appendChild(e)}})(E);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},X=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:g,maxDate:p,input:w,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),b=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?n.setDate(n.getDate()-7):t===0?n.setDate(n.getDate()+(t-x)):n.setDate(n.getDate()+1);let c={currentMonth:n.getMonth()===k,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:g&&n<g||p&&n>p};b.push(c)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),w&&l(!1))};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:j.map((t,c)=>a.jsx("p",{children:t},c))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:b.map((t,c)=>{const i=t.isDisabled;return a.jsx("p",{className:`${t.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${t.selected?"sa-calendar-days-active":""}`,style:{color:i?"#ccc":void 0,pointerEvents:i?"none":void 0,cursor:i?"not-allowed":"pointer",...w?{}:{width:"100%"}},onClick:()=>{i||h(t.date)},children:t.number},c)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{const x=r.getMonth(),b=r.getFullYear(),M=g.getFullYear(),k=h=>{(!w||h>=w)&&(!u||h<=u)&&(s?(l(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((h,t)=>{const c=w&&new Date(M,t,1)<w||u&&new Date(M,t+1,0)>u;return a.jsx("p",{className:t===x&&M===b?"sa-calendar-months-active":"",style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c||k(new Date(M,t))},children:h.slice(0,3)},t)})})},I=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},R=({date:r,filter:e,setViews:s,setDate:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{let x=[];const b=g.getFullYear(),{start:M,end:k}=I(b),h=r.getFullYear();for(let c=M;c<k;c++){let i=w&&new Date(c,0,1)<w||u&&new Date(c,11,31)>u;x.push({year:c,active:c===h,isDisabled:i})}const t=c=>{(!w||c>=w)&&(!u||c<=u)&&(e?(l(c),o(c),p(c)):(s("months"),p(c)))};return a.jsx("div",{className:"sa-calendar-years-preview",children:x.map((c,i)=>a.jsx("p",{className:c.active?"sa-calendar-months-active":"",style:{color:c.isDisabled?"#ccc":void 0,pointerEvents:c.isDisabled?"none":void 0,cursor:c.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c.isDisabled||t(new Date(c.year,0))},children:c.year},i))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})},J="sa-calendar-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(E);const ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,c]=m.useState("days"),[i,y]=m.useState(new Date),[d,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&c(s)},[s]),m.useEffect(()=>{s||c("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?N(i):s==="months"?`${F[i.getMonth()]} ${i.getFullYear()}`:s==="years"?i.getFullYear():N(i):"",C=()=>{if(h.current&&b.current&&o){const v=b.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<v.left+$.width?h.current.style.left=`${v.left-$.width+v.width}px`:h.current.style.left=`${v.left}px`,v.top+$.height>window.innerHeight?h.current.style.top=`${v.y-(v.height+$.height-28)}px`:h.current.style.top=`${v.y+v.height}px`}};return m.useEffect(()=>{h.current&&b.current&&o&&C()},[h,b,M]),m.useEffect(()=>{const v=x==null?void 0:x.current;return v&&v.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{v&&v.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:w,disabled:l,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:c,views:t,filter:s,previewDate:d,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"sa-calendar-body",children:t==="days"?a.jsx(Z,{date:i,setDate:y,previewDate:d,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:i,setDate:y,previewDate:d,setPreviewDate:f,filter:s,setViews:c,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:i,setDate:y,previewDate:d,setPreviewDate:f,filter:s,setViews:c,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:l,disabled:g,minDate:p,maxDate:w,placeholder:u,size:n,status:x},b)=>a.jsx(a.Fragment,{children:l?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
|
|
257
|
+
|
|
258
|
+
/* CLEAR BUTTON */
|
|
259
|
+
.sa-calendar-input-clear {
|
|
260
|
+
display: inline-flex;
|
|
261
|
+
align-items: center;
|
|
262
|
+
justify-content: center;
|
|
263
|
+
background: transparent;
|
|
264
|
+
border: 0;
|
|
265
|
+
padding: 0;
|
|
266
|
+
cursor: pointer;
|
|
267
|
+
color: var(--sa-date-text-subtle);
|
|
268
|
+
border-radius: 999px;
|
|
269
|
+
transition: background-color 0.12s ease;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.sa-calendar-input-clear:hover {
|
|
273
|
+
background: var(--sa-date-brand-subtle);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.sa-calendar-input-clear:focus-visible {
|
|
277
|
+
outline: 2px solid var(--sa-date-brand);
|
|
278
|
+
outline-offset: 1px;
|
|
279
|
+
}
|
|
280
|
+
`,B=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function V(t){const[e,s]=x.useState(t),o=x.useRef(null),i=f=>{o.current&&!o.current.contains(f.target)&&s(!1)};return x.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const W="sa-calendar-input-styles";(t=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=t,document.head.appendChild(e)}})(T);const L=t=>{if(t==="sm")return 16;if(t==="md")return 16;if(t==="lg")return 20},U=t=>{const{size:e="md",status:s="default",variant:o="outline",clearable:i,onClear:f,...g}=t,p=x.useRef(null),h=()=>{p.current&&g.onClick&&(p.current.focus(),g.onClick(""))},n=s==="disable"||g.disabled,k=!!g.value,w=i&&k&&!n,b=M=>{M.stopPropagation(),f==null||f()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:h,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...g,disabled:n,value:g.value,ref:p})}),w?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:b,children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},q=({date:t,setDate:e,dateRange:s,setDateRange:o,onChange:i,minDate:f,maxDate:g,input:p})=>{var y,r,l;let h=new Date(t.getFullYear(),t.getMonth(),1),n=h.getDay(),k=[];const w=t.getMonth();for(let d=0;d<42;d++){d===0&&n===0?h.setDate(h.getDate()-7):d===0?h.setDate(h.getDate()+(d-n)):h.setDate(h.getDate()+1);let v={currentMonth:h.getMonth()===w,date:new Date(h),month:h.getMonth(),number:h.getDate(),selected:h.toDateString()===((y=s.from)==null?void 0:y.toDateString())||h.toDateString()===(((r=s.to)==null?void 0:r.toDateString())||((l=s.from)==null?void 0:l.toDateString())),year:h.getFullYear(),isDisabled:f&&h<f||g&&h>g};k.push(v)}const b=d=>{e(d)},M=d=>{var c;let v={...s};if(v.from&&v.to)v={from:d,to:null};else{const u=((c=v.from)==null?void 0:c.getTime())||0;d.getTime()>u?v={from:v.from,to:d}:v={from:d,to:v.from}}o(v),i(v)};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:B.map((d,v)=>a.jsx("p",{children:d},v))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:k.map((d,v)=>{var C;const c=d.date.getTime()>s.from.getTime()&&d.date.getTime()<(((C=s.to)==null?void 0:C.getTime())||s.from.getTime()),u=d.isDisabled;return a.jsx("p",{className:`${d.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${d.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:u?"none":void 0,cursor:u?"not-allowed":"pointer",color:u?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...p?{}:{width:"100%"}},onClick:()=>{u||(b(d.date),M(d.date))},children:d.number},v)})})]})},G=({date:t,setDate:e,filter:s,setViews:o,dateRange:i,setDateRange:f,onChange:g,minDate:p,maxDate:h,input:n})=>{const k=i.from.getFullYear(),w=t.getFullYear(),b=y=>{s?(M(y),e(y)):(o("days"),e(y))},M=y=>{var l;let r={...i};if(r.from&&r.to)r={from:y,to:null};else{const d=((l=r.from)==null?void 0:l.getTime())||0;y.getTime()>d?r={from:r.from,to:y}:r={from:y,to:r.from}}f(r),g(r)};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((y,r)=>{var v,c,u;const l=new Date(w,r).getTime()>i.from.getTime()&&new Date(w,r).getTime()<(((v=i.to)==null?void 0:v.getTime())||i.from.getTime()),d=p&&new Date(w,r)<p||h&&new Date(w,r)>h;return a.jsx("p",{className:k===w&&(r===((c=i.from)==null?void 0:c.getMonth())||r===((u=i.to)==null?void 0:u.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:l?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",color:d?"var(--sa-color-gray-400, #b7b9be)":l?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{d||b(new Date(w,r))},children:y.slice(0,3)},r)})})},I=t=>{const e=Math.floor(t/10)*10,s=e+10;return{start:e,end:s}},K=({date:t,filter:e,setViews:s,setDate:o,dateRange:i,setDateRange:f,onChange:g,minDate:p,maxDate:h,input:n})=>{var v;let k=[];const w=t.getFullYear(),{start:b,end:M}=I(w),y=i.from.getFullYear(),r=(v=i.to)==null?void 0:v.getFullYear();for(let c=b;c<M;c++){const u=new Date(c,0),C=(!p||u>=p)&&(!h||u<=h),N=c===y||c===r,D=u>i.from&&u<i.to;k.push({year:c,active:N&&C,highlight:D&&C,disabled:!C})}const l=c=>{e?(d(c),o(c)):(o(c),s("months"))},d=c=>{var C;let u={...i};if(u.from&&u.to)u={from:c,to:null};else{const N=((C=u.from)==null?void 0:C.getTime())||0;c.getTime()>N?u={from:u.from,to:c}:u={from:c,to:u.from}}f(u),g(u)};return a.jsx("div",{className:"sa-calendar-years-preview",children:k.map((c,u)=>a.jsx("p",{className:`${c.active?"sa-calendar-months-active":""} ${c.highlight?"sa-calendar-months-highlight":""} ${c.disabled?"sa-calendar-disabled":""}`,onClick:()=>{c.disabled||l(new Date(c.year,0))},style:{backgroundColor:c.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:c.highlight?"var(--sa-color-gray-500, #8c8f97)":c.active?"":c.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:c.disabled?"not-allowed":"pointer",pointerEvents:c.disbled?"none":"all",...n?{}:{width:"100%"}},children:c.year},u))})},z=({...t})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...t,children:a.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"})}),O=({...t})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...t,children:a.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"})}),Q=({setViews:t,views:e,filter:s,date:o,setDate:i})=>{const f=()=>{s||t(n=>n==="days"?"months":n==="months"?"years":"days")},g=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},h=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:f,children:h()}),a.jsx(O,{onClick:()=>g()})]})};function E(t){const e=new Date(t),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${P[o]} ${s}`}const H="sa-calendar-styles";(t=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=t,document.head.appendChild(e)}})(T);const X=x.forwardRef(({value:t,onChange:e,filter:s,input:o=!0,disabled:i,minDate:f,maxDate:g,placeholder:p,size:h,status:n,clearable:k},w)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:y}=V(!1),r=x.useRef(null),[l,d]=x.useState("days"),[v,c]=x.useState(new Date),[u,C]=x.useState({from:(t==null?void 0:t.from)||new Date,to:(t==null?void 0:t.to)||new Date});x.useEffect(()=>{t?(c(t.from),C(t)):(c(new Date),C({from:new Date,to:new Date}))},[t]),x.useEffect(()=>{s&&d(s)},[s]),x.useEffect(()=>{s||d("days")},[M]),x.useEffect(()=>{o||y(!0)},[o]);const N=()=>{var m,$;if(!t)return"";if(s){if(l==="days")return`${E(u.from)} ~ ${E(u.to||u.from)||"-"}`;if(l==="months")return`${F[u.from.getMonth()]} ~ ${u.to?F[u.to.getMonth()]:"-"}`;if(l==="years")return`${(m=u.from)==null?void 0:m.getFullYear()} ~ ${(($=u.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(u.from)} ~ ${E(u.to||u.from)||"-"}`},D=()=>{if(r.current&&b.current&&o){const m=b.current.getBoundingClientRect(),$=r.current.getBoundingClientRect();window.innerWidth<m.left+$.width?r.current.style.left=`${m.left-$.width+m.width}px`:r.current.style.left=`${m.left}px`,m.top+$.height>window.innerHeight?r.current.style.top=`${m.y-(m.height+$.height-28)}px`:r.current.style.top=`${m.y+m.height}px`}};return x.useEffect(()=>{r.current&&b.current&&o&&D()},[r,b,M]),x.useEffect(()=>{const m=w==null?void 0:w.current;return m&&m.addEventListener("scroll",D),window.addEventListener("scroll",D),()=>{m&&m.removeEventListener("scroll",D),window.removeEventListener("scroll",D)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(U,{value:N(),inputMode:"none",onClick:()=>{y(!0)},onChange:()=>{},disabled:i,placeholder:p,size:h,status:n,clearable:k,onClear:()=>e(void 0)}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:r,children:[a.jsx(Q,{setViews:d,views:l,filter:s,date:v,setDate:c}),a.jsx("div",{className:"sa-calendar-body",children:l==="days"?a.jsx(q,{date:v,setDate:c,setIsComponentVisible:y,dateRange:u,setDateRange:C,input:o,onChange:e,minDate:f,maxDate:g}):l==="months"?a.jsx(G,{date:v,setDate:c,filter:s,setViews:d,dateRange:u,setDateRange:C,setIsComponentVisible:y,input:o,onChange:e,minDate:f,maxDate:g}):a.jsx(K,{date:v,setDate:c,filter:s,setViews:d,dateRange:u,setDateRange:C,setIsComponentVisible:y,input:o,onChange:e,minDate:f,maxDate:g})})]}):null]})}),A="sa-calendar-input-styles";(t=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=t,document.head.appendChild(e)}})(T);const S=t=>{if(t==="sm")return 16;if(t==="md")return 16;if(t==="lg")return 20},Z=t=>{const{size:e="md",status:s="default",variant:o="outline",clearable:i,onClear:f,...g}=t,p=x.useRef(null),h=()=>{p.current&&g.onClick&&(p.current.focus(),g.onClick(""))},n=s==="disable"||g.disabled,k=!!g.value,w=i&&k&&!n,b=M=>{M.stopPropagation(),f==null||f()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:h,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...g,disabled:n,value:g.value,ref:p})}),w?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:b,children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.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"})})})]})},_=({date:t,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:i,minDate:f,maxDate:g,input:p,onChange:h})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),k=n.getDay(),w=[];const b=t.toDateString(),M=s.getMonth();for(let r=0;r<42;r++){r===0&&k===0?n.setDate(n.getDate()-7):r===0?n.setDate(n.getDate()+(r-k)):n.setDate(n.getDate()+1);let l={currentMonth:n.getMonth()===M,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===b,year:n.getFullYear(),isDisabled:f&&n<f||g&&n>g};w.push(l)}const y=r=>{(!f||r>=f)&&(!g||r<=g)&&(e(r),h(r),o(r),p&&i(!1))};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:B.map((r,l)=>a.jsx("p",{children:r},l))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:w.map((r,l)=>{const d=r.isDisabled;return a.jsx("p",{className:`${r.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${r.selected?"sa-calendar-days-active":""}`,style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{d||y(r.date)},children:r.number},l)})})]})},R=({date:t,setDate:e,filter:s,setViews:o,onChange:i,previewDate:f,setPreviewDate:g,minDate:p,maxDate:h,input:n})=>{const k=t.getMonth(),w=t.getFullYear(),b=f.getFullYear(),M=y=>{(!p||y>=p)&&(!h||y<=h)&&(s?(i(y),e(y),g(y)):(o("days"),g(y)))};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((y,r)=>{const l=p&&new Date(b,r,1)<p||h&&new Date(b,r+1,0)>h;return a.jsx("p",{className:r===k&&b===w?"sa-calendar-months-active":"",style:{color:l?"#ccc":void 0,pointerEvents:l?"none":void 0,cursor:l?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{l||M(new Date(b,r))},children:y.slice(0,3)},r)})})},j=t=>{const e=Math.floor(t/10)*10,s=e+10;return{start:e,end:s}},ee=({date:t,filter:e,setViews:s,setDate:o,onChange:i,previewDate:f,setPreviewDate:g,minDate:p,maxDate:h,input:n})=>{let k=[];const w=f.getFullYear(),{start:b,end:M}=j(w),y=t.getFullYear();for(let l=b;l<M;l++){let d=p&&new Date(l,0,1)<p||h&&new Date(l,11,31)>h;k.push({year:l,active:l===y,isDisabled:d})}const r=l=>{(!p||l>=p)&&(!h||l<=h)&&(e?(i(l),o(l),g(l)):(s("months"),g(l)))};return a.jsx("div",{className:"sa-calendar-years-preview",children:k.map((l,d)=>a.jsx("p",{className:l.active?"sa-calendar-months-active":"",style:{color:l.isDisabled?"#ccc":void 0,pointerEvents:l.isDisabled?"none":void 0,cursor:l.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{l.isDisabled||r(new Date(l.year,0))},children:l.year},d))})},ne=({setViews:t,views:e,filter:s,previewDate:o,setPreviewDate:i})=>{const f=()=>{s||t(n=>n==="days"?"months":n==="months"?"years":"days")},g=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},h=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${j(o.getFullYear()).start} ~ ${j(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:f,children:h()}),a.jsx(O,{onClick:()=>g()})]})},J="sa-calendar-styles";(t=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=t,document.head.appendChild(e)}})(T);const ae=x.forwardRef(({value:t,onChange:e,filter:s,input:o=!0,disabled:i,minDate:f,maxDate:g,placeholder:p,size:h,status:n,clearable:k},w)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:y}=V(!1),r=x.useRef(null),[l,d]=x.useState("days"),[v,c]=x.useState(new Date),[u,C]=x.useState(new Date);x.useEffect(()=>{t?(c(t),C(t)):(c(new Date),C(new Date))},[t]),x.useEffect(()=>{s&&d(s)},[s]),x.useEffect(()=>{s||d("days")},[M]),x.useEffect(()=>{o||y(!0)},[o]);const N=()=>t?s==="days"?E(v):s==="months"?`${F[v.getMonth()]} ${v.getFullYear()}`:s==="years"?v.getFullYear():E(v):"",D=()=>{if(r.current&&b.current&&o){const m=b.current.getBoundingClientRect(),$=r.current.getBoundingClientRect();window.innerWidth<m.left+$.width?r.current.style.left=`${m.left-$.width+m.width}px`:r.current.style.left=`${m.left}px`,m.top+$.height>window.innerHeight?r.current.style.top=`${m.y-(m.height+$.height-28)}px`:r.current.style.top=`${m.y+m.height}px`}};return x.useEffect(()=>{r.current&&b.current&&o&&D()},[r,b,M]),x.useEffect(()=>{const m=w==null?void 0:w.current;return m&&m.addEventListener("scroll",D),window.addEventListener("scroll",D),()=>{m&&m.removeEventListener("scroll",D),window.removeEventListener("scroll",D)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(Z,{value:N(),onClick:()=>y(!0),onChange:()=>{},placeholder:p,disabled:i,size:h,status:n,inputMode:"none",clearable:k,onClear:()=>e(void 0)}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:r,children:[a.jsx(ne,{setViews:d,views:l,filter:s,previewDate:u,setPreviewDate:C,isComponentVisible:M}),a.jsx("div",{className:"sa-calendar-body",children:l==="days"?a.jsx(_,{date:v,setDate:c,previewDate:u,setPreviewDate:C,setIsComponentVisible:y,input:o,minDate:f,maxDate:g,onChange:e}):l==="months"?a.jsx(R,{date:v,setDate:c,previewDate:u,setPreviewDate:C,filter:s,setViews:d,onChange:e,minDate:f,maxDate:g,input:o}):a.jsx(ee,{date:v,setDate:c,previewDate:u,setPreviewDate:C,filter:s,setViews:d,onChange:e,minDate:f,maxDate:g,input:o})})]}):null]})}),re=x.forwardRef(({value:t,onChange:e,filter:s,input:o=!0,rangedDate:i,disabled:f,minDate:g,maxDate:p,placeholder:h,size:n,status:k,clearable:w},b)=>a.jsx(a.Fragment,{children:i?a.jsx(X,{onChange:e,value:t,input:o,filter:s,disabled:f,ref:b,minDate:g,maxDate:p,placeholder:h,size:n,status:k,clearable:w}):a.jsx(ae,{onChange:e,value:t,input:o,filter:s,disabled:f,ref:b,minDate:g,maxDate:p,placeholder:h,size:n,status:k,clearable:w})}));Y.StarasiaDate=re,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface IDateProps {
|
|
|
10
10
|
placeholder?: string;
|
|
11
11
|
size?: "sm" | "md" | "lg";
|
|
12
12
|
status?: "error" | "warning";
|
|
13
|
+
clearable?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export interface IDateRange {
|
|
15
16
|
from: Date | null;
|
|
@@ -19,6 +20,8 @@ export interface IInputDateProps extends Omit<React.InputHTMLAttributes<HTMLInpu
|
|
|
19
20
|
size?: "sm" | "md" | "lg";
|
|
20
21
|
status?: "error" | "warning" | "disable" | "default";
|
|
21
22
|
variant?: "outline" | "filled" | "flushed";
|
|
23
|
+
clearable?: boolean;
|
|
24
|
+
onClear?: () => void;
|
|
22
25
|
}
|
|
23
26
|
export interface IHeaderDateProps {
|
|
24
27
|
setViews: React.Dispatch<React.SetStateAction<"days" | "months" | "years">>;
|