@starasia/date 1.0.5 → 2.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.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(Y,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):(Y=typeof globalThis<"u"?globalThis:Y||self,e(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,e,m){"use strict";const N=`@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");
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,m){"use strict";const N=`@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;
@@ -8,105 +8,36 @@
8
8
  /* box-sizing: border-box; */
9
9
  }
10
10
  :root {
11
- /* border radius */
12
- --starasia-ui-date-border-radius: var(--starasia-ui-radii-md, 8px);
13
- --starasia-ui-date-border-radius-sm: var(--starasia-ui-radii-md, 8px);
14
- --starasia-ui-date-border-radius-md: var(--starasia-ui-radii-md, 8px);
15
- --starasia-ui-date-border-radius-lg: var(--starasia-ui-radii-lg, 12px);
16
-
17
- /* color */
18
- --starasia-ui-date-color-black-secondary: var(
19
- --starasia-ui-color-gray-50,
20
- rgba(249, 250, 251, 1)
21
- );
22
- --starasia-ui-date-color-white: var(--starasia-ui-color-gray-50, rgba(255, 254, 255, 1));
23
- --starasia-ui-date-color-border: rgba(120, 134, 127, 0.2);
24
- --starasia-ui-date-color-disabled-border: rgba(120, 134, 127, 0.2);
25
- --starasia-ui-date-color-disabled-bg: rgba(120, 134, 127, 0.1);
26
-
27
- /* box shadow */
28
- --starasia-ui-date-box-shadow: var(
29
- --starasia-ui-shadow-md,
30
- 0 4px 6px -1px rgb(0 0 0 / 0.1),
31
- 0 2px 4px -2px rgb(0 0 0 / 0.1)
32
- );
33
-
34
- /* color */
35
- /* gray / black */
36
- --starasia-ui-date-color-primary-black: var(
37
- --starasia-ui-color-gray-700,
38
- rgba(55, 65, 81, 1)
39
- );
40
- --starasia-ui-date-color-secondary-black: var(
41
- --starasia-ui-color-gray-500,
42
- rgba(107, 114, 128, 1)
43
- );
44
- --starasia-ui-date-color-tertiary-black: var(
45
- --starasia-ui-color-gray-300,
46
- rgba(209, 213, 219, 1)
47
- );
48
- --starasia-ui-date-color-quaternary-black: var(
49
- --starasia-ui-color-gray-50,
50
- rgba(249, 250, 251, 1)
51
- );
52
-
53
- /* brand */
54
- --starasia-ui-date-color-primary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
55
- --starasia-ui-date-color-secondary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
56
- --starasia-ui-date-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary, rgba(144, 176, 218, 1));
57
- --starasia-ui-date-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
58
-
59
- /* spacing */
60
- --starasia-ui-date-spacing-xs: var(--starasia-ui-spacing-xs, 4px);
61
- --starasia-ui-date-spacing-sm: var(--starasia-ui-spacing-sm, 8px);
62
- --starasia-ui-date-spacing-ms: var(--starasia-ui-spacing-3, 12px);
63
- --starasia-ui-date-spacing-md: var(--starasia-ui-spacing-md, 16);
64
- --starasia-ui-date-spacing-lg: var(--starasia-ui-spacing-lg, 24px);
65
-
66
- /* height */
67
- --starasia-ui-date-input-height: var(--starasia-ui-h-10, 40px);
68
- --starasia-ui-date-height-sm: var(--starasia-ui-h-8, 32px);
69
- --starasia-ui-date-height-md: 38px;
70
- --starasia-ui-date-height-lg: var(--starasia-ui-h-12, 48px);
71
-
72
- /* color */
73
- --starasia-ui-input-color-tertiary-gray: var(
74
- --starasia-ui-color-gray-300,
75
- rgba(209, 213, 219, 1)
76
- );
77
-
78
- --starasia-ui-date-placholder-color: var(
79
- --starasia-ui-color-gray-200,
80
- rgba(201, 206, 204, 1)
81
- );
82
- --starasia-ui-date-placholder-fontWeight: var(
83
- --starasia-ui-fontWeights-normal,
84
- 300
85
- );
86
-
87
- --starasia-ui-input-color-secondary-red: var(
88
- --starasia-ui-color-red-500,
89
- rgba(239, 68, 68, 1)
90
- );
91
- --starasia-ui-input-color-secondary-yellow: var(
92
- --starasia-ui-color-yellow-500,
93
- rgba(234, 179, 8, 1)
94
- );
11
+ --sa-date-radius: var(--sa-radii-md, 0.5rem);
12
+ --sa-date-radius-lg: var(--sa-radii-lg, 0.75rem);
13
+ --sa-date-bg: var(--sa-background-primary, #ffffff);
14
+ --sa-date-border-color: rgba(120, 134, 127, 0.2);
15
+ --sa-date-border-disabled: rgba(120, 134, 127, 0.2);
16
+ --sa-date-bg-disabled: rgba(120, 134, 127, 0.1);
17
+ --sa-date-shadow: var(--sa-shadow-md, 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1));
18
+ --sa-date-text-primary: var(--sa-color-gray-700, #6b6e76);
19
+ --sa-date-text-subtle: var(--sa-color-gray-500, #8c8f97);
20
+ --sa-date-text-muted: var(--sa-color-gray-300, #dddee1);
21
+ --sa-date-brand: var(--sa-background-brand, #04254f);
22
+ --sa-date-brand-secondary: var(--sa-color-brand-200, #99b3db);
23
+ --sa-date-brand-subtle: var(--sa-color-brand-50, #e6edf6);
24
+ --sa-date-placeholder: var(--sa-color-gray-400, #b7b9be);
25
+ --sa-date-border-error: var(--sa-color-error-500, #ff4d6d);
26
+ --sa-date-border-warning: var(--sa-color-warning-400, #ed9f30);
95
27
  }
96
28
  .starasia-calendar-wrapper {
97
29
  position: relative;
98
30
  }
99
31
 
100
32
  .starasia-calendar {
101
- border-radius: var(--starasia-ui-date-border-radius);
102
- border: var(--starasia-ui-border, 1px) solid
103
- var(--starasia-ui-date-color-black-secondary);
104
- background: var(--starasia-ui-date-color-black-secondary);
105
- box-shadow: var(--starasia-ui-date-box-shadow);
106
- padding: var(--starasia-ui-date-spacing-lg) var(--starasia-ui-date-spacing-md);
33
+ border-radius: var(--sa-date-radius);
34
+ border: var(--sa-border, 1px) solid var(--sa-date-bg);
35
+ background: var(--sa-date-bg);
36
+ box-shadow: var(--sa-date-shadow);
37
+ padding: var(--sa-spacing-lg, 24px) var(--sa-spacing-md, 16px);
107
38
  width: max-content;
108
39
  display: flex;
109
- gap: var(--starasia-ui-date-spacing-ms);
40
+ gap: var(--sa-spacing-3, 12px);
110
41
  flex-direction: column;
111
42
  position: fixed;
112
43
  z-index: 999;
@@ -120,7 +51,7 @@
120
51
  width: 100%;
121
52
  box-shadow: unset;
122
53
  border: none;
123
- background-color: var(--starasia-ui-date-color-white);
54
+ background-color: var(--sa-date-bg);
124
55
  /* background-color: white; */
125
56
  height: 100%;
126
57
  border-radius: 0;
@@ -131,17 +62,17 @@
131
62
  flex-direction: row;
132
63
  align-items: center;
133
64
  justify-content: space-between;
134
- gap: var(--starasia-ui-date-spacing-xs);
65
+ gap: var(--sa-spacing-xs, 4px);
135
66
  }
136
67
 
137
68
  .starasia-calendar-days-name-preivew {
138
69
  display: flex;
139
- gap: var(--starasia-ui-date-spacing-sm);
70
+ gap: var(--sa-spacing-sm, 8px);
140
71
  }
141
72
 
142
73
  .starasia-calendar-days-name-preivew p {
143
- color: var(--starasia-ui-date-color-secondary-black);
144
- font-size: var(--starasia-ui-fontSizes-md, 14px);
74
+ color: var(--sa-date-text-subtle);
75
+ font-size: var(--sa-font-size-md, 14px);
145
76
  flex: 1;
146
77
  display: grid;
147
78
  place-content: center;
@@ -149,11 +80,11 @@
149
80
  .starasia-calendar-days-number-preivew {
150
81
  display: grid;
151
82
  grid-template-columns: repeat(7, 1fr);
152
- gap: var(--starasia-ui-date-spacing-sm);
83
+ gap: var(--sa-spacing-sm, 8px);
153
84
  }
154
85
 
155
86
  .starasia-calendar-days-number-preivew p {
156
- font-size: var(--starasia-ui-fontSizes-md, 14px);
87
+ font-size: var(--sa-font-size-md, 14px);
157
88
  text-align: center;
158
89
  width: 35px;
159
90
  height: 32px;
@@ -162,31 +93,31 @@
162
93
  place-content: center;
163
94
  cursor: pointer;
164
95
  font-weight: 500;
165
- border-radius: var(--starasia-ui-date-border-radius);
96
+ border-radius: var(--sa-date-radius);
166
97
  }
167
98
 
168
99
  .starasia-calendar-days {
169
- color: var(--starasia-ui-date-color-tertiary-black);
100
+ color: var(--sa-date-text-muted);
170
101
  }
171
102
  .starasia-calendar-days-current {
172
- color: var(--starasia-ui-date-color-primary-black);
103
+ color: var(--sa-date-text-primary);
173
104
  }
174
105
 
175
106
  .starasia-calendar-days-number-preivew p:hover {
176
- background: var(--starasia-ui-date-color-quaternary-blue);
177
- color: var(--starasia-ui-date-color-tertiary-blue);
107
+ background: var(--sa-date-brand-subtle);
108
+ color: var(--sa-date-brand-secondary);
178
109
  }
179
110
 
180
111
  .starasia-calendar-days-active {
181
- background: var(--starasia-ui-date-color-tertiary-blue);
182
- color: var(--starasia-ui-date-color-primary-blue);
112
+ background: var(--sa-date-brand-secondary);
113
+ color: var(--sa-date-brand);
183
114
  }
184
115
 
185
116
  /* MONTH STYLING */
186
117
  .starasia-calendar-months-preview {
187
118
  display: grid;
188
119
  grid-template-columns: repeat(3, 1fr);
189
- row-gap: var(--starasia-ui-date-spacing-xs);
120
+ row-gap: var(--sa-spacing-xs, 4px);
190
121
  }
191
122
 
192
123
  .starasia-calendar-months-preview p {
@@ -195,23 +126,23 @@
195
126
  display: grid;
196
127
  place-content: center;
197
128
  cursor: pointer;
198
- border-radius: var(--starasia-ui-date-border-radius);
129
+ border-radius: var(--sa-date-radius);
199
130
  }
200
131
 
201
132
  .starasia-calendar-months-preview p:hover {
202
- background: var(--starasia-ui-date-color-quaternary-blue);
203
- color: var(--starasia-ui-date-color-tertiary-blue);
133
+ background: var(--sa-date-brand-subtle);
134
+ color: var(--sa-date-brand-secondary);
204
135
  }
205
136
 
206
137
  .starasia-calendar-months-active {
207
- background: var(--starasia-ui-date-color-tertiary-blue);
208
- color: var(--starasia-ui-date-color-primary-blue);
138
+ background: var(--sa-date-brand-secondary);
139
+ color: var(--sa-date-brand);
209
140
  }
210
141
  /* Year STYLING */
211
142
  .starasia-calendar-years-preview {
212
143
  display: grid;
213
144
  grid-template-columns: repeat(3, 1fr);
214
- row-gap: var(--starasia-ui-date-spacing-xs);
145
+ row-gap: var(--sa-spacing-xs, 4px);
215
146
  }
216
147
 
217
148
  .starasia-calendar-years-preview p {
@@ -220,17 +151,17 @@
220
151
  display: grid;
221
152
  place-content: center;
222
153
  cursor: pointer;
223
- border-radius: var(--starasia-ui-date-border-radius);
154
+ border-radius: var(--sa-date-radius);
224
155
  }
225
156
 
226
157
  .starasia-calendar-years-preview p:hover {
227
- background: var(--starasia-ui-date-color-quaternary-blue);
228
- color: var(--starasia-ui-date-color-tertiary-blue);
158
+ background: var(--sa-date-brand-subtle);
159
+ color: var(--sa-date-brand-secondary);
229
160
  }
230
161
 
231
162
  .starasia-calendar-years-active {
232
- background: var(--starasia-ui-date-color-tertiary-blue);
233
- color: var(--starasia-ui-date-color-primary-blue);
163
+ background: var(--sa-date-brand-secondary);
164
+ color: var(--sa-date-brand);
234
165
  }
235
166
 
236
167
  /* INPUT */
@@ -240,50 +171,48 @@
240
171
  overflow: hidden;
241
172
  display: flex;
242
173
  align-items: center;
243
- gap: var(--starasia-ui-date-spacing-sm);
174
+ gap: var(--sa-spacing-sm, 8px);
244
175
  cursor: pointer;
245
176
  }
246
177
 
247
178
  .starasia-calendar-input-container:has(input:focus) {
248
- border-color: var(--starasia-ui-date-color-primary-blue);
249
- box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.2);
179
+ border-color: var(--sa-date-brand);
180
+ box-shadow: 0px 0px 0px 2px var(--sa-date-brand-subtle);
250
181
  }
251
182
  .starasia-calendar-input-container:has(input:disabled) {
252
- /* border-color: var(--starasia-ui-input-color-tertiary-gray); */
253
- /* background-color: var(--starasia-ui-input-color-tertiary-gray); */
254
- border-color: var(--starasia-ui-date-color-disabled-border);
255
- background-color: var(--starasia-ui-date-color-disabled-bg);
183
+ border-color: var(--sa-date-border-disabled);
184
+ background-color: var(--sa-date-bg-disabled);
256
185
  pointer-events: none;
257
186
  }
258
187
 
259
188
  .starasia-calendar-input-outline {
260
- border-color: var(--starasia-ui-date-color-border);
261
- /* border-color: var(--starasia-ui-date-color-tertiary-black); */
189
+ border-color: var(--sa-date-border-color);
190
+ /* border-color: var(--sa-date-text-muted); */
262
191
  background-color: transparent;
263
- border-width: var(--starasia-ui-border, 1px);
192
+ border-width: var(--sa-border, 1px);
264
193
  border-style: solid;
265
- /* height: var(--starasia-ui-date-input-height); */
266
- /* border-radius: var(--starasia-ui-date-border-radius); */
267
- /* padding-inline: var(--starasia-ui-date-spacing-ms); */
194
+ /* height: var(--sa-h-10, 40px); */
195
+ /* border-radius: var(--sa-date-radius); */
196
+ /* padding-inline: var(--sa-spacing-3, 12px); */
268
197
  }
269
198
 
270
199
  .starasia-calendar-input-container.sm {
271
- height: var(--starasia-ui-date-height-sm);
272
- border-radius: var(--starasia-ui-date-border-radius-sm);
273
- font-size: var(--starasia-ui-fontSizes-sm, 12px);
274
- padding-inline: var(--starasia-ui-date-spacing-sm);
200
+ height: var(--sa-h-8, 32px);
201
+ border-radius: var(--sa-date-radius);
202
+ font-size: var(--sa-font-size-sm, 12px);
203
+ padding-inline: var(--sa-spacing-sm, 8px);
275
204
  }
276
205
  .starasia-calendar-input-container.md {
277
- height: var(--starasia-ui-date-height-md);
278
- border-radius: var(--starasia-ui-date-border-radius-md);
279
- font-size: var(--starasia-ui-fontSizes-md, 14px);
280
- padding-inline: var(--starasia-ui-date-spacing-ms);
206
+ height: 38px;
207
+ border-radius: var(--sa-date-radius);
208
+ font-size: var(--sa-font-size-md, 14px);
209
+ padding-inline: var(--sa-spacing-3, 12px);
281
210
  }
282
211
  .starasia-calendar-input-container.lg {
283
- height: var(--starasia-ui-date-height-lg);
284
- border-radius: var(--starasia-ui-date-border-radius-lg);
285
- font-size: var(--starasia-ui-fontSizes-lg, 16px);
286
- padding-inline: var(--starasia-ui-date-spacing-ms);
212
+ height: var(--sa-h-12, 48px);
213
+ border-radius: var(--sa-date-radius-lg);
214
+ font-size: var(--sa-font-size-lg, 16px);
215
+ padding-inline: var(--sa-spacing-3, 12px);
287
216
  }
288
217
 
289
218
  .starasia-calendar-input-preview-container {
@@ -304,8 +233,8 @@
304
233
  }
305
234
 
306
235
  .starasia-calendar-input::placeholder {
307
- color: var(--starasia-ui-date-placholder-color);
308
- font-weight: var(--starasia-ui-date-placholder-fontWeight);
236
+ color: var(--sa-date-placeholder);
237
+ font-weight: var(--sa-font-weight-normal, 300);
309
238
  }
310
239
 
311
240
  /* INPUT ICON */
@@ -317,10 +246,10 @@
317
246
  }
318
247
 
319
248
  .starasia-calendar-input-container-error {
320
- border-color: var(--starasia-ui-input-color-secondary-red) !important;
249
+ border-color: var(--sa-date-border-error) !important;
321
250
  }
322
251
 
323
252
  .starasia-calendar-input-container-warning {
324
- border-color: var(--starasia-ui-input-color-secondary-yellow) !important;
253
+ border-color: var(--sa-date-border-warning) !important;
325
254
  }
326
- `,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],q=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(n){const[a,s]=m.useState(n),i=m.useRef(null),o=g=>{i.current&&!i.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:i,isComponentVisible:a,setIsComponentVisible:s}}const V="starasia-calendar-input-styles";(n=>{if(!document.getElementById(V)){const a=document.createElement("style");a.id=V,a.textContent=n,document.head.appendChild(a)}})(N);const S=n=>{if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},J=n=>{const{size:a="md",status:s="default",variant:i="outline",...o}=n,g=m.useRef(null),f=()=>{g.current&&o.onClick&&(g.current.focus(),o.onClick(""))};return e.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${i} starasia-calendar-input-container-${s} ${a} `,onClick:f,children:[e.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(a),height:S(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:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"starasia-calendar-input-preview-container",children:e.jsx("input",{className:"starasia-calendar-input",...o,disabled:s==="disable"?!0:o.disabled,value:o.value,ref:g})}),e.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(a),height:S(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},P=({date:n,setDate:a,dateRange:s,setDateRange:i,onChange:o,minDate:g,maxDate:f,input:w})=>{var u,t,c;let h=new Date(n.getFullYear(),n.getMonth(),1),r=h.getDay(),k=[];const v=n.getMonth();for(let d=0;d<42;d++){d===0&&r===0?h.setDate(h.getDate()-7):d===0?h.setDate(h.getDate()+(d-r)):h.setDate(h.getDate()+1);let y={currentMonth:h.getMonth()===v,date:new Date(h),month:h.getMonth(),number:h.getDate(),selected:h.toDateString()===((u=s.from)==null?void 0:u.toDateString())||h.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((c=s.from)==null?void 0:c.toDateString())),year:h.getFullYear(),isDisabled:g&&h<g||f&&h>f};k.push(y)}const M=d=>{a(d)},x=d=>{var l;let y={...s};if(y.from&&y.to)y={from:d,to:null};else{const p=((l=y.from)==null?void 0:l.getTime())||0;d.getTime()>p?y={from:y.from,to:d}:y={from:d,to:y.from}}i(y),o(y)};return e.jsxs("div",{className:"starasia-calendar-days-preivew",children:[e.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((d,y)=>e.jsx("p",{children:d},y))}),e.jsx("div",{className:"starasia-calendar-days-number-preivew",children:k.map((d,y)=>{var D;const l=d.date.getTime()>s.from.getTime()&&d.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),p=d.isDisabled;return e.jsx("p",{className:`${d.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${d.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:l?"rgba(100, 181, 246, 0.1)":"",pointerEvents:p?"none":void 0,cursor:p?"not-allowed":"pointer",color:p?"#ccc":l?"#b0b0b0":"",...w?{}:{width:"100%"}},onClick:()=>{p||(M(d.date),x(d.date))},children:d.number},y)})})]})},G=({date:n,setDate:a,filter:s,setViews:i,dateRange:o,setDateRange:g,onChange:f,minDate:w,maxDate:h,input:r})=>{const k=o.from.getFullYear(),v=n.getFullYear(),M=u=>{s?(x(u),a(u)):(i("days"),a(u))},x=u=>{var c;let t={...o};if(t.from&&t.to)t={from:u,to:null};else{const d=((c=t.from)==null?void 0:c.getTime())||0;u.getTime()>d?t={from:t.from,to:u}:t={from:u,to:t.from}}g(t),f(t)};return e.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((u,t)=>{var y,l,p;const c=new Date(v,t).getTime()>o.from.getTime()&&new Date(v,t).getTime()<(((y=o.to)==null?void 0:y.getTime())||o.from.getTime()),d=w&&new Date(v,t)<w||h&&new Date(v,t)>h;return e.jsx("p",{className:k===v&&(t===((l=o.from)==null?void 0:l.getMonth())||t===((p=o.to)==null?void 0:p.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:c?"rgba(100, 181, 246, 0.1)":"",pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",color:d?"#ccc":c?"#b0b0b0":"",...r?{}:{width:"100%"}},onClick:()=>{d||M(new Date(v,t))},children:u.slice(0,3)},t)})})},T=n=>{const a=Math.floor(n/10)*10,s=a+10;return{start:a,end:s}},U=({date:n,filter:a,setViews:s,setDate:i,dateRange:o,setDateRange:g,onChange:f,minDate:w,maxDate:h,input:r})=>{var y;let k=[];const v=n.getFullYear(),{start:M,end:x}=T(v),u=o.from.getFullYear(),t=(y=o.to)==null?void 0:y.getFullYear();for(let l=M;l<x;l++){const p=new Date(l,0),D=(!w||p>=w)&&(!h||p<=h),C=l===u||l===t,b=p>o.from&&p<o.to;k.push({year:l,active:C&&D,highlight:b&&D,disabled:!D})}const c=l=>{a?(d(l),i(l)):(i(l),s("months"))},d=l=>{var D;let p={...o};if(p.from&&p.to)p={from:l,to:null};else{const C=((D=p.from)==null?void 0:D.getTime())||0;l.getTime()>C?p={from:p.from,to:l}:p={from:l,to:p.from}}g(p),f(p)};return e.jsx("div",{className:"starasia-calendar-years-preview",children:k.map((l,p)=>e.jsx("p",{className:`${l.active?"starasia-calendar-months-active":""} ${l.highlight?"starasia-calendar-months-highlight":""} ${l.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{l.disabled||c(new Date(l.year,0))},style:{backgroundColor:l.highlight?"rgba(100, 181, 246, 0.1)":"",color:l.highlight?"#b0b0b0":l.active?"":l.disabled?"#ccc":"",cursor:l.disabled?"not-allowed":"pointer",pointerEvents:l.disbled?"none":"all",...r?{}:{width:"100%"}},children:l.year},p))})},W=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),z=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:n,views:a,filter:s,date:i,setDate:o})=>{const g=()=>{s||n(r=>r==="days"?"months":r==="months"?"years":"days")},f=()=>{if(a==="years"){o(r=>new Date(r.getFullYear()+10,0));return}if(a==="months"){o(r=>new Date(r.getFullYear()+1,r.getMonth()));return}o(r=>new Date(r.getFullYear(),r.getMonth()+1))},w=()=>{if(a==="years"){o(r=>new Date(r.getFullYear()-10,0));return}if(a==="months"){o(r=>new Date(r.getFullYear()-1,r.getMonth()));return}o(r=>new Date(r.getMonth()===0?r.getFullYear()-1:r.getFullYear(),r.getMonth()===0?11:r.getMonth()-1))},h=()=>{if(a==="days")return`${F[i.getMonth()]} ${i.getFullYear()}`;if(a==="months")return`${i.getFullYear()}`;if(a==="years")return`${T(i.getFullYear()).start} ~ ${T(i.getFullYear()).end}`};return e.jsxs("div",{className:"starasia-calendar-header",children:[e.jsx(W,{onClick:()=>w()}),e.jsx("div",{style:{cursor:"pointer"},onClick:g,children:h()}),e.jsx(z,{onClick:()=>f()})]})};function E(n){const a=new Date(n),s=a.getFullYear(),i=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${q[i]} ${s}`}const O="starasia-calendar-styles";(n=>{if(!document.getElementById(O)){const a=document.createElement("style");a.id=O,a.textContent=n,document.head.appendChild(a)}})(N);const Q=m.forwardRef(({value:n,onChange:a,filter:s,input:i=!0,disabled:o,minDate:g,maxDate:f,placeholder:w,size:h,status:r},k)=>{const{ref:v,isComponentVisible:M,setIsComponentVisible:x}=B(!1),u=m.useRef(null),[t,c]=m.useState("days"),[d,y]=m.useState(new Date),[l,p]=m.useState({from:(n==null?void 0:n.from)||new Date,to:(n==null?void 0:n.to)||new Date});m.useEffect(()=>{n?(y(n.from),p(n)):(y(new Date),p({from:new Date,to:new Date}))},[n]),m.useEffect(()=>{s&&c(s)},[s]),m.useEffect(()=>{s||c("days")},[M]),m.useEffect(()=>{i||x(!0)},[i]);const D=()=>{var b,$;if(!n)return"";if(s){if(t==="days")return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`;if(t==="months")return`${F[l.from.getMonth()]} ~ ${l.to?F[l.to.getMonth()]:"-"}`;if(t==="years")return`${(b=l.from)==null?void 0:b.getFullYear()} ~ ${(($=l.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`},C=()=>{if(u.current&&v.current&&i){const b=v.current.getBoundingClientRect(),$=u.current.getBoundingClientRect();window.innerWidth<b.left+$.width?u.current.style.left=`${b.left-$.width+b.width}px`:u.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?u.current.style.top=`${b.y-(b.height+$.height-28)}px`:u.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{u.current&&v.current&&i&&C()},[u,v,M]),m.useEffect(()=>{const b=k==null?void 0:k.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),e.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:i?"auto":"100%"},ref:i?v:null,children:[i?e.jsx(J,{value:D(),inputMode:"none",onClick:()=>{x(!0)},onChange:()=>{},disabled:o,placeholder:w,size:h,status:r}):null,M?e.jsxs("div",{className:`starasia-calendar ${i?"":"starasia-calendar-no-input"}`,ref:u,children:[e.jsx(K,{setViews:c,views:t,filter:s,date:d,setDate:y}),e.jsx("div",{className:"starasia-calendar-body",children:t==="days"?e.jsx(P,{date:d,setDate:y,setIsComponentVisible:x,dateRange:l,setDateRange:p,input:i,onChange:a,minDate:g,maxDate:f}):t==="months"?e.jsx(G,{date:d,setDate:y,filter:s,setViews:c,dateRange:l,setDateRange:p,setIsComponentVisible:x,input:i,onChange:a,minDate:g,maxDate:f}):e.jsx(U,{date:d,setDate:y,filter:s,setViews:c,dateRange:l,setDateRange:p,setIsComponentVisible:x,input:i,onChange:a,minDate:g,maxDate:f})})]}):null]})}),H="starasia-calendar-input-styles";(n=>{if(!document.getElementById(H)){const a=document.createElement("style");a.id=H,a.textContent=n,document.head.appendChild(a)}})(N);const L=n=>{if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},X=n=>{const{size:a="md",status:s="default",variant:i="outline",...o}=n,g=m.useRef(null),f=()=>{g.current&&o.onClick&&(g.current.focus(),o.onClick(""))};return e.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${i} starasia-calendar-input-container-${s} ${a} `,onClick:f,children:[e.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(a),height:L(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:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"starasia-calendar-input-preview-container",children:e.jsx("input",{className:"starasia-calendar-input",...o,disabled:s==="disable"?!0:o.disabled,value:o.value,ref:g})}),e.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(a),height:L(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:n,setDate:a,previewDate:s,setPreviewDate:i,setIsComponentVisible:o,minDate:g,maxDate:f,input:w,onChange:h})=>{let r=new Date(s.getFullYear(),s.getMonth(),1),k=r.getDay(),v=[];const M=n.toDateString(),x=s.getMonth();for(let t=0;t<42;t++){t===0&&k===0?r.setDate(r.getDate()-7):t===0?r.setDate(r.getDate()+(t-k)):r.setDate(r.getDate()+1);let c={currentMonth:r.getMonth()===x,date:new Date(r),month:r.getMonth(),number:r.getDate(),selected:r.toDateString()===M,year:r.getFullYear(),isDisabled:g&&r<g||f&&r>f};v.push(c)}const u=t=>{(!g||t>=g)&&(!f||t<=f)&&(a(t),h(t),i(t),w&&o(!1))};return e.jsxs("div",{className:"starasia-calendar-days-preivew",children:[e.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,c)=>e.jsx("p",{children:t},c))}),e.jsx("div",{className:"starasia-calendar-days-number-preivew",children:v.map((t,c)=>{const d=t.isDisabled;return e.jsx("p",{className:`${t.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${t.selected?"starasia-calendar-days-active":""}`,style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...w?{}:{width:"100%"}},onClick:()=>{d||u(t.date)},children:t.number},c)})})]})},_=({date:n,setDate:a,filter:s,setViews:i,onChange:o,previewDate:g,setPreviewDate:f,minDate:w,maxDate:h,input:r})=>{const k=n.getMonth(),v=n.getFullYear(),M=g.getFullYear(),x=u=>{(!w||u>=w)&&(!h||u<=h)&&(s?(o(u),a(u),f(u)):(i("days"),f(u)))};return e.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((u,t)=>{const c=w&&new Date(M,t,1)<w||h&&new Date(M,t+1,0)>h;return e.jsx("p",{className:t===k&&M===v?"starasia-calendar-months-active":"",style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...r?{}:{width:"100%"}},onClick:()=>{c||x(new Date(M,t))},children:u.slice(0,3)},t)})})},I=n=>{const a=Math.floor(n/10)*10,s=a+10;return{start:a,end:s}},R=({date:n,filter:a,setViews:s,setDate:i,onChange:o,previewDate:g,setPreviewDate:f,minDate:w,maxDate:h,input:r})=>{let k=[];const v=g.getFullYear(),{start:M,end:x}=I(v),u=n.getFullYear();for(let c=M;c<x;c++){let d=w&&new Date(c,0,1)<w||h&&new Date(c,11,31)>h;k.push({year:c,active:c===u,isDisabled:d})}const t=c=>{(!w||c>=w)&&(!h||c<=h)&&(a?(o(c),i(c),f(c)):(s("months"),f(c)))};return e.jsx("div",{className:"starasia-calendar-years-preview",children:k.map((c,d)=>e.jsx("p",{className:c.active?"starasia-calendar-months-active":"",style:{color:c.isDisabled?"#ccc":void 0,pointerEvents:c.isDisabled?"none":void 0,cursor:c.isDisabled?"not-allowed":"pointer",...r?{}:{width:"100%"}},onClick:()=>{c.isDisabled||t(new Date(c.year,0))},children:c.year},d))})},aa=({setViews:n,views:a,filter:s,previewDate:i,setPreviewDate:o})=>{const g=()=>{s||n(r=>r==="days"?"months":r==="months"?"years":"days")},f=()=>{if(a==="years"){o(r=>new Date(r.getFullYear()+10,0));return}if(a==="months"){o(r=>new Date(r.getFullYear()+1,r.getMonth()));return}o(r=>new Date(r.getFullYear(),r.getMonth()+1))},w=()=>{if(a==="years"){o(r=>new Date(r.getFullYear()-10,0));return}if(a==="months"){o(r=>new Date(r.getFullYear()-1,r.getMonth()));return}o(r=>new Date(r.getMonth()===0?r.getFullYear()-1:r.getFullYear(),r.getMonth()===0?11:r.getMonth()-1))},h=()=>{if(a==="days")return`${F[i.getMonth()]} ${i.getFullYear()}`;if(a==="months")return`${i.getFullYear()}`;if(a==="years")return`${I(i.getFullYear()).start} ~ ${I(i.getFullYear()).end}`};return e.jsxs("div",{className:"starasia-calendar-header",children:[e.jsx(W,{onClick:()=>w()}),e.jsx("div",{style:{cursor:"pointer"},onClick:g,children:h()}),e.jsx(z,{onClick:()=>f()})]})},A="starasia-calendar-styles";(n=>{if(!document.getElementById(A)){const a=document.createElement("style");a.id=A,a.textContent=n,document.head.appendChild(a)}})(N);const ra=m.forwardRef(({value:n,onChange:a,filter:s,input:i=!0,disabled:o,minDate:g,maxDate:f,placeholder:w,size:h,status:r},k)=>{const{ref:v,isComponentVisible:M,setIsComponentVisible:x}=B(!1),u=m.useRef(null),[t,c]=m.useState("days"),[d,y]=m.useState(new Date),[l,p]=m.useState(new Date);m.useEffect(()=>{n?(y(n),p(n)):(y(new Date),p(new Date))},[n]),m.useEffect(()=>{s&&c(s)},[s]),m.useEffect(()=>{s||c("days")},[M]),m.useEffect(()=>{i||x(!0)},[i]);const D=()=>n?s==="days"?E(d):s==="months"?`${F[d.getMonth()]} ${d.getFullYear()}`:s==="years"?d.getFullYear():E(d):"",C=()=>{if(u.current&&v.current&&i){const b=v.current.getBoundingClientRect(),$=u.current.getBoundingClientRect();window.innerWidth<b.left+$.width?u.current.style.left=`${b.left-$.width+b.width}px`:u.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?u.current.style.top=`${b.y-(b.height+$.height-28)}px`:u.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{u.current&&v.current&&i&&C()},[u,v,M]),m.useEffect(()=>{const b=k==null?void 0:k.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),e.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:i?"auto":"100%"},ref:i?v:null,children:[i?e.jsx(X,{value:D(),onClick:()=>x(!0),onChange:()=>{},placeholder:w,disabled:o,size:h,status:r,inputMode:"none"}):null,M?e.jsxs("div",{className:`starasia-calendar ${i?"":"starasia-calendar-no-input"}`,ref:u,children:[e.jsx(aa,{setViews:c,views:t,filter:s,previewDate:l,setPreviewDate:p,isComponentVisible:M}),e.jsx("div",{className:"starasia-calendar-body",children:t==="days"?e.jsx(Z,{date:d,setDate:y,previewDate:l,setPreviewDate:p,setIsComponentVisible:x,input:i,minDate:g,maxDate:f,onChange:a}):t==="months"?e.jsx(_,{date:d,setDate:y,previewDate:l,setPreviewDate:p,filter:s,setViews:c,onChange:a,minDate:g,maxDate:f,input:i}):e.jsx(R,{date:d,setDate:y,previewDate:l,setPreviewDate:p,filter:s,setViews:c,onChange:a,minDate:g,maxDate:f,input:i})})]}):null]})}),ea=m.forwardRef(({value:n,onChange:a,filter:s,input:i=!0,rangedDate:o,disabled:g,minDate:f,maxDate:w,placeholder:h,size:r,status:k},v)=>e.jsx(e.Fragment,{children:o?e.jsx(Q,{onChange:a,value:n,input:i,filter:s,disabled:g,ref:v,minDate:f,maxDate:w,placeholder:h,size:r,status:k}):e.jsx(ra,{onChange:a,value:n,input:i,filter:s,disabled:g,ref:v,minDate:f,maxDate:w,placeholder:h,size:r,status:k})}));Y.StarasiaDate=ea,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
255
+ `,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],J=["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),i=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!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)}})(N);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",...i}=r,g=m.useRef(null),p=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-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:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...i,disabled:s==="disable"?!0:i.disabled,value:i.value,ref:g})}),a.jsx("div",{className:"starasia-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:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:i,minDate:g,maxDate:p,input:v})=>{var h,t,d;let u=new Date(r.getFullYear(),r.getMonth(),1),n=u.getDay(),x=[];const w=r.getMonth();for(let c=0;c<42;c++){c===0&&n===0?u.setDate(u.getDate()-7):c===0?u.setDate(u.getDate()+(c-n)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===w,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 l;let y={...s};if(y.from&&y.to)y={from:c,to:null};else{const f=((l=y.from)==null?void 0:l.getTime())||0;c.getTime()>f?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),i(y)};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((c,y)=>a.jsx("p",{children:c},y))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:x.map((c,y)=>{var D;const l=c.date.getTime()>s.from.getTime()&&c.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=c.isDisabled;return a.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:l?"rgba(100, 181, 246, 0.1)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"#ccc":l?"#b0b0b0":"",...v?{}:{width:"100%"}},onClick:()=>{f||(M(c.date),k(c.date))},children:c.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:i,setDateRange:g,onChange:p,minDate:v,maxDate:u,input:n})=>{const x=i.from.getFullYear(),w=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var d;let t={...i};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 a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,l,f;const d=new Date(w,t).getTime()>i.from.getTime()&&new Date(w,t).getTime()<(((y=i.to)==null?void 0:y.getTime())||i.from.getTime()),c=v&&new Date(w,t)<v||u&&new Date(w,t)>u;return a.jsx("p",{className:x===w&&(t===((l=i.from)==null?void 0:l.getMonth())||t===((f=i.to)==null?void 0:f.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:d?"rgba(100, 181, 246, 0.1)":"",pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",color:c?"#ccc":d?"#b0b0b0":"",...n?{}:{width:"100%"}},onClick:()=>{c||M(new Date(w,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:i,setDateRange:g,onChange:p,minDate:v,maxDate:u,input:n})=>{var y;let x=[];const w=r.getFullYear(),{start:M,end:k}=T(w),h=i.from.getFullYear(),t=(y=i.to)==null?void 0:y.getFullYear();for(let l=M;l<k;l++){const f=new Date(l,0),D=(!v||f>=v)&&(!u||f<=u),C=l===h||l===t,b=f>i.from&&f<i.to;x.push({year:l,active:C&&D,highlight:b&&D,disabled:!D})}const d=l=>{e?(c(l),o(l)):(o(l),s("months"))},c=l=>{var D;let f={...i};if(f.from&&f.to)f={from:l,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;l.getTime()>C?f={from:f.from,to:l}:f={from:l,to:f.from}}g(f),p(f)};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((l,f)=>a.jsx("p",{className:`${l.active?"starasia-calendar-months-active":""} ${l.highlight?"starasia-calendar-months-highlight":""} ${l.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{l.disabled||d(new Date(l.year,0))},style:{backgroundColor:l.highlight?"rgba(100, 181, 246, 0.1)":"",color:l.highlight?"#b0b0b0":l.active?"":l.disabled?"#ccc":"",cursor:l.disabled?"not-allowed":"pointer",pointerEvents:l.disbled?"none":"all",...n?{}:{width:"100%"}},children:l.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:i})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},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.getFullYear(),n.getMonth()+1))},v=()=>{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))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>v()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function E(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${J[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)}})(N);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:i,minDate:g,maxDate:p,placeholder:v,size:u,status:n},x)=>{const{ref:w,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[l,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 b,$;if(!r)return"";if(s){if(t==="days")return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`;if(t==="months")return`${F[l.from.getMonth()]} ~ ${l.to?F[l.to.getMonth()]:"-"}`;if(t==="years")return`${(b=l.from)==null?void 0:b.getFullYear()} ~ ${(($=l.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`},C=()=>{if(h.current&&w.current&&o){const b=w.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&w.current&&o&&C()},[h,w,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?w:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:i,placeholder:v,size:u,status:n}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(K,{setViews:d,views:t,filter:s,date:c,setDate:y}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(q,{date:c,setDate:y,setIsComponentVisible:k,dateRange:l,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:l,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.jsx(U,{date:c,setDate:y,filter:s,setViews:d,dateRange:l,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)}})(N);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",...i}=r,g=m.useRef(null),p=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-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:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...i,disabled:s==="disable"?!0:i.disabled,value:i.value,ref:g})}),a.jsx("div",{className:"starasia-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:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:i,minDate:g,maxDate:p,input:v,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),w=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?n.setDate(n.getDate()-7):t===0?n.setDate(n.getDate()+(t-x)):n.setDate(n.getDate()+1);let d={currentMonth:n.getMonth()===k,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:g&&n<g||p&&n>p};w.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),v&&i(!1))};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,d)=>a.jsx("p",{children:t},d))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:w.map((t,d)=>{const c=t.isDisabled;return a.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",...v?{}:{width:"100%"}},onClick:()=>{c||h(t.date)},children:t.number},d)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:i,previewDate:g,setPreviewDate:p,minDate:v,maxDate:u,input:n})=>{const x=r.getMonth(),w=r.getFullYear(),M=g.getFullYear(),k=h=>{(!v||h>=v)&&(!u||h<=u)&&(s?(i(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{const d=v&&new Date(M,t,1)<v||u&&new Date(M,t+1,0)>u;return a.jsx("p",{className:t===x&&M===w?"starasia-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...n?{}:{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:i,previewDate:g,setPreviewDate:p,minDate:v,maxDate:u,input:n})=>{let x=[];const w=g.getFullYear(),{start:M,end:k}=I(w),h=r.getFullYear();for(let d=M;d<k;d++){let c=v&&new Date(d,0,1)<v||u&&new Date(d,11,31)>u;x.push({year:d,active:d===h,isDisabled:c})}const t=d=>{(!v||d>=v)&&(!u||d<=u)&&(e?(i(d),o(d),p(d)):(s("months"),p(d)))};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((d,c)=>a.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",...n?{}:{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:i})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},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.getFullYear(),n.getMonth()+1))},v=()=>{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))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>v()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})},A="starasia-calendar-styles";(r=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=r,document.head.appendChild(e)}})(N);const ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:i,minDate:g,maxDate:p,placeholder:v,size:u,status:n},x)=>{const{ref:w,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[l,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"?E(c):s==="months"?`${F[c.getMonth()]} ${c.getFullYear()}`:s==="years"?c.getFullYear():E(c):"",C=()=>{if(h.current&&w.current&&o){const b=w.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&w.current&&o&&C()},[h,w,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?w:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:v,disabled:i,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:d,views:t,filter:s,previewDate:l,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(Z,{date:c,setDate:y,previewDate:l,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:c,setDate:y,previewDate:l,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:c,setDate:y,previewDate:l,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:i,disabled:g,minDate:p,maxDate:v,placeholder:u,size:n,status:x},w)=>a.jsx(a.Fragment,{children:i?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:w,minDate:p,maxDate:v,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:w,minDate:p,maxDate:v,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "1.0.5",
3
+ "version": "2.0.0",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",