@starasia/date 2.0.1 → 3.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
@@ -11,10 +11,10 @@
11
11
  --sa-date-radius: var(--sa-radii-md, 0.5rem);
12
12
  --sa-date-radius-lg: var(--sa-radii-lg, 0.75rem);
13
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));
14
+ --sa-date-border-color: var(--sa-color-gray-alpha-a20, #78867f33);
15
+ --sa-date-border-disabled: var(--sa-color-gray-alpha-a20, #78867f33);
16
+ --sa-date-bg-disabled: var(--sa-color-gray-alpha-a10, #78867f1a);
17
+ --sa-date-shadow: var(--sa-shadow-md, 0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a);
18
18
  --sa-date-text-primary: var(--sa-color-gray-700, #6b6e76);
19
19
  --sa-date-text-subtle: var(--sa-color-gray-500, #8c8f97);
20
20
  --sa-date-text-muted: var(--sa-color-gray-300, #dddee1);
@@ -25,11 +25,11 @@
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
- .starasia-calendar-wrapper {
28
+ .sa-calendar-wrapper {
29
29
  position: relative;
30
30
  }
31
31
 
32
- .starasia-calendar {
32
+ .sa-calendar {
33
33
  border-radius: var(--sa-date-radius);
34
34
  border: var(--sa-border, 1px) solid var(--sa-date-bg);
35
35
  background: var(--sa-date-bg);
@@ -43,7 +43,7 @@
43
43
  z-index: 999;
44
44
  }
45
45
 
46
- .starasia-calendar.starasia-calendar-no-input {
46
+ .sa-calendar.sa-calendar-no-input {
47
47
  position: relative !important;
48
48
  margin-top: 0px;
49
49
 
@@ -57,7 +57,7 @@
57
57
  border-radius: 0;
58
58
  }
59
59
 
60
- .starasia-calendar-header {
60
+ .sa-calendar-header {
61
61
  display: flex;
62
62
  flex-direction: row;
63
63
  align-items: center;
@@ -65,25 +65,25 @@
65
65
  gap: var(--sa-spacing-xs, 4px);
66
66
  }
67
67
 
68
- .starasia-calendar-days-name-preivew {
68
+ .sa-calendar-days-name-preivew {
69
69
  display: flex;
70
70
  gap: var(--sa-spacing-sm, 8px);
71
71
  }
72
72
 
73
- .starasia-calendar-days-name-preivew p {
73
+ .sa-calendar-days-name-preivew p {
74
74
  color: var(--sa-date-text-subtle);
75
75
  font-size: var(--sa-font-size-md, 14px);
76
76
  flex: 1;
77
77
  display: grid;
78
78
  place-content: center;
79
79
  }
80
- .starasia-calendar-days-number-preivew {
80
+ .sa-calendar-days-number-preivew {
81
81
  display: grid;
82
82
  grid-template-columns: repeat(7, 1fr);
83
83
  gap: var(--sa-spacing-sm, 8px);
84
84
  }
85
85
 
86
- .starasia-calendar-days-number-preivew p {
86
+ .sa-calendar-days-number-preivew p {
87
87
  font-size: var(--sa-font-size-md, 14px);
88
88
  text-align: center;
89
89
  width: 35px;
@@ -96,31 +96,31 @@
96
96
  border-radius: var(--sa-date-radius);
97
97
  }
98
98
 
99
- .starasia-calendar-days {
99
+ .sa-calendar-days {
100
100
  color: var(--sa-date-text-muted);
101
101
  }
102
- .starasia-calendar-days-current {
102
+ .sa-calendar-days-current {
103
103
  color: var(--sa-date-text-primary);
104
104
  }
105
105
 
106
- .starasia-calendar-days-number-preivew p:hover {
106
+ .sa-calendar-days-number-preivew p:hover {
107
107
  background: var(--sa-date-brand-subtle);
108
108
  color: var(--sa-date-brand-secondary);
109
109
  }
110
110
 
111
- .starasia-calendar-days-active {
111
+ .sa-calendar-days-active {
112
112
  background: var(--sa-date-brand-secondary);
113
113
  color: var(--sa-date-brand);
114
114
  }
115
115
 
116
116
  /* MONTH STYLING */
117
- .starasia-calendar-months-preview {
117
+ .sa-calendar-months-preview {
118
118
  display: grid;
119
119
  grid-template-columns: repeat(3, 1fr);
120
120
  row-gap: var(--sa-spacing-xs, 4px);
121
121
  }
122
122
 
123
- .starasia-calendar-months-preview p {
123
+ .sa-calendar-months-preview p {
124
124
  width: 98px;
125
125
  height: 48px;
126
126
  display: grid;
@@ -129,23 +129,23 @@
129
129
  border-radius: var(--sa-date-radius);
130
130
  }
131
131
 
132
- .starasia-calendar-months-preview p:hover {
132
+ .sa-calendar-months-preview p:hover {
133
133
  background: var(--sa-date-brand-subtle);
134
134
  color: var(--sa-date-brand-secondary);
135
135
  }
136
136
 
137
- .starasia-calendar-months-active {
137
+ .sa-calendar-months-active {
138
138
  background: var(--sa-date-brand-secondary);
139
139
  color: var(--sa-date-brand);
140
140
  }
141
141
  /* Year STYLING */
142
- .starasia-calendar-years-preview {
142
+ .sa-calendar-years-preview {
143
143
  display: grid;
144
144
  grid-template-columns: repeat(3, 1fr);
145
145
  row-gap: var(--sa-spacing-xs, 4px);
146
146
  }
147
147
 
148
- .starasia-calendar-years-preview p {
148
+ .sa-calendar-years-preview p {
149
149
  width: 98px;
150
150
  height: 48px;
151
151
  display: grid;
@@ -154,19 +154,19 @@
154
154
  border-radius: var(--sa-date-radius);
155
155
  }
156
156
 
157
- .starasia-calendar-years-preview p:hover {
157
+ .sa-calendar-years-preview p:hover {
158
158
  background: var(--sa-date-brand-subtle);
159
159
  color: var(--sa-date-brand-secondary);
160
160
  }
161
161
 
162
- .starasia-calendar-years-active {
162
+ .sa-calendar-years-active {
163
163
  background: var(--sa-date-brand-secondary);
164
164
  color: var(--sa-date-brand);
165
165
  }
166
166
 
167
167
  /* INPUT */
168
168
 
169
- .starasia-calendar-input-container {
169
+ .sa-calendar-input-container {
170
170
  box-sizing: border-box;
171
171
  overflow: hidden;
172
172
  display: flex;
@@ -175,17 +175,17 @@
175
175
  cursor: pointer;
176
176
  }
177
177
 
178
- .starasia-calendar-input-container:has(input:focus) {
178
+ .sa-calendar-input-container:has(input:focus) {
179
179
  border-color: var(--sa-date-brand);
180
180
  box-shadow: 0px 0px 0px 2px var(--sa-date-brand-subtle);
181
181
  }
182
- .starasia-calendar-input-container:has(input:disabled) {
182
+ .sa-calendar-input-container:has(input:disabled) {
183
183
  border-color: var(--sa-date-border-disabled);
184
184
  background-color: var(--sa-date-bg-disabled);
185
185
  pointer-events: none;
186
186
  }
187
187
 
188
- .starasia-calendar-input-outline {
188
+ .sa-calendar-input-outline {
189
189
  border-color: var(--sa-date-border-color);
190
190
  /* border-color: var(--sa-date-text-muted); */
191
191
  background-color: transparent;
@@ -196,31 +196,31 @@
196
196
  /* padding-inline: var(--sa-spacing-3, 12px); */
197
197
  }
198
198
 
199
- .starasia-calendar-input-container.sm {
199
+ .sa-calendar-input-container.sm {
200
200
  height: var(--sa-h-8, 32px);
201
201
  border-radius: var(--sa-date-radius);
202
202
  font-size: var(--sa-font-size-sm, 12px);
203
203
  padding-inline: var(--sa-spacing-sm, 8px);
204
204
  }
205
- .starasia-calendar-input-container.md {
205
+ .sa-calendar-input-container.md {
206
206
  height: 38px;
207
207
  border-radius: var(--sa-date-radius);
208
208
  font-size: var(--sa-font-size-md, 14px);
209
209
  padding-inline: var(--sa-spacing-3, 12px);
210
210
  }
211
- .starasia-calendar-input-container.lg {
211
+ .sa-calendar-input-container.lg {
212
212
  height: var(--sa-h-12, 48px);
213
213
  border-radius: var(--sa-date-radius-lg);
214
214
  font-size: var(--sa-font-size-lg, 16px);
215
215
  padding-inline: var(--sa-spacing-3, 12px);
216
216
  }
217
217
 
218
- .starasia-calendar-input-preview-container {
218
+ .sa-calendar-input-preview-container {
219
219
  width: 100%;
220
220
  position: relative;
221
221
  }
222
222
 
223
- .starasia-calendar-input {
223
+ .sa-calendar-input {
224
224
  width: 100%;
225
225
  box-sizing: border-box;
226
226
  height: 100%;
@@ -232,24 +232,24 @@
232
232
  cursor: pointer;
233
233
  }
234
234
 
235
- .starasia-calendar-input::placeholder {
235
+ .sa-calendar-input::placeholder {
236
236
  color: var(--sa-date-placeholder);
237
237
  font-weight: var(--sa-font-weight-normal, 300);
238
238
  }
239
239
 
240
240
  /* INPUT ICON */
241
- .starasia-calendar-input-container-icon-left {
241
+ .sa-calendar-input-container-icon-left {
242
242
  display: flex;
243
243
  }
244
- .starasia-calendar-input-container-icon-right {
244
+ .sa-calendar-input-container-icon-right {
245
245
  display: flex;
246
246
  }
247
247
 
248
- .starasia-calendar-input-container-error {
248
+ .sa-calendar-input-container-error {
249
249
  border-color: var(--sa-date-border-error) !important;
250
250
  }
251
251
 
252
- .starasia-calendar-input-container-warning {
252
+ .sa-calendar-input-container-warning {
253
253
  border-color: var(--sa-date-border-warning) !important;
254
254
  }
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 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:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.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:"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),n=u.getDay(),x=[];const v=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()===v,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 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 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 a.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:i?"rgba(100, 181, 246, 0.1)":"",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:n})=>{const x=l.from.getFullYear(),v=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 a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,i,f;const d=new Date(v,t).getTime()>l.from.getTime()&&new Date(v,t).getTime()<(((y=l.to)==null?void 0:y.getTime())||l.from.getTime()),c=w&&new Date(v,t)<w||u&&new Date(v,t)>u;return a.jsx("p",{className:x===v&&(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?"rgba(100, 181, 246, 0.1)":"",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)":"",...n?{}:{width:"100%"}},onClick:()=>{c||M(new Date(v,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{var y;let x=[];const v=r.getFullYear(),{start:M,end:k}=T(v),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,b=f>l.from&&f<l.to;x.push({year:i,active:C&&D,highlight:b&&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 a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((i,f)=>a.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?"rgba(100, 181, 246, 0.1)":"",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",...n?{}:{width:"100%"}},children:i.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function N(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${A[o]} ${s}`}const W="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:n},x)=>{const{ref:v,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 b,$;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`${(b=i.from)==null?void 0:b.getFullYear()} ~ ${(($=i.to)==null?void 0:$.getFullYear())||"-"}`}else return`${N(i.from)} ~ ${N(i.to||i.from)||"-"}`},C=()=>{if(h.current&&v.current&&o){const b=v.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&&v.current&&o&&C()},[h,v,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?v:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:l,placeholder:w,size:u,status:n}):null,M?a.jsxs("div",{className:`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:i,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.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 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:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.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:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:g,maxDate:p,input:w,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),v=[];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};v.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),w&&l(!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:v.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",...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:n})=>{const x=r.getMonth(),v=r.getFullYear(),M=g.getFullYear(),k=h=>{(!w||h>=w)&&(!u||h<=u)&&(s?(l(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"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 a.jsx("p",{className:t===x&&M===v?"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:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{let x=[];const v=g.getFullYear(),{start:M,end:k}=I(v),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 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:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.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 ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:v,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&&v.current&&o){const b=v.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&&v.current&&o&&C()},[h,v,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?v:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:w,disabled:l,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:d,views:t,filter:s,previewDate:i,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(Z,{date:c,setDate:y,previewDate:i,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:c,setDate:y,previewDate:i,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:l,disabled:g,minDate:p,maxDate:w,placeholder:u,size:n,status:x},v)=>a.jsx(a.Fragment,{children:l?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:v,minDate:p,maxDate:w,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:v,minDate:p,maxDate:w,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,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"],A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(r){const[e,s]=m.useState(r),o=m.useRef(null),l=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const V="sa-calendar-input-styles";(r=>{if(!document.getElementById(V)){const e=document.createElement("style");e.id=V,e.textContent=r,document.head.appendChild(e)}})(E);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},P=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:l,minDate:g,maxDate:p,input:w})=>{var h,t,c;let u=new Date(r.getFullYear(),r.getMonth(),1),n=u.getDay(),x=[];const b=r.getMonth();for(let i=0;i<42;i++){i===0&&n===0?u.setDate(u.getDate()-7):i===0?u.setDate(u.getDate()+(i-n)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===b,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((h=s.from)==null?void 0:h.toDateString())||u.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((c=s.from)==null?void 0:c.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=i=>{e(i)},k=i=>{var d;let y={...s};if(y.from&&y.to)y={from:i,to:null};else{const f=((d=y.from)==null?void 0:d.getTime())||0;i.getTime()>f?y={from:y.from,to:i}:y={from:i,to:y.from}}o(y),l(y)};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:j.map((i,y)=>a.jsx("p",{children:i},y))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:x.map((i,y)=>{var D;const d=i.date.getTime()>s.from.getTime()&&i.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=i.isDisabled;return a.jsx("p",{className:`${i.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${i.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...w?{}:{width:"100%"}},onClick:()=>{f||(M(i.date),k(i.date))},children:i.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{const x=l.from.getFullYear(),b=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var c;let t={...l};if(t.from&&t.to)t={from:h,to:null};else{const i=((c=t.from)==null?void 0:c.getTime())||0;h.getTime()>i?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((h,t)=>{var y,d,f;const c=new Date(b,t).getTime()>l.from.getTime()&&new Date(b,t).getTime()<(((y=l.to)==null?void 0:y.getTime())||l.from.getTime()),i=w&&new Date(b,t)<w||u&&new Date(b,t)>u;return a.jsx("p",{className:x===b&&(t===((d=l.from)==null?void 0:d.getMonth())||t===((f=l.to)==null?void 0:f.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:i?"none":void 0,cursor:i?"not-allowed":"pointer",color:i?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{i||M(new Date(b,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{var y;let x=[];const b=r.getFullYear(),{start:M,end:k}=T(b),h=l.from.getFullYear(),t=(y=l.to)==null?void 0:y.getFullYear();for(let d=M;d<k;d++){const f=new Date(d,0),D=(!w||f>=w)&&(!u||f<=u),C=d===h||d===t,v=f>l.from&&f<l.to;x.push({year:d,active:C&&D,highlight:v&&D,disabled:!D})}const c=d=>{e?(i(d),o(d)):(o(d),s("months"))},i=d=>{var D;let f={...l};if(f.from&&f.to)f={from:d,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;d.getTime()>C?f={from:f.from,to:d}:f={from:d,to:f.from}}g(f),p(f)};return a.jsx("div",{className:"sa-calendar-years-preview",children:x.map((d,f)=>a.jsx("p",{className:`${d.active?"sa-calendar-months-active":""} ${d.highlight?"sa-calendar-months-highlight":""} ${d.disabled?"sa-calendar-disabled":""}`,onClick:()=>{d.disabled||c(new Date(d.year,0))},style:{backgroundColor:d.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:d.highlight?"var(--sa-color-gray-500, #8c8f97)":d.active?"":d.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:d.disabled?"not-allowed":"pointer",pointerEvents:d.disbled?"none":"all",...n?{}:{width:"100%"}},children:d.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function N(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${A[o]} ${s}`}const W="sa-calendar-styles";(r=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=r,document.head.appendChild(e)}})(E);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,c]=m.useState("days"),[i,y]=m.useState(new Date),[d,f]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(y(r.from),f(r)):(y(new Date),f({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{s&&c(s)},[s]),m.useEffect(()=>{s||c("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var v,$;if(!r)return"";if(s){if(t==="days")return`${N(d.from)} ~ ${N(d.to||d.from)||"-"}`;if(t==="months")return`${F[d.from.getMonth()]} ~ ${d.to?F[d.to.getMonth()]:"-"}`;if(t==="years")return`${(v=d.from)==null?void 0:v.getFullYear()} ~ ${(($=d.to)==null?void 0:$.getFullYear())||"-"}`}else return`${N(d.from)} ~ ${N(d.to||d.from)||"-"}`},C=()=>{if(h.current&&b.current&&o){const v=b.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<v.left+$.width?h.current.style.left=`${v.left-$.width+v.width}px`:h.current.style.left=`${v.left}px`,v.top+$.height>window.innerHeight?h.current.style.top=`${v.y-(v.height+$.height-28)}px`:h.current.style.top=`${v.y+v.height}px`}};return m.useEffect(()=>{h.current&&b.current&&o&&C()},[h,b,M]),m.useEffect(()=>{const v=x==null?void 0:x.current;return v&&v.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{v&&v.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:l,placeholder:w,size:u,status:n}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:h,children:[a.jsx(K,{setViews:c,views:t,filter:s,date:i,setDate:y}),a.jsx("div",{className:"sa-calendar-body",children:t==="days"?a.jsx(q,{date:i,setDate:y,setIsComponentVisible:k,dateRange:d,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:i,setDate:y,filter:s,setViews:c,dateRange:d,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.jsx(U,{date:i,setDate:y,filter:s,setViews:c,dateRange:d,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="sa-calendar-input-styles";(r=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=r,document.head.appendChild(e)}})(E);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},X=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return a.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"sa-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"sa-calendar-input-preview-container",children:a.jsx("input",{className:"sa-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),a.jsx("div",{className:"sa-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:g,maxDate:p,input:w,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),b=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?n.setDate(n.getDate()-7):t===0?n.setDate(n.getDate()+(t-x)):n.setDate(n.getDate()+1);let c={currentMonth:n.getMonth()===k,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:g&&n<g||p&&n>p};b.push(c)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),w&&l(!1))};return a.jsxs("div",{className:"sa-calendar-days-preivew",children:[a.jsx("div",{className:"sa-calendar-days-name-preivew",children:j.map((t,c)=>a.jsx("p",{children:t},c))}),a.jsx("div",{className:"sa-calendar-days-number-preivew",children:b.map((t,c)=>{const i=t.isDisabled;return a.jsx("p",{className:`${t.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${t.selected?"sa-calendar-days-active":""}`,style:{color:i?"#ccc":void 0,pointerEvents:i?"none":void 0,cursor:i?"not-allowed":"pointer",...w?{}:{width:"100%"}},onClick:()=>{i||h(t.date)},children:t.number},c)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{const x=r.getMonth(),b=r.getFullYear(),M=g.getFullYear(),k=h=>{(!w||h>=w)&&(!u||h<=u)&&(s?(l(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"sa-calendar-months-preview",children:F.map((h,t)=>{const c=w&&new Date(M,t,1)<w||u&&new Date(M,t+1,0)>u;return a.jsx("p",{className:t===x&&M===b?"sa-calendar-months-active":"",style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c||k(new Date(M,t))},children:h.slice(0,3)},t)})})},I=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},R=({date:r,filter:e,setViews:s,setDate:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{let x=[];const b=g.getFullYear(),{start:M,end:k}=I(b),h=r.getFullYear();for(let c=M;c<k;c++){let i=w&&new Date(c,0,1)<w||u&&new Date(c,11,31)>u;x.push({year:c,active:c===h,isDisabled:i})}const t=c=>{(!w||c>=w)&&(!u||c<=u)&&(e?(l(c),o(c),p(c)):(s("months"),p(c)))};return a.jsx("div",{className:"sa-calendar-years-preview",children:x.map((c,i)=>a.jsx("p",{className:c.active?"sa-calendar-months-active":"",style:{color:c.isDisabled?"#ccc":void 0,pointerEvents:c.isDisabled?"none":void 0,cursor:c.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c.isDisabled||t(new Date(c.year,0))},children:c.year},i))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"sa-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})},J="sa-calendar-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(E);const ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,c]=m.useState("days"),[i,y]=m.useState(new Date),[d,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&c(s)},[s]),m.useEffect(()=>{s||c("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?N(i):s==="months"?`${F[i.getMonth()]} ${i.getFullYear()}`:s==="years"?i.getFullYear():N(i):"",C=()=>{if(h.current&&b.current&&o){const v=b.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<v.left+$.width?h.current.style.left=`${v.left-$.width+v.width}px`:h.current.style.left=`${v.left}px`,v.top+$.height>window.innerHeight?h.current.style.top=`${v.y-(v.height+$.height-28)}px`:h.current.style.top=`${v.y+v.height}px`}};return m.useEffect(()=>{h.current&&b.current&&o&&C()},[h,b,M]),m.useEffect(()=>{const v=x==null?void 0:x.current;return v&&v.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{v&&v.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:w,disabled:l,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`sa-calendar ${o?"":"sa-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:c,views:t,filter:s,previewDate:d,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"sa-calendar-body",children:t==="days"?a.jsx(Z,{date:i,setDate:y,previewDate:d,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:i,setDate:y,previewDate:d,setPreviewDate:f,filter:s,setViews:c,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:i,setDate:y,previewDate:d,setPreviewDate:f,filter:s,setViews:c,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:l,disabled:g,minDate:p,maxDate:w,placeholder:u,size:n,status:x},b)=>a.jsx(a.Fragment,{children:l?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",
@@ -12,10 +12,6 @@
12
12
  "dist/*.map",
13
13
  "dist/*.css"
14
14
  ],
15
- "scripts": {
16
- "dev": "vite --config vite.config.ts --port 3000",
17
- "build": "vite build --config vite.config.ts"
18
- },
19
15
  "keywords": [],
20
16
  "license": "ISC",
21
17
  "type": "module",
@@ -37,5 +33,9 @@
37
33
  "react-dom": "^18.2.0",
38
34
  "@types/react": "^18.2.55",
39
35
  "@types/react-dom": "^18.2.19"
36
+ },
37
+ "scripts": {
38
+ "dev": "vite --config vite.config.ts --port 3000",
39
+ "build": "vite build --config vite.config.ts"
40
40
  }
41
- }
41
+ }