@starasia/date 5.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/date.es.js +762 -594
- package/dist/date.umd.js +148 -6
- 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,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.Date={},B.jsxRuntime,B.React))})(this,function(B,e,
|
|
1
|
+
(function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.Date={},B.jsxRuntime,B.React))})(this,function(B,e,x){"use strict";const O=`@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;
|
|
@@ -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);
|
|
@@ -268,13 +312,9 @@
|
|
|
268
312
|
|
|
269
313
|
.sa-calendar-input-outline {
|
|
270
314
|
border-color: var(--sa-date-border-color);
|
|
271
|
-
/* border-color: var(--sa-date-text-muted); */
|
|
272
315
|
background-color: transparent;
|
|
273
316
|
border-width: var(--sa-border, 1px);
|
|
274
317
|
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
318
|
}
|
|
279
319
|
|
|
280
320
|
.sa-calendar-input-container.sm {
|
|
@@ -296,6 +336,40 @@
|
|
|
296
336
|
padding-inline: var(--sa-spacing-3, 12px);
|
|
297
337
|
}
|
|
298
338
|
|
|
339
|
+
/* filled variant — gray background, no visible border */
|
|
340
|
+
.sa-calendar-input-container.sa-calendar-input-filled {
|
|
341
|
+
background-color: var(--sa-date-accent-subtle, #f0f1f2);
|
|
342
|
+
border-color: transparent;
|
|
343
|
+
border-width: 1px;
|
|
344
|
+
border-style: solid;
|
|
345
|
+
}
|
|
346
|
+
.sa-calendar-input-container.sa-calendar-input-filled:has(input:focus) {
|
|
347
|
+
border-color: var(--sa-date-brand);
|
|
348
|
+
background-color: var(--sa-date-accent-subtle, #f0f1f2);
|
|
349
|
+
box-shadow: 0px 0px 0px 2px var(--sa-date-brand-subtle);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/* flushed variant — bottom border only */
|
|
353
|
+
.sa-calendar-input-container.sa-calendar-input-flushed {
|
|
354
|
+
background-color: transparent;
|
|
355
|
+
border-top: none;
|
|
356
|
+
border-left: none;
|
|
357
|
+
border-right: none;
|
|
358
|
+
border-bottom: 1px solid var(--sa-date-border-color);
|
|
359
|
+
border-radius: 0;
|
|
360
|
+
padding-inline: 0;
|
|
361
|
+
}
|
|
362
|
+
.sa-calendar-input-container.sa-calendar-input-flushed:has(input:focus) {
|
|
363
|
+
border-bottom-color: var(--sa-date-brand);
|
|
364
|
+
box-shadow: none;
|
|
365
|
+
}
|
|
366
|
+
.sa-calendar-input-container.sa-calendar-input-flushed.sa-calendar-input-container-error {
|
|
367
|
+
border-bottom-color: var(--sa-date-border-error) !important;
|
|
368
|
+
}
|
|
369
|
+
.sa-calendar-input-container.sa-calendar-input-flushed.sa-calendar-input-container-warning {
|
|
370
|
+
border-bottom-color: var(--sa-date-border-warning) !important;
|
|
371
|
+
}
|
|
372
|
+
|
|
299
373
|
.sa-calendar-input-preview-container {
|
|
300
374
|
width: 100%;
|
|
301
375
|
position: relative;
|
|
@@ -356,4 +430,72 @@
|
|
|
356
430
|
outline: 2px solid var(--sa-date-brand);
|
|
357
431
|
outline-offset: 1px;
|
|
358
432
|
}
|
|
359
|
-
`,U=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],V=["January","February","March","April","May","June","July","August","September","October","November","December"],ne=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function G(r){const[a,t]=m.useState(r),s=m.useRef(null),l=p=>{s.current&&!s.current.contains(p.target)&&t(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:s,isComponentVisible:a,setIsComponentVisible:t}}const K="sa-calendar-input-styles";(r=>{if(!document.getElementById(K)){const a=document.createElement("style");a.id=K,a.textContent=r,document.head.appendChild(a)}})(H);const z=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},ae=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:p,...i}=r,u=m.useRef(null),d=()=>{u.current&&i.onClick&&(u.current.focus(),i.onClick(""))},n=t==="disable"||i.disabled,x=!!i.value,v=l&&x&&!n,M=C=>{C.stopPropagation(),p==null||p()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:d,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:z(a),height:z(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:n,value:i.value,ref:u})}),v?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:M,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:z(a),height:z(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:z(a),height:z(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},re=({date:r,setDate:a,dateRange:t,setDateRange:s,onChange:l,minDate:p,maxDate:i,input:u})=>{var g,o,c;let d=new Date(r.getFullYear(),r.getMonth(),1),n=d.getDay(),x=[];const v=r.getMonth();for(let h=0;h<42;h++){h===0&&n===0?d.setDate(d.getDate()-7):h===0?d.setDate(d.getDate()+(h-n)):d.setDate(d.getDate()+1);let w={currentMonth:d.getMonth()===v,date:new Date(d),month:d.getMonth(),number:d.getDate(),selected:d.toDateString()===((g=t.from)==null?void 0:g.toDateString())||d.toDateString()===(((o=t.to)==null?void 0:o.toDateString())||((c=t.from)==null?void 0:c.toDateString())),year:d.getFullYear(),isDisabled:p&&d<p||i&&d>i};x.push(w)}const M=h=>{a(h)},C=h=>{var f;let w={...t};if(w.from&&w.to)w={from:h,to:null};else{const y=((f=w.from)==null?void 0:f.getTime())||0;h.getTime()>y?w={from:w.from,to:h}:w={from:h,to:w.from}}s(w),l(w)};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:U.map((h,w)=>e.jsx("p",{children:h},w))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:x.map((h,w)=>{var k;const f=h.date.getTime()>t.from.getTime()&&h.date.getTime()<(((k=t.to)==null?void 0:k.getTime())||t.from.getTime()),y=h.isDisabled;return e.jsx("p",{className:`${h.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${h.selected?"sa-calendar-days-active":""}`,style:{backgroundColor:f?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:y?"none":void 0,cursor:y?"not-allowed":"pointer",color:y?"var(--sa-color-gray-400, #b7b9be)":f?"var(--sa-color-gray-500, #8c8f97)":"",...u?{}:{width:"100%"}},onClick:()=>{y||(M(h.date),C(h.date))},children:h.number},w)})})]})},te=({date:r,setDate:a,filter:t,setViews:s,dateRange:l,setDateRange:p,onChange:i,minDate:u,maxDate:d,input:n})=>{const x=l.from.getFullYear(),v=r.getFullYear(),M=g=>{t?(C(g),a(g)):(s("days"),a(g))},C=g=>{var c;let o={...l};if(o.from&&o.to)o={from:g,to:null};else{const h=((c=o.from)==null?void 0:c.getTime())||0;g.getTime()>h?o={from:o.from,to:g}:o={from:g,to:o.from}}p(o),i(o)};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((g,o)=>{var w,f,y;const c=new Date(v,o).getTime()>l.from.getTime()&&new Date(v,o).getTime()<(((w=l.to)==null?void 0:w.getTime())||l.from.getTime()),h=u&&new Date(v,o)<u||d&&new Date(v,o)>d;return e.jsx("p",{className:x===v&&(o===((f=l.from)==null?void 0:f.getMonth())||o===((y=l.to)==null?void 0:y.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:c?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:h?"none":void 0,cursor:h?"not-allowed":"pointer",color:h?"var(--sa-color-gray-400, #b7b9be)":c?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{h||M(new Date(v,o))},children:g.slice(0,3)},o)})})},P=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},se=({date:r,filter:a,setViews:t,setDate:s,dateRange:l,setDateRange:p,onChange:i,minDate:u,maxDate:d,input:n})=>{var w;let x=[];const v=r.getFullYear(),{start:M,end:C}=P(v),g=l.from.getFullYear(),o=(w=l.to)==null?void 0:w.getFullYear();for(let f=M;f<C;f++){const y=new Date(f,0),k=(!u||y>=u)&&(!d||y<=d),Y=f===g||f===o,F=y>l.from&&y<l.to;x.push({year:f,active:Y&&k,highlight:F&&k,disabled:!k})}const c=f=>{a?(h(f),s(f)):(s(f),t("months"))},h=f=>{var k;let y={...l};if(y.from&&y.to)y={from:f,to:null};else{const Y=((k=y.from)==null?void 0:k.getTime())||0;f.getTime()>Y?y={from:y.from,to:f}:y={from:f,to:y.from}}p(y),i(y)};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((f,y)=>e.jsx("p",{className:`${f.active?"sa-calendar-months-active":""} ${f.highlight?"sa-calendar-months-highlight":""} ${f.disabled?"sa-calendar-disabled":""}`,onClick:()=>{f.disabled||c(new Date(f.year,0))},style:{backgroundColor:f.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:f.highlight?"var(--sa-color-gray-500, #8c8f97)":f.active?"":f.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:f.disabled?"not-allowed":"pointer",pointerEvents:f.disbled?"none":"all",...n?{}:{width:"100%"}},children:f.year},y))})},Q=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),X=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),oe=({setViews:r,views:a,filter:t,date:s,setDate:l})=>{const p=()=>{t||r(n=>n==="days"?"months":n==="months"?"years":"days")},i=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},u=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},d=()=>{if(a==="days")return`${V[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${P(s.getFullYear()).start} ~ ${P(s.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx(Q,{onClick:()=>u()}),e.jsx("div",{style:{cursor:"pointer"},onClick:p,children:d()}),e.jsx(X,{onClick:()=>i()})]})};function W(r){const a=new Date(r),t=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${ne[s]} ${t}`}const Z=({label:r,labelPosition:a="outside-top",required:t,optional:s,description:l,helperText:p,errorText:i,fullWidth:u,children:d})=>{const n=["sa-date-field",u?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),x=r?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:r}),s&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,v=e.jsxs(e.Fragment,{children:[p&&!i&&e.jsx("p",{className:"sa-date-field-helper",children:p}),i&&e.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return r?a==="outside-left"?e.jsxs("div",{className:`${n} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[x,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[d,v]})]}):e.jsxs("div",{className:n,children:[x,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),d,v]}):e.jsxs("div",{className:n,children:[l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),d,v]})},_="sa-calendar-styles";(r=>{if(!document.getElementById(_)){const a=document.createElement("style");a.id=_,a.textContent=r,document.head.appendChild(a)}})(H);const le=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:p,maxDate:i,placeholder:u,size:d,status:n,clearable:x,fullWidth:v=!0,label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w},f)=>{const y=w?"error":n,{ref:k,isComponentVisible:Y,setIsComponentVisible:F}=G(!1),D=m.useRef(null),[j,T]=m.useState("days"),[N,E]=m.useState(new Date),[$,L]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(E(r.from),L(r)):(E(new Date),L({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{t&&T(t)},[t]),m.useEffect(()=>{t||T("days")},[Y]),m.useEffect(()=>{s||F(!0)},[s]);const J=()=>{var b,S;if(!r)return"";if(t){if(j==="days")return`${W($.from)} ~ ${W($.to||$.from)||"-"}`;if(j==="months")return`${V[$.from.getMonth()]} ~ ${$.to?V[$.to.getMonth()]:"-"}`;if(j==="years")return`${(b=$.from)==null?void 0:b.getFullYear()} ~ ${((S=$.to)==null?void 0:S.getFullYear())||"-"}`}else return`${W($.from)} ~ ${W($.to||$.from)||"-"}`},I=()=>{if(D.current&&k.current&&s){const b=k.current.getBoundingClientRect(),S=D.current.getBoundingClientRect();window.innerWidth<b.left+S.width?D.current.style.left=`${b.left-S.width+b.width}px`:D.current.style.left=`${b.left}px`,b.top+S.height>window.innerHeight?D.current.style.top=`${b.y-(b.height+S.height-28)}px`:D.current.style.top=`${b.y+b.height}px`}};m.useEffect(()=>{D.current&&k.current&&s&&I()},[D,k,Y]),m.useEffect(()=>{const b=f==null?void 0:f.current;return b&&b.addEventListener("scroll",I),window.addEventListener("scroll",I),()=>{b&&b.removeEventListener("scroll",I),window.removeEventListener("scroll",I)}},[]);const q=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?k:null,children:[s?e.jsx(ae,{value:J(),inputMode:"none",onClick:()=>{F(!0)},onChange:()=>{},disabled:l,placeholder:u,size:d,status:y,clearable:x,onClear:()=>a(void 0)}):null,Y?e.jsxs("div",{className:`sa-calendar ${s?"":"sa-calendar-no-input"}`,ref:D,children:[e.jsx(oe,{setViews:T,views:j,filter:t,date:N,setDate:E}),e.jsx("div",{className:"sa-calendar-body",children:j==="days"?e.jsx(re,{date:N,setDate:E,setIsComponentVisible:F,dateRange:$,setDateRange:L,input:s,onChange:a,minDate:p,maxDate:i}):j==="months"?e.jsx(te,{date:N,setDate:E,filter:t,setViews:T,dateRange:$,setDateRange:L,setIsComponentVisible:F,input:s,onChange:a,minDate:p,maxDate:i}):e.jsx(se,{date:N,setDate:E,filter:t,setViews:T,dateRange:$,setDateRange:L,setIsComponentVisible:F,input:s,onChange:a,minDate:p,maxDate:i})})]}):null]});return e.jsx(Z,{label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w,fullWidth:v,children:q})}),R="sa-calendar-input-styles";(r=>{if(!document.getElementById(R)){const a=document.createElement("style");a.id=R,a.textContent=r,document.head.appendChild(a)}})(H);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},de=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:p,...i}=r,u=m.useRef(null),d=()=>{u.current&&i.onClick&&(u.current.focus(),i.onClick(""))},n=t==="disable"||i.disabled,x=!!i.value,v=l&&x&&!n,M=C=>{C.stopPropagation(),p==null||p()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:d,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:n,value:i.value,ref:u})}),v?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:M,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},ie=({date:r,setDate:a,previewDate:t,setPreviewDate:s,setIsComponentVisible:l,minDate:p,maxDate:i,input:u,onChange:d})=>{let n=new Date(t.getFullYear(),t.getMonth(),1),x=n.getDay(),v=[];const M=r.toDateString(),C=t.getMonth();for(let o=0;o<42;o++){o===0&&x===0?n.setDate(n.getDate()-7):o===0?n.setDate(n.getDate()+(o-x)):n.setDate(n.getDate()+1);let c={currentMonth:n.getMonth()===C,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:p&&n<p||i&&n>i};v.push(c)}const g=o=>{(!p||o>=p)&&(!i||o<=i)&&(a(o),d(o),s(o),u&&l(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:U.map((o,c)=>e.jsx("p",{children:o},c))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:v.map((o,c)=>{const h=o.isDisabled;return e.jsx("p",{className:`${o.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${o.selected?"sa-calendar-days-active":""}`,style:{color:h?"#ccc":void 0,pointerEvents:h?"none":void 0,cursor:h?"not-allowed":"pointer",...u?{}:{width:"100%"}},onClick:()=>{h||g(o.date)},children:o.number},c)})})]})},ce=({date:r,setDate:a,filter:t,setViews:s,onChange:l,previewDate:p,setPreviewDate:i,minDate:u,maxDate:d,input:n})=>{const x=r.getMonth(),v=r.getFullYear(),M=p.getFullYear(),C=g=>{(!u||g>=u)&&(!d||g<=d)&&(t?(l(g),a(g),i(g)):(s("days"),i(g)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((g,o)=>{const c=u&&new Date(M,o,1)<u||d&&new Date(M,o+1,0)>d;return e.jsx("p",{className:o===x&&M===v?"sa-calendar-months-active":"",style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c||C(new Date(M,o))},children:g.slice(0,3)},o)})})},A=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},he=({date:r,filter:a,setViews:t,setDate:s,onChange:l,previewDate:p,setPreviewDate:i,minDate:u,maxDate:d,input:n})=>{let x=[];const v=p.getFullYear(),{start:M,end:C}=A(v),g=r.getFullYear();for(let c=M;c<C;c++){let h=u&&new Date(c,0,1)<u||d&&new Date(c,11,31)>d;x.push({year:c,active:c===g,isDisabled:h})}const o=c=>{(!u||c>=u)&&(!d||c<=d)&&(a?(l(c),s(c),i(c)):(t("months"),i(c)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((c,h)=>e.jsx("p",{className:c.active?"sa-calendar-months-active":"",style:{color:c.isDisabled?"#ccc":void 0,pointerEvents:c.isDisabled?"none":void 0,cursor:c.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{c.isDisabled||o(new Date(c.year,0))},children:c.year},h))})},fe=({setViews:r,views:a,filter:t,previewDate:s,setPreviewDate:l})=>{const p=()=>{t||r(n=>n==="days"?"months":n==="months"?"years":"days")},i=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},u=()=>{if(a==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(a==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},d=()=>{if(a==="days")return`${V[s.getMonth()]} ${s.getFullYear()}`;if(a==="months")return`${s.getFullYear()}`;if(a==="years")return`${A(s.getFullYear()).start} ~ ${A(s.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx(Q,{onClick:()=>u()}),e.jsx("div",{style:{cursor:"pointer"},onClick:p,children:d()}),e.jsx(X,{onClick:()=>i()})]})},ee="sa-calendar-styles";(r=>{if(!document.getElementById(ee)){const a=document.createElement("style");a.id=ee,a.textContent=r,document.head.appendChild(a)}})(H);const pe=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:p,maxDate:i,placeholder:u,size:d,status:n,clearable:x,fullWidth:v=!0,label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w},f)=>{const y=w?"error":n,{ref:k,isComponentVisible:Y,setIsComponentVisible:F}=G(!1),D=m.useRef(null),[j,T]=m.useState("days"),[N,E]=m.useState(new Date),[$,L]=m.useState(new Date);m.useEffect(()=>{r?(E(r),L(r)):(E(new Date),L(new Date))},[r]),m.useEffect(()=>{t&&T(t)},[t]),m.useEffect(()=>{t||T("days")},[Y]),m.useEffect(()=>{s||F(!0)},[s]);const J=()=>r?t==="days"?W(N):t==="months"?`${V[N.getMonth()]} ${N.getFullYear()}`:t==="years"?N.getFullYear():W(N):"",I=()=>{if(D.current&&k.current&&s){const b=k.current.getBoundingClientRect(),S=D.current.getBoundingClientRect();window.innerWidth<b.left+S.width?D.current.style.left=`${b.left-S.width+b.width}px`:D.current.style.left=`${b.left}px`,b.top+S.height>window.innerHeight?D.current.style.top=`${b.y-(b.height+S.height-28)}px`:D.current.style.top=`${b.y+b.height}px`}};m.useEffect(()=>{D.current&&k.current&&s&&I()},[D,k,Y]),m.useEffect(()=>{const b=f==null?void 0:f.current;return b&&b.addEventListener("scroll",I),window.addEventListener("scroll",I),()=>{b&&b.removeEventListener("scroll",I),window.removeEventListener("scroll",I)}},[]);const q=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?k:null,children:[s?e.jsx(de,{value:J(),onClick:()=>F(!0),onChange:()=>{},placeholder:u,disabled:l,size:d,status:y,inputMode:"none",clearable:x,onClear:()=>a(void 0)}):null,Y?e.jsxs("div",{className:`sa-calendar ${s?"":"sa-calendar-no-input"}`,ref:D,children:[e.jsx(fe,{setViews:T,views:j,filter:t,previewDate:$,setPreviewDate:L,isComponentVisible:Y}),e.jsx("div",{className:"sa-calendar-body",children:j==="days"?e.jsx(ie,{date:N,setDate:E,previewDate:$,setPreviewDate:L,setIsComponentVisible:F,input:s,minDate:p,maxDate:i,onChange:a}):j==="months"?e.jsx(ce,{date:N,setDate:E,previewDate:$,setPreviewDate:L,filter:t,setViews:T,onChange:a,minDate:p,maxDate:i,input:s}):e.jsx(he,{date:N,setDate:E,previewDate:$,setPreviewDate:L,filter:t,setViews:T,onChange:a,minDate:p,maxDate:i,input:s})})]}):null]});return e.jsx(Z,{label:M,labelPosition:C,required:g,optional:o,description:c,helperText:h,errorText:w,fullWidth:v,children:q})}),ue=m.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,rangedDate:l,disabled:p,minDate:i,maxDate:u,placeholder:d,size:n,status:x,clearable:v,fullWidth:M,label:C,labelPosition:g,required:o,optional:c,description:h,helperText:w,errorText:f},y)=>{const k={onChange:a,value:r,input:s,filter:t,disabled:p,minDate:i,maxDate:u,placeholder:d,size:n,status:x,clearable:v,fullWidth:M,label:C,labelPosition:g,required:o,optional:c,description:h,helperText:w,errorText:f};return e.jsx(e.Fragment,{children:l?e.jsx(le,{...k,ref:y}):e.jsx(pe,{...k,ref:y})})});B.StarasiaDate=ue,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
|
433
|
+
|
|
434
|
+
/* === CALENDAR PANEL SIZE VARIANTS === */
|
|
435
|
+
/* sa-calendar-size-md is the default — no override needed */
|
|
436
|
+
|
|
437
|
+
.sa-calendar.sa-calendar-size-sm {
|
|
438
|
+
padding: 16px 12px;
|
|
439
|
+
gap: 8px;
|
|
440
|
+
}
|
|
441
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-name-preivew {
|
|
442
|
+
gap: 4px;
|
|
443
|
+
}
|
|
444
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-name-preivew p {
|
|
445
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
446
|
+
}
|
|
447
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-number-preivew {
|
|
448
|
+
gap: 4px;
|
|
449
|
+
}
|
|
450
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-days-number-preivew p {
|
|
451
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
452
|
+
width: 28px;
|
|
453
|
+
height: 26px;
|
|
454
|
+
}
|
|
455
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-months-preview p,
|
|
456
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-years-preview p {
|
|
457
|
+
font-size: var(--sa-font-size-sm, 12px);
|
|
458
|
+
width: 76px;
|
|
459
|
+
height: 38px;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
.sa-calendar.sa-calendar-size-lg {
|
|
463
|
+
padding: 28px 20px;
|
|
464
|
+
gap: 16px;
|
|
465
|
+
}
|
|
466
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-name-preivew {
|
|
467
|
+
gap: 10px;
|
|
468
|
+
}
|
|
469
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-name-preivew p {
|
|
470
|
+
font-size: 16px;
|
|
471
|
+
}
|
|
472
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-number-preivew {
|
|
473
|
+
gap: 10px;
|
|
474
|
+
}
|
|
475
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-days-number-preivew p {
|
|
476
|
+
font-size: 16px;
|
|
477
|
+
width: 40px;
|
|
478
|
+
height: 36px;
|
|
479
|
+
}
|
|
480
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-months-preview p,
|
|
481
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-years-preview p {
|
|
482
|
+
font-size: 16px;
|
|
483
|
+
width: 110px;
|
|
484
|
+
height: 54px;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-header-title {
|
|
488
|
+
font-size: 13px;
|
|
489
|
+
}
|
|
490
|
+
.sa-calendar.sa-calendar-size-sm .sa-calendar-nav-btn {
|
|
491
|
+
width: 24px;
|
|
492
|
+
height: 24px;
|
|
493
|
+
}
|
|
494
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-header-title {
|
|
495
|
+
font-size: 16px;
|
|
496
|
+
}
|
|
497
|
+
.sa-calendar.sa-calendar-size-lg .sa-calendar-nav-btn {
|
|
498
|
+
width: 32px;
|
|
499
|
+
height: 32px;
|
|
500
|
+
}
|
|
501
|
+
`,G=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],V=["January","February","March","April","May","June","July","August","September","October","November","December"],ae=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Z(r){const[a,t]=x.useState(r),s=x.useRef(null),l=c=>{s.current&&!s.current.contains(c.target)&&t(!1)};return x.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)}})(O);const A=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},re=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:c,...d}=r,g=x.useRef(null),h=()=>{g.current&&d.onClick&&(g.current.focus(),d.onClick(""))},n=t==="disable"||d.disabled,p=!!d.value,w=l&&p&&!n,k=N=>{N.stopPropagation(),c==null||c()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:A(a),height:A(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:g})}),w?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:A(a),height:A(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:A(a),height:A(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"})})})]})},te=({date:r,setDate:a,dateRange:t,setDateRange:s,onChange:l,minDate:c,maxDate:d,input:g})=>{var z,f,y;const[h,n]=x.useState(null);let p=new Date(r.getFullYear(),r.getMonth(),1),w=p.getDay(),k=[];const N=r.getMonth(),v=!!(t.from&&!t.to),o=v&&h?h:null;for(let u=0;u<42;u++){u===0&&w===0?p.setDate(p.getDate()-7):u===0?p.setDate(p.getDate()+(u-w)):p.setDate(p.getDate()+1);let b={currentMonth:p.getMonth()===N,date:new Date(p),month:p.getMonth(),number:p.getDate(),selected:p.toDateString()===((z=t.from)==null?void 0:z.toDateString())||p.toDateString()===(((f=t.to)==null?void 0:f.toDateString())||((y=t.from)==null?void 0:y.toDateString())),year:p.getFullYear(),isDisabled:c&&p<c||d&&p>d};k.push(b)}const i=u=>{a(u)},M=u=>{var $;let b={...t};if(b.from&&b.to)b={from:u,to:null};else{const S=(($=b.from)==null?void 0:$.getTime())||0;u.getTime()>S?b={from:b.from,to:u}:b={from:u,to:b.from}}s(b),l(b)};return e.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>n(null),children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:G.map((u,b)=>e.jsx("p",{children:u},b))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:k.map((u,b)=>{const $=t.from&&t.to&&u.date.getTime()>t.from.getTime()&&u.date.getTime()<t.to.getTime(),S=(()=>{if(!o||!t.from)return!1;const Y=u.date.getTime(),D=t.from.getTime(),E=o.getTime();return E>D?Y>D&&Y<E:Y<D&&Y>E})(),C=v&&h&&u.date.toDateString()===h.toDateString(),F=u.isDisabled,T=()=>$||S?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",L=()=>F?"var(--sa-color-gray-400, #b7b9be)":$||S?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${u.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${u.selected||C?"sa-calendar-days-active":""}`,style:{backgroundColor:T(),pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",color:L(),opacity:C&&!u.selected?.75:1,...g?{}:{width:"100%"}},onClick:()=>{F||(i(u.date),M(u.date))},onMouseEnter:()=>{F||n(u.date)},children:u.number},b)})})]})},se=({date:r,setDate:a,filter:t,setViews:s,dateRange:l,setDateRange:c,onChange:d,minDate:g,maxDate:h,input:n})=>{const p=l.from.getFullYear(),w=r.getFullYear(),k=v=>{t?(N(v),a(v)):(s("days"),a(v))},N=v=>{var i;let o={...l};if(o.from&&o.to)o={from:v,to:null};else{const M=((i=o.from)==null?void 0:i.getTime())||0;v.getTime()>M?o={from:o.from,to:v}:o={from:v,to:o.from}}c(o),d(o)};return e.jsx("div",{className:"sa-calendar-months-preview",children:V.map((v,o)=>{var z,f,y;const i=new Date(w,o).getTime()>l.from.getTime()&&new Date(w,o).getTime()<(((z=l.to)==null?void 0:z.getTime())||l.from.getTime()),M=g&&new Date(w,o)<g||h&&new Date(w,o)>h;return e.jsx("p",{className:p===w&&(o===((f=l.from)==null?void 0:f.getMonth())||o===((y=l.to)==null?void 0:y.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:i?"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)":i?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{M||k(new Date(w,o))},children:v.slice(0,3)},o)})})},P=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},oe=({date:r,filter:a,setViews:t,setDate:s,dateRange:l,setDateRange:c,onChange:d,minDate:g,maxDate:h,input:n})=>{var z;let p=[];const w=r.getFullYear(),{start:k,end:N}=P(w),v=l.from.getFullYear(),o=(z=l.to)==null?void 0:z.getFullYear();for(let f=k;f<N;f++){const y=new Date(f,0),u=(!g||y>=g)&&(!h||y<=h),b=f===v||f===o,$=y>l.from&&y<l.to;p.push({year:f,active:b&&u,highlight:$&&u,disabled:!u})}const i=f=>{a?(M(f),s(f)):(s(f),t("months"))},M=f=>{var u;let y={...l};if(y.from&&y.to)y={from:f,to:null};else{const b=((u=y.from)==null?void 0:u.getTime())||0;f.getTime()>b?y={from:y.from,to:f}:y={from:f,to:y.from}}c(y),d(y)};return e.jsx("div",{className:"sa-calendar-years-preview",children:p.map((f,y)=>e.jsx("p",{className:`${f.active?"sa-calendar-months-active":""} ${f.highlight?"sa-calendar-months-highlight":""} ${f.disabled?"sa-calendar-disabled":""}`,onClick:()=>{f.disabled||i(new Date(f.year,0))},style:{backgroundColor:f.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:f.highlight?"var(--sa-color-gray-500, #8c8f97)":f.active?"":f.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:f.disabled?"not-allowed":"pointer",pointerEvents:f.disbled?"none":"all",...n?{}:{width:"100%"}},children:f.year},y))})},Q=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),X=({...r})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),le=({setViews:r,views:a,filter:t,date:s,setDate:l})=>{const c=()=>{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))},g=()=>{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))},h=()=>{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("div",{className:"sa-calendar-header-title",onClick:c,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:g,children:e.jsx(Q,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:e.jsx(X,{})})]})]})};function W(r){const a=new Date(r),t=a.getFullYear(),s=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${ae[s]} ${t}`}const _=({label:r,labelPosition:a="outside-top",required:t,optional:s,description:l,helperText:c,errorText:d,fullWidth:g,children:h})=>{const n=["sa-date-field",g?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),p=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,w=e.jsxs(e.Fragment,{children:[c&&!d&&e.jsx("p",{className:"sa-date-field-helper",children:c}),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:[p,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[h,w]})]}):e.jsxs("div",{className:n,children:[p,l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,w]}):e.jsxs("div",{className:n,children:[l&&e.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,w]})},R="sa-calendar-styles";(r=>{if(!document.getElementById(R)){const a=document.createElement("style");a.id=R,a.textContent=r,document.head.appendChild(a)}})(O);const de=x.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:c,maxDate:d,placeholder:g,size:h,variant:n,status:p,clearable:w,fullWidth:k=!0,label:N,labelPosition:v,required:o,optional:i,description:M,helperText:z,errorText:f},y)=>{const u=f?"error":p,{ref:b,isComponentVisible:$,setIsComponentVisible:S}=Z(!1),C=x.useRef(null),[F,T]=x.useState("days"),[L,Y]=x.useState(new Date),[D,E]=x.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});x.useEffect(()=>{r?(Y(r.from),E(r)):(Y(new Date),E({from:new Date,to:new Date}))},[r]),x.useEffect(()=>{t&&T(t)},[t]),x.useEffect(()=>{t||T("days")},[$]),x.useEffect(()=>{s||S(!0)},[s]);const q=()=>{var m,I;if(!r)return"";if(t){if(F==="days")return`${W(D.from)} ~ ${W(D.to||D.from)||"-"}`;if(F==="months")return`${V[D.from.getMonth()]} ~ ${D.to?V[D.to.getMonth()]:"-"}`;if(F==="years")return`${(m=D.from)==null?void 0:m.getFullYear()} ~ ${((I=D.to)==null?void 0:I.getFullYear())||"-"}`}else return`${W(D.from)} ~ ${W(D.to||D.from)||"-"}`},j=()=>{if(C.current&&b.current&&s){const m=b.current.getBoundingClientRect(),I=C.current.getBoundingClientRect();window.innerWidth<m.left+I.width?C.current.style.left=`${m.left-I.width+m.width}px`:C.current.style.left=`${m.left}px`,m.top+I.height>window.innerHeight?C.current.style.top=`${m.y-(m.height+I.height-28)}px`:C.current.style.top=`${m.y+m.height}px`}};x.useEffect(()=>{C.current&&b.current&&s&&j()},[C,b,$]),x.useEffect(()=>{const m=y==null?void 0:y.current;return m&&m.addEventListener("scroll",j),window.addEventListener("scroll",j),()=>{m&&m.removeEventListener("scroll",j),window.removeEventListener("scroll",j)}},[]);const U=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?b:null,children:[s?e.jsx(re,{value:q(),inputMode:"none",onClick:()=>{S(!0)},onChange:()=>{},disabled:l,placeholder:g,size:h,variant:n,status:u,clearable:w,onClear:()=>a(void 0)}):null,$?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${s?"":"sa-calendar-no-input"}`,ref:C,children:[e.jsx(le,{setViews:T,views:F,filter:t,date:L,setDate:Y}),e.jsx("div",{className:"sa-calendar-body",children:F==="days"?e.jsx(te,{date:L,setDate:Y,setIsComponentVisible:S,dateRange:D,setDateRange:E,input:s,onChange:a,minDate:c,maxDate:d}):F==="months"?e.jsx(se,{date:L,setDate:Y,filter:t,setViews:T,dateRange:D,setDateRange:E,setIsComponentVisible:S,input:s,onChange:a,minDate:c,maxDate:d}):e.jsx(oe,{date:L,setDate:Y,filter:t,setViews:T,dateRange:D,setDateRange:E,setIsComponentVisible:S,input:s,onChange:a,minDate:c,maxDate:d})})]}):null]});return e.jsx(_,{label:N,labelPosition:v,required:o,optional:i,description:M,helperText:z,errorText:f,fullWidth:k,children:U})}),ee="sa-calendar-input-styles";(r=>{if(!document.getElementById(ee)){const a=document.createElement("style");a.id=ee,a.textContent=r,document.head.appendChild(a)}})(O);const H=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},ie=r=>{const{size:a="md",status:t="default",variant:s="outline",clearable:l,onClear:c,...d}=r,g=x.useRef(null),h=()=>{g.current&&d.onClick&&(g.current.focus(),d.onClick(""))},n=t==="disable"||d.disabled,p=!!d.value,w=l&&p&&!n,k=N=>{N.stopPropagation(),c==null||c()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${s} sa-calendar-input-container-${t} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(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:g})}),w?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:H(a),height:H(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:H(a),height:H(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"})})})]})},ce=({date:r,setDate:a,previewDate:t,setPreviewDate:s,setIsComponentVisible:l,minDate:c,maxDate:d,input:g,onChange:h})=>{let n=new Date(t.getFullYear(),t.getMonth(),1),p=n.getDay(),w=[];const k=r.toDateString(),N=t.getMonth();for(let o=0;o<42;o++){o===0&&p===0?n.setDate(n.getDate()-7):o===0?n.setDate(n.getDate()+(o-p)):n.setDate(n.getDate()+1);let i={currentMonth:n.getMonth()===N,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===k,year:n.getFullYear(),isDisabled:c&&n<c||d&&n>d};w.push(i)}const v=o=>{(!c||o>=c)&&(!d||o<=d)&&(a(o),h(o),s(o),g&&l(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:G.map((o,i)=>e.jsx("p",{children:o},i))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:w.map((o,i)=>{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",...g?{}:{width:"100%"}},onClick:()=>{M||v(o.date)},children:o.number},i)})})]})},he=({date:r,setDate:a,filter:t,setViews:s,onChange:l,previewDate:c,setPreviewDate:d,minDate:g,maxDate:h,input:n})=>{const p=r.getMonth(),w=r.getFullYear(),k=c.getFullYear(),N=v=>{(!g||v>=g)&&(!h||v<=h)&&(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 i=g&&new Date(k,o,1)<g||h&&new Date(k,o+1,0)>h;return e.jsx("p",{className:o===p&&k===w?"sa-calendar-months-active":"",style:{color:i?"#ccc":void 0,pointerEvents:i?"none":void 0,cursor:i?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{i||N(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}},pe=({date:r,filter:a,setViews:t,setDate:s,onChange:l,previewDate:c,setPreviewDate:d,minDate:g,maxDate:h,input:n})=>{let p=[];const w=c.getFullYear(),{start:k,end:N}=J(w),v=r.getFullYear();for(let i=k;i<N;i++){let M=g&&new Date(i,0,1)<g||h&&new Date(i,11,31)>h;p.push({year:i,active:i===v,isDisabled:M})}const o=i=>{(!g||i>=g)&&(!h||i<=h)&&(a?(l(i),s(i),d(i)):(t("months"),d(i)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:p.map((i,M)=>e.jsx("p",{className:i.active?"sa-calendar-months-active":"",style:{color:i.isDisabled?"#ccc":void 0,pointerEvents:i.isDisabled?"none":void 0,cursor:i.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{i.isDisabled||o(new Date(i.year,0))},children:i.year},M))})},fe=({setViews:r,views:a,filter:t,previewDate:s,setPreviewDate:l})=>{const c=()=>{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))},g=()=>{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))},h=()=>{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("div",{className:"sa-calendar-header-title",onClick:c,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:g,children:e.jsx(Q,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:e.jsx(X,{})})]})]})},ne="sa-calendar-styles";(r=>{if(!document.getElementById(ne)){const a=document.createElement("style");a.id=ne,a.textContent=r,document.head.appendChild(a)}})(O);const ue=x.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,disabled:l,minDate:c,maxDate:d,placeholder:g,size:h,variant:n,status:p,clearable:w,fullWidth:k=!0,label:N,labelPosition:v,required:o,optional:i,description:M,helperText:z,errorText:f},y)=>{const u=f?"error":p,{ref:b,isComponentVisible:$,setIsComponentVisible:S}=Z(!1),C=x.useRef(null),[F,T]=x.useState("days"),[L,Y]=x.useState(new Date),[D,E]=x.useState(new Date);x.useEffect(()=>{r?(Y(r),E(r)):(Y(new Date),E(new Date))},[r]),x.useEffect(()=>{t&&T(t)},[t]),x.useEffect(()=>{t||T("days")},[$]),x.useEffect(()=>{s||S(!0)},[s]);const q=()=>r?t==="days"?W(L):t==="months"?`${V[L.getMonth()]} ${L.getFullYear()}`:t==="years"?L.getFullYear():W(L):"",j=()=>{if(C.current&&b.current&&s){const m=b.current.getBoundingClientRect(),I=C.current.getBoundingClientRect();window.innerWidth<m.left+I.width?C.current.style.left=`${m.left-I.width+m.width}px`:C.current.style.left=`${m.left}px`,m.top+I.height>window.innerHeight?C.current.style.top=`${m.y-(m.height+I.height-28)}px`:C.current.style.top=`${m.y+m.height}px`}};x.useEffect(()=>{C.current&&b.current&&s&&j()},[C,b,$]),x.useEffect(()=>{const m=y==null?void 0:y.current;return m&&m.addEventListener("scroll",j),window.addEventListener("scroll",j),()=>{m&&m.removeEventListener("scroll",j),window.removeEventListener("scroll",j)}},[]);const U=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:s?"auto":"100%"},ref:s?b:null,children:[s?e.jsx(ie,{value:q(),onClick:()=>S(!0),onChange:()=>{},placeholder:g,disabled:l,size:h,variant:n,status:u,inputMode:"none",clearable:w,onClear:()=>a(void 0)}):null,$?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${s?"":"sa-calendar-no-input"}`,ref:C,children:[e.jsx(fe,{setViews:T,views:F,filter:t,previewDate:D,setPreviewDate:E,isComponentVisible:$}),e.jsx("div",{className:"sa-calendar-body",children:F==="days"?e.jsx(ce,{date:L,setDate:Y,previewDate:D,setPreviewDate:E,setIsComponentVisible:S,input:s,minDate:c,maxDate:d,onChange:a}):F==="months"?e.jsx(he,{date:L,setDate:Y,previewDate:D,setPreviewDate:E,filter:t,setViews:T,onChange:a,minDate:c,maxDate:d,input:s}):e.jsx(pe,{date:L,setDate:Y,previewDate:D,setPreviewDate:E,filter:t,setViews:T,onChange:a,minDate:c,maxDate:d,input:s})})]}):null]});return e.jsx(_,{label:N,labelPosition:v,required:o,optional:i,description:M,helperText:z,errorText:f,fullWidth:k,children:U})}),ge=x.forwardRef(({value:r,onChange:a,filter:t,input:s=!0,rangedDate:l,disabled:c,minDate:d,maxDate:g,placeholder:h,size:n,variant:p,status:w,clearable:k,fullWidth:N,label:v,labelPosition:o,required:i,optional:M,description:z,helperText:f,errorText:y},u)=>{const b={onChange:a,value:r,input:s,filter:t,disabled:c,minDate:d,maxDate:g,placeholder:h,size:n,variant:p,status:w,clearable:k,fullWidth:N,label:v,labelPosition:o,required:i,optional:M,description:z,helperText:f,errorText:y};return e.jsx(e.Fragment,{children:l?e.jsx(de,{...b,ref:u}):e.jsx(ue,{...b,ref:u})})});B.StarasiaDate=ge,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interfaces.d.ts
CHANGED