@starasia/date 2.0.2 → 3.1.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 +686 -578
- package/dist/date.umd.js +64 -39
- 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,
|
|
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;
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
--sa-date-border-error: var(--sa-color-error-500, #ff4d6d);
|
|
26
26
|
--sa-date-border-warning: var(--sa-color-warning-400, #ed9f30);
|
|
27
27
|
}
|
|
28
|
-
.
|
|
28
|
+
.sa-calendar-wrapper {
|
|
29
29
|
position: relative;
|
|
30
|
+
width: 100%;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
.
|
|
33
|
+
.sa-calendar {
|
|
33
34
|
border-radius: var(--sa-date-radius);
|
|
34
35
|
border: var(--sa-border, 1px) solid var(--sa-date-bg);
|
|
35
36
|
background: var(--sa-date-bg);
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
z-index: 999;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
.
|
|
47
|
+
.sa-calendar.sa-calendar-no-input {
|
|
47
48
|
position: relative !important;
|
|
48
49
|
margin-top: 0px;
|
|
49
50
|
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
border-radius: 0;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
.
|
|
61
|
+
.sa-calendar-header {
|
|
61
62
|
display: flex;
|
|
62
63
|
flex-direction: row;
|
|
63
64
|
align-items: center;
|
|
@@ -65,25 +66,25 @@
|
|
|
65
66
|
gap: var(--sa-spacing-xs, 4px);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
.
|
|
69
|
+
.sa-calendar-days-name-preivew {
|
|
69
70
|
display: flex;
|
|
70
71
|
gap: var(--sa-spacing-sm, 8px);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
.
|
|
74
|
+
.sa-calendar-days-name-preivew p {
|
|
74
75
|
color: var(--sa-date-text-subtle);
|
|
75
76
|
font-size: var(--sa-font-size-md, 14px);
|
|
76
77
|
flex: 1;
|
|
77
78
|
display: grid;
|
|
78
79
|
place-content: center;
|
|
79
80
|
}
|
|
80
|
-
.
|
|
81
|
+
.sa-calendar-days-number-preivew {
|
|
81
82
|
display: grid;
|
|
82
83
|
grid-template-columns: repeat(7, 1fr);
|
|
83
84
|
gap: var(--sa-spacing-sm, 8px);
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
.
|
|
87
|
+
.sa-calendar-days-number-preivew p {
|
|
87
88
|
font-size: var(--sa-font-size-md, 14px);
|
|
88
89
|
text-align: center;
|
|
89
90
|
width: 35px;
|
|
@@ -96,31 +97,31 @@
|
|
|
96
97
|
border-radius: var(--sa-date-radius);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
.
|
|
100
|
+
.sa-calendar-days {
|
|
100
101
|
color: var(--sa-date-text-muted);
|
|
101
102
|
}
|
|
102
|
-
.
|
|
103
|
+
.sa-calendar-days-current {
|
|
103
104
|
color: var(--sa-date-text-primary);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
.
|
|
107
|
+
.sa-calendar-days-number-preivew p:hover {
|
|
107
108
|
background: var(--sa-date-brand-subtle);
|
|
108
109
|
color: var(--sa-date-brand-secondary);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
.
|
|
112
|
+
.sa-calendar-days-active {
|
|
112
113
|
background: var(--sa-date-brand-secondary);
|
|
113
114
|
color: var(--sa-date-brand);
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
/* MONTH STYLING */
|
|
117
|
-
.
|
|
118
|
+
.sa-calendar-months-preview {
|
|
118
119
|
display: grid;
|
|
119
120
|
grid-template-columns: repeat(3, 1fr);
|
|
120
121
|
row-gap: var(--sa-spacing-xs, 4px);
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
.
|
|
124
|
+
.sa-calendar-months-preview p {
|
|
124
125
|
width: 98px;
|
|
125
126
|
height: 48px;
|
|
126
127
|
display: grid;
|
|
@@ -129,23 +130,23 @@
|
|
|
129
130
|
border-radius: var(--sa-date-radius);
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
.
|
|
133
|
+
.sa-calendar-months-preview p:hover {
|
|
133
134
|
background: var(--sa-date-brand-subtle);
|
|
134
135
|
color: var(--sa-date-brand-secondary);
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
.
|
|
138
|
+
.sa-calendar-months-active {
|
|
138
139
|
background: var(--sa-date-brand-secondary);
|
|
139
140
|
color: var(--sa-date-brand);
|
|
140
141
|
}
|
|
141
142
|
/* Year STYLING */
|
|
142
|
-
.
|
|
143
|
+
.sa-calendar-years-preview {
|
|
143
144
|
display: grid;
|
|
144
145
|
grid-template-columns: repeat(3, 1fr);
|
|
145
146
|
row-gap: var(--sa-spacing-xs, 4px);
|
|
146
147
|
}
|
|
147
148
|
|
|
148
|
-
.
|
|
149
|
+
.sa-calendar-years-preview p {
|
|
149
150
|
width: 98px;
|
|
150
151
|
height: 48px;
|
|
151
152
|
display: grid;
|
|
@@ -154,38 +155,39 @@
|
|
|
154
155
|
border-radius: var(--sa-date-radius);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
.
|
|
158
|
+
.sa-calendar-years-preview p:hover {
|
|
158
159
|
background: var(--sa-date-brand-subtle);
|
|
159
160
|
color: var(--sa-date-brand-secondary);
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
.
|
|
163
|
+
.sa-calendar-years-active {
|
|
163
164
|
background: var(--sa-date-brand-secondary);
|
|
164
165
|
color: var(--sa-date-brand);
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
/* INPUT */
|
|
168
169
|
|
|
169
|
-
.
|
|
170
|
+
.sa-calendar-input-container {
|
|
170
171
|
box-sizing: border-box;
|
|
171
172
|
overflow: hidden;
|
|
172
173
|
display: flex;
|
|
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) {
|
|
179
181
|
border-color: var(--sa-date-brand);
|
|
180
182
|
box-shadow: 0px 0px 0px 2px var(--sa-date-brand-subtle);
|
|
181
183
|
}
|
|
182
|
-
.
|
|
184
|
+
.sa-calendar-input-container:has(input:disabled) {
|
|
183
185
|
border-color: var(--sa-date-border-disabled);
|
|
184
186
|
background-color: var(--sa-date-bg-disabled);
|
|
185
187
|
pointer-events: none;
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
.
|
|
190
|
+
.sa-calendar-input-outline {
|
|
189
191
|
border-color: var(--sa-date-border-color);
|
|
190
192
|
/* border-color: var(--sa-date-text-muted); */
|
|
191
193
|
background-color: transparent;
|
|
@@ -196,31 +198,31 @@
|
|
|
196
198
|
/* padding-inline: var(--sa-spacing-3, 12px); */
|
|
197
199
|
}
|
|
198
200
|
|
|
199
|
-
.
|
|
201
|
+
.sa-calendar-input-container.sm {
|
|
200
202
|
height: var(--sa-h-8, 32px);
|
|
201
203
|
border-radius: var(--sa-date-radius);
|
|
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
|
-
.
|
|
206
|
-
height:
|
|
207
|
+
.sa-calendar-input-container.md {
|
|
208
|
+
height: var(--sa-h-10, 40px);
|
|
207
209
|
border-radius: var(--sa-date-radius);
|
|
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
215
|
border-radius: var(--sa-date-radius-lg);
|
|
214
|
-
font-size: var(--sa-font-size-
|
|
216
|
+
font-size: var(--sa-font-size-md, 14px);
|
|
215
217
|
padding-inline: var(--sa-spacing-3, 12px);
|
|
216
218
|
}
|
|
217
219
|
|
|
218
|
-
.
|
|
220
|
+
.sa-calendar-input-preview-container {
|
|
219
221
|
width: 100%;
|
|
220
222
|
position: relative;
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
.
|
|
225
|
+
.sa-calendar-input {
|
|
224
226
|
width: 100%;
|
|
225
227
|
box-sizing: border-box;
|
|
226
228
|
height: 100%;
|
|
@@ -232,24 +234,47 @@
|
|
|
232
234
|
cursor: pointer;
|
|
233
235
|
}
|
|
234
236
|
|
|
235
|
-
.
|
|
237
|
+
.sa-calendar-input::placeholder {
|
|
236
238
|
color: var(--sa-date-placeholder);
|
|
237
239
|
font-weight: var(--sa-font-weight-normal, 300);
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
/* INPUT ICON */
|
|
241
|
-
.
|
|
243
|
+
.sa-calendar-input-container-icon-left {
|
|
242
244
|
display: flex;
|
|
243
245
|
}
|
|
244
|
-
.
|
|
246
|
+
.sa-calendar-input-container-icon-right {
|
|
245
247
|
display: flex;
|
|
246
248
|
}
|
|
247
249
|
|
|
248
|
-
.
|
|
250
|
+
.sa-calendar-input-container-error {
|
|
249
251
|
border-color: var(--sa-date-border-error) !important;
|
|
250
252
|
}
|
|
251
253
|
|
|
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="starasia-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 n.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[n.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),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:"starasia-calendar-input-preview-container",children:n.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),n.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),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"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:l,minDate:g,maxDate:p,input:w})=>{var h,t,d;let u=new Date(r.getFullYear(),r.getMonth(),1),a=u.getDay(),x=[];const b=r.getMonth();for(let c=0;c<42;c++){c===0&&a===0?u.setDate(u.getDate()-7):c===0?u.setDate(u.getDate()+(c-a)):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())||((d=s.from)==null?void 0:d.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=c=>{e(c)},k=c=>{var i;let y={...s};if(y.from&&y.to)y={from:c,to:null};else{const f=((i=y.from)==null?void 0:i.getTime())||0;c.getTime()>f?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),l(y)};return n.jsxs("div",{className:"starasia-calendar-days-preivew",children:[n.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((c,y)=>n.jsx("p",{children:c},y))}),n.jsx("div",{className:"starasia-calendar-days-number-preivew",children:x.map((c,y)=>{var D;const i=c.date.getTime()>s.from.getTime()&&c.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=c.isDisabled;return n.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:i?"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)":i?"var(--sa-color-gray-500, #8c8f97)":"",...w?{}:{width:"100%"}},onClick:()=>{f||(M(c.date),k(c.date))},children:c.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:a})=>{const x=l.from.getFullYear(),b=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var d;let t={...l};if(t.from&&t.to)t={from:h,to:null};else{const c=((d=t.from)==null?void 0:d.getTime())||0;h.getTime()>c?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return n.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,i,f;const d=new Date(b,t).getTime()>l.from.getTime()&&new Date(b,t).getTime()<(((y=l.to)==null?void 0:y.getTime())||l.from.getTime()),c=w&&new Date(b,t)<w||u&&new Date(b,t)>u;return n.jsx("p",{className:x===b&&(t===((i=l.from)==null?void 0:i.getMonth())||t===((f=l.to)==null?void 0:f.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",color:c?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...a?{}:{width:"100%"}},onClick:()=>{c||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:a})=>{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 i=M;i<k;i++){const f=new Date(i,0),D=(!w||f>=w)&&(!u||f<=u),C=i===h||i===t,v=f>l.from&&f<l.to;x.push({year:i,active:C&&D,highlight:v&&D,disabled:!D})}const d=i=>{e?(c(i),o(i)):(o(i),s("months"))},c=i=>{var D;let f={...l};if(f.from&&f.to)f={from:i,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;i.getTime()>C?f={from:f.from,to:i}:f={from:i,to:f.from}}g(f),p(f)};return n.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((i,f)=>n.jsx("p",{className:`${i.active?"starasia-calendar-months-active":""} ${i.highlight?"starasia-calendar-months-highlight":""} ${i.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{i.disabled||d(new Date(i.year,0))},style:{backgroundColor:i.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:i.highlight?"var(--sa-color-gray-500, #8c8f97)":i.active?"":i.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:i.disabled?"not-allowed":"pointer",pointerEvents:i.disbled?"none":"all",...a?{}:{width:"100%"}},children:i.year},f))})},z=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,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"})}),O=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,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"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:l})=>{const g=()=>{s||r(a=>a==="days"?"months":a==="months"?"years":"days")},p=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()+10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()+1,a.getMonth()));return}l(a=>new Date(a.getFullYear(),a.getMonth()+1))},w=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()-10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()-1,a.getMonth()));return}l(a=>new Date(a.getMonth()===0?a.getFullYear()-1:a.getFullYear(),a.getMonth()===0?11:a.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 n.jsxs("div",{className:"starasia-calendar-header",children:[n.jsx(z,{onClick:()=>w()}),n.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),n.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="starasia-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:a},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[i,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&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var v,$;if(!r)return"";if(s){if(t==="days")return`${N(i.from)} ~ ${N(i.to||i.from)||"-"}`;if(t==="months")return`${F[i.from.getMonth()]} ~ ${i.to?F[i.to.getMonth()]:"-"}`;if(t==="years")return`${(v=i.from)==null?void 0:v.getFullYear()} ~ ${(($=i.to)==null?void 0:$.getFullYear())||"-"}`}else return`${N(i.from)} ~ ${N(i.to||i.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)}},[]),n.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:l,placeholder:w,size:u,status:a}):null,M?n.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[n.jsx(K,{setViews:d,views:t,filter:s,date:c,setDate:y}),n.jsx("div",{className:"starasia-calendar-body",children:t==="days"?n.jsx(q,{date:c,setDate:y,setIsComponentVisible:k,dateRange:i,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?n.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):n.jsx(U,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="starasia-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 n.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[n.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),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:"starasia-calendar-input-preview-container",children:n.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),n.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),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"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:g,maxDate:p,input:w,onChange:u})=>{let a=new Date(s.getFullYear(),s.getMonth(),1),x=a.getDay(),b=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?a.setDate(a.getDate()-7):t===0?a.setDate(a.getDate()+(t-x)):a.setDate(a.getDate()+1);let d={currentMonth:a.getMonth()===k,date:new Date(a),month:a.getMonth(),number:a.getDate(),selected:a.toDateString()===M,year:a.getFullYear(),isDisabled:g&&a<g||p&&a>p};b.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),w&&l(!1))};return n.jsxs("div",{className:"starasia-calendar-days-preivew",children:[n.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,d)=>n.jsx("p",{children:t},d))}),n.jsx("div",{className:"starasia-calendar-days-number-preivew",children:b.map((t,d)=>{const c=t.isDisabled;return n.jsx("p",{className:`${t.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${t.selected?"starasia-calendar-days-active":""}`,style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...w?{}:{width:"100%"}},onClick:()=>{c||h(t.date)},children:t.number},d)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:a})=>{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 n.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{const d=w&&new Date(M,t,1)<w||u&&new Date(M,t+1,0)>u;return n.jsx("p",{className:t===x&&M===b?"starasia-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...a?{}:{width:"100%"}},onClick:()=>{d||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:a})=>{let x=[];const b=g.getFullYear(),{start:M,end:k}=I(b),h=r.getFullYear();for(let d=M;d<k;d++){let c=w&&new Date(d,0,1)<w||u&&new Date(d,11,31)>u;x.push({year:d,active:d===h,isDisabled:c})}const t=d=>{(!w||d>=w)&&(!u||d<=u)&&(e?(l(d),o(d),p(d)):(s("months"),p(d)))};return n.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((d,c)=>n.jsx("p",{className:d.active?"starasia-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...a?{}:{width:"100%"}},onClick:()=>{d.isDisabled||t(new Date(d.year,0))},children:d.year},c))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:l})=>{const g=()=>{s||r(a=>a==="days"?"months":a==="months"?"years":"days")},p=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()+10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()+1,a.getMonth()));return}l(a=>new Date(a.getFullYear(),a.getMonth()+1))},w=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()-10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()-1,a.getMonth()));return}l(a=>new Date(a.getMonth()===0?a.getFullYear()-1:a.getFullYear(),a.getMonth()===0?11:a.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 n.jsxs("div",{className:"starasia-calendar-header",children:[n.jsx(z,{onClick:()=>w()}),n.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),n.jsx(O,{onClick:()=>p()})]})},J="starasia-calendar-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(E);const ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:a},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[i,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?N(c):s==="months"?`${F[c.getMonth()]} ${c.getFullYear()}`:s==="years"?c.getFullYear():N(c):"",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)}},[]),n.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:w,disabled:l,size:u,status:a,inputMode:"none"}):null,M?n.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[n.jsx(ee,{setViews:d,views:t,filter:s,previewDate:i,setPreviewDate:f,isComponentVisible:M}),n.jsx("div",{className:"starasia-calendar-body",children:t==="days"?n.jsx(Z,{date:c,setDate:y,previewDate:i,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?n.jsx(_,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):n.jsx(R,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:l,disabled:g,minDate:p,maxDate:w,placeholder:u,size:a,status:x},b)=>n.jsx(n.Fragment,{children:l?n.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:a,status:x}):n.jsx(ae,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:a,status:x})}));Y.StarasiaDate=ne,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">>;
|