@starasia/date 5.0.3 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/date.es.js +829 -655
- package/dist/date.umd.js +170 -8
- package/dist/interfaces.d.ts +1 -0
- package/package.json +1 -1
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(B,
|
|
1
|
+
(function(B,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(B=typeof globalThis<"u"?globalThis:B||self,n(B.Date={},B.jsxRuntime,B.React))})(this,function(B,n,m){"use strict";const P=`@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,7 +8,7 @@
|
|
|
8
8
|
/* box-sizing: border-box; */
|
|
9
9
|
}
|
|
10
10
|
:root {
|
|
11
|
-
--sa-date-radius: var(--sa-radii-
|
|
11
|
+
--sa-date-radius: var(--sa-radii-sm, 0.375rem);
|
|
12
12
|
--sa-date-radius-lg: var(--sa-radii-lg, 0.75rem);
|
|
13
13
|
--sa-date-bg: var(--sa-background-primary, #ffffff);
|
|
14
14
|
--sa-date-border-color: var(--sa-color-gray-alpha-a20, #78867f33);
|
|
@@ -145,6 +145,50 @@
|
|
|
145
145
|
gap: var(--sa-spacing-xs, 4px);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
.sa-calendar-header-title {
|
|
149
|
+
font-size: 15px;
|
|
150
|
+
font-weight: 600;
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
color: var(--sa-date-text-primary);
|
|
153
|
+
flex: 1;
|
|
154
|
+
line-height: 1.3;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.sa-calendar-header-nav {
|
|
158
|
+
display: flex;
|
|
159
|
+
align-items: center;
|
|
160
|
+
gap: 2px;
|
|
161
|
+
flex-shrink: 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.sa-calendar-nav-btn {
|
|
165
|
+
display: inline-flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
justify-content: center;
|
|
168
|
+
width: 28px;
|
|
169
|
+
height: 28px;
|
|
170
|
+
border: 0;
|
|
171
|
+
padding: 0;
|
|
172
|
+
background: transparent;
|
|
173
|
+
border-radius: var(--sa-date-radius);
|
|
174
|
+
cursor: pointer;
|
|
175
|
+
color: var(--sa-date-brand);
|
|
176
|
+
transition: background-color 120ms ease;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.sa-calendar-nav-btn:hover {
|
|
180
|
+
background: var(--sa-date-brand-subtle);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.sa-calendar-nav-btn:active {
|
|
184
|
+
background: var(--sa-date-brand-secondary);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.sa-calendar-nav-btn:focus-visible {
|
|
188
|
+
outline: 2px solid var(--sa-date-brand);
|
|
189
|
+
outline-offset: 1px;
|
|
190
|
+
}
|
|
191
|
+
|
|
148
192
|
.sa-calendar-days-name-preivew {
|
|
149
193
|
display: flex;
|
|
150
194
|
gap: var(--sa-spacing-sm, 8px);
|
|
@@ -189,8 +233,28 @@
|
|
|
189
233
|
}
|
|
190
234
|
|
|
191
235
|
.sa-calendar-days-active {
|
|
192
|
-
background: var(--sa-date-brand
|
|
236
|
+
background: var(--sa-date-brand);
|
|
237
|
+
color: #fff;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.sa-calendar-days-today {
|
|
241
|
+
position: relative;
|
|
193
242
|
color: var(--sa-date-brand);
|
|
243
|
+
font-weight: 700;
|
|
244
|
+
background: transparent;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.sa-calendar-days-today::before {
|
|
248
|
+
content: '';
|
|
249
|
+
position: absolute;
|
|
250
|
+
top: 50%;
|
|
251
|
+
left: 50%;
|
|
252
|
+
transform: translate(-50%, -50%);
|
|
253
|
+
width: 32px;
|
|
254
|
+
height: 32px;
|
|
255
|
+
background: var(--sa-date-brand-secondary);
|
|
256
|
+
border-radius: 50%;
|
|
257
|
+
z-index: -1;
|
|
194
258
|
}
|
|
195
259
|
|
|
196
260
|
/* MONTH STYLING */
|
|
@@ -268,13 +332,9 @@
|
|
|
268
332
|
|
|
269
333
|
.sa-calendar-input-outline {
|
|
270
334
|
border-color: var(--sa-date-border-color);
|
|
271
|
-
/* border-color: var(--sa-date-text-muted); */
|
|
272
335
|
background-color: transparent;
|
|
273
336
|
border-width: var(--sa-border, 1px);
|
|
274
337
|
border-style: solid;
|
|
275
|
-
/* height: var(--sa-h-10, 40px); */
|
|
276
|
-
/* border-radius: var(--sa-date-radius); */
|
|
277
|
-
/* padding-inline: var(--sa-spacing-3, 12px); */
|
|
278
338
|
}
|
|
279
339
|
|
|
280
340
|
.sa-calendar-input-container.sm {
|
|
@@ -296,6 +356,40 @@
|
|
|
296
356
|
padding-inline: var(--sa-spacing-3, 12px);
|
|
297
357
|
}
|
|
298
358
|
|
|
359
|
+
/* filled variant — gray background, no visible border */
|
|
360
|
+
.sa-calendar-input-container.sa-calendar-input-filled {
|
|
361
|
+
background-color: var(--sa-date-accent-subtle, #f0f1f2);
|
|
362
|
+
border-color: transparent;
|
|
363
|
+
border-width: 1px;
|
|
364
|
+
border-style: solid;
|
|
365
|
+
}
|
|
366
|
+
.sa-calendar-input-container.sa-calendar-input-filled:has(input:focus) {
|
|
367
|
+
border-color: var(--sa-date-brand);
|
|
368
|
+
background-color: var(--sa-date-accent-subtle, #f0f1f2);
|
|
369
|
+
box-shadow: 0px 0px 0px 2px var(--sa-date-brand-subtle);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/* flushed variant — bottom border only */
|
|
373
|
+
.sa-calendar-input-container.sa-calendar-input-flushed {
|
|
374
|
+
background-color: transparent;
|
|
375
|
+
border-top: none;
|
|
376
|
+
border-left: none;
|
|
377
|
+
border-right: none;
|
|
378
|
+
border-bottom: 1px solid var(--sa-date-border-color);
|
|
379
|
+
border-radius: 0;
|
|
380
|
+
padding-inline: 0;
|
|
381
|
+
}
|
|
382
|
+
.sa-calendar-input-container.sa-calendar-input-flushed:has(input:focus) {
|
|
383
|
+
border-bottom-color: var(--sa-date-brand);
|
|
384
|
+
box-shadow: none;
|
|
385
|
+
}
|
|
386
|
+
.sa-calendar-input-container.sa-calendar-input-flushed.sa-calendar-input-container-error {
|
|
387
|
+
border-bottom-color: var(--sa-date-border-error) !important;
|
|
388
|
+
}
|
|
389
|
+
.sa-calendar-input-container.sa-calendar-input-flushed.sa-calendar-input-container-warning {
|
|
390
|
+
border-bottom-color: var(--sa-date-border-warning) !important;
|
|
391
|
+
}
|
|
392
|
+
|
|
299
393
|
.sa-calendar-input-preview-container {
|
|
300
394
|
width: 100%;
|
|
301
395
|
position: relative;
|
|
@@ -356,4 +450,72 @@
|
|
|
356
450
|
outline: 2px solid var(--sa-date-brand);
|
|
357
451
|
outline-offset: 1px;
|
|
358
452
|
}
|
|
359
|
-
`,U=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],V=["January","February","March","April","May","June","July","August","September","October","November","December"],ne=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function G(r){const[a,t]=m.useState(r),s=m.useRef(null),l=f=>{s.current&&!s.current.contains(f.target)&&t(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:t}}const K="sa-calendar-input-styles";(r=>{if(!document.getElementById(K)){const a=document.createElement("style");a.id=K,a.textContent=r,document.head.appendChild(a)}})(A);const W=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},ae=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:f,...d}=r,p=m.useRef(null),g=()=>{p.current&&d.onClick&&(p.current.focus(),d.onClick(""))},n=t==="disable"||d.disabled,u=!!d.value,y=l&&u&&!n,k=$=>{$.stopPropagation(),f==null||f()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:g,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:W(a),height:W(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...d,disabled:n,value:d.value,ref:p})}),y?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:k,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:W(a),height:W(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:W(a),height:W(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},re=({date:r,setDate:a,dateRange:t,setDateRange:s,onChange:l,minDate:f,maxDate:d,input:p})=>{var Y,h,w;const[g,n]=m.useState(null);let u=new Date(r.getFullYear(),r.getMonth(),1),y=u.getDay(),k=[];const $=r.getMonth(),v=!!(t.from&&!t.to),o=v&&g?g:null;for(let i=0;i<42;i++){i===0&&y===0?u.setDate(u.getDate()-7):i===0?u.setDate(u.getDate()+(i-y)):u.setDate(u.getDate()+1);let x={currentMonth:u.getMonth()===$,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((Y=t.from)==null?void 0:Y.toDateString())||u.toDateString()===(((h=t.to)==null?void 0:h.toDateString())||((w=t.from)==null?void 0:w.toDateString())),year:u.getFullYear(),isDisabled:f&&u<f||d&&u>d};k.push(x)}const c=i=>{a(i)},M=i=>{var N;let x={...t};if(x.from&&x.to)x={from:i,to:null};else{const C=((N=x.from)==null?void 0:N.getTime())||0;i.getTime()>C?x={from:x.from,to:i}:x={from:i,to:x.from}}s(x),l(x)};return e.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>n(null),children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:U.map((i,x)=>e.jsx("p",{children:i},x))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:k.map((i,x)=>{const N=t.from&&t.to&&i.date.getTime()>t.from.getTime()&&i.date.getTime()<t.to.getTime(),C=(()=>{if(!o||!t.from)return!1;const D=i.date.getTime(),E=t.from.getTime(),z=o.getTime();return z>E?D>E&&D<z:D<E&&D>z})(),S=v&&g&&i.date.toDateString()===g.toDateString(),F=i.isDisabled,L=()=>N||C?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",T=()=>F?"var(--sa-color-gray-400, #b7b9be)":N||C?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${i.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${i.selected||S?"sa-calendar-days-active":""}`,style:{backgroundColor:L(),pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",color:T(),opacity:S&&!i.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{F||(c(i.date),M(i.date))},onMouseEnter:()=>{F||n(i.date)},children:i.number},x)})})]})},te=({date:r,setDate:a,filter:t,setViews:s,dateRange:l,setDateRange:f,onChange:d,minDate:p,maxDate:g,input:n})=>{const u=l.from.getFullYear(),y=r.getFullYear(),k=v=>{t?($(v),a(v)):(s("days"),a(v))},$=v=>{var c;let o={...l};if(o.from&&o.to)o={from:v,to:null};else{const M=((c=o.from)==null?void 0:c.getTime())||0;v.getTime()>M?o={from:o.from,to:v}:o={from:v,to:o.from}}f(o),d(o)};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((v,o)=>{var Y,h,w;const c=new Date(y,o).getTime()>l.from.getTime()&&new Date(y,o).getTime()<(((Y=l.to)==null?void 0:Y.getTime())||l.from.getTime()),M=p&&new Date(y,o)<p||g&&new Date(y,o)>g;return e.jsx("p",{className:u===y&&(o===((h=l.from)==null?void 0:h.getMonth())||o===((w=l.to)==null?void 0:w.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:M?"none":void 0,cursor:M?"not-allowed":"pointer",color:M?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{M||k(new Date(y,o))},children:v.slice(0,3)},o)})})},P=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},se=({date:r,filter:a,setViews:t,setDate:s,dateRange:l,setDateRange:f,onChange:d,minDate:p,maxDate:g,input:n})=>{var Y;let u=[];const y=r.getFullYear(),{start:k,end:$}=P(y),v=l.from.getFullYear(),o=(Y=l.to)==null?void 0:Y.getFullYear();for(let h=k;h<$;h++){const w=new Date(h,0),i=(!p||w>=p)&&(!g||w<=g),x=h===v||h===o,N=w>l.from&&w<l.to;u.push({year:h,active:x&&i,highlight:N&&i,disabled:!i})}const c=h=>{a?(M(h),s(h)):(s(h),t("months"))},M=h=>{var i;let w={...l};if(w.from&&w.to)w={from:h,to:null};else{const x=((i=w.from)==null?void 0:i.getTime())||0;h.getTime()>x?w={from:w.from,to:h}:w={from:h,to:w.from}}f(w),d(w)};return e.jsx("div",{className:"sa-calendar-years-preview",children:u.map((h,w)=>e.jsx("p",{className:`${h.active?"sa-calendar-months-active":""} ${h.highlight?"sa-calendar-months-highlight":""} ${h.disabled?"sa-calendar-disabled":""}`,onClick:()=>{h.disabled||c(new Date(h.year,0))},style:{backgroundColor:h.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:h.highlight?"var(--sa-color-gray-500, #8c8f97)":h.active?"":h.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:h.disabled?"not-allowed":"pointer",pointerEvents:h.disbled?"none":"all",...n?{}:{width:"100%"}},children:h.year},w))})},Q=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),X=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),oe=({setViews:r,views:a,filter:t,date:s,setDate:l})=>{const f=()=>{t||r(n=>n==="days"?"months":n==="months"?"years":"days")},d=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},g=()=>{if(a==="days")return`${V[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${P(s.getFullYear()).start} ~ ${P(s.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx(Q,{onClick:()=>p()}),e.jsx("div",{style:{cursor:"pointer"},onClick:f,children:g()}),e.jsx(X,{onClick:()=>d()})]})};function H(r){const a=new Date(r),t=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${ne[s]} ${t}`}const Z=({label:r,labelPosition:a="outside-top",required:t,optional:s,description:l,helperText:f,errorText:d,fullWidth:p,children:g})=>{const n=["sa-date-field",p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),u=r?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:r}),s&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,y=e.jsxs(e.Fragment,{children:[f&&!d&&e.jsx("p",{className:"sa-date-field-helper",children:f}),d&&e.jsx("p",{className:"sa-date-field-error-msg",children:d})]});return r?a==="outside-left"?e.jsxs("div",{className:`${n} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[u,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[g,y]})]}):e.jsxs("div",{className:n,children:[u,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),g,y]}):e.jsxs("div",{className:n,children:[l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),g,y]})},_="sa-calendar-styles";(r=>{if(!document.getElementById(_)){const a=document.createElement("style");a.id=_,a.textContent=r,document.head.appendChild(a)}})(A);const le=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:f,maxDate:d,placeholder:p,size:g,status:n,clearable:u,fullWidth:y=!0,label:k,labelPosition:$,required:v,optional:o,description:c,helperText:M,errorText:Y},h)=>{const w=Y?"error":n,{ref:i,isComponentVisible:x,setIsComponentVisible:N}=G(!1),C=m.useRef(null),[S,F]=m.useState("days"),[L,T]=m.useState(new Date),[D,E]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(T(r.from),E(r)):(T(new Date),E({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{t&&F(t)},[t]),m.useEffect(()=>{t||F("days")},[x]),m.useEffect(()=>{s||N(!0)},[s]);const z=()=>{var b,I;if(!r)return"";if(t){if(S==="days")return`${H(D.from)} ~ ${H(D.to||D.from)||"-"}`;if(S==="months")return`${V[D.from.getMonth()]} ~ ${D.to?V[D.to.getMonth()]:"-"}`;if(S==="years")return`${(b=D.from)==null?void 0:b.getFullYear()} ~ ${((I=D.to)==null?void 0:I.getFullYear())||"-"}`}else return`${H(D.from)} ~ ${H(D.to||D.from)||"-"}`},j=()=>{if(C.current&&i.current&&s){const b=i.current.getBoundingClientRect(),I=C.current.getBoundingClientRect();window.innerWidth<b.left+I.width?C.current.style.left=`${b.left-I.width+b.width}px`:C.current.style.left=`${b.left}px`,b.top+I.height>window.innerHeight?C.current.style.top=`${b.y-(b.height+I.height-28)}px`:C.current.style.top=`${b.y+b.height}px`}};m.useEffect(()=>{C.current&&i.current&&s&&j()},[C,i,x]),m.useEffect(()=>{const b=h==null?void 0:h.current;return b&&b.addEventListener("scroll",j),window.addEventListener("scroll",j),()=>{b&&b.removeEventListener("scroll",j),window.removeEventListener("scroll",j)}},[]);const q=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?i:null,children:[s?e.jsx(ae,{value:z(),inputMode:"none",onClick:()=>{N(!0)},onChange:()=>{},disabled:l,placeholder:p,size:g,status:w,clearable:u,onClear:()=>a(void 0)}):null,x?e.jsxs("div",{className:`sa-calendar ${s?"":"sa-calendar-no-input"}`,ref:C,children:[e.jsx(oe,{setViews:F,views:S,filter:t,date:L,setDate:T}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(re,{date:L,setDate:T,setIsComponentVisible:N,dateRange:D,setDateRange:E,input:s,onChange:a,minDate:f,maxDate:d}):S==="months"?e.jsx(te,{date:L,setDate:T,filter:t,setViews:F,dateRange:D,setDateRange:E,setIsComponentVisible:N,input:s,onChange:a,minDate:f,maxDate:d}):e.jsx(se,{date:L,setDate:T,filter:t,setViews:F,dateRange:D,setDateRange:E,setIsComponentVisible:N,input:s,onChange:a,minDate:f,maxDate:d})})]}):null]});return e.jsx(Z,{label:k,labelPosition:$,required:v,optional:o,description:c,helperText:M,errorText:Y,fullWidth:y,children:q})}),R="sa-calendar-input-styles";(r=>{if(!document.getElementById(R)){const a=document.createElement("style");a.id=R,a.textContent=r,document.head.appendChild(a)}})(A);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},de=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:f,...d}=r,p=m.useRef(null),g=()=>{p.current&&d.onClick&&(p.current.focus(),d.onClick(""))},n=t==="disable"||d.disabled,u=!!d.value,y=l&&u&&!n,k=$=>{$.stopPropagation(),f==null||f()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:g,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...d,disabled:n,value:d.value,ref:p})}),y?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:k,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},ie=({date:r,setDate:a,previewDate:t,setPreviewDate:s,setIsComponentVisible:l,minDate:f,maxDate:d,input:p,onChange:g})=>{let n=new Date(t.getFullYear(),t.getMonth(),1),u=n.getDay(),y=[];const k=r.toDateString(),$=t.getMonth();for(let o=0;o<42;o++){o===0&&u===0?n.setDate(n.getDate()-7):o===0?n.setDate(n.getDate()+(o-u)):n.setDate(n.getDate()+1);let c={currentMonth:n.getMonth()===$,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===k,year:n.getFullYear(),isDisabled:f&&n<f||d&&n>d};y.push(c)}const v=o=>{(!f||o>=f)&&(!d||o<=d)&&(a(o),g(o),s(o),p&&l(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:U.map((o,c)=>e.jsx("p",{children:o},c))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:y.map((o,c)=>{const M=o.isDisabled;return e.jsx("p",{className:`${o.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${o.selected?"sa-calendar-days-active":""}`,style:{color:M?"#ccc":void 0,pointerEvents:M?"none":void 0,cursor:M?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{M||v(o.date)},children:o.number},c)})})]})},ce=({date:r,setDate:a,filter:t,setViews:s,onChange:l,previewDate:f,setPreviewDate:d,minDate:p,maxDate:g,input:n})=>{const u=r.getMonth(),y=r.getFullYear(),k=f.getFullYear(),$=v=>{(!p||v>=p)&&(!g||v<=g)&&(t?(l(v),a(v),d(v)):(s("days"),d(v)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((v,o)=>{const c=p&&new Date(k,o,1)<p||g&&new Date(k,o+1,0)>g;return e.jsx("p",{className:o===u&&k===y?"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||$(new Date(k,o))},children:v.slice(0,3)},o)})})},J=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},he=({date:r,filter:a,setViews:t,setDate:s,onChange:l,previewDate:f,setPreviewDate:d,minDate:p,maxDate:g,input:n})=>{let u=[];const y=f.getFullYear(),{start:k,end:$}=J(y),v=r.getFullYear();for(let c=k;c<$;c++){let M=p&&new Date(c,0,1)<p||g&&new Date(c,11,31)>g;u.push({year:c,active:c===v,isDisabled:M})}const o=c=>{(!p||c>=p)&&(!g||c<=g)&&(a?(l(c),s(c),d(c)):(t("months"),d(c)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:u.map((c,M)=>e.jsx("p",{className:c.active?"sa-calendar-months-active":"",style:{color:c.isDisabled?"#ccc":void 0,pointerEvents:c.isDisabled?"none":void 0,cursor:c.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c.isDisabled||o(new Date(c.year,0))},children:c.year},M))})},fe=({setViews:r,views:a,filter:t,previewDate:s,setPreviewDate:l})=>{const f=()=>{t||r(n=>n==="days"?"months":n==="months"?"years":"days")},d=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},p=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},g=()=>{if(a==="days")return`${V[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${J(s.getFullYear()).start} ~ ${J(s.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx(Q,{onClick:()=>p()}),e.jsx("div",{style:{cursor:"pointer"},onClick:f,children:g()}),e.jsx(X,{onClick:()=>d()})]})},ee="sa-calendar-styles";(r=>{if(!document.getElementById(ee)){const a=document.createElement("style");a.id=ee,a.textContent=r,document.head.appendChild(a)}})(A);const ue=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:f,maxDate:d,placeholder:p,size:g,status:n,clearable:u,fullWidth:y=!0,label:k,labelPosition:$,required:v,optional:o,description:c,helperText:M,errorText:Y},h)=>{const w=Y?"error":n,{ref:i,isComponentVisible:x,setIsComponentVisible:N}=G(!1),C=m.useRef(null),[S,F]=m.useState("days"),[L,T]=m.useState(new Date),[D,E]=m.useState(new Date);m.useEffect(()=>{r?(T(r),E(r)):(T(new Date),E(new Date))},[r]),m.useEffect(()=>{t&&F(t)},[t]),m.useEffect(()=>{t||F("days")},[x]),m.useEffect(()=>{s||N(!0)},[s]);const z=()=>r?t==="days"?H(L):t==="months"?`${V[L.getMonth()]} ${L.getFullYear()}`:t==="years"?L.getFullYear():H(L):"",j=()=>{if(C.current&&i.current&&s){const b=i.current.getBoundingClientRect(),I=C.current.getBoundingClientRect();window.innerWidth<b.left+I.width?C.current.style.left=`${b.left-I.width+b.width}px`:C.current.style.left=`${b.left}px`,b.top+I.height>window.innerHeight?C.current.style.top=`${b.y-(b.height+I.height-28)}px`:C.current.style.top=`${b.y+b.height}px`}};m.useEffect(()=>{C.current&&i.current&&s&&j()},[C,i,x]),m.useEffect(()=>{const b=h==null?void 0:h.current;return b&&b.addEventListener("scroll",j),window.addEventListener("scroll",j),()=>{b&&b.removeEventListener("scroll",j),window.removeEventListener("scroll",j)}},[]);const q=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?i:null,children:[s?e.jsx(de,{value:z(),onClick:()=>N(!0),onChange:()=>{},placeholder:p,disabled:l,size:g,status:w,inputMode:"none",clearable:u,onClear:()=>a(void 0)}):null,x?e.jsxs("div",{className:`sa-calendar ${s?"":"sa-calendar-no-input"}`,ref:C,children:[e.jsx(fe,{setViews:F,views:S,filter:t,previewDate:D,setPreviewDate:E,isComponentVisible:x}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(ie,{date:L,setDate:T,previewDate:D,setPreviewDate:E,setIsComponentVisible:N,input:s,minDate:f,maxDate:d,onChange:a}):S==="months"?e.jsx(ce,{date:L,setDate:T,previewDate:D,setPreviewDate:E,filter:t,setViews:F,onChange:a,minDate:f,maxDate:d,input:s}):e.jsx(he,{date:L,setDate:T,previewDate:D,setPreviewDate:E,filter:t,setViews:F,onChange:a,minDate:f,maxDate:d,input:s})})]}):null]});return e.jsx(Z,{label:k,labelPosition:$,required:v,optional:o,description:c,helperText:M,errorText:Y,fullWidth:y,children:q})}),pe=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,rangedDate:l,disabled:f,minDate:d,maxDate:p,placeholder:g,size:n,status:u,clearable:y,fullWidth:k,label:$,labelPosition:v,required:o,optional:c,description:M,helperText:Y,errorText:h},w)=>{const i={onChange:a,value:r,input:s,filter:t,disabled:f,minDate:d,maxDate:p,placeholder:g,size:n,status:u,clearable:y,fullWidth:k,label:$,labelPosition:v,required:o,optional:c,description:M,helperText:Y,errorText:h};return e.jsx(e.Fragment,{children:l?e.jsx(le,{...i,ref:w}):e.jsx(ue,{...i,ref:w})})});B.StarasiaDate=pe,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
|
453
|
+
|
|
454
|
+
/* === CALENDAR PANEL SIZE VARIANTS === */
|
|
455
|
+
/* sa-calendar-size-md is the default — no override needed */
|
|
456
|
+
|
|
457
|
+
.sa-calendar.sa-calendar-size-sm {
|
|
458
|
+
padding: 16px 12px;
|
|
459
|
+
gap: 8px;
|
|
460
|
+
}
|
|
461
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-name-preivew {
|
|
462
|
+
gap: 4px;
|
|
463
|
+
}
|
|
464
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-name-preivew p {
|
|
465
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
466
|
+
}
|
|
467
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-number-preivew {
|
|
468
|
+
gap: 4px;
|
|
469
|
+
}
|
|
470
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-number-preivew p {
|
|
471
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
472
|
+
width: 28px;
|
|
473
|
+
height: 26px;
|
|
474
|
+
}
|
|
475
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-months-preview p,
|
|
476
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-years-preview p {
|
|
477
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
478
|
+
width: 76px;
|
|
479
|
+
height: 38px;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.sa-calendar.sa-calendar-size-lg {
|
|
483
|
+
padding: 28px 20px;
|
|
484
|
+
gap: 16px;
|
|
485
|
+
}
|
|
486
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-name-preivew {
|
|
487
|
+
gap: 10px;
|
|
488
|
+
}
|
|
489
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-name-preivew p {
|
|
490
|
+
font-size: 16px;
|
|
491
|
+
}
|
|
492
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-number-preivew {
|
|
493
|
+
gap: 10px;
|
|
494
|
+
}
|
|
495
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-number-preivew p {
|
|
496
|
+
font-size: 16px;
|
|
497
|
+
width: 40px;
|
|
498
|
+
height: 36px;
|
|
499
|
+
}
|
|
500
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-months-preview p,
|
|
501
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-years-preview p {
|
|
502
|
+
font-size: 16px;
|
|
503
|
+
width: 110px;
|
|
504
|
+
height: 54px;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-header-title {
|
|
508
|
+
font-size: 13px;
|
|
509
|
+
}
|
|
510
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-nav-btn {
|
|
511
|
+
width: 24px;
|
|
512
|
+
height: 24px;
|
|
513
|
+
}
|
|
514
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-header-title {
|
|
515
|
+
font-size: 16px;
|
|
516
|
+
}
|
|
517
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-nav-btn {
|
|
518
|
+
width: 32px;
|
|
519
|
+
height: 32px;
|
|
520
|
+
}
|
|
521
|
+
`,G=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],V=["January","February","March","April","May","June","July","August","September","October","November","December"],an=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Z(r){const[a,t]=m.useState(r),o=m.useRef(null),l=h=>{o.current&&!o.current.contains(h.target)&&t(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:t}}const K="sa-calendar-input-styles";(r=>{if(!document.getElementById(K)){const a=document.createElement("style");a.id=K,a.textContent=r,document.head.appendChild(a)}})(P);const W=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},rn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:h,...d}=r,u=m.useRef(null),p=()=>{u.current&&d.onClick&&(u.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,c=!!d.value,y=l&&c&&!e,M=N=>{N.stopPropagation(),h==null||h()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:p,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:W(a),height:W(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...d,disabled:e,value:d.value,ref:u})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:M,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:W(a),height:W(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:W(a),height:W(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},tn=({date:r,setDate:a,dateRange:t,setDateRange:o,onChange:l,minDate:h,maxDate:d,input:u})=>{var f,v,F;const[p,e]=m.useState(null);let c=new Date(r.getFullYear(),r.getMonth(),1),y=c.getDay(),M=[];const N=r.getMonth(),b=new Date().toDateString(),g=!!(t.from&&!t.to),s=g&&p?p:null;for(let i=0;i<42;i++){i===0&&y===0?c.setDate(c.getDate()-7):i===0?c.setDate(c.getDate()+(i-y)):c.setDate(c.getDate()+1);let x={currentMonth:c.getMonth()===N,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((f=t.from)==null?void 0:f.toDateString())||c.toDateString()===(((v=t.to)==null?void 0:v.toDateString())||((F=t.from)==null?void 0:F.toDateString())),isToday:c.toDateString()===b,year:c.getFullYear(),isDisabled:h&&c<h||d&&c>d};M.push(x)}const k=i=>{a(i)},$=i=>{var E;let x={...t};if(x.from&&x.to)x={from:i,to:null};else{const D=((E=x.from)==null?void 0:E.getTime())||0;i.getTime()>D?x={from:x.from,to:i}:x={from:i,to:x.from}}o(x),l(x)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>e(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:G.map((i,x)=>n.jsx("p",{children:i},x))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:M.map((i,x)=>{const E=t.from&&t.to&&i.date.getTime()>t.from.getTime()&&i.date.getTime()<t.to.getTime(),D=(()=>{if(!s||!t.from)return!1;const C=i.date.getTime(),z=t.from.getTime(),A=s.getTime();return A>z?C>z&&C<A:C<z&&C>A})(),L=g&&p&&i.date.toDateString()===p.toDateString(),Y=i.isDisabled,S=()=>E||D?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",T=()=>Y?"var(--sa-color-gray-400, #b7b9be)":E||D?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${i.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${i.selected||L?"sa-calendar-days-active":""} ${i.isToday&&!i.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:S(),pointerEvents:Y?"none":void 0,cursor:Y?"not-allowed":"pointer",color:T(),opacity:L&&!i.selected?.75:1,...u?{}:{width:"100%"}},onClick:()=>{Y||(k(i.date),$(i.date))},onMouseEnter:()=>{Y||e(i.date)},children:i.number},x)})})]})},sn=({date:r,setDate:a,filter:t,setViews:o,dateRange:l,setDateRange:h,onChange:d,minDate:u,maxDate:p,input:e})=>{const c=l.from.getFullYear(),y=r.getFullYear(),M=b=>{t?(N(b),a(b)):(o("days"),a(b))},N=b=>{var s;let g={...l};if(g.from&&g.to)g={from:b,to:null};else{const k=((s=g.from)==null?void 0:s.getTime())||0;b.getTime()>k?g={from:g.from,to:b}:g={from:b,to:g.from}}h(g),d(g)};return n.jsx("div",{className:"sa-calendar-months-preview",children:V.map((b,g)=>{var $,f,v;const s=new Date(y,g).getTime()>l.from.getTime()&&new Date(y,g).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=u&&new Date(y,g)<u||p&&new Date(y,g)>p;return n.jsx("p",{className:c===y&&(g===((f=l.from)==null?void 0:f.getMonth())||g===((v=l.to)==null?void 0:v.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:s?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:k?"none":void 0,cursor:k?"not-allowed":"pointer",color:k?"var(--sa-color-gray-400, #b7b9be)":s?"var(--sa-color-gray-500, #8c8f97)":"",...e?{}:{width:"100%"}},onClick:()=>{k||M(new Date(y,g))},children:b.slice(0,3)},g)})})},J=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},on=({date:r,filter:a,setViews:t,setDate:o,dateRange:l,setDateRange:h,onChange:d,minDate:u,maxDate:p,input:e})=>{var $;let c=[];const y=r.getFullYear(),{start:M,end:N}=J(y),b=l.from.getFullYear(),g=($=l.to)==null?void 0:$.getFullYear();for(let f=M;f<N;f++){const v=new Date(f,0),F=(!u||v>=u)&&(!p||v<=p),i=f===b||f===g,x=v>l.from&&v<l.to;c.push({year:f,active:i&&F,highlight:x&&F,disabled:!F})}const s=f=>{a?(k(f),o(f)):(o(f),t("months"))},k=f=>{var F;let v={...l};if(v.from&&v.to)v={from:f,to:null};else{const i=((F=v.from)==null?void 0:F.getTime())||0;f.getTime()>i?v={from:v.from,to:f}:v={from:f,to:v.from}}h(v),d(v)};return n.jsx("div",{className:"sa-calendar-years-preview",children:c.map((f,v)=>n.jsx("p",{className:`${f.active?"sa-calendar-months-active":""} ${f.highlight?"sa-calendar-months-highlight":""} ${f.disabled?"sa-calendar-disabled":""}`,onClick:()=>{f.disabled||s(new Date(f.year,0))},style:{backgroundColor:f.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:f.highlight?"var(--sa-color-gray-500, #8c8f97)":f.active?"":f.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:f.disabled?"not-allowed":"pointer",pointerEvents:f.disbled?"none":"all",...e?{}:{width:"100%"}},children:f.year},v))})},Q=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),X=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),ln=({setViews:r,views:a,filter:t,date:o,setDate:l})=>{const h=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},u=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},p=()=>{if(a==="days")return`${V[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${J(o.getFullYear()).start} ~ ${J(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:h,children:p()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:u,children:n.jsx(Q,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(X,{})})]})]})};function H(r){const a=new Date(r),t=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${an[o]} ${t}`}const _=({label:r,labelPosition:a="outside-top",required:t,optional:o,description:l,helperText:h,errorText:d,fullWidth:u,children:p})=>{const e=["sa-date-field",u?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),c=r?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:r}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,y=n.jsxs(n.Fragment,{children:[h&&!d&&n.jsx("p",{className:"sa-date-field-helper",children:h}),d&&n.jsx("p",{className:"sa-date-field-error-msg",children:d})]});return r?a==="outside-left"?n.jsxs("div",{className:`${e} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[c,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[p,y]})]}):n.jsxs("div",{className:e,children:[c,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),p,y]}):n.jsxs("div",{className:e,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),p,y]})},R="sa-calendar-styles";(r=>{if(!document.getElementById(R)){const a=document.createElement("style");a.id=R,a.textContent=r,document.head.appendChild(a)}})(P);const dn=m.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:h,maxDate:d,placeholder:u,size:p,variant:e,status:c,clearable:y,fullWidth:M=!0,label:N,labelPosition:b,required:g,optional:s,description:k,helperText:$,errorText:f},v)=>{const F=f?"error":c,{ref:i,isComponentVisible:x,setIsComponentVisible:E}=Z(!1),D=m.useRef(null),[L,Y]=m.useState("days"),[S,T]=m.useState(new Date),[C,z]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(T(r.from),z(r)):(T(new Date),z({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{t&&Y(t)},[t]),m.useEffect(()=>{t||Y("days")},[x]),m.useEffect(()=>{o||E(!0)},[o]);const A=()=>{var w,I;if(!r)return"";if(t){if(L==="days")return`${H(C.from)} ~ ${H(C.to||C.from)||"-"}`;if(L==="months")return`${V[C.from.getMonth()]} ~ ${C.to?V[C.to.getMonth()]:"-"}`;if(L==="years")return`${(w=C.from)==null?void 0:w.getFullYear()} ~ ${((I=C.to)==null?void 0:I.getFullYear())||"-"}`}else return`${H(C.from)} ~ ${H(C.to||C.from)||"-"}`},j=()=>{if(D.current&&i.current&&o){const w=i.current.getBoundingClientRect(),I=D.current.getBoundingClientRect();window.innerWidth<w.left+I.width?D.current.style.left=`${w.left-I.width+w.width}px`:D.current.style.left=`${w.left}px`,w.top+I.height>window.innerHeight?D.current.style.top=`${w.y-(w.height+I.height-28)}px`:D.current.style.top=`${w.y+w.height}px`}};m.useEffect(()=>{D.current&&i.current&&o&&j()},[D,i,x]),m.useEffect(()=>{const w=v==null?void 0:v.current;return w&&w.addEventListener("scroll",j),window.addEventListener("scroll",j),()=>{w&&w.removeEventListener("scroll",j),window.removeEventListener("scroll",j)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?i:null,children:[o?n.jsx(rn,{value:A(),inputMode:"none",onClick:()=>{E(!0)},onChange:()=>{},disabled:l,placeholder:u,size:p,variant:e,status:F,clearable:y,onClear:()=>a(void 0)}):null,x?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${p||"md"} ${o?"":"sa-calendar-no-input"}`,ref:D,children:[n.jsx(ln,{setViews:Y,views:L,filter:t,date:S,setDate:T}),n.jsx("div",{className:"sa-calendar-body",children:L==="days"?n.jsx(tn,{date:S,setDate:T,setIsComponentVisible:E,dateRange:C,setDateRange:z,input:o,onChange:a,minDate:h,maxDate:d}):L==="months"?n.jsx(sn,{date:S,setDate:T,filter:t,setViews:Y,dateRange:C,setDateRange:z,setIsComponentVisible:E,input:o,onChange:a,minDate:h,maxDate:d}):n.jsx(on,{date:S,setDate:T,filter:t,setViews:Y,dateRange:C,setDateRange:z,setIsComponentVisible:E,input:o,onChange:a,minDate:h,maxDate:d})})]}):null]});return n.jsx(_,{label:N,labelPosition:b,required:g,optional:s,description:k,helperText:$,errorText:f,fullWidth:M,children:U})}),nn="sa-calendar-input-styles";(r=>{if(!document.getElementById(nn)){const a=document.createElement("style");a.id=nn,a.textContent=r,document.head.appendChild(a)}})(P);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},cn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:h,...d}=r,u=m.useRef(null),p=()=>{u.current&&d.onClick&&(u.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,c=!!d.value,y=l&&c&&!e,M=N=>{N.stopPropagation(),h==null||h()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:p,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...d,disabled:e,value:d.value,ref:u})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:M,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},hn=({date:r,setDate:a,previewDate:t,setPreviewDate:o,setIsComponentVisible:l,minDate:h,maxDate:d,input:u,onChange:p})=>{let e=new Date(t.getFullYear(),t.getMonth(),1),c=e.getDay(),y=[];const M=r.toDateString(),N=new Date().toDateString(),b=t.getMonth();for(let s=0;s<42;s++){s===0&&c===0?e.setDate(e.getDate()-7):s===0?e.setDate(e.getDate()+(s-c)):e.setDate(e.getDate()+1);let k={currentMonth:e.getMonth()===b,date:new Date(e),month:e.getMonth(),number:e.getDate(),selected:e.toDateString()===M,isToday:e.toDateString()===N,year:e.getFullYear(),isDisabled:h&&e<h||d&&e>d};y.push(k)}const g=s=>{(!h||s>=h)&&(!d||s<=d)&&(a(s),p(s),o(s),u&&l(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:G.map((s,k)=>n.jsx("p",{children:s},k))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:y.map((s,k)=>{const $=s.isDisabled;return n.jsx("p",{className:`${s.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${s.selected?"sa-calendar-days-active":""} ${s.isToday&&!s.selected?"sa-calendar-days-today":""}`,style:{color:$?"#ccc":void 0,pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",...u?{}:{width:"100%"}},onClick:()=>{$||g(s.date)},children:s.number},k)})})]})},pn=({date:r,setDate:a,filter:t,setViews:o,onChange:l,previewDate:h,setPreviewDate:d,minDate:u,maxDate:p,input:e})=>{const c=r.getMonth(),y=r.getFullYear(),M=h.getFullYear(),N=b=>{(!u||b>=u)&&(!p||b<=p)&&(t?(l(b),a(b),d(b)):(o("days"),d(b)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:V.map((b,g)=>{const s=u&&new Date(M,g,1)<u||p&&new Date(M,g+1,0)>p;return n.jsx("p",{className:g===c&&M===y?"sa-calendar-months-active":"",style:{color:s?"#ccc":void 0,pointerEvents:s?"none":void 0,cursor:s?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s||N(new Date(M,g))},children:b.slice(0,3)},g)})})},q=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},fn=({date:r,filter:a,setViews:t,setDate:o,onChange:l,previewDate:h,setPreviewDate:d,minDate:u,maxDate:p,input:e})=>{let c=[];const y=h.getFullYear(),{start:M,end:N}=q(y),b=r.getFullYear();for(let s=M;s<N;s++){let k=u&&new Date(s,0,1)<u||p&&new Date(s,11,31)>p;c.push({year:s,active:s===b,isDisabled:k})}const g=s=>{(!u||s>=u)&&(!p||s<=p)&&(a?(l(s),o(s),d(s)):(t("months"),d(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:c.map((s,k)=>n.jsx("p",{className:s.active?"sa-calendar-months-active":"",style:{color:s.isDisabled?"#ccc":void 0,pointerEvents:s.isDisabled?"none":void 0,cursor:s.isDisabled?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s.isDisabled||g(new Date(s.year,0))},children:s.year},k))})},un=({setViews:r,views:a,filter:t,previewDate:o,setPreviewDate:l})=>{const h=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},u=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},p=()=>{if(a==="days")return`${V[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${q(o.getFullYear()).start} ~ ${q(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:h,children:p()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:u,children:n.jsx(Q,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(X,{})})]})]})},en="sa-calendar-styles";(r=>{if(!document.getElementById(en)){const a=document.createElement("style");a.id=en,a.textContent=r,document.head.appendChild(a)}})(P);const gn=m.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:h,maxDate:d,placeholder:u,size:p,variant:e,status:c,clearable:y,fullWidth:M=!0,label:N,labelPosition:b,required:g,optional:s,description:k,helperText:$,errorText:f},v)=>{const F=f?"error":c,{ref:i,isComponentVisible:x,setIsComponentVisible:E}=Z(!1),D=m.useRef(null),[L,Y]=m.useState("days"),[S,T]=m.useState(new Date),[C,z]=m.useState(new Date);m.useEffect(()=>{r?(T(r),z(r)):(T(new Date),z(new Date))},[r]),m.useEffect(()=>{t&&Y(t)},[t]),m.useEffect(()=>{t||Y("days")},[x]),m.useEffect(()=>{o||E(!0)},[o]);const A=()=>r?t==="days"?H(S):t==="months"?`${V[S.getMonth()]} ${S.getFullYear()}`:t==="years"?S.getFullYear():H(S):"",j=()=>{if(D.current&&i.current&&o){const w=i.current.getBoundingClientRect(),I=D.current.getBoundingClientRect();window.innerWidth<w.left+I.width?D.current.style.left=`${w.left-I.width+w.width}px`:D.current.style.left=`${w.left}px`,w.top+I.height>window.innerHeight?D.current.style.top=`${w.y-(w.height+I.height-28)}px`:D.current.style.top=`${w.y+w.height}px`}};m.useEffect(()=>{D.current&&i.current&&o&&j()},[D,i,x]),m.useEffect(()=>{const w=v==null?void 0:v.current;return w&&w.addEventListener("scroll",j),window.addEventListener("scroll",j),()=>{w&&w.removeEventListener("scroll",j),window.removeEventListener("scroll",j)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?i:null,children:[o?n.jsx(cn,{value:A(),onClick:()=>E(!0),onChange:()=>{},placeholder:u,disabled:l,size:p,variant:e,status:F,inputMode:"none",clearable:y,onClear:()=>a(void 0)}):null,x?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${p||"md"} ${o?"":"sa-calendar-no-input"}`,ref:D,children:[n.jsx(un,{setViews:Y,views:L,filter:t,previewDate:C,setPreviewDate:z,isComponentVisible:x}),n.jsx("div",{className:"sa-calendar-body",children:L==="days"?n.jsx(hn,{date:S,setDate:T,previewDate:C,setPreviewDate:z,setIsComponentVisible:E,input:o,minDate:h,maxDate:d,onChange:a}):L==="months"?n.jsx(pn,{date:S,setDate:T,previewDate:C,setPreviewDate:z,filter:t,setViews:Y,onChange:a,minDate:h,maxDate:d,input:o}):n.jsx(fn,{date:S,setDate:T,previewDate:C,setPreviewDate:z,filter:t,setViews:Y,onChange:a,minDate:h,maxDate:d,input:o})})]}):null]});return n.jsx(_,{label:N,labelPosition:b,required:g,optional:s,description:k,helperText:$,errorText:f,fullWidth:M,children:U})}),bn=m.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,rangedDate:l,disabled:h,minDate:d,maxDate:u,placeholder:p,size:e,variant:c,status:y,clearable:M,fullWidth:N,label:b,labelPosition:g,required:s,optional:k,description:$,helperText:f,errorText:v},F)=>{const i={onChange:a,value:r,input:o,filter:t,disabled:h,minDate:d,maxDate:u,placeholder:p,size:e,variant:c,status:y,clearable:M,fullWidth:N,label:b,labelPosition:g,required:s,optional:k,description:$,helperText:f,errorText:v};return n.jsx(n.Fragment,{children:l?n.jsx(dn,{...i,ref:F}):n.jsx(gn,{...i,ref:F})})});B.StarasiaDate=bn,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interfaces.d.ts
CHANGED