@starasia/date 4.0.0 → 5.0.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/FieldWrapper.d.ts +14 -0
- package/dist/date.es.js +794 -637
- package/dist/date.umd.js +79 -3
- package/dist/interfaces.d.ts +9 -0
- package/package.json +1 -1
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.Date={},B.jsxRuntime,B.React))})(this,function(B,e,m){"use strict";const H=`@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,11 +27,87 @@
|
|
|
27
27
|
}
|
|
28
28
|
.sa-calendar-wrapper {
|
|
29
29
|
position: relative;
|
|
30
|
+
width: 100%;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* === DATE FIELD WRAPPER === */
|
|
34
|
+
.sa-date-field {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
gap: 6px;
|
|
30
38
|
width: max-content;
|
|
39
|
+
font-family: "Poppins", sans-serif;
|
|
31
40
|
}
|
|
32
|
-
.sa-
|
|
41
|
+
.sa-date-field-fullwidth {
|
|
33
42
|
width: 100%;
|
|
34
43
|
}
|
|
44
|
+
.sa-date-field-left {
|
|
45
|
+
flex-direction: row;
|
|
46
|
+
align-items: flex-start;
|
|
47
|
+
gap: 16px;
|
|
48
|
+
}
|
|
49
|
+
.sa-date-field-left-label {
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: 4px;
|
|
53
|
+
flex: 0 0 auto;
|
|
54
|
+
width: 35%;
|
|
55
|
+
padding-top: 8px;
|
|
56
|
+
}
|
|
57
|
+
.sa-date-field-input-wrap {
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
gap: 6px;
|
|
61
|
+
flex: 1;
|
|
62
|
+
min-width: 0;
|
|
63
|
+
}
|
|
64
|
+
.sa-date-field-label-row {
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
gap: 6px;
|
|
68
|
+
flex-wrap: wrap;
|
|
69
|
+
}
|
|
70
|
+
.sa-date-field-label-text {
|
|
71
|
+
font-size: 14px;
|
|
72
|
+
font-weight: 500;
|
|
73
|
+
color: var(--sa-date-text-primary);
|
|
74
|
+
line-height: 1.3;
|
|
75
|
+
}
|
|
76
|
+
.sa-date-field-required {
|
|
77
|
+
font-size: 14px;
|
|
78
|
+
font-weight: 500;
|
|
79
|
+
color: var(--sa-date-border-error);
|
|
80
|
+
line-height: 1;
|
|
81
|
+
}
|
|
82
|
+
.sa-date-field-optional-badge {
|
|
83
|
+
display: inline-flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
padding: 0 6px;
|
|
87
|
+
border: 0.8px solid var(--sa-date-border-color);
|
|
88
|
+
border-radius: 4px;
|
|
89
|
+
background-color: transparent;
|
|
90
|
+
font-size: 10px;
|
|
91
|
+
font-weight: 500;
|
|
92
|
+
color: var(--sa-date-text-subtle);
|
|
93
|
+
line-height: 18px;
|
|
94
|
+
text-transform: lowercase;
|
|
95
|
+
}
|
|
96
|
+
.sa-date-field-helper-top,
|
|
97
|
+
.sa-date-field-helper {
|
|
98
|
+
font-size: 12px;
|
|
99
|
+
font-weight: 400;
|
|
100
|
+
color: var(--sa-date-text-subtle);
|
|
101
|
+
line-height: 1.4;
|
|
102
|
+
margin: 0;
|
|
103
|
+
}
|
|
104
|
+
.sa-date-field-error-msg {
|
|
105
|
+
font-size: 12px;
|
|
106
|
+
font-weight: 400;
|
|
107
|
+
color: var(--sa-date-border-error);
|
|
108
|
+
line-height: 1.4;
|
|
109
|
+
margin: 0;
|
|
110
|
+
}
|
|
35
111
|
|
|
36
112
|
.sa-calendar {
|
|
37
113
|
border-radius: var(--sa-date-radius);
|
|
@@ -280,4 +356,4 @@
|
|
|
280
356
|
outline: 2px solid var(--sa-date-brand);
|
|
281
357
|
outline-offset: 1px;
|
|
282
358
|
}
|
|
283
|
-
`,V=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],N=["January","February","March","April","May","June","July","August","September","October","November","December"],U=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function z(r){const[e,o]=k.useState(r),l=k.useRef(null),i=g=>{l.current&&!l.current.contains(g.target)&&o(!1)};return k.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:o}}const O="sa-calendar-input-styles";(r=>{if(!document.getElementById(O)){const e=document.createElement("style");e.id=O,e.textContent=r,document.head.appendChild(e)}})(I);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},q=r=>{const{size:e="md",status:o="default",variant:l="outline",clearable:i,onClear:g,...u}=r,p=k.useRef(null),h=()=>{p.current&&u.onClick&&(p.current.focus(),u.onClick(""))},n=o==="disable"||u.disabled,C=!!u.value,M=i&&C&&!n,x=w=>{w.stopPropagation(),g==null||g()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${l} sa-calendar-input-container-${o} ${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",...u,disabled:n,value:u.value,ref:p})}),M?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:x,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"})})})]})},G=({date:r,setDate:e,dateRange:o,setDateRange:l,onChange:i,minDate:g,maxDate:u,input:p})=>{var y,s,t;let h=new Date(r.getFullYear(),r.getMonth(),1),n=h.getDay(),C=[];const M=r.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()===M,date:new Date(h),month:h.getMonth(),number:h.getDate(),selected:h.toDateString()===((y=o.from)==null?void 0:y.toDateString())||h.toDateString()===(((s=o.to)==null?void 0:s.toDateString())||((t=o.from)==null?void 0:t.toDateString())),year:h.getFullYear(),isDisabled:g&&h<g||u&&h>u};C.push(v)}const x=d=>{e(d)},w=d=>{var c;let v={...o};if(v.from&&v.to)v={from:d,to:null};else{const f=((c=v.from)==null?void 0:c.getTime())||0;d.getTime()>f?v={from:v.from,to:d}:v={from:d,to:v.from}}l(v),i(v)};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:V.map((d,v)=>a.jsx("p",{children:d},v))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((d,v)=>{var m;const c=d.date.getTime()>o.from.getTime()&&d.date.getTime()<(((m=o.to)==null?void 0:m.getTime())||o.from.getTime()),f=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:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...p?{}:{width:"100%"}},onClick:()=>{f||(x(d.date),w(d.date))},children:d.number},v)})})]})},K=({date:r,setDate:e,filter:o,setViews:l,dateRange:i,setDateRange:g,onChange:u,minDate:p,maxDate:h,input:n})=>{const C=i.from.getFullYear(),M=r.getFullYear(),x=y=>{o?(w(y),e(y)):(l("days"),e(y))},w=y=>{var t;let s={...i};if(s.from&&s.to)s={from:y,to:null};else{const d=((t=s.from)==null?void 0:t.getTime())||0;y.getTime()>d?s={from:s.from,to:y}:s={from:y,to:s.from}}g(s),u(s)};return a.jsx("div",{className:"sa-calendar-months-preview",children:N.map((y,s)=>{var v,c,f;const t=new Date(M,s).getTime()>i.from.getTime()&&new Date(M,s).getTime()<(((v=i.to)==null?void 0:v.getTime())||i.from.getTime()),d=p&&new Date(M,s)<p||h&&new Date(M,s)>h;return a.jsx("p",{className:C===M&&(s===((c=i.from)==null?void 0:c.getMonth())||s===((f=i.to)==null?void 0:f.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:t?"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)":t?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{d||x(new Date(M,s))},children:y.slice(0,3)},s)})})},j=r=>{const e=Math.floor(r/10)*10,o=e+10;return{start:e,end:o}},Q=({date:r,filter:e,setViews:o,setDate:l,dateRange:i,setDateRange:g,onChange:u,minDate:p,maxDate:h,input:n})=>{var v;let C=[];const M=r.getFullYear(),{start:x,end:w}=j(M),y=i.from.getFullYear(),s=(v=i.to)==null?void 0:v.getFullYear();for(let c=x;c<w;c++){const f=new Date(c,0),m=(!p||f>=p)&&(!h||f<=h),D=c===y||c===s,T=f>i.from&&f<i.to;C.push({year:c,active:D&&m,highlight:T&&m,disabled:!m})}const t=c=>{e?(d(c),l(c)):(l(c),o("months"))},d=c=>{var m;let f={...i};if(f.from&&f.to)f={from:c,to:null};else{const D=((m=f.from)==null?void 0:m.getTime())||0;c.getTime()>D?f={from:f.from,to:c}:f={from:c,to:f.from}}g(f),u(f)};return a.jsx("div",{className:"sa-calendar-years-preview",children:C.map((c,f)=>a.jsx("p",{className:`${c.active?"sa-calendar-months-active":""} ${c.highlight?"sa-calendar-months-highlight":""} ${c.disabled?"sa-calendar-disabled":""}`,onClick:()=>{c.disabled||t(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},f))})},W=({...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"})}),H=({...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"})}),X=({setViews:r,views:e,filter:o,date:l,setDate:i})=>{const g=()=>{o||r(n=>n==="days"?"months":n==="months"?"years":"days")},u=()=>{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`${N[l.getMonth()]} ${l.getFullYear()}`;if(e==="months")return`${l.getFullYear()}`;if(e==="years")return`${j(l.getFullYear()).start} ~ ${j(l.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(W,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:h()}),a.jsx(H,{onClick:()=>u()})]})};function E(r){const e=new Date(r),o=e.getFullYear(),l=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${U[l]} ${o}`}const A="sa-calendar-styles";(r=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=r,document.head.appendChild(e)}})(I);const Z=k.forwardRef(({value:r,onChange:e,filter:o,input:l=!0,disabled:i,minDate:g,maxDate:u,placeholder:p,size:h,status:n,clearable:C,fullWidth:M=!1},x)=>{const{ref:w,isComponentVisible:y,setIsComponentVisible:s}=z(!1),t=k.useRef(null),[d,v]=k.useState("days"),[c,f]=k.useState(new Date),[m,D]=k.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});k.useEffect(()=>{r?(f(r.from),D(r)):(f(new Date),D({from:new Date,to:new Date}))},[r]),k.useEffect(()=>{o&&v(o)},[o]),k.useEffect(()=>{o||v("days")},[y]),k.useEffect(()=>{l||s(!0)},[l]);const T=()=>{var b,$;if(!r)return"";if(o){if(d==="days")return`${E(m.from)} ~ ${E(m.to||m.from)||"-"}`;if(d==="months")return`${N[m.from.getMonth()]} ~ ${m.to?N[m.to.getMonth()]:"-"}`;if(d==="years")return`${(b=m.from)==null?void 0:b.getFullYear()} ~ ${(($=m.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(m.from)} ~ ${E(m.to||m.from)||"-"}`},Y=()=>{if(t.current&&w.current&&l){const b=w.current.getBoundingClientRect(),$=t.current.getBoundingClientRect();window.innerWidth<b.left+$.width?t.current.style.left=`${b.left-$.width+b.width}px`:t.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?t.current.style.top=`${b.y-(b.height+$.height-28)}px`:t.current.style.top=`${b.y+b.height}px`}};return k.useEffect(()=>{t.current&&w.current&&l&&Y()},[t,w,y]),k.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",Y),window.addEventListener("scroll",Y),()=>{b&&b.removeEventListener("scroll",Y),window.removeEventListener("scroll",Y)}},[]),a.jsxs("div",{className:`sa-calendar-wrapper${M?" sa-calendar-wrapper-fullwidth":""}`,style:{height:l?"auto":"100%"},ref:l?w:null,children:[l?a.jsx(q,{value:T(),inputMode:"none",onClick:()=>{s(!0)},onChange:()=>{},disabled:i,placeholder:p,size:h,status:n,clearable:C,onClear:()=>e(void 0)}):null,y?a.jsxs("div",{className:`sa-calendar ${l?"":"sa-calendar-no-input"}`,ref:t,children:[a.jsx(X,{setViews:v,views:d,filter:o,date:c,setDate:f}),a.jsx("div",{className:"sa-calendar-body",children:d==="days"?a.jsx(G,{date:c,setDate:f,setIsComponentVisible:s,dateRange:m,setDateRange:D,input:l,onChange:e,minDate:g,maxDate:u}):d==="months"?a.jsx(K,{date:c,setDate:f,filter:o,setViews:v,dateRange:m,setDateRange:D,setIsComponentVisible:s,input:l,onChange:e,minDate:g,maxDate:u}):a.jsx(Q,{date:c,setDate:f,filter:o,setViews:v,dateRange:m,setDateRange:D,setIsComponentVisible:s,input:l,onChange:e,minDate:g,maxDate:u})})]}):null]})}),J="sa-calendar-input-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(I);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},_=r=>{const{size:e="md",status:o="default",variant:l="outline",clearable:i,onClear:g,...u}=r,p=k.useRef(null),h=()=>{p.current&&u.onClick&&(p.current.focus(),u.onClick(""))},n=o==="disable"||u.disabled,C=!!u.value,M=i&&C&&!n,x=w=>{w.stopPropagation(),g==null||g()};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${l} sa-calendar-input-container-${o} ${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",...u,disabled:n,value:u.value,ref:p})}),M?a.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:x,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"})})})]})},R=({date:r,setDate:e,previewDate:o,setPreviewDate:l,setIsComponentVisible:i,minDate:g,maxDate:u,input:p,onChange:h})=>{let n=new Date(o.getFullYear(),o.getMonth(),1),C=n.getDay(),M=[];const x=r.toDateString(),w=o.getMonth();for(let s=0;s<42;s++){s===0&&C===0?n.setDate(n.getDate()-7):s===0?n.setDate(n.getDate()+(s-C)):n.setDate(n.getDate()+1);let t={currentMonth:n.getMonth()===w,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===x,year:n.getFullYear(),isDisabled:g&&n<g||u&&n>u};M.push(t)}const y=s=>{(!g||s>=g)&&(!u||s<=u)&&(e(s),h(s),l(s),p&&i(!1))};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:V.map((s,t)=>a.jsx("p",{children:s},t))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:M.map((s,t)=>{const d=s.isDisabled;return a.jsx("p",{className:`${s.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${s.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(s.date)},children:s.number},t)})})]})},ee=({date:r,setDate:e,filter:o,setViews:l,onChange:i,previewDate:g,setPreviewDate:u,minDate:p,maxDate:h,input:n})=>{const C=r.getMonth(),M=r.getFullYear(),x=g.getFullYear(),w=y=>{(!p||y>=p)&&(!h||y<=h)&&(o?(i(y),e(y),u(y)):(l("days"),u(y)))};return a.jsx("div",{className:"sa-calendar-months-preview",children:N.map((y,s)=>{const t=p&&new Date(x,s,1)<p||h&&new Date(x,s+1,0)>h;return a.jsx("p",{className:s===C&&x===M?"sa-calendar-months-active":"",style:{color:t?"#ccc":void 0,pointerEvents:t?"none":void 0,cursor:t?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{t||w(new Date(x,s))},children:y.slice(0,3)},s)})})},B=r=>{const e=Math.floor(r/10)*10,o=e+10;return{start:e,end:o}},ne=({date:r,filter:e,setViews:o,setDate:l,onChange:i,previewDate:g,setPreviewDate:u,minDate:p,maxDate:h,input:n})=>{let C=[];const M=g.getFullYear(),{start:x,end:w}=B(M),y=r.getFullYear();for(let t=x;t<w;t++){let d=p&&new Date(t,0,1)<p||h&&new Date(t,11,31)>h;C.push({year:t,active:t===y,isDisabled:d})}const s=t=>{(!p||t>=p)&&(!h||t<=h)&&(e?(i(t),l(t),u(t)):(o("months"),u(t)))};return a.jsx("div",{className:"sa-calendar-years-preview",children:C.map((t,d)=>a.jsx("p",{className:t.active?"sa-calendar-months-active":"",style:{color:t.isDisabled?"#ccc":void 0,pointerEvents:t.isDisabled?"none":void 0,cursor:t.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{t.isDisabled||s(new Date(t.year,0))},children:t.year},d))})},ae=({setViews:r,views:e,filter:o,previewDate:l,setPreviewDate:i})=>{const g=()=>{o||r(n=>n==="days"?"months":n==="months"?"years":"days")},u=()=>{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`${N[l.getMonth()]} ${l.getFullYear()}`;if(e==="months")return`${l.getFullYear()}`;if(e==="years")return`${B(l.getFullYear()).start} ~ ${B(l.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(W,{onClick:()=>p()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:h()}),a.jsx(H,{onClick:()=>u()})]})},P="sa-calendar-styles";(r=>{if(!document.getElementById(P)){const e=document.createElement("style");e.id=P,e.textContent=r,document.head.appendChild(e)}})(I);const re=k.forwardRef(({value:r,onChange:e,filter:o,input:l=!0,disabled:i,minDate:g,maxDate:u,placeholder:p,size:h,status:n,clearable:C,fullWidth:M=!1},x)=>{const{ref:w,isComponentVisible:y,setIsComponentVisible:s}=z(!1),t=k.useRef(null),[d,v]=k.useState("days"),[c,f]=k.useState(new Date),[m,D]=k.useState(new Date);k.useEffect(()=>{r?(f(r),D(r)):(f(new Date),D(new Date))},[r]),k.useEffect(()=>{o&&v(o)},[o]),k.useEffect(()=>{o||v("days")},[y]),k.useEffect(()=>{l||s(!0)},[l]);const T=()=>r?o==="days"?E(c):o==="months"?`${N[c.getMonth()]} ${c.getFullYear()}`:o==="years"?c.getFullYear():E(c):"",Y=()=>{if(t.current&&w.current&&l){const b=w.current.getBoundingClientRect(),$=t.current.getBoundingClientRect();window.innerWidth<b.left+$.width?t.current.style.left=`${b.left-$.width+b.width}px`:t.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?t.current.style.top=`${b.y-(b.height+$.height-28)}px`:t.current.style.top=`${b.y+b.height}px`}};return k.useEffect(()=>{t.current&&w.current&&l&&Y()},[t,w,y]),k.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",Y),window.addEventListener("scroll",Y),()=>{b&&b.removeEventListener("scroll",Y),window.removeEventListener("scroll",Y)}},[]),a.jsxs("div",{className:`sa-calendar-wrapper${M?" sa-calendar-wrapper-fullwidth":""}`,style:{height:l?"auto":"100%"},ref:l?w:null,children:[l?a.jsx(_,{value:T(),onClick:()=>s(!0),onChange:()=>{},placeholder:p,disabled:i,size:h,status:n,inputMode:"none",clearable:C,onClear:()=>e(void 0)}):null,y?a.jsxs("div",{className:`sa-calendar ${l?"":"sa-calendar-no-input"}`,ref:t,children:[a.jsx(ae,{setViews:v,views:d,filter:o,previewDate:m,setPreviewDate:D,isComponentVisible:y}),a.jsx("div",{className:"sa-calendar-body",children:d==="days"?a.jsx(R,{date:c,setDate:f,previewDate:m,setPreviewDate:D,setIsComponentVisible:s,input:l,minDate:g,maxDate:u,onChange:e}):d==="months"?a.jsx(ee,{date:c,setDate:f,previewDate:m,setPreviewDate:D,filter:o,setViews:v,onChange:e,minDate:g,maxDate:u,input:l}):a.jsx(ne,{date:c,setDate:f,previewDate:m,setPreviewDate:D,filter:o,setViews:v,onChange:e,minDate:g,maxDate:u,input:l})})]}):null]})}),te=k.forwardRef(({value:r,onChange:e,filter:o,input:l=!0,rangedDate:i,disabled:g,minDate:u,maxDate:p,placeholder:h,size:n,status:C,clearable:M,fullWidth:x},w)=>a.jsx(a.Fragment,{children:i?a.jsx(Z,{onChange:e,value:r,input:l,filter:o,disabled:g,ref:w,minDate:u,maxDate:p,placeholder:h,size:n,status:C,clearable:M,fullWidth:x}):a.jsx(re,{onChange:e,value:r,input:l,filter:o,disabled:g,ref:w,minDate:u,maxDate:p,placeholder:h,size:n,status:C,clearable:M,fullWidth:x})}));F.StarasiaDate=te,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|
|
359
|
+
`,U=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],V=["January","February","March","April","May","June","July","August","September","October","November","December"],ne=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function G(r){const[a,t]=m.useState(r),s=m.useRef(null),l=p=>{s.current&&!s.current.contains(p.target)&&t(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:t}}const K="sa-calendar-input-styles";(r=>{if(!document.getElementById(K)){const a=document.createElement("style");a.id=K,a.textContent=r,document.head.appendChild(a)}})(H);const z=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},ae=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:p,...i}=r,u=m.useRef(null),d=()=>{u.current&&i.onClick&&(u.current.focus(),i.onClick(""))},n=t==="disable"||i.disabled,x=!!i.value,b=l&&x&&!n,M=C=>{C.stopPropagation(),p==null||p()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:d,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:z(a),height:z(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:n,value:i.value,ref:u})}),b?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:M,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:z(a),height:z(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:z(a),height:z(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},re=({date:r,setDate:a,dateRange:t,setDateRange:s,onChange:l,minDate:p,maxDate:i,input:u})=>{var g,o,c;let d=new Date(r.getFullYear(),r.getMonth(),1),n=d.getDay(),x=[];const b=r.getMonth();for(let h=0;h<42;h++){h===0&&n===0?d.setDate(d.getDate()-7):h===0?d.setDate(d.getDate()+(h-n)):d.setDate(d.getDate()+1);let w={currentMonth:d.getMonth()===b,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:d.toDateString()===((g=t.from)==null?void 0:g.toDateString())||d.toDateString()===(((o=t.to)==null?void 0:o.toDateString())||((c=t.from)==null?void 0:c.toDateString())),year:d.getFullYear(),isDisabled:p&&d<p||i&&d>i};x.push(w)}const M=h=>{a(h)},C=h=>{var f;let w={...t};if(w.from&&w.to)w={from:h,to:null};else{const y=((f=w.from)==null?void 0:f.getTime())||0;h.getTime()>y?w={from:w.from,to:h}:w={from:h,to:w.from}}s(w),l(w)};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:U.map((h,w)=>e.jsx("p",{children:h},w))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:x.map((h,w)=>{var k;const f=h.date.getTime()>t.from.getTime()&&h.date.getTime()<(((k=t.to)==null?void 0:k.getTime())||t.from.getTime()),y=h.isDisabled;return e.jsx("p",{className:`${h.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${h.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:f?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:y?"none":void 0,cursor:y?"not-allowed":"pointer",color:y?"var(--sa-color-gray-400, #b7b9be)":f?"var(--sa-color-gray-500, #8c8f97)":"",...u?{}:{width:"100%"}},onClick:()=>{y||(M(h.date),C(h.date))},children:h.number},w)})})]})},te=({date:r,setDate:a,filter:t,setViews:s,dateRange:l,setDateRange:p,onChange:i,minDate:u,maxDate:d,input:n})=>{const x=l.from.getFullYear(),b=r.getFullYear(),M=g=>{t?(C(g),a(g)):(s("days"),a(g))},C=g=>{var c;let o={...l};if(o.from&&o.to)o={from:g,to:null};else{const h=((c=o.from)==null?void 0:c.getTime())||0;g.getTime()>h?o={from:o.from,to:g}:o={from:g,to:o.from}}p(o),i(o)};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((g,o)=>{var w,f,y;const c=new Date(b,o).getTime()>l.from.getTime()&&new Date(b,o).getTime()<(((w=l.to)==null?void 0:w.getTime())||l.from.getTime()),h=u&&new Date(b,o)<u||d&&new Date(b,o)>d;return e.jsx("p",{className:x===b&&(o===((f=l.from)==null?void 0:f.getMonth())||o===((y=l.to)==null?void 0:y.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:h?"none":void 0,cursor:h?"not-allowed":"pointer",color:h?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{h||M(new Date(b,o))},children:g.slice(0,3)},o)})})},P=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},se=({date:r,filter:a,setViews:t,setDate:s,dateRange:l,setDateRange:p,onChange:i,minDate:u,maxDate:d,input:n})=>{var w;let x=[];const b=r.getFullYear(),{start:M,end:C}=P(b),g=l.from.getFullYear(),o=(w=l.to)==null?void 0:w.getFullYear();for(let f=M;f<C;f++){const y=new Date(f,0),k=(!u||y>=u)&&(!d||y<=d),Y=f===g||f===o,F=y>l.from&&y<l.to;x.push({year:f,active:Y&&k,highlight:F&&k,disabled:!k})}const c=f=>{a?(h(f),s(f)):(s(f),t("months"))},h=f=>{var k;let y={...l};if(y.from&&y.to)y={from:f,to:null};else{const Y=((k=y.from)==null?void 0:k.getTime())||0;f.getTime()>Y?y={from:y.from,to:f}:y={from:f,to:y.from}}p(y),i(y)};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((f,y)=>e.jsx("p",{className:`${f.active?"sa-calendar-months-active":""} ${f.highlight?"sa-calendar-months-highlight":""} ${f.disabled?"sa-calendar-disabled":""}`,onClick:()=>{f.disabled||c(new Date(f.year,0))},style:{backgroundColor:f.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:f.highlight?"var(--sa-color-gray-500, #8c8f97)":f.active?"":f.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:f.disabled?"not-allowed":"pointer",pointerEvents:f.disbled?"none":"all",...n?{}:{width:"100%"}},children:f.year},y))})},Q=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),X=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),oe=({setViews:r,views:a,filter:t,date:s,setDate:l})=>{const p=()=>{t||r(n=>n==="days"?"months":n==="months"?"years":"days")},i=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},u=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(a==="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))},d=()=>{if(a==="days")return`${V[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${P(s.getFullYear()).start} ~ ${P(s.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx(Q,{onClick:()=>u()}),e.jsx("div",{style:{cursor:"pointer"},onClick:p,children:d()}),e.jsx(X,{onClick:()=>i()})]})};function W(r){const a=new Date(r),t=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${ne[s]} ${t}`}const Z=({label:r,labelPosition:a="outside-top",required:t,optional:s,description:l,helperText:p,errorText:i,fullWidth:u,children:d})=>{const n=["sa-date-field",u?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),x=r?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:r}),s&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,b=e.jsxs(e.Fragment,{children:[p&&!i&&e.jsx("p",{className:"sa-date-field-helper",children:p}),i&&e.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return r?a==="outside-left"?e.jsxs("div",{className:`${n} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[x,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[d,b]})]}):e.jsxs("div",{className:n,children:[x,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),d,b]}):e.jsxs("div",{className:n,children:[l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),d,b]})},_="sa-calendar-styles";(r=>{if(!document.getElementById(_)){const a=document.createElement("style");a.id=_,a.textContent=r,document.head.appendChild(a)}})(H);const le=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:p,maxDate:i,placeholder:u,size:d,status:n,clearable:x,fullWidth:b=!0,label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w},f)=>{const y=w?"error":n,{ref:k,isComponentVisible:Y,setIsComponentVisible:F}=G(!1),D=m.useRef(null),[j,T]=m.useState("days"),[N,E]=m.useState(new Date),[$,L]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(E(r.from),L(r)):(E(new Date),L({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{t&&T(t)},[t]),m.useEffect(()=>{t||T("days")},[Y]),m.useEffect(()=>{s||F(!0)},[s]);const J=()=>{var v,S;if(!r)return"";if(t){if(j==="days")return`${W($.from)} ~ ${W($.to||$.from)||"-"}`;if(j==="months")return`${V[$.from.getMonth()]} ~ ${$.to?V[$.to.getMonth()]:"-"}`;if(j==="years")return`${(v=$.from)==null?void 0:v.getFullYear()} ~ ${((S=$.to)==null?void 0:S.getFullYear())||"-"}`}else return`${W($.from)} ~ ${W($.to||$.from)||"-"}`},I=()=>{if(D.current&&k.current&&s){const v=k.current.getBoundingClientRect(),S=D.current.getBoundingClientRect();window.innerWidth<v.left+S.width?D.current.style.left=`${v.left-S.width+v.width}px`:D.current.style.left=`${v.left}px`,v.top+S.height>window.innerHeight?D.current.style.top=`${v.y-(v.height+S.height-28)}px`:D.current.style.top=`${v.y+v.height}px`}};m.useEffect(()=>{D.current&&k.current&&s&&I()},[D,k,Y]),m.useEffect(()=>{const v=f==null?void 0:f.current;return v&&v.addEventListener("scroll",I),window.addEventListener("scroll",I),()=>{v&&v.removeEventListener("scroll",I),window.removeEventListener("scroll",I)}},[]);const q=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?k:null,children:[s?e.jsx(ae,{value:J(),inputMode:"none",onClick:()=>{F(!0)},onChange:()=>{},disabled:l,placeholder:u,size:d,status:y,clearable:x,onClear:()=>a(void 0)}):null,Y?e.jsxs("div",{className:`sa-calendar ${s?"":"sa-calendar-no-input"}`,ref:D,children:[e.jsx(oe,{setViews:T,views:j,filter:t,date:N,setDate:E}),e.jsx("div",{className:"sa-calendar-body",children:j==="days"?e.jsx(re,{date:N,setDate:E,setIsComponentVisible:F,dateRange:$,setDateRange:L,input:s,onChange:a,minDate:p,maxDate:i}):j==="months"?e.jsx(te,{date:N,setDate:E,filter:t,setViews:T,dateRange:$,setDateRange:L,setIsComponentVisible:F,input:s,onChange:a,minDate:p,maxDate:i}):e.jsx(se,{date:N,setDate:E,filter:t,setViews:T,dateRange:$,setDateRange:L,setIsComponentVisible:F,input:s,onChange:a,minDate:p,maxDate:i})})]}):null]});return e.jsx(Z,{label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w,fullWidth:b,children:q})}),R="sa-calendar-input-styles";(r=>{if(!document.getElementById(R)){const a=document.createElement("style");a.id=R,a.textContent=r,document.head.appendChild(a)}})(H);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},de=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:p,...i}=r,u=m.useRef(null),d=()=>{u.current&&i.onClick&&(u.current.focus(),i.onClick(""))},n=t==="disable"||i.disabled,x=!!i.value,b=l&&x&&!n,M=C=>{C.stopPropagation(),p==null||p()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:d,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:n,value:i.value,ref:u})}),b?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:M,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},ie=({date:r,setDate:a,previewDate:t,setPreviewDate:s,setIsComponentVisible:l,minDate:p,maxDate:i,input:u,onChange:d})=>{let n=new Date(t.getFullYear(),t.getMonth(),1),x=n.getDay(),b=[];const M=r.toDateString(),C=t.getMonth();for(let o=0;o<42;o++){o===0&&x===0?n.setDate(n.getDate()-7):o===0?n.setDate(n.getDate()+(o-x)):n.setDate(n.getDate()+1);let c={currentMonth:n.getMonth()===C,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:p&&n<p||i&&n>i};b.push(c)}const g=o=>{(!p||o>=p)&&(!i||o<=i)&&(a(o),d(o),s(o),u&&l(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:U.map((o,c)=>e.jsx("p",{children:o},c))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:b.map((o,c)=>{const h=o.isDisabled;return e.jsx("p",{className:`${o.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${o.selected?"sa-calendar-days-active":""}`,style:{color:h?"#ccc":void 0,pointerEvents:h?"none":void 0,cursor:h?"not-allowed":"pointer",...u?{}:{width:"100%"}},onClick:()=>{h||g(o.date)},children:o.number},c)})})]})},ce=({date:r,setDate:a,filter:t,setViews:s,onChange:l,previewDate:p,setPreviewDate:i,minDate:u,maxDate:d,input:n})=>{const x=r.getMonth(),b=r.getFullYear(),M=p.getFullYear(),C=g=>{(!u||g>=u)&&(!d||g<=d)&&(t?(l(g),a(g),i(g)):(s("days"),i(g)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((g,o)=>{const c=u&&new Date(M,o,1)<u||d&&new Date(M,o+1,0)>d;return e.jsx("p",{className:o===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||C(new Date(M,o))},children:g.slice(0,3)},o)})})},A=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},he=({date:r,filter:a,setViews:t,setDate:s,onChange:l,previewDate:p,setPreviewDate:i,minDate:u,maxDate:d,input:n})=>{let x=[];const b=p.getFullYear(),{start:M,end:C}=A(b),g=r.getFullYear();for(let c=M;c<C;c++){let h=u&&new Date(c,0,1)<u||d&&new Date(c,11,31)>d;x.push({year:c,active:c===g,isDisabled:h})}const o=c=>{(!u||c>=u)&&(!d||c<=d)&&(a?(l(c),s(c),i(c)):(t("months"),i(c)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((c,h)=>e.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||o(new Date(c.year,0))},children:c.year},h))})},fe=({setViews:r,views:a,filter:t,previewDate:s,setPreviewDate:l})=>{const p=()=>{t||r(n=>n==="days"?"months":n==="months"?"years":"days")},i=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},u=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(a==="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))},d=()=>{if(a==="days")return`${V[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${A(s.getFullYear()).start} ~ ${A(s.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx(Q,{onClick:()=>u()}),e.jsx("div",{style:{cursor:"pointer"},onClick:p,children:d()}),e.jsx(X,{onClick:()=>i()})]})},ee="sa-calendar-styles";(r=>{if(!document.getElementById(ee)){const a=document.createElement("style");a.id=ee,a.textContent=r,document.head.appendChild(a)}})(H);const pe=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:p,maxDate:i,placeholder:u,size:d,status:n,clearable:x,fullWidth:b=!0,label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w},f)=>{const y=w?"error":n,{ref:k,isComponentVisible:Y,setIsComponentVisible:F}=G(!1),D=m.useRef(null),[j,T]=m.useState("days"),[N,E]=m.useState(new Date),[$,L]=m.useState(new Date);m.useEffect(()=>{r?(E(r),L(r)):(E(new Date),L(new Date))},[r]),m.useEffect(()=>{t&&T(t)},[t]),m.useEffect(()=>{t||T("days")},[Y]),m.useEffect(()=>{s||F(!0)},[s]);const J=()=>r?t==="days"?W(N):t==="months"?`${V[N.getMonth()]} ${N.getFullYear()}`:t==="years"?N.getFullYear():W(N):"",I=()=>{if(D.current&&k.current&&s){const v=k.current.getBoundingClientRect(),S=D.current.getBoundingClientRect();window.innerWidth<v.left+S.width?D.current.style.left=`${v.left-S.width+v.width}px`:D.current.style.left=`${v.left}px`,v.top+S.height>window.innerHeight?D.current.style.top=`${v.y-(v.height+S.height-28)}px`:D.current.style.top=`${v.y+v.height}px`}};m.useEffect(()=>{D.current&&k.current&&s&&I()},[D,k,Y]),m.useEffect(()=>{const v=f==null?void 0:f.current;return v&&v.addEventListener("scroll",I),window.addEventListener("scroll",I),()=>{v&&v.removeEventListener("scroll",I),window.removeEventListener("scroll",I)}},[]);const q=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?k:null,children:[s?e.jsx(de,{value:J(),onClick:()=>F(!0),onChange:()=>{},placeholder:u,disabled:l,size:d,status:y,inputMode:"none",clearable:x,onClear:()=>a(void 0)}):null,Y?e.jsxs("div",{className:`sa-calendar ${s?"":"sa-calendar-no-input"}`,ref:D,children:[e.jsx(fe,{setViews:T,views:j,filter:t,previewDate:$,setPreviewDate:L,isComponentVisible:Y}),e.jsx("div",{className:"sa-calendar-body",children:j==="days"?e.jsx(ie,{date:N,setDate:E,previewDate:$,setPreviewDate:L,setIsComponentVisible:F,input:s,minDate:p,maxDate:i,onChange:a}):j==="months"?e.jsx(ce,{date:N,setDate:E,previewDate:$,setPreviewDate:L,filter:t,setViews:T,onChange:a,minDate:p,maxDate:i,input:s}):e.jsx(he,{date:N,setDate:E,previewDate:$,setPreviewDate:L,filter:t,setViews:T,onChange:a,minDate:p,maxDate:i,input:s})})]}):null]});return e.jsx(Z,{label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w,fullWidth:b,children:q})}),ue=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,rangedDate:l,disabled:p,minDate:i,maxDate:u,placeholder:d,size:n,status:x,clearable:b,fullWidth:M,label:C,labelPosition:g,required:o,optional:c,description:h,helperText:w,errorText:f},y)=>{const k={onChange:a,value:r,input:s,filter:t,disabled:p,minDate:i,maxDate:u,placeholder:d,size:n,status:x,clearable:b,fullWidth:M,label:C,labelPosition:g,required:o,optional:c,description:h,helperText:w,errorText:f};return e.jsx(e.Fragment,{children:l?e.jsx(le,{...k,ref:y}):e.jsx(pe,{...k,ref:y})})});B.StarasiaDate=ue,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type DateLabelPosition = "outside-top" | "outside-left";
|
|
1
3
|
export interface IDateProps {
|
|
2
4
|
value?: Date | IDateRange;
|
|
3
5
|
onChange: (props: any) => void;
|
|
@@ -12,6 +14,13 @@ export interface IDateProps {
|
|
|
12
14
|
status?: "error" | "warning";
|
|
13
15
|
clearable?: boolean;
|
|
14
16
|
fullWidth?: boolean;
|
|
17
|
+
label?: React.ReactNode;
|
|
18
|
+
labelPosition?: DateLabelPosition;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
optional?: boolean;
|
|
21
|
+
description?: string;
|
|
22
|
+
helperText?: string;
|
|
23
|
+
errorText?: string;
|
|
15
24
|
}
|
|
16
25
|
export interface IDateRange {
|
|
17
26
|
from: Date | null;
|