@starasia/date 5.1.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/date.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(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");
1
+ (function(V,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):(V=typeof globalThis<"u"?globalThis:V||self,n(V.Date={},V.jsxRuntime,V.React))})(this,function(V,n,x){"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-md, 0.5rem);
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);
@@ -233,8 +233,28 @@
233
233
  }
234
234
 
235
235
  .sa-calendar-days-active {
236
- background: var(--sa-date-brand-secondary);
236
+ background: var(--sa-date-brand);
237
+ color: #fff;
238
+ }
239
+
240
+ .sa-calendar-days-today {
241
+ position: relative;
237
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;
238
258
  }
239
259
 
240
260
  /* MONTH STYLING */
@@ -431,6 +451,13 @@
431
451
  outline-offset: 1px;
432
452
  }
433
453
 
454
+ /* === NO PADDING OVERRIDE === */
455
+ .sa-calendar.sa-calendar-no-padding,
456
+ .sa-calendar.sa-calendar-size-sm.sa-calendar-no-padding,
457
+ .sa-calendar.sa-calendar-size-lg.sa-calendar-no-padding {
458
+ padding: 0;
459
+ }
460
+
434
461
  /* === CALENDAR PANEL SIZE VARIANTS === */
435
462
  /* sa-calendar-size-md is the default — no override needed */
436
463
 
@@ -452,6 +479,10 @@
452
479
  width: 28px;
453
480
  height: 26px;
454
481
  }
482
+ .sa-calendar.sa-calendar-size-sm .sa-calendar-days-today::before {
483
+ width: 26px;
484
+ height: 26px;
485
+ }
455
486
  .sa-calendar.sa-calendar-size-sm .sa-calendar-months-preview p,
456
487
  .sa-calendar.sa-calendar-size-sm .sa-calendar-years-preview p {
457
488
  font-size: var(--sa-font-size-sm, 12px);
@@ -477,6 +508,10 @@
477
508
  width: 40px;
478
509
  height: 36px;
479
510
  }
511
+ .sa-calendar.sa-calendar-size-lg .sa-calendar-days-today::before {
512
+ width: 36px;
513
+ height: 36px;
514
+ }
480
515
  .sa-calendar.sa-calendar-size-lg .sa-calendar-months-preview p,
481
516
  .sa-calendar.sa-calendar-size-lg .sa-calendar-years-preview p {
482
517
  font-size: 16px;
@@ -498,4 +533,4 @@
498
533
  width: 32px;
499
534
  height: 32px;
500
535
  }
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"})});
536
+ `,Z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A=["January","February","March","April","May","June","July","August","September","October","November","December"],rn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function K(r){const[a,t]=x.useState(r),o=x.useRef(null),l=c=>{o.current&&!o.current.contains(c.target)&&t(!1)};return x.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:t}}const Q="sa-calendar-input-styles";(r=>{if(!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,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},tn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,p=x.useRef(null),h=()=>{p.current&&d.onClick&&(p.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:h,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:p})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,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"})})})]})},sn=({date:r,setDate:a,dateRange:t,setDateRange:o,onChange:l,minDate:c,maxDate:d,input:p})=>{var u,m,Y;const[h,e]=x.useState(null);let i=new Date(r.getFullYear(),r.getMonth(),1),y=i.getDay(),D=[];const N=r.getMonth(),v=new Date().toDateString(),f=!!(t.from&&!t.to),s=f&&h?h:null;for(let g=0;g<42;g++){g===0&&y===0?i.setDate(i.getDate()-7):g===0?i.setDate(i.getDate()+(g-y)):i.setDate(i.getDate()+1);let b={currentMonth:i.getMonth()===N,date:new Date(i),month:i.getMonth(),number:i.getDate(),selected:i.toDateString()===((u=t.from)==null?void 0:u.toDateString())||i.toDateString()===(((m=t.to)==null?void 0:m.toDateString())||((Y=t.from)==null?void 0:Y.toDateString())),isToday:i.toDateString()===v,year:i.getFullYear(),isDisabled:c&&i<c||d&&i>d};D.push(b)}const k=g=>{a(g)},$=g=>{var L;let b={...t};if(b.from&&b.to)b={from:g,to:null};else{const T=((L=b.from)==null?void 0:L.getTime())||0;g.getTime()>T?b={from:b.from,to:g}:b={from:g,to:b.from}}o(b),l(b)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>e(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((g,b)=>n.jsx("p",{children:g},b))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((g,b)=>{const L=t.from&&t.to&&g.date.getTime()>t.from.getTime()&&g.date.getTime()<t.to.getTime(),T=(()=>{if(!s||!t.from)return!1;const z=g.date.getTime(),C=t.from.getTime(),F=s.getTime();return F>C?z>C&&z<F:z<C&&z>F})(),M=f&&h&&g.date.toDateString()===h.toDateString(),E=g.isDisabled,I=()=>L||T?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",S=()=>E?"var(--sa-color-gray-400, #b7b9be)":L||T?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${g.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${g.selected||M?"sa-calendar-days-active":""} ${g.isToday&&!g.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:I(),pointerEvents:E?"none":void 0,cursor:E?"not-allowed":"pointer",color:S(),opacity:M&&!g.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{E||(k(g.date),$(g.date))},onMouseEnter:()=>{E||e(g.date)},children:g.number},b)})})]})},on=({date:r,setDate:a,filter:t,setViews:o,dateRange:l,setDateRange:c,onChange:d,minDate:p,maxDate:h,input:e})=>{const i=l.from.getFullYear(),y=r.getFullYear(),D=v=>{t?(N(v),a(v)):(o("days"),a(v))},N=v=>{var s;let f={...l};if(f.from&&f.to)f={from:v,to:null};else{const k=((s=f.from)==null?void 0:s.getTime())||0;v.getTime()>k?f={from:f.from,to:v}:f={from:v,to:f.from}}c(f),d(f)};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{var $,u,m;const s=new Date(y,f).getTime()>l.from.getTime()&&new Date(y,f).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=p&&new Date(y,f)<p||h&&new Date(y,f)>h;return n.jsx("p",{className:i===y&&(f===((u=l.from)==null?void 0:u.getMonth())||f===((m=l.to)==null?void 0:m.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||D(new Date(y,f))},children:v.slice(0,3)},f)})})},J=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},ln=({date:r,filter:a,setViews:t,setDate:o,dateRange:l,setDateRange:c,onChange:d,minDate:p,maxDate:h,input:e})=>{var $;let i=[];const y=r.getFullYear(),{start:D,end:N}=J(y),v=l.from.getFullYear(),f=($=l.to)==null?void 0:$.getFullYear();for(let u=D;u<N;u++){const m=new Date(u,0),Y=(!p||m>=p)&&(!h||m<=h),g=u===v||u===f,b=m>l.from&&m<l.to;i.push({year:u,active:g&&Y,highlight:b&&Y,disabled:!Y})}const s=u=>{a?(k(u),o(u)):(o(u),t("months"))},k=u=>{var Y;let m={...l};if(m.from&&m.to)m={from:u,to:null};else{const g=((Y=m.from)==null?void 0:Y.getTime())||0;u.getTime()>g?m={from:m.from,to:u}:m={from:u,to:m.from}}c(m),d(m)};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.map((u,m)=>n.jsx("p",{className:`${u.active?"sa-calendar-months-active":""} ${u.highlight?"sa-calendar-months-highlight":""} ${u.disabled?"sa-calendar-disabled":""}`,onClick:()=>{u.disabled||s(new Date(u.year,0))},style:{backgroundColor:u.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:u.highlight?"var(--sa-color-gray-500, #8c8f97)":u.active?"":u.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:u.disabled?"not-allowed":"pointer",pointerEvents:u.disbled?"none":"all",...e?{}:{width:"100%"}},children:u.year},m))})},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:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),_=({...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"})}),dn=({setViews:r,views:a,filter:t,date:o,setDate:l})=>{const c=()=>{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))},p=()=>{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))},h=()=>{if(a==="days")return`${A[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:c,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})};function W(r){const a=new Date(r),t=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${rn[o]} ${t}`}const R=({label:r,labelPosition:a="outside-top",required:t,optional:o,description:l,helperText:c,errorText:d,fullWidth:p,children:h})=>{const e=["sa-date-field",p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),i=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:[c&&!d&&n.jsx("p",{className:"sa-date-field-helper",children:c}),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:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[h,y]})]}):n.jsxs("div",{className:e,children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,y]}):n.jsxs("div",{className:e,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,y]})},nn="sa-calendar-styles";(r=>{if(!document.getElementById(nn)){const a=document.createElement("style");a.id=nn,a.textContent=r,document.head.appendChild(a)}})(P);const cn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:p,size:h,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});x.useEffect(()=>{r?(z(r.from),F(r)):(z(new Date),F({from:new Date,to:new Date}))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var w,j;if(!r)return"";if(t){if(E==="days")return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`;if(E==="months")return`${A[C.from.getMonth()]} ~ ${C.to?A[C.to.getMonth()]:"-"}`;if(E==="years")return`${(w=C.from)==null?void 0:w.getFullYear()} ~ ${((j=C.to)==null?void 0:j.getFullYear())||"-"}`}else return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`},B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(tn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:p,size:h,variant:e,status:g,clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,ref:M,children:[n.jsx(dn,{setViews:I,views:E,filter:t,date:S,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(sn,{date:S,setDate:z,setIsComponentVisible:T,dateRange:C,setDateRange:F,input:o,onChange:a,minDate:c,maxDate:d}):E==="months"?n.jsx(on,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d}):n.jsx(ln,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),en="sa-calendar-input-styles";(r=>{if(!document.getElementById(en)){const a=document.createElement("style");a.id=en,a.textContent=r,document.head.appendChild(a)}})(P);const H=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},hn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,p=x.useRef(null),h=()=>{p.current&&d.onClick&&(p.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(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:p})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(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:H(a),height:H(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"})})})]})},pn=({date:r,setDate:a,previewDate:t,setPreviewDate:o,setIsComponentVisible:l,minDate:c,maxDate:d,input:p,onChange:h})=>{let e=new Date(t.getFullYear(),t.getMonth(),1),i=e.getDay(),y=[];const D=r.toDateString(),N=new Date().toDateString(),v=t.getMonth();for(let s=0;s<42;s++){s===0&&i===0?e.setDate(e.getDate()-7):s===0?e.setDate(e.getDate()+(s-i)):e.setDate(e.getDate()+1);let k={currentMonth:e.getMonth()===v,date:new Date(e),month:e.getMonth(),number:e.getDate(),selected:e.toDateString()===D,isToday:e.toDateString()===N,year:e.getFullYear(),isDisabled:c&&e<c||d&&e>d};y.push(k)}const f=s=>{(!c||s>=c)&&(!d||s<=d)&&(a(s),h(s),o(s),p&&l(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.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",...p?{}:{width:"100%"}},onClick:()=>{$||f(s.date)},children:s.number},k)})})]})},fn=({date:r,setDate:a,filter:t,setViews:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:p,maxDate:h,input:e})=>{const i=r.getMonth(),y=r.getFullYear(),D=c.getFullYear(),N=v=>{(!p||v>=p)&&(!h||v<=h)&&(t?(l(v),a(v),d(v)):(o("days"),d(v)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{const s=p&&new Date(D,f,1)<p||h&&new Date(D,f+1,0)>h;return n.jsx("p",{className:f===i&&D===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(D,f))},children:v.slice(0,3)},f)})})},q=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},un=({date:r,filter:a,setViews:t,setDate:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:p,maxDate:h,input:e})=>{let i=[];const y=c.getFullYear(),{start:D,end:N}=q(y),v=r.getFullYear();for(let s=D;s<N;s++){let k=p&&new Date(s,0,1)<p||h&&new Date(s,11,31)>h;i.push({year:s,active:s===v,isDisabled:k})}const f=s=>{(!p||s>=p)&&(!h||s<=h)&&(a?(l(s),o(s),d(s)):(t("months"),d(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.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||f(new Date(s.year,0))},children:s.year},k))})},gn=({setViews:r,views:a,filter:t,previewDate:o,setPreviewDate:l})=>{const c=()=>{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))},p=()=>{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))},h=()=>{if(a==="days")return`${A[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:c,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})},an="sa-calendar-styles";(r=>{if(!document.getElementById(an)){const a=document.createElement("style");a.id=an,a.textContent=r,document.head.appendChild(a)}})(P);const bn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:p,size:h,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState(new Date);x.useEffect(()=>{r?(z(r),F(r)):(z(new Date),F(new Date))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>r?t==="days"?W(S):t==="months"?`${A[S.getMonth()]} ${S.getFullYear()}`:t==="years"?S.getFullYear():W(S):"",B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(hn,{value:G(),onClick:()=>T(!0),onChange:()=>{},placeholder:p,disabled:l,size:h,variant:e,status:g,inputMode:"none",clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,ref:M,children:[n.jsx(gn,{setViews:I,views:E,filter:t,previewDate:C,setPreviewDate:F,isComponentVisible:L}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(pn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,setIsComponentVisible:T,input:o,minDate:c,maxDate:d,onChange:a}):E==="months"?n.jsx(fn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o}):n.jsx(un,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),vn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,rangedDate:l,disabled:c,minDate:d,maxDate:p,placeholder:h,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y},g)=>{const b={onChange:a,value:r,input:o,filter:t,disabled:c,minDate:d,maxDate:p,placeholder:h,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y};return n.jsx(n.Fragment,{children:l?n.jsx(cn,{...b,ref:g}):n.jsx(bn,{...b,ref:g})})});V.StarasiaDate=vn,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
@@ -15,6 +15,7 @@ export interface IDateProps {
15
15
  status?: "error" | "warning";
16
16
  clearable?: boolean;
17
17
  fullWidth?: boolean;
18
+ withPadding?: boolean;
18
19
  label?: React.ReactNode;
19
20
  labelPosition?: DateLabelPosition;
20
21
  required?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",