@telsho/react-google-flight-datepicker 1.1.3 → 1.1.5
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/index.js +1393 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1367 -1
- package/dist/index.mjs.map +1 -1
- package/dist/styles.scss +779 -0
- package/package.json +45 -39
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,1368 @@
|
|
|
1
|
-
var kt=Object.defineProperty,Jt=Object.defineProperties;var vt=Object.getOwnPropertyDescriptors;var me=Object.getOwnPropertySymbols;var Pe=Object.prototype.hasOwnProperty,Ke=Object.prototype.propertyIsEnumerable;var Se=(e,t,o)=>t in e?kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,O=(e,t)=>{for(var o in t||(t={}))Pe.call(t,o)&&Se(e,o,t[o]);if(me)for(var o of me(t))Ke.call(t,o)&&Se(e,o,t[o]);return e},U=(e,t)=>Jt(e,vt(t));var fe=(e,t)=>{var o={};for(var a in e)Pe.call(e,a)&&t.indexOf(a)<0&&(o[a]=e[a]);if(e!=null&&me)for(var a of me(e))t.indexOf(a)<0&&Ke.call(e,a)&&(o[a]=e[a]);return o};import{useState as _,useRef as ze,useEffect as ie,useLayoutEffect as fo,useCallback as Le}from"react";import W from"dayjs";import yo from"classnames";import Go from"dayjs/plugin/localeData";import wt from"dayjs";function ye(e,t,o){let a=[],n=new Date(e,t,1),d=new Date(e,t+1,0).getDate(),A=1,g=n.getDay()===0?1:7-n.getDay()+1;for(o==="sunday"&&(g=7-n.getDay());A<=d;)a.push({start:A,days:g-A+1}),A=g+1,g+=7,g=A===1&&g===8?1:g,g>d&&(g=d);return{totalWeek:a,totalDay:d}}function Ge(e,t){let o=[...Array(7)].map((a,n)=>wt().day(n).format(t==="dd"?"dd":t==="ddd"?"ddd":"dddd"));if(e==="sunday"){let a=o.pop();a&&o.unshift(a)}return o}function $e(e,t){let o;return function(...n){let l=()=>{o=null,e.apply(this,n)};o&&clearTimeout(o),o=setTimeout(l,t)}}import{createContext as se,useContext as Xe,useState as Nt,useEffect as Wt}from"react";import Je from"dayjs";import{jsx as Ie}from"react/jsx-runtime";var _e=se(null),qe=se(null),et=se(null),tt=se(null),Vt=se(null),v=()=>{let e=Xe(_e);if(!e)throw new Error("useDateState must be used within DatePickerProvider");return e},k=()=>{let e=Xe(qe);if(!e)throw new Error("useDatePickerConfig must be used within DatePickerProvider");return e},ne=()=>{let e=Xe(et);if(!e)throw new Error("useUIState must be used within DatePickerProvider");return e},w=()=>{let e=Xe(tt);if(!e)throw new Error("useDisplayCustomization must be used within DatePickerProvider");return e};var Tt=async e=>{if(e==="en")return!0;try{return await import(`dayjs/locale/${e}.js`),!0}catch(t){return console.error(`Failed to load locale ${e}:`,t),!1}},ot=({children:e,dateState:t,config:o,uiState:a,display:n,locale:l="en"})=>{let[d,A]=Nt({currentLocale:"en",isLocaleReady:l==="en"});return Wt(()=>{l!=="en"?(A(g=>U(O({},g),{isLocaleReady:!1})),Tt(l).then(g=>{g?(Je.locale(l),A({currentLocale:l,isLocaleReady:!0})):(Je.locale("en"),A({currentLocale:"en",isLocaleReady:!0}))})):(Je.locale("en"),A({currentLocale:"en",isLocaleReady:!0}))},[l]),d.isLocaleReady?Ie(Vt.Provider,{value:d,children:Ie(_e.Provider,{value:t,children:Ie(qe.Provider,{value:o,children:Ie(et.Provider,{value:a,children:Ie(tt.Provider,{value:n,children:e})})})})}):null};import"react";import{jsx as ct}from"react/jsx-runtime";var Yt=e=>ct("svg",U(O({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},e),{children:ct("path",{d:"M9 11H7v2h2v-2zm4 0h-2v2h2v-2zm4 0h-2v2h2v-2zm2-7h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20a2 2 0 002 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z"})})),De=Yt;import{useEffect as zt,useState as ve}from"react";import Lt from"classnames";import we from"dayjs";import"react";import{jsx as at}from"react/jsx-runtime";var jt=e=>at("svg",U(O({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},e),{children:at("path",{d:"M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z"})})),he=jt;import"react";import{jsx as gt}from"react/jsx-runtime";var Mt=e=>gt("svg",U(O({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},e),{children:gt("path",{d:"M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z"})})),Be=Mt;import{jsx as ce,jsxs as it}from"react/jsx-runtime";var Ne=({type:e,showIcon:t=!1,tabIndex:o=0,nonFocusable:a=!1})=>{let[n,l]=ve(null),[d,A]=ve(!1),[g,s]=ve(!1),{fromDate:r,toDate:p,inputFocus:G,handleClickDateInput:B,handleChangeDate:x}=v(),{isSingle:D,minDate:y,maxDate:X,dateFormat:c}=k(),{startDatePlaceholder:m,endDatePlaceholder:C}=w(),f=e==="from"?r:p,V=e==="from"?m:C;zt(()=>{if(f){let Z=f.clone().locale(we.locale()).format("ddd, DD MMM");c&&(Z=f.format(c)),l(Z);let Q=y?we(y):null,H=X?we(X):null;Q!=null&&Q.add(1,"day").isAfter(f,"date")||e==="to"&&r&&f.isBefore(r.add(1,"day"),"date")?A(!0):A(!1),H!=null&&H.subtract(1,"day").isBefore(f,"date")?s(!0):s(!1)}else l(null)},[f,r,y,X,c,e]);let N=J=>{J.stopPropagation(),f&&x(f.subtract(1,"day"),e)},S=J=>{J.stopPropagation(),f&&x(f.add(1,"day"),e)},u=()=>{B(e)};return it("div",{className:Lt("date",{"is-focus":G===e&&!D,"is-single":D}),role:"button",tabIndex:a?-1:o,onClick:u,id:`${e}-date-input-button`,children:[t&&ce(De,{className:"icon-calendar",viewBox:"0 0 24 24"}),ce("div",{className:"selected-date",children:n!=null?n:ce("div",{className:"date-placeholder",children:V})}),n&&it("div",{className:"change-date-group",children:[ce("button",{type:"button",className:"btn-outline change-date-button",onClick:N,tabIndex:a?-1:0,disabled:d,children:ce(he,{viewBox:"0 0 24 24",className:"icon-arrow"})}),ce("button",{type:"button",className:"btn-outline change-date-button",onClick:S,tabIndex:a?-1:0,disabled:g,children:ce(Be,{viewBox:"0 0 24 24",className:"icon-arrow"})})]})]})};import{jsx as He,jsxs as lt}from"react/jsx-runtime";var Fe=({showIcon:e=!1,nonFocusable:t=!1})=>{let{isSingle:o}=k(),{dateInputSeperator:a}=w();return lt("div",{className:"date-picker-input",children:[e&&He(De,{className:"icon-calendar mobile",viewBox:"0 0 24 24"}),lt("div",{className:"date-picker-date-group",children:[He(Ne,{type:"from",tabIndex:t?-1:0,showIcon:!0,nonFocusable:t}),!o&&a&&He("div",{className:"date-input-separator",children:a}),!o&&He(Ne,{type:"to",tabIndex:t?-1:0,showIcon:!1,nonFocusable:t})]})]})};import{createPortal as Pt}from"react-dom";import{useEffect as Et,useState as St}from"react";var rt=()=>{let[e,t]=St(!1);return Et(()=>{t(!0)},[]),e};import{jsx as $t}from"react/jsx-runtime";var Kt=({children:e=null,isMobile:t=!1})=>rt()?t?Pt($t("div",{children:e}),document.body):e:null,nt=Kt;import{useEffect as po,useState as ft,useRef as xo}from"react";import mo from"classnames";import"react";import{jsx as dt}from"react/jsx-runtime";var _t=e=>dt("svg",U(O({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 492 492"},e),{children:dt("path",{d:"M464.3 207.4l.8.2H136l103.5-103.7c5-5.1 7.8-12 7.8-19.2 0-7.2-2.7-14-7.8-19l-16.1-16.2c-5-5-11.8-7.8-19-7.8-7.2 0-14 2.8-19 7.8L7.8 227C2.8 232 0 238.8 0 246c0 7.3 2.8 14 7.8 19.2l177.5 177.4c5 5 11.8 7.8 19 7.8 7.2 0 14-2.8 19-7.8l16-16.1a26.6 26.6 0 000-37.7L134.8 284.4h330a27.9 27.9 0 0027.3-27.6V234a27.3 27.3 0 00-27.7-26.6z"})})),It=_t;import no,{useEffect as bt,useState as Io,useRef as so}from"react";import z from"dayjs";import{VariableSizeList as Co}from"react-window";import Ao from"react-virtualized-auto-sizer";import{forwardRef as go}from"react";import io from"classnames";import lo from"dayjs";import{forwardRef as oo}from"react";import co from"classnames";import ao from"dayjs";import{forwardRef as qt,useCallback as st,useEffect as eo,useRef as to}from"react";import Ct from"classnames";import{jsx as We,jsxs as At}from"react/jsx-runtime";var Ve=qt(({dateIndex:e,dateValue:t,isEndDay:o,selected:a,hovered:n,disabled:l,totalDay:d,highlight:A,handleHoverDay:g,subText:s},r)=>{let p=to(null),{onSelectDate:G,onHoverDate:B}=v(),x=c=>{c.stopPropagation(),c.preventDefault(),!l&&G(t)},D=()=>{l||(B(t),g(t))},y=st(()=>{if(!r||typeof r=="function")return;let c=r.current;c&&p.current&&(c.style.left=`${p.current.offsetLeft-c.offsetWidth+135}px`,c.style.top=`${p.current.offsetTop-c.offsetHeight-15}px`,c.style.visibility="visible")},[r]),X=st(()=>{if(!r||typeof r=="function")return;let c=r.current;c&&(c.style.visibility="hidden")},[r]);return eo(()=>{let c=p.current;return c&&(c.addEventListener("mouseover",y),c.addEventListener("mouseleave",X)),()=>{c&&(c.removeEventListener("mouseover",y),c.removeEventListener("mouseleave",X))}},[y,X]),At("div",{className:Ct("day",{selected:a,hovered:n,disabled:l,highlight:A,end:o,"has-subtext":!!s}),onClick:x,onMouseEnter:D,role:"button",tabIndex:-1,"data-day-index":e,"data-date-value":t.valueOf(),ref:p,children:[n&&!(o&&e===d)&&!(e===1&&a&&!o)&&We("div",{className:Ct("background-day",{"first-day":e===1,"last-day":e===d})}),At("div",{className:"day-content",children:[We("div",{className:"text-day",children:e}),s&&We("div",{className:"sub-text",style:{position:"relative",zIndex:3,color:a&&!n?"#fff":"#666"},children:s})]})]})});Ve.displayName="Day";import{jsx as ut}from"react/jsx-runtime";var Te=oo(({isFirst:e,week:t,month:o,year:a,totalDay:n,weekIndex:l,handleHoverDay:d},A)=>{let{fromDate:g,toDate:s,hoverDate:r}=v(),{minDate:p,maxDate:G,isSingle:B,highlightToday:x}=k(),{subTextDict:D}=w(),y=()=>Array.from({length:t.days},(X,c)=>{var Z;let m=c+t.start,C=ao(`${a}-${o+1}-${m}`),f=p&&C.isBefore(p,"date")||G&&C.isAfter(G,"date"),V=g&&C.isSame(g,"date")||s&&C.isSame(s,"date"),N=!1,S=x&&C.isSame(new Date,"date");g&&!g.isSame(s,"date")&&!B&&(s&&!g.isAfter(C,"date")&&!s.isBefore(C,"date")&&(N=!0),!s&&!C.isBefore(g,"date")&&!(r&&r.isBefore(C,"date"))&&g.isBefore(r,"date")&&(N=!0));let u=s&&C.isSame(s,"date")||!s&&r&&C.isSame(r,"date"),J=D?(Z=D[C.format("YYYY-MM-DD")])!=null?Z:"\xA0":"";return ut(Ve,{dateIndex:m,dateValue:C,selected:V,hovered:N,highlight:S,disabled:f,isEndDay:u,totalDay:n,handleHoverDay:d,subText:J,ref:A},c)});return ut("div",{className:co("week",{first:e}),children:y()})});Te.displayName="Week";import{jsx as Ce,jsxs as ro}from"react/jsx-runtime";var Ae=go(({month:e,year:t,hidden:o=!1,isAnimating:a=!1,handleHoverDay:n,className:l},d)=>{let{startWeekDay:A,weekDayFormat:g,monthFormat:s,singleCalendar:r}=k(),p=()=>{let{totalWeek:x,totalDay:D}=ye(t,e,A);return x.map(y=>{let X=`${t}-${e}-${y.start}`;return Ce(Te,{week:y,month:e,year:t,isFirst:y===x[0],totalDay:D,weekIndex:x.indexOf(y),handleHoverDay:n,ref:d},X)})},G=()=>Ge(A,g).map(D=>Ce("div",{className:"weekday",children:D},`weekday-${D.toLowerCase()}`)),B=()=>{let x=lo(`${t}-${e+1}-1`);return s?x.format(s):x.format("MMMM - YYYY")};return ro("div",{className:io("month-calendar",{isAnimating:a,hidden:o,single:r},l),"data-month-index":e+1,children:[Ce("div",{className:"month-name",children:B()}),Ce("div",{className:"weekdays",children:G()}),Ce("div",{className:"week-container",children:p()})]})});Ae.displayName="MonthCalendar";import{jsx as ae,jsxs as uo}from"react/jsx-runtime";var pt=()=>{let[e,t]=Io(2400),o=so(null),{fromDate:a}=v(),{startWeekDay:n,minDate:l,maxDate:d,weekDayFormat:A}=k(),{complsOpen:g}=ne(),{tooltip:s,subTextDict:r}=w(),p=l?z(l).year():1900,G=l?z(l).month():0;bt(()=>{if(d){let c=l?z(l):z("1900-01-01");t(z(d).diff(c,"month")+1)}},[d,l]),bt(()=>{if(o.current&&g){let c=a?z(a):z(),m=c.diff(z("1900-01-01"),"month");l&&(m=c.diff(z(l),"month")),o.current.scrollToItem(m+1,"smart")}},[g,a,l]);let B=c=>{let m=c+G,C=p+Math.floor(m/12),f=m%12;return{year:C,month:f}},x=no.memo(({index:c,style:m})=>{let{year:C,month:f}=B(c);return ae("div",{style:m,children:ae(Ae,{month:f,year:C,hidden:!1,isAnimating:!1,handleHoverDay:()=>{}})})});x.displayName="CalendarRow";let D=c=>{let{year:m,month:C}=B(c),{totalWeek:f}=ye(m,C,n||"monday");return f.length*48+34},y=()=>ae(Ao,{children:({height:c,width:m})=>ae(Co,{ref:o,width:m,height:c-36,itemCount:e,itemSize:D,children:x})});return ae("div",{className:"calendar-wrapper",children:uo("div",{className:"calendar-content",children:[ae("div",{className:"weekdays mobile",children:Ge(n||"monday",A).map((m,C)=>ae("div",{className:"weekday",children:m},C))}),y()]})})};import{useEffect as be,useState as L,useRef as xt,useCallback as Qe,useMemo as Ye}from"react";import ue from"classnames";import Ze from"dayjs";import{jsx as ge,jsxs as je}from"react/jsx-runtime";var bo=()=>{let[e,t]=L(!1);return be(()=>{t(!0)},[]),e},mt=({dateChanged:e=null})=>{let t=bo(),o=xt(null),a=xt(null),[n,l]=L(0),[d,A]=L([]),[g,s]=L(null),[r,p]=L(!1),[G,B]=L(!1),[x,D]=L(0),[y,X]=L(null),[c,m]=L(!1),{fromDate:C}=v(),{minDate:f,maxDate:V,singleCalendar:N}=k(),{complsOpen:S}=ne(),{tooltip:u}=w(),J=Qe(I=>[I.subtract(1,"month"),I,I.add(1,"month"),I.add(2,"month")],[]);be(()=>{if(!t||!o.current)return;let I=()=>{let R=o.current.offsetWidth,F=window.getComputedStyle(o.current),Y=N?R+parseInt(F.marginLeft)-8:R/2;D(Y)};I();let b=new ResizeObserver(I);return b.observe(o.current),()=>b.disconnect()},[t,N]),be(()=>{s(C!=null?C:Ze())},[S,C]),be(()=>{if(!g)return;let I=f?Ze(f):null,b=V?Ze(V):null;p(!!(I&&g.isBefore(I.add(1,"month"),"month"))),B(!!(b&&g.isAfter(b.subtract(2,"month"),"month"))),A(J(g))},[g,f,V,J]),be(()=>{if(!e||!g)return;let I=e.diff(g,"month");I<-1&&H(),I>1&&Q()},[e,g]);let Z=Qe(I=>()=>{if(I==="next"&&G||I==="prev"&&r||c)return;m(!0),l(I==="next"?-x:x);let b=setTimeout(()=>{s(R=>{let F=I==="next"?R.add(1,"month"):R.subtract(1,"month");return A(J(F)),F}),l(0),m(!1)},200);return()=>clearTimeout(b)},[G,r,c,x,J]),[Q,H]=Ye(()=>[Z("next"),Z("prev")],[Z]),P=Qe(()=>{if(!t||!o.current)return;let b=o.current.querySelector(".day.selected, .month-calendar:not(.hidden) .day:not(.disabled)");b==null||b.focus()},[t]),q=Qe(I=>{var te,le;let b=I.target,R=b.getAttribute("data-day-index");if(!R)return;I.preventDefault();let F=b.closest(".calendar-wrapper"),Y=parseInt((te=b.dataset.dateValue)!=null?te:"0"),ee=Ze(Y),ke=ee.endOf("month").date(),j=parseInt(R);switch(I.key){case"ArrowLeft":j--;break;case"ArrowUp":j-=7;break;case"ArrowRight":j++;break;case"ArrowDown":j+=7;break;case" ":b.click();return;default:return}if(j>0&&j<=ke)(le=F==null?void 0:F.querySelector(`[data-day-index="${j}"]`))==null||le.focus();else{let M=ee.add(j-parseInt(R),"day"),K=M.diff(g,"month");K>1&&!G&&Q(),K<0&&!r&&H(),setTimeout(()=>{var oe;(oe=F==null?void 0:F.querySelector(`[data-month-index="${M.month()+1}"] [data-day-index="${M.date()}"]`))==null||oe.focus()},200)}},[g,G,r,Q,H]),Ue=Ye(()=>{var b;if(!u||!t)return null;let I=typeof u=="function"?u((b=y==null?void 0:y.toDate())!=null?b:new Date):u;return ge("div",{id:"day-tooltip",className:"tooltip-text",ref:a,children:I})},[u,y,t]),T=Ye(()=>d.map((I,b)=>{let R=b===1||b===2,F=c&&n<0&&b===3,Y=c&&n>0&&b===0;return ge(Ae,{hidden:!R&&!F&&!Y,isAnimating:F||Y,month:I.month(),year:I.year(),handleHoverDay:X,ref:a,className:ue({"slide-next":F,"slide-prev":Y})},`${I.year()}-${I.month()}`)}),[d,c,n]);return je("div",{className:"relative",children:[Ue,je("div",{className:ue("calendar-wrapper",{single:N}),ref:o,onKeyDown:q,role:"grid","aria-label":"Calendar",children:[ge("div",{className:ue("calendar-content",{isAnimating:c}),style:{transform:`translateX(${n}px)`},children:T}),je("div",{className:"calendar-flippers",children:[ge("button",{className:ue("flipper-button",{disabled:r}),onClick:H,onKeyDown:I=>I.key===" "&&H(),disabled:r,"aria-label":"Previous month",children:ge(he,{viewBox:"0 0 24 24"})}),ge("button",{className:ue("flipper-button",{disabled:G}),onClick:Q,onKeyDown:I=>I.key===" "&&Q(),disabled:G,"aria-label":"Next month",onBlur:P,children:ge(Be,{viewBox:"0 0 24 24"})})]})]})]})};import{jsx as E,jsxs as Me}from"react/jsx-runtime";var yt=({containerRef:e})=>{let[t,o]=ft(!1),[a,n]=ft(null),l=xo(null),d=e||l,{handleChangeDate:A,handleReset:g}=v(),{singleCalendar:s,expandDirection:r}=k(),{complsOpen:p,isMobile:G,toggleDialog:B}=ne(),{hideDialogHeader:x,hideDialogFooter:D}=w(),y=(X,c)=>{n(X),A(X,c)};return po(()=>{p&&!t&&o(!0),p&&setTimeout(()=>{var c;let X=(c=d.current)==null?void 0:c.querySelector("#start-date-input-button");X&&X.focus()},50)},[p,d,t]),Me("div",{className:mo("dialog-date-picker",{open:p,hide:!p&&t,single:s&&!G,"expand-left":r==="left","expand-right":r==="right"}),ref:d,children:[!x&&Me("div",{className:"dialog-header",children:[E("button",{type:"button",className:"btn-outline back-button",onClick:B,children:E(It,{viewBox:"0 0 492 492"})}),E(Fe,{showIcon:!0,nonFocusable:!p}),E("button",{type:"button",className:"btn-outline reset-button",onClick:g,children:"Reset"})]}),E("div",{className:"dialog-content",children:G?E(pt,{}):E(mt,{dateChanged:a})}),!D&&Me("div",{className:"dialog-footer",children:[E("button",{type:"button",className:"submit-button",onClick:B,tabIndex:0,children:"Done"}),E("button",{type:"button",className:"btn-outline reset-button mobile",onClick:g,children:"Reset"})]})]})};import{jsx as pe,jsxs as Do}from"react/jsx-runtime";W.extend(Go);var Xo=({startDate:e=null,endDate:t=null,className:o="",disabled:a=!1,startDatePlaceholder:n,endDatePlaceholder:l,onChange:d,onFocus:A=()=>{},startWeekDay:g="monday",minDate:s=null,maxDate:r=null,weekDayFormat:p="dd",dateFormat:G="",monthFormat:B="",highlightToday:x=!1,dateInputSeperator:D=null,hideDialogHeader:y=!1,hideDialogFooter:X=!1,hideDialogAfterSelectEndDate:c=!1,isOpen:m=!1,onCloseCalendar:C,tooltip:f="",subTextDict:V=null,expandDirection:N="right",locale:S="en",isSingle:u=!1,singleCalendar:J=!1})=>{let[Z,Q]=_(m),[H,P]=_(u?"from":null),[q,Ue]=_(e?W(e):void 0),[T,I]=_(t?W(t):void 0),[b,R]=_(),[F,Y]=_(!1),[ee,ke]=_(!1),te=(()=>{let[i,h]=_(!1);return ie(()=>{h(!0)},[]),i})(),le=ze(null),M=ze(null),K=ze(null),oe=Le(()=>{te&&Y(window.innerWidth<768)},[te]),Ee=$e(()=>{let i=M.current?M.current.toDate():null,h=!u&&K.current?K.current.toDate():null;u?d(i,null):d(i,h)},20),de=(i,h=!1)=>{Ue(i||void 0),M.current=i||null,h&&Ee()},re=(i,h=!1)=>{u||(I(i||void 0),K.current=i||null,h&&Ee())};fo(()=>{if(te)return oe(),window.addEventListener("resize",oe),()=>window.removeEventListener("resize",oe)},[te,oe]),ie(()=>{ke(!0);let i=h=>{le.current&&h.target instanceof Node&&!le.current.contains(h.target)&&window.innerWidth>=768&&Q(!1)};return document.addEventListener("click",i),()=>document.removeEventListener("click",i)},[]),ie(()=>{let i=e?W(e):null;M.current=i,de(i,!1)},[e]),ie(()=>{if(!u){let i=t?W(t):null;K.current=i,re(i,!1)}},[t,u]),ie(()=>{var i,h;if(!Z&&ee){let $=((i=M.current)==null?void 0:i.toDate())||null,xe=((h=K.current)==null?void 0:h.toDate())||null;u?C($,null):C($,xe)}},[Z,ee,u,C]),ie(()=>{Q(m)},[m]),ie(()=>{ee&&A(H==="from"?"Start Date":H==="to"?"End Date":"")},[H,ee,A]);let Dt=()=>{Q(!Z)},ht=i=>{a||!u&&i==="to"&&!q||(Z||Q(!0),P(i))},Bt=Le(i=>{let h=s?W(s):null,$=r?W(r):null;h&&h.isAfter(i,"date")||$&&$.isBefore(i,"date")||(u?(de(i,!0),c&&setTimeout(()=>Q(!1),50)):H==="from"||q&&i.isBefore(q,"date")?(de(i,!0),T&&i.isAfter(T,"date")&&re(null,!0),P("to")):(re(i,!0),P(null),c&&setTimeout(()=>Q(!1),50)))},[s,r,u,c,H,q,T]),Ht=i=>{R(i)},Ft=()=>{R(void 0),de(null,!0),u||re(null,!0),P("from")},Qt=Le((i,h)=>{let $=s?W(s):null,xe=r?W(r):null;$&&$.isAfter(i,"date")||xe&&xe.isBefore(i,"date")||(h==="from"||u?(P("from"),de(i,!0),!u&&T&&i.isAfter(T,"date")&&re(null,!0)):(P("to"),re(i,!0)))},[s,r,u,T,H]),Zt={fromDate:q,toDate:T,hoverDate:b,inputFocus:H,onSelectDate:Bt,onHoverDate:Ht,handleChangeDate:Qt,handleReset:Ft,handleClickDateInput:ht},Rt={isSingle:u,startWeekDay:g,minDate:s?W(s).toDate():null,maxDate:r?W(r).toDate():null,weekDayFormat:p,dateFormat:G,monthFormat:B,highlightToday:x,singleCalendar:J,expandDirection:N,locale:S},Ot={complsOpen:Z,isMobile:F,disabled:a,toggleDialog:Dt},Ut={startDatePlaceholder:n,endDatePlaceholder:l,dateInputSeperator:D,hideDialogHeader:y,hideDialogFooter:X,hideDialogAfterSelectEndDate:c,tooltip:f,subTextDict:V};return pe("div",{className:"react-google-flight-datepicker",children:pe("div",{className:yo("date-picker",o,{disabled:a}),ref:le,children:Do(ot,{dateState:Zt,config:Rt,uiState:Ot,display:Ut,locale:S,children:[pe(Fe,{}),pe(nt,{children:pe(yt,{})})]})})})},Re=Xo;import{useState as ho,useEffect as Bo}from"react";import{Fragment as Ho,jsx as Fo}from"react/jsx-runtime";var Oe=({children:e})=>{let[t,o]=ho(!1);return Bo(()=>{o(!0)},[]),t?Fo(Ho,{children:e}):null};import{jsx as Gt}from"react/jsx-runtime";var Qo=l=>{var d=l,{onChange:e=()=>{},onCloseCalendar:t=()=>{},startDatePlaceholder:o="Start date",endDatePlaceholder:a="End date"}=d,n=fe(d,["onChange","onCloseCalendar","startDatePlaceholder","endDatePlaceholder"]);return Gt(Oe,{children:Gt(Re,U(O({},n),{isSingle:!1,startDate:n.startDate,endDate:n.endDate,startDatePlaceholder:o,endDatePlaceholder:a,onChange:e,onCloseCalendar:t}))})};import{jsx as Xt}from"react/jsx-runtime";var Zo=n=>{var l=n,{onChange:e=()=>{},onCloseCalendar:t=()=>{},startDatePlaceholder:o="Date"}=l,a=fe(l,["onChange","onCloseCalendar","startDatePlaceholder"]);return Xt(Oe,{children:Xt(Re,U(O({},a),{endDate:null,isSingle:!0,startDate:a.startDate,startDatePlaceholder:o,onChange:d=>e(d),onCloseCalendar:d=>t(d)}))})};export{Qo as RangeDatePicker,Zo as SingleDatePicker};
|
|
1
|
+
// src/lib/components/DatePicker/BaseDatePicker.tsx
|
|
2
|
+
import {
|
|
3
|
+
useState as useState7,
|
|
4
|
+
useRef as useRef5,
|
|
5
|
+
useEffect as useEffect8,
|
|
6
|
+
useLayoutEffect,
|
|
7
|
+
useCallback as useCallback4
|
|
8
|
+
} from "react";
|
|
9
|
+
import dayjs8 from "dayjs";
|
|
10
|
+
import cx7 from "classnames";
|
|
11
|
+
import localeData from "dayjs/plugin/localeData";
|
|
12
|
+
|
|
13
|
+
// src/lib/helpers/index.ts
|
|
14
|
+
import dayjs from "dayjs";
|
|
15
|
+
function getMonthInfo(year, month, startDay) {
|
|
16
|
+
const weeks = [];
|
|
17
|
+
const firstDate = new Date(year, month, 1);
|
|
18
|
+
const lastDate = new Date(year, month + 1, 0);
|
|
19
|
+
const numDays = lastDate.getDate();
|
|
20
|
+
let start = 1;
|
|
21
|
+
let end = firstDate.getDay() === 0 ? 1 : 7 - firstDate.getDay() + 1;
|
|
22
|
+
if (startDay === "sunday") {
|
|
23
|
+
end = 7 - firstDate.getDay();
|
|
24
|
+
}
|
|
25
|
+
while (start <= numDays) {
|
|
26
|
+
weeks.push({ start, days: end - start + 1 });
|
|
27
|
+
start = end + 1;
|
|
28
|
+
end += 7;
|
|
29
|
+
end = start === 1 && end === 8 ? 1 : end;
|
|
30
|
+
if (end > numDays) {
|
|
31
|
+
end = numDays;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { totalWeek: weeks, totalDay: numDays };
|
|
35
|
+
}
|
|
36
|
+
function getWeekDay(startWeekDay, weekDayFormat) {
|
|
37
|
+
const days = [...Array(7)].map(
|
|
38
|
+
(_, i) => dayjs().day(i).format(weekDayFormat === "dd" ? "dd" : weekDayFormat === "ddd" ? "ddd" : "dddd")
|
|
39
|
+
);
|
|
40
|
+
if (startWeekDay === "sunday") {
|
|
41
|
+
const last = days.pop();
|
|
42
|
+
if (last) {
|
|
43
|
+
days.unshift(last);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return days;
|
|
47
|
+
}
|
|
48
|
+
function debounce(func, wait) {
|
|
49
|
+
let timeout;
|
|
50
|
+
return function executedFunction(...args) {
|
|
51
|
+
const later = () => {
|
|
52
|
+
timeout = null;
|
|
53
|
+
func.apply(this, args);
|
|
54
|
+
};
|
|
55
|
+
if (timeout) {
|
|
56
|
+
clearTimeout(timeout);
|
|
57
|
+
}
|
|
58
|
+
timeout = setTimeout(later, wait);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/lib/components/DatePicker/DatePickerProvider.tsx
|
|
63
|
+
import { createContext, useContext, useState, useEffect } from "react";
|
|
64
|
+
import dayjs2 from "dayjs";
|
|
65
|
+
import { jsx } from "react/jsx-runtime";
|
|
66
|
+
var DateStateContext = createContext(null);
|
|
67
|
+
var DatePickerConfigContext = createContext(null);
|
|
68
|
+
var UIStateContext = createContext(null);
|
|
69
|
+
var DisplayContext = createContext(null);
|
|
70
|
+
var LocaleContext = createContext(null);
|
|
71
|
+
var useDateState = () => {
|
|
72
|
+
const context = useContext(DateStateContext);
|
|
73
|
+
if (!context) throw new Error("useDateState must be used within DatePickerProvider");
|
|
74
|
+
return context;
|
|
75
|
+
};
|
|
76
|
+
var useDatePickerConfig = () => {
|
|
77
|
+
const context = useContext(DatePickerConfigContext);
|
|
78
|
+
if (!context) throw new Error("useDatePickerConfig must be used within DatePickerProvider");
|
|
79
|
+
return context;
|
|
80
|
+
};
|
|
81
|
+
var useUIState = () => {
|
|
82
|
+
const context = useContext(UIStateContext);
|
|
83
|
+
if (!context) throw new Error("useUIState must be used within DatePickerProvider");
|
|
84
|
+
return context;
|
|
85
|
+
};
|
|
86
|
+
var useDisplayCustomization = () => {
|
|
87
|
+
const context = useContext(DisplayContext);
|
|
88
|
+
if (!context) throw new Error("useDisplayCustomization must be used within DatePickerProvider");
|
|
89
|
+
return context;
|
|
90
|
+
};
|
|
91
|
+
var loadLocale = async (locale) => {
|
|
92
|
+
if (locale === "en") return true;
|
|
93
|
+
try {
|
|
94
|
+
await import(`dayjs/locale/${locale}.js`);
|
|
95
|
+
return true;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(`Failed to load locale ${locale}:`, error);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var DatePickerProvider = ({
|
|
102
|
+
children,
|
|
103
|
+
dateState,
|
|
104
|
+
config,
|
|
105
|
+
uiState,
|
|
106
|
+
display,
|
|
107
|
+
locale = "en"
|
|
108
|
+
}) => {
|
|
109
|
+
const [localeState, setLocaleState] = useState({
|
|
110
|
+
currentLocale: "en",
|
|
111
|
+
isLocaleReady: locale === "en"
|
|
112
|
+
});
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (locale !== "en") {
|
|
115
|
+
setLocaleState((prev) => ({ ...prev, isLocaleReady: false }));
|
|
116
|
+
loadLocale(locale).then((success) => {
|
|
117
|
+
if (success) {
|
|
118
|
+
dayjs2.locale(locale);
|
|
119
|
+
setLocaleState({
|
|
120
|
+
currentLocale: locale,
|
|
121
|
+
isLocaleReady: true
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
dayjs2.locale("en");
|
|
125
|
+
setLocaleState({
|
|
126
|
+
currentLocale: "en",
|
|
127
|
+
isLocaleReady: true
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
dayjs2.locale("en");
|
|
133
|
+
setLocaleState({
|
|
134
|
+
currentLocale: "en",
|
|
135
|
+
isLocaleReady: true
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, [locale]);
|
|
139
|
+
if (!localeState.isLocaleReady) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return /* @__PURE__ */ jsx(LocaleContext.Provider, { value: localeState, children: /* @__PURE__ */ jsx(DateStateContext.Provider, { value: dateState, children: /* @__PURE__ */ jsx(DatePickerConfigContext.Provider, { value: config, children: /* @__PURE__ */ jsx(UIStateContext.Provider, { value: uiState, children: /* @__PURE__ */ jsx(DisplayContext.Provider, { value: display, children }) }) }) }) });
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/lib/assets/svg/calendar.svg
|
|
146
|
+
import * as React2 from "react";
|
|
147
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
148
|
+
var SvgCalendar = (props) => /* @__PURE__ */ jsx2("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: /* @__PURE__ */ jsx2("path", { d: "M9 11H7v2h2v-2zm4 0h-2v2h2v-2zm4 0h-2v2h2v-2zm2-7h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20a2 2 0 002 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z" }) });
|
|
149
|
+
var calendar_default = SvgCalendar;
|
|
150
|
+
|
|
151
|
+
// src/lib/components/DatePicker/DateInput.tsx
|
|
152
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
153
|
+
import cx from "classnames";
|
|
154
|
+
import dayjs3 from "dayjs";
|
|
155
|
+
|
|
156
|
+
// src/lib/assets/svg/prev.svg
|
|
157
|
+
import * as React3 from "react";
|
|
158
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
159
|
+
var SvgPrev = (props) => /* @__PURE__ */ jsx3("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: /* @__PURE__ */ jsx3("path", { d: "M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z" }) });
|
|
160
|
+
var prev_default = SvgPrev;
|
|
161
|
+
|
|
162
|
+
// src/lib/assets/svg/next.svg
|
|
163
|
+
import * as React4 from "react";
|
|
164
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
165
|
+
var SvgNext = (props) => /* @__PURE__ */ jsx4("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", ...props, children: /* @__PURE__ */ jsx4("path", { d: "M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z" }) });
|
|
166
|
+
var next_default = SvgNext;
|
|
167
|
+
|
|
168
|
+
// src/lib/components/DatePicker/DateInput.tsx
|
|
169
|
+
import { jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
170
|
+
var DateInput = ({
|
|
171
|
+
type,
|
|
172
|
+
showIcon = false,
|
|
173
|
+
tabIndex = 0,
|
|
174
|
+
nonFocusable = false
|
|
175
|
+
}) => {
|
|
176
|
+
const [formattedDate, setFormattedDate] = useState2(null);
|
|
177
|
+
const [disablePrev, setDisablePrev] = useState2(false);
|
|
178
|
+
const [disableNext, setDisableNext] = useState2(false);
|
|
179
|
+
const {
|
|
180
|
+
fromDate,
|
|
181
|
+
toDate,
|
|
182
|
+
inputFocus,
|
|
183
|
+
handleClickDateInput,
|
|
184
|
+
handleChangeDate
|
|
185
|
+
} = useDateState();
|
|
186
|
+
const {
|
|
187
|
+
isSingle,
|
|
188
|
+
minDate,
|
|
189
|
+
maxDate,
|
|
190
|
+
dateFormat
|
|
191
|
+
} = useDatePickerConfig();
|
|
192
|
+
const {
|
|
193
|
+
startDatePlaceholder,
|
|
194
|
+
endDatePlaceholder
|
|
195
|
+
} = useDisplayCustomization();
|
|
196
|
+
const value = type === "from" ? fromDate : toDate;
|
|
197
|
+
const placeholder = type === "from" ? startDatePlaceholder : endDatePlaceholder;
|
|
198
|
+
useEffect2(() => {
|
|
199
|
+
if (value) {
|
|
200
|
+
let formattedValue = value.clone().locale(dayjs3.locale());
|
|
201
|
+
let text = formattedValue.format("ddd, DD MMM");
|
|
202
|
+
if (dateFormat) {
|
|
203
|
+
text = value.format(dateFormat);
|
|
204
|
+
}
|
|
205
|
+
setFormattedDate(text);
|
|
206
|
+
const minDateDayjs = minDate ? dayjs3(minDate) : null;
|
|
207
|
+
const maxDateDayjs = maxDate ? dayjs3(maxDate) : null;
|
|
208
|
+
if (minDateDayjs?.add(1, "day").isAfter(value, "date") || type === "to" && fromDate && value.isBefore(fromDate.add(1, "day"), "date")) {
|
|
209
|
+
setDisablePrev(true);
|
|
210
|
+
} else {
|
|
211
|
+
setDisablePrev(false);
|
|
212
|
+
}
|
|
213
|
+
if (maxDateDayjs?.subtract(1, "day").isBefore(value, "date")) {
|
|
214
|
+
setDisableNext(true);
|
|
215
|
+
} else {
|
|
216
|
+
setDisableNext(false);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
setFormattedDate(null);
|
|
220
|
+
}
|
|
221
|
+
}, [value, fromDate, minDate, maxDate, dateFormat, type]);
|
|
222
|
+
const prevDate = (e) => {
|
|
223
|
+
e.stopPropagation();
|
|
224
|
+
if (value) {
|
|
225
|
+
handleChangeDate(value.subtract(1, "day"), type);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const nextDate = (e) => {
|
|
229
|
+
e.stopPropagation();
|
|
230
|
+
if (value) {
|
|
231
|
+
handleChangeDate(value.add(1, "day"), type);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const handleClick = () => {
|
|
235
|
+
handleClickDateInput(type);
|
|
236
|
+
};
|
|
237
|
+
return /* @__PURE__ */ jsxs(
|
|
238
|
+
"div",
|
|
239
|
+
{
|
|
240
|
+
className: cx("date", {
|
|
241
|
+
"is-focus": inputFocus === type && !isSingle,
|
|
242
|
+
"is-single": isSingle
|
|
243
|
+
}),
|
|
244
|
+
role: "button",
|
|
245
|
+
tabIndex: nonFocusable ? -1 : tabIndex,
|
|
246
|
+
onClick: handleClick,
|
|
247
|
+
id: `${type}-date-input-button`,
|
|
248
|
+
children: [
|
|
249
|
+
showIcon && /* @__PURE__ */ jsx5(calendar_default, { className: "icon-calendar", viewBox: "0 0 24 24" }),
|
|
250
|
+
/* @__PURE__ */ jsx5("div", { className: "selected-date", children: formattedDate ?? /* @__PURE__ */ jsx5("div", { className: "date-placeholder", children: placeholder }) }),
|
|
251
|
+
formattedDate && /* @__PURE__ */ jsxs("div", { className: "change-date-group", children: [
|
|
252
|
+
/* @__PURE__ */ jsx5(
|
|
253
|
+
"button",
|
|
254
|
+
{
|
|
255
|
+
type: "button",
|
|
256
|
+
className: "btn-outline change-date-button",
|
|
257
|
+
onClick: prevDate,
|
|
258
|
+
tabIndex: nonFocusable ? -1 : 0,
|
|
259
|
+
disabled: disablePrev,
|
|
260
|
+
children: /* @__PURE__ */ jsx5(prev_default, { viewBox: "0 0 24 24", className: "icon-arrow" })
|
|
261
|
+
}
|
|
262
|
+
),
|
|
263
|
+
/* @__PURE__ */ jsx5(
|
|
264
|
+
"button",
|
|
265
|
+
{
|
|
266
|
+
type: "button",
|
|
267
|
+
className: "btn-outline change-date-button",
|
|
268
|
+
onClick: nextDate,
|
|
269
|
+
tabIndex: nonFocusable ? -1 : 0,
|
|
270
|
+
disabled: disableNext,
|
|
271
|
+
children: /* @__PURE__ */ jsx5(next_default, { viewBox: "0 0 24 24", className: "icon-arrow" })
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
] })
|
|
275
|
+
]
|
|
276
|
+
}
|
|
277
|
+
);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// src/lib/components/DatePicker/DateInputGroup.tsx
|
|
281
|
+
import { jsx as jsx6, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
282
|
+
var DateInputGroup = ({
|
|
283
|
+
showIcon = false,
|
|
284
|
+
nonFocusable = false
|
|
285
|
+
}) => {
|
|
286
|
+
const { isSingle } = useDatePickerConfig();
|
|
287
|
+
const { dateInputSeperator } = useDisplayCustomization();
|
|
288
|
+
return /* @__PURE__ */ jsxs2("div", { className: "date-picker-input", children: [
|
|
289
|
+
showIcon && /* @__PURE__ */ jsx6(calendar_default, { className: "icon-calendar mobile", viewBox: "0 0 24 24" }),
|
|
290
|
+
/* @__PURE__ */ jsxs2("div", { className: "date-picker-date-group", children: [
|
|
291
|
+
/* @__PURE__ */ jsx6(
|
|
292
|
+
DateInput,
|
|
293
|
+
{
|
|
294
|
+
type: "from",
|
|
295
|
+
tabIndex: nonFocusable ? -1 : 0,
|
|
296
|
+
showIcon: true,
|
|
297
|
+
nonFocusable
|
|
298
|
+
}
|
|
299
|
+
),
|
|
300
|
+
!isSingle && dateInputSeperator && /* @__PURE__ */ jsx6("div", { className: "date-input-separator", children: dateInputSeperator }),
|
|
301
|
+
!isSingle && /* @__PURE__ */ jsx6(
|
|
302
|
+
DateInput,
|
|
303
|
+
{
|
|
304
|
+
type: "to",
|
|
305
|
+
tabIndex: nonFocusable ? -1 : 0,
|
|
306
|
+
showIcon: false,
|
|
307
|
+
nonFocusable
|
|
308
|
+
}
|
|
309
|
+
)
|
|
310
|
+
] })
|
|
311
|
+
] });
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// src/lib/components/DatePicker/DialogWrapper.tsx
|
|
315
|
+
import { createPortal } from "react-dom";
|
|
316
|
+
|
|
317
|
+
// src/lib/hooks/useClientSide.ts
|
|
318
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
319
|
+
var useClientSide = () => {
|
|
320
|
+
const [isClient, setIsClient] = useState3(false);
|
|
321
|
+
useEffect3(() => {
|
|
322
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
323
|
+
setIsClient(true);
|
|
324
|
+
} else {
|
|
325
|
+
console.warn("Client-side context not available");
|
|
326
|
+
}
|
|
327
|
+
}, []);
|
|
328
|
+
return isClient;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/lib/components/DatePicker/DialogWrapper.tsx
|
|
332
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
333
|
+
var DialogWrapper = ({
|
|
334
|
+
children = null,
|
|
335
|
+
isMobile = false
|
|
336
|
+
}) => {
|
|
337
|
+
const isClient = useClientSide();
|
|
338
|
+
if (!isClient) return null;
|
|
339
|
+
return isMobile ? createPortal(/* @__PURE__ */ jsx7("div", { children }), document.body) : children;
|
|
340
|
+
};
|
|
341
|
+
var DialogWrapper_default = DialogWrapper;
|
|
342
|
+
|
|
343
|
+
// src/lib/components/DatePicker/Dialog.tsx
|
|
344
|
+
import { useEffect as useEffect7, useState as useState6, useRef as useRef4 } from "react";
|
|
345
|
+
import cx6 from "classnames";
|
|
346
|
+
|
|
347
|
+
// src/lib/assets/svg/back.svg
|
|
348
|
+
import * as React6 from "react";
|
|
349
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
350
|
+
var SvgBack = (props) => /* @__PURE__ */ jsx8("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 492 492", ...props, children: /* @__PURE__ */ jsx8("path", { d: "M464.3 207.4l.8.2H136l103.5-103.7c5-5.1 7.8-12 7.8-19.2 0-7.2-2.7-14-7.8-19l-16.1-16.2c-5-5-11.8-7.8-19-7.8-7.2 0-14 2.8-19 7.8L7.8 227C2.8 232 0 238.8 0 246c0 7.3 2.8 14 7.8 19.2l177.5 177.4c5 5 11.8 7.8 19 7.8 7.2 0 14-2.8 19-7.8l16-16.1a26.6 26.6 0 000-37.7L134.8 284.4h330a27.9 27.9 0 0027.3-27.6V234a27.3 27.3 0 00-27.7-26.6z" }) });
|
|
351
|
+
var back_default = SvgBack;
|
|
352
|
+
|
|
353
|
+
// src/lib/components/DatePicker/DialogContentMobile.tsx
|
|
354
|
+
import React10, { useEffect as useEffect5, useState as useState4, useRef as useRef2 } from "react";
|
|
355
|
+
import dayjs6 from "dayjs";
|
|
356
|
+
import { VariableSizeList as List } from "react-window";
|
|
357
|
+
import AutoSizer from "react-virtualized-auto-sizer";
|
|
358
|
+
|
|
359
|
+
// src/lib/components/DatePicker/MonthCalendar.tsx
|
|
360
|
+
import { forwardRef as forwardRef3 } from "react";
|
|
361
|
+
import cx4 from "classnames";
|
|
362
|
+
import dayjs5 from "dayjs";
|
|
363
|
+
|
|
364
|
+
// src/lib/components/DatePicker/Week.tsx
|
|
365
|
+
import { forwardRef as forwardRef2 } from "react";
|
|
366
|
+
import cx3 from "classnames";
|
|
367
|
+
import dayjs4 from "dayjs";
|
|
368
|
+
|
|
369
|
+
// src/lib/components/DatePicker/Day.tsx
|
|
370
|
+
import { forwardRef, useCallback as useCallback2, useEffect as useEffect4, useRef } from "react";
|
|
371
|
+
import cx2 from "classnames";
|
|
372
|
+
import { jsx as jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
373
|
+
var Day = forwardRef(({
|
|
374
|
+
dateIndex,
|
|
375
|
+
dateValue,
|
|
376
|
+
isEndDay,
|
|
377
|
+
selected,
|
|
378
|
+
hovered,
|
|
379
|
+
disabled,
|
|
380
|
+
totalDay,
|
|
381
|
+
highlight,
|
|
382
|
+
handleHoverDay,
|
|
383
|
+
subText
|
|
384
|
+
}, ref) => {
|
|
385
|
+
const dayRef = useRef(null);
|
|
386
|
+
const { onSelectDate, onHoverDate } = useDateState();
|
|
387
|
+
const selectDate = (e) => {
|
|
388
|
+
e.stopPropagation();
|
|
389
|
+
e.preventDefault();
|
|
390
|
+
if (disabled) return;
|
|
391
|
+
onSelectDate(dateValue);
|
|
392
|
+
};
|
|
393
|
+
const handleHoverDate = () => {
|
|
394
|
+
if (disabled) return;
|
|
395
|
+
onHoverDate(dateValue);
|
|
396
|
+
handleHoverDay(dateValue);
|
|
397
|
+
};
|
|
398
|
+
const handleTooltipPosition = useCallback2(() => {
|
|
399
|
+
if (!ref || typeof ref === "function") return;
|
|
400
|
+
const element = ref.current;
|
|
401
|
+
if (element && dayRef.current) {
|
|
402
|
+
element.style.left = `${dayRef.current.offsetLeft - element.offsetWidth + 135}px`;
|
|
403
|
+
element.style.top = `${dayRef.current.offsetTop - element.offsetHeight - 15}px`;
|
|
404
|
+
element.style.visibility = "visible";
|
|
405
|
+
}
|
|
406
|
+
}, [ref]);
|
|
407
|
+
const handleTooltipHidden = useCallback2(() => {
|
|
408
|
+
if (!ref || typeof ref === "function") return;
|
|
409
|
+
const element = ref.current;
|
|
410
|
+
if (element) {
|
|
411
|
+
element.style.visibility = "hidden";
|
|
412
|
+
}
|
|
413
|
+
}, [ref]);
|
|
414
|
+
useEffect4(() => {
|
|
415
|
+
const currentRef = dayRef.current;
|
|
416
|
+
if (currentRef) {
|
|
417
|
+
currentRef.addEventListener("mouseover", handleTooltipPosition);
|
|
418
|
+
currentRef.addEventListener("mouseleave", handleTooltipHidden);
|
|
419
|
+
}
|
|
420
|
+
return () => {
|
|
421
|
+
if (currentRef) {
|
|
422
|
+
currentRef.removeEventListener("mouseover", handleTooltipPosition);
|
|
423
|
+
currentRef.removeEventListener("mouseleave", handleTooltipHidden);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
}, [handleTooltipPosition, handleTooltipHidden]);
|
|
427
|
+
return /* @__PURE__ */ jsxs3(
|
|
428
|
+
"div",
|
|
429
|
+
{
|
|
430
|
+
className: cx2("day", {
|
|
431
|
+
selected,
|
|
432
|
+
hovered,
|
|
433
|
+
disabled,
|
|
434
|
+
highlight,
|
|
435
|
+
end: isEndDay,
|
|
436
|
+
"has-subtext": !!subText
|
|
437
|
+
}),
|
|
438
|
+
onClick: selectDate,
|
|
439
|
+
onMouseEnter: handleHoverDate,
|
|
440
|
+
role: "button",
|
|
441
|
+
tabIndex: -1,
|
|
442
|
+
"data-day-index": dateIndex,
|
|
443
|
+
"data-date-value": dateValue.valueOf(),
|
|
444
|
+
ref: dayRef,
|
|
445
|
+
children: [
|
|
446
|
+
hovered && !(isEndDay && dateIndex === totalDay) && !(dateIndex === 1 && selected && !isEndDay) && /* @__PURE__ */ jsx9(
|
|
447
|
+
"div",
|
|
448
|
+
{
|
|
449
|
+
className: cx2("background-day", {
|
|
450
|
+
"first-day": dateIndex === 1,
|
|
451
|
+
"last-day": dateIndex === totalDay
|
|
452
|
+
})
|
|
453
|
+
}
|
|
454
|
+
),
|
|
455
|
+
/* @__PURE__ */ jsxs3("div", { className: "day-content", children: [
|
|
456
|
+
/* @__PURE__ */ jsx9("div", { className: "text-day", children: dateIndex }),
|
|
457
|
+
subText && /* @__PURE__ */ jsx9(
|
|
458
|
+
"div",
|
|
459
|
+
{
|
|
460
|
+
className: "sub-text",
|
|
461
|
+
style: {
|
|
462
|
+
position: "relative",
|
|
463
|
+
zIndex: 3,
|
|
464
|
+
color: selected && !hovered ? "#fff" : "#666"
|
|
465
|
+
},
|
|
466
|
+
children: subText
|
|
467
|
+
}
|
|
468
|
+
)
|
|
469
|
+
] })
|
|
470
|
+
]
|
|
471
|
+
}
|
|
472
|
+
);
|
|
473
|
+
});
|
|
474
|
+
Day.displayName = "Day";
|
|
475
|
+
|
|
476
|
+
// src/lib/components/DatePicker/Week.tsx
|
|
477
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
478
|
+
var Week = forwardRef2(({
|
|
479
|
+
isFirst,
|
|
480
|
+
week,
|
|
481
|
+
month,
|
|
482
|
+
year,
|
|
483
|
+
totalDay,
|
|
484
|
+
weekIndex,
|
|
485
|
+
handleHoverDay
|
|
486
|
+
}, ref) => {
|
|
487
|
+
const {
|
|
488
|
+
fromDate,
|
|
489
|
+
toDate,
|
|
490
|
+
hoverDate
|
|
491
|
+
} = useDateState();
|
|
492
|
+
const {
|
|
493
|
+
minDate,
|
|
494
|
+
maxDate,
|
|
495
|
+
isSingle,
|
|
496
|
+
highlightToday
|
|
497
|
+
} = useDatePickerConfig();
|
|
498
|
+
const { subTextDict } = useDisplayCustomization();
|
|
499
|
+
const generateDay = () => {
|
|
500
|
+
return Array.from({ length: week.days }, (_, index) => {
|
|
501
|
+
const dateIndex = index + week.start;
|
|
502
|
+
const dateValue = dayjs4(`${year}-${month + 1}-${dateIndex}`);
|
|
503
|
+
const disabled = minDate && dateValue.isBefore(minDate, "date") || maxDate && dateValue.isAfter(maxDate, "date");
|
|
504
|
+
const selected = fromDate && dateValue.isSame(fromDate, "date") || toDate && dateValue.isSame(toDate, "date");
|
|
505
|
+
let hovered = false;
|
|
506
|
+
const highlight = highlightToday && dateValue.isSame(/* @__PURE__ */ new Date(), "date");
|
|
507
|
+
if (fromDate && !fromDate.isSame(toDate, "date") && !isSingle) {
|
|
508
|
+
if (toDate && !fromDate.isAfter(dateValue, "date") && !toDate.isBefore(dateValue, "date")) {
|
|
509
|
+
hovered = true;
|
|
510
|
+
}
|
|
511
|
+
if (!toDate && !dateValue.isBefore(fromDate, "date") && !(hoverDate && hoverDate.isBefore(dateValue, "date")) && fromDate.isBefore(hoverDate, "date")) {
|
|
512
|
+
hovered = true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const isEndDate = toDate && dateValue.isSame(toDate, "date") || !toDate && hoverDate && dateValue.isSame(hoverDate, "date");
|
|
516
|
+
const subText = !subTextDict ? "" : subTextDict[dateValue.format("YYYY-MM-DD")] ?? "\xA0";
|
|
517
|
+
return /* @__PURE__ */ jsx10(
|
|
518
|
+
Day,
|
|
519
|
+
{
|
|
520
|
+
dateIndex,
|
|
521
|
+
dateValue,
|
|
522
|
+
selected,
|
|
523
|
+
hovered,
|
|
524
|
+
highlight,
|
|
525
|
+
disabled,
|
|
526
|
+
isEndDay: isEndDate,
|
|
527
|
+
totalDay,
|
|
528
|
+
handleHoverDay,
|
|
529
|
+
subText,
|
|
530
|
+
ref
|
|
531
|
+
},
|
|
532
|
+
index
|
|
533
|
+
);
|
|
534
|
+
});
|
|
535
|
+
};
|
|
536
|
+
return /* @__PURE__ */ jsx10("div", { className: cx3("week", { first: isFirst }), children: generateDay() });
|
|
537
|
+
});
|
|
538
|
+
Week.displayName = "Week";
|
|
539
|
+
|
|
540
|
+
// src/lib/components/DatePicker/MonthCalendar.tsx
|
|
541
|
+
import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
542
|
+
var MonthCalendar = forwardRef3(({
|
|
543
|
+
month,
|
|
544
|
+
year,
|
|
545
|
+
hidden = false,
|
|
546
|
+
isAnimating = false,
|
|
547
|
+
handleHoverDay,
|
|
548
|
+
className
|
|
549
|
+
}, ref) => {
|
|
550
|
+
const {
|
|
551
|
+
startWeekDay,
|
|
552
|
+
weekDayFormat,
|
|
553
|
+
monthFormat,
|
|
554
|
+
singleCalendar
|
|
555
|
+
} = useDatePickerConfig();
|
|
556
|
+
const generateWeek = () => {
|
|
557
|
+
const { totalWeek, totalDay } = getMonthInfo(year, month, startWeekDay);
|
|
558
|
+
return totalWeek.map((week) => {
|
|
559
|
+
const weekKey = `${year}-${month}-${week.start}`;
|
|
560
|
+
return /* @__PURE__ */ jsx11(
|
|
561
|
+
Week,
|
|
562
|
+
{
|
|
563
|
+
week,
|
|
564
|
+
month,
|
|
565
|
+
year,
|
|
566
|
+
isFirst: week === totalWeek[0],
|
|
567
|
+
totalDay,
|
|
568
|
+
weekIndex: totalWeek.indexOf(week),
|
|
569
|
+
handleHoverDay,
|
|
570
|
+
ref
|
|
571
|
+
},
|
|
572
|
+
weekKey
|
|
573
|
+
);
|
|
574
|
+
});
|
|
575
|
+
};
|
|
576
|
+
const generateWeekDay = () => {
|
|
577
|
+
const arrWeekDay = getWeekDay(startWeekDay, weekDayFormat);
|
|
578
|
+
return arrWeekDay.map((day) => {
|
|
579
|
+
return /* @__PURE__ */ jsx11("div", { className: "weekday", children: day }, `weekday-${day.toLowerCase()}`);
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
const getMonthDisplay = () => {
|
|
583
|
+
const date = dayjs5(`${year}-${month + 1}-1`);
|
|
584
|
+
return monthFormat ? date.format(monthFormat) : date.format("MMMM - YYYY");
|
|
585
|
+
};
|
|
586
|
+
return /* @__PURE__ */ jsxs4(
|
|
587
|
+
"div",
|
|
588
|
+
{
|
|
589
|
+
className: cx4("month-calendar", {
|
|
590
|
+
isAnimating,
|
|
591
|
+
hidden,
|
|
592
|
+
single: singleCalendar
|
|
593
|
+
}, className),
|
|
594
|
+
"data-month-index": month + 1,
|
|
595
|
+
children: [
|
|
596
|
+
/* @__PURE__ */ jsx11("div", { className: "month-name", children: getMonthDisplay() }),
|
|
597
|
+
/* @__PURE__ */ jsx11("div", { className: "weekdays", children: generateWeekDay() }),
|
|
598
|
+
/* @__PURE__ */ jsx11("div", { className: "week-container", children: generateWeek() })
|
|
599
|
+
]
|
|
600
|
+
}
|
|
601
|
+
);
|
|
602
|
+
});
|
|
603
|
+
MonthCalendar.displayName = "MonthCalendar";
|
|
604
|
+
|
|
605
|
+
// src/lib/components/DatePicker/DialogContentMobile.tsx
|
|
606
|
+
import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
607
|
+
var DialogContentMobile = () => {
|
|
608
|
+
const [rowCount, setRowCount] = useState4(2400);
|
|
609
|
+
const listRef = useRef2(null);
|
|
610
|
+
const {
|
|
611
|
+
fromDate
|
|
612
|
+
} = useDateState();
|
|
613
|
+
const {
|
|
614
|
+
startWeekDay,
|
|
615
|
+
minDate,
|
|
616
|
+
maxDate,
|
|
617
|
+
weekDayFormat
|
|
618
|
+
} = useDatePickerConfig();
|
|
619
|
+
const {
|
|
620
|
+
complsOpen
|
|
621
|
+
} = useUIState();
|
|
622
|
+
const {
|
|
623
|
+
tooltip,
|
|
624
|
+
subTextDict
|
|
625
|
+
} = useDisplayCustomization();
|
|
626
|
+
const minYear = minDate ? dayjs6(minDate).year() : 1900;
|
|
627
|
+
const minMonth = minDate ? dayjs6(minDate).month() : 0;
|
|
628
|
+
useEffect5(() => {
|
|
629
|
+
if (maxDate) {
|
|
630
|
+
const _minDate = minDate ? dayjs6(minDate) : dayjs6("1900-01-01");
|
|
631
|
+
setRowCount(dayjs6(maxDate).diff(_minDate, "month") + 1);
|
|
632
|
+
}
|
|
633
|
+
}, [maxDate, minDate]);
|
|
634
|
+
useEffect5(() => {
|
|
635
|
+
if (listRef.current && complsOpen) {
|
|
636
|
+
const date = fromDate ? dayjs6(fromDate) : dayjs6();
|
|
637
|
+
let monthDiff = date.diff(dayjs6("1900-01-01"), "month");
|
|
638
|
+
if (minDate) {
|
|
639
|
+
monthDiff = date.diff(dayjs6(minDate), "month");
|
|
640
|
+
}
|
|
641
|
+
listRef.current.scrollToItem(monthDiff + 1, "smart");
|
|
642
|
+
}
|
|
643
|
+
}, [complsOpen, fromDate, minDate]);
|
|
644
|
+
const getMonthYearFromIndex = (index) => {
|
|
645
|
+
const _index = index + minMonth;
|
|
646
|
+
const year = minYear + Math.floor(_index / 12);
|
|
647
|
+
const month = _index % 12;
|
|
648
|
+
return { year, month };
|
|
649
|
+
};
|
|
650
|
+
const Row = React10.memo(({ index, style }) => {
|
|
651
|
+
const { year, month } = getMonthYearFromIndex(index);
|
|
652
|
+
return /* @__PURE__ */ jsx12("div", { style, children: /* @__PURE__ */ jsx12(
|
|
653
|
+
MonthCalendar,
|
|
654
|
+
{
|
|
655
|
+
month,
|
|
656
|
+
year,
|
|
657
|
+
hidden: false,
|
|
658
|
+
isAnimating: false,
|
|
659
|
+
handleHoverDay: () => {
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
) });
|
|
663
|
+
});
|
|
664
|
+
Row.displayName = "CalendarRow";
|
|
665
|
+
const getItemSize = (index) => {
|
|
666
|
+
const { year, month } = getMonthYearFromIndex(index);
|
|
667
|
+
const { totalWeek } = getMonthInfo(year, month, startWeekDay || "monday");
|
|
668
|
+
return totalWeek.length * 48 + 34;
|
|
669
|
+
};
|
|
670
|
+
const renderMonthCalendars = () => {
|
|
671
|
+
return /* @__PURE__ */ jsx12(AutoSizer, { children: ({ height, width }) => /* @__PURE__ */ jsx12(
|
|
672
|
+
List,
|
|
673
|
+
{
|
|
674
|
+
ref: listRef,
|
|
675
|
+
width,
|
|
676
|
+
height: height - 36,
|
|
677
|
+
itemCount: rowCount,
|
|
678
|
+
itemSize: getItemSize,
|
|
679
|
+
children: Row
|
|
680
|
+
}
|
|
681
|
+
) });
|
|
682
|
+
};
|
|
683
|
+
const generateWeekDay = () => {
|
|
684
|
+
const arrWeekDay = getWeekDay(startWeekDay || "monday", weekDayFormat);
|
|
685
|
+
return arrWeekDay.map((day, index) => /* @__PURE__ */ jsx12("div", { className: "weekday", children: day }, index));
|
|
686
|
+
};
|
|
687
|
+
return /* @__PURE__ */ jsx12("div", { className: "calendar-wrapper", children: /* @__PURE__ */ jsxs5("div", { className: "calendar-content", children: [
|
|
688
|
+
/* @__PURE__ */ jsx12("div", { className: "weekdays mobile", children: generateWeekDay() }),
|
|
689
|
+
renderMonthCalendars()
|
|
690
|
+
] }) });
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// src/lib/components/DatePicker/DialogContentDesktop.tsx
|
|
694
|
+
import {
|
|
695
|
+
useEffect as useEffect6,
|
|
696
|
+
useState as useState5,
|
|
697
|
+
useRef as useRef3,
|
|
698
|
+
useCallback as useCallback3,
|
|
699
|
+
useMemo
|
|
700
|
+
} from "react";
|
|
701
|
+
import cx5 from "classnames";
|
|
702
|
+
import dayjs7 from "dayjs";
|
|
703
|
+
import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
704
|
+
var useClientSide2 = () => {
|
|
705
|
+
const [isClient, setIsClient] = useState5(false);
|
|
706
|
+
useEffect6(() => {
|
|
707
|
+
setIsClient(true);
|
|
708
|
+
}, []);
|
|
709
|
+
return isClient;
|
|
710
|
+
};
|
|
711
|
+
var DialogContentDesktop = ({
|
|
712
|
+
dateChanged = null
|
|
713
|
+
}) => {
|
|
714
|
+
const isClient = useClientSide2();
|
|
715
|
+
const containerRef = useRef3(null);
|
|
716
|
+
const tooltipRef = useRef3(null);
|
|
717
|
+
const [translateAmount, setTranslateAmount] = useState5(0);
|
|
718
|
+
const [monthArray, setMonthArray] = useState5([]);
|
|
719
|
+
const [focusDate, setFocusDate] = useState5(null);
|
|
720
|
+
const [disablePrev, setDisablePrev] = useState5(false);
|
|
721
|
+
const [disableNext, setDisableNext] = useState5(false);
|
|
722
|
+
const [wrapperWidth, setWrapperWidth] = useState5(0);
|
|
723
|
+
const [dayValue, setDayValue] = useState5(null);
|
|
724
|
+
const [isAnimating, setIsAnimating] = useState5(false);
|
|
725
|
+
const { fromDate } = useDateState();
|
|
726
|
+
const { minDate, maxDate, singleCalendar } = useDatePickerConfig();
|
|
727
|
+
const { complsOpen } = useUIState();
|
|
728
|
+
const { tooltip } = useDisplayCustomization();
|
|
729
|
+
const getArrayMonth = useCallback3((date) => [
|
|
730
|
+
date.subtract(1, "month"),
|
|
731
|
+
date,
|
|
732
|
+
date.add(1, "month"),
|
|
733
|
+
date.add(2, "month")
|
|
734
|
+
], []);
|
|
735
|
+
useEffect6(() => {
|
|
736
|
+
if (!isClient || !containerRef.current) return;
|
|
737
|
+
const updateDimensions = () => {
|
|
738
|
+
const width = containerRef.current.offsetWidth;
|
|
739
|
+
const style = window.getComputedStyle(containerRef.current);
|
|
740
|
+
const translateValue = singleCalendar ? width + parseInt(style.marginLeft) - 8 : width / 2;
|
|
741
|
+
setWrapperWidth(translateValue);
|
|
742
|
+
};
|
|
743
|
+
updateDimensions();
|
|
744
|
+
const resizeObserver = new ResizeObserver(updateDimensions);
|
|
745
|
+
resizeObserver.observe(containerRef.current);
|
|
746
|
+
return () => resizeObserver.disconnect();
|
|
747
|
+
}, [isClient, singleCalendar]);
|
|
748
|
+
useEffect6(() => {
|
|
749
|
+
setFocusDate(fromDate ?? dayjs7());
|
|
750
|
+
}, [complsOpen, fromDate]);
|
|
751
|
+
useEffect6(() => {
|
|
752
|
+
if (!focusDate) return;
|
|
753
|
+
const minDayjs = minDate ? dayjs7(minDate) : null;
|
|
754
|
+
const maxDayjs = maxDate ? dayjs7(maxDate) : null;
|
|
755
|
+
setDisablePrev(
|
|
756
|
+
Boolean(
|
|
757
|
+
minDayjs && focusDate.isBefore(minDayjs.add(1, "month"), "month")
|
|
758
|
+
)
|
|
759
|
+
);
|
|
760
|
+
setDisableNext(
|
|
761
|
+
Boolean(
|
|
762
|
+
maxDayjs && focusDate.isAfter(maxDayjs.subtract(2, "month"), "month")
|
|
763
|
+
)
|
|
764
|
+
);
|
|
765
|
+
setMonthArray(getArrayMonth(focusDate));
|
|
766
|
+
}, [focusDate, minDate, maxDate, getArrayMonth]);
|
|
767
|
+
useEffect6(() => {
|
|
768
|
+
if (!dateChanged || !focusDate) return;
|
|
769
|
+
const monthDiff = dateChanged.diff(focusDate, "month");
|
|
770
|
+
if (monthDiff < -1) decreaseCurrentMonth();
|
|
771
|
+
if (monthDiff > 1) increaseCurrentMonth();
|
|
772
|
+
}, [dateChanged, focusDate]);
|
|
773
|
+
const handleMonthChange = useCallback3((direction) => () => {
|
|
774
|
+
if (direction === "next" && disableNext || direction === "prev" && disablePrev || isAnimating) return;
|
|
775
|
+
setIsAnimating(true);
|
|
776
|
+
setTranslateAmount(direction === "next" ? -wrapperWidth : wrapperWidth);
|
|
777
|
+
const timer = setTimeout(() => {
|
|
778
|
+
setFocusDate((prev) => {
|
|
779
|
+
const newDate = direction === "next" ? prev.add(1, "month") : prev.subtract(1, "month");
|
|
780
|
+
setMonthArray(getArrayMonth(newDate));
|
|
781
|
+
return newDate;
|
|
782
|
+
});
|
|
783
|
+
setTranslateAmount(0);
|
|
784
|
+
setIsAnimating(false);
|
|
785
|
+
}, 200);
|
|
786
|
+
return () => clearTimeout(timer);
|
|
787
|
+
}, [disableNext, disablePrev, isAnimating, wrapperWidth, getArrayMonth]);
|
|
788
|
+
const [increaseCurrentMonth, decreaseCurrentMonth] = useMemo(
|
|
789
|
+
() => [handleMonthChange("next"), handleMonthChange("prev")],
|
|
790
|
+
[handleMonthChange]
|
|
791
|
+
);
|
|
792
|
+
const focusOnCalendar = useCallback3(() => {
|
|
793
|
+
if (!isClient || !containerRef.current) return;
|
|
794
|
+
const selector = ".day.selected, .month-calendar:not(.hidden) .day:not(.disabled)";
|
|
795
|
+
const focusTarget = containerRef.current.querySelector(selector);
|
|
796
|
+
focusTarget?.focus();
|
|
797
|
+
}, [isClient]);
|
|
798
|
+
const handleKeyDown = useCallback3((e) => {
|
|
799
|
+
const target = e.target;
|
|
800
|
+
const dayIndex = target.getAttribute("data-day-index");
|
|
801
|
+
if (!dayIndex) return;
|
|
802
|
+
e.preventDefault();
|
|
803
|
+
const calendarContainer = target.closest(".calendar-wrapper");
|
|
804
|
+
const dateValue = parseInt(target.dataset.dateValue ?? "0");
|
|
805
|
+
const date = dayjs7(dateValue);
|
|
806
|
+
const lastDate = date.endOf("month").date();
|
|
807
|
+
let newIndex = parseInt(dayIndex);
|
|
808
|
+
switch (e.key) {
|
|
809
|
+
case "ArrowLeft":
|
|
810
|
+
newIndex--;
|
|
811
|
+
break;
|
|
812
|
+
case "ArrowUp":
|
|
813
|
+
newIndex -= 7;
|
|
814
|
+
break;
|
|
815
|
+
case "ArrowRight":
|
|
816
|
+
newIndex++;
|
|
817
|
+
break;
|
|
818
|
+
case "ArrowDown":
|
|
819
|
+
newIndex += 7;
|
|
820
|
+
break;
|
|
821
|
+
case " ":
|
|
822
|
+
target.click();
|
|
823
|
+
return;
|
|
824
|
+
default:
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (newIndex > 0 && newIndex <= lastDate) {
|
|
828
|
+
calendarContainer?.querySelector(`[data-day-index="${newIndex}"]`)?.focus();
|
|
829
|
+
} else {
|
|
830
|
+
const newDate = date.add(newIndex - parseInt(dayIndex), "day");
|
|
831
|
+
const monthDiff = newDate.diff(focusDate, "month");
|
|
832
|
+
if (monthDiff > 1 && !disableNext) increaseCurrentMonth();
|
|
833
|
+
if (monthDiff < 0 && !disablePrev) decreaseCurrentMonth();
|
|
834
|
+
setTimeout(() => {
|
|
835
|
+
calendarContainer?.querySelector(
|
|
836
|
+
`[data-month-index="${newDate.month() + 1}"] [data-day-index="${newDate.date()}"]`
|
|
837
|
+
)?.focus();
|
|
838
|
+
}, 200);
|
|
839
|
+
}
|
|
840
|
+
}, [focusDate, disableNext, disablePrev, increaseCurrentMonth, decreaseCurrentMonth]);
|
|
841
|
+
const renderTooltip = useMemo(() => {
|
|
842
|
+
if (!tooltip || !isClient) return null;
|
|
843
|
+
const content = typeof tooltip === "function" ? tooltip(dayValue?.toDate() ?? /* @__PURE__ */ new Date()) : tooltip;
|
|
844
|
+
return /* @__PURE__ */ jsx13("div", { id: "day-tooltip", className: "tooltip-text", ref: tooltipRef, children: content });
|
|
845
|
+
}, [tooltip, dayValue, isClient]);
|
|
846
|
+
const calendarMonths = useMemo(
|
|
847
|
+
() => monthArray.map((date, index) => {
|
|
848
|
+
const isVisible = index === 1 || index === 2;
|
|
849
|
+
const isSlidingNext = isAnimating && translateAmount < 0 && index === 3;
|
|
850
|
+
const isSlidingPrev = isAnimating && translateAmount > 0 && index === 0;
|
|
851
|
+
return /* @__PURE__ */ jsx13(
|
|
852
|
+
MonthCalendar,
|
|
853
|
+
{
|
|
854
|
+
hidden: !isVisible && !isSlidingNext && !isSlidingPrev,
|
|
855
|
+
isAnimating: isSlidingNext || isSlidingPrev,
|
|
856
|
+
month: date.month(),
|
|
857
|
+
year: date.year(),
|
|
858
|
+
handleHoverDay: setDayValue,
|
|
859
|
+
ref: tooltipRef,
|
|
860
|
+
className: cx5({ "slide-next": isSlidingNext, "slide-prev": isSlidingPrev })
|
|
861
|
+
},
|
|
862
|
+
`${date.year()}-${date.month()}`
|
|
863
|
+
);
|
|
864
|
+
}),
|
|
865
|
+
[monthArray, isAnimating, translateAmount]
|
|
866
|
+
);
|
|
867
|
+
return /* @__PURE__ */ jsxs6("div", { className: "relative", children: [
|
|
868
|
+
renderTooltip,
|
|
869
|
+
/* @__PURE__ */ jsxs6(
|
|
870
|
+
"div",
|
|
871
|
+
{
|
|
872
|
+
className: cx5("calendar-wrapper", { single: singleCalendar }),
|
|
873
|
+
ref: containerRef,
|
|
874
|
+
onKeyDown: handleKeyDown,
|
|
875
|
+
role: "grid",
|
|
876
|
+
"aria-label": "Calendar",
|
|
877
|
+
children: [
|
|
878
|
+
/* @__PURE__ */ jsx13(
|
|
879
|
+
"div",
|
|
880
|
+
{
|
|
881
|
+
className: cx5("calendar-content", { isAnimating }),
|
|
882
|
+
style: { transform: `translateX(${translateAmount}px)` },
|
|
883
|
+
children: calendarMonths
|
|
884
|
+
}
|
|
885
|
+
),
|
|
886
|
+
/* @__PURE__ */ jsxs6("div", { className: "calendar-flippers", children: [
|
|
887
|
+
/* @__PURE__ */ jsx13(
|
|
888
|
+
"button",
|
|
889
|
+
{
|
|
890
|
+
className: cx5("flipper-button", { disabled: disablePrev }),
|
|
891
|
+
onClick: decreaseCurrentMonth,
|
|
892
|
+
onKeyDown: (e) => e.key === " " && decreaseCurrentMonth(),
|
|
893
|
+
disabled: disablePrev,
|
|
894
|
+
"aria-label": "Previous month",
|
|
895
|
+
children: /* @__PURE__ */ jsx13(prev_default, { viewBox: "0 0 24 24" })
|
|
896
|
+
}
|
|
897
|
+
),
|
|
898
|
+
/* @__PURE__ */ jsx13(
|
|
899
|
+
"button",
|
|
900
|
+
{
|
|
901
|
+
className: cx5("flipper-button", { disabled: disableNext }),
|
|
902
|
+
onClick: increaseCurrentMonth,
|
|
903
|
+
onKeyDown: (e) => e.key === " " && increaseCurrentMonth(),
|
|
904
|
+
disabled: disableNext,
|
|
905
|
+
"aria-label": "Next month",
|
|
906
|
+
onBlur: focusOnCalendar,
|
|
907
|
+
children: /* @__PURE__ */ jsx13(next_default, { viewBox: "0 0 24 24" })
|
|
908
|
+
}
|
|
909
|
+
)
|
|
910
|
+
] })
|
|
911
|
+
]
|
|
912
|
+
}
|
|
913
|
+
)
|
|
914
|
+
] });
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
// src/lib/components/DatePicker/Dialog.tsx
|
|
918
|
+
import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
919
|
+
var Dialog = ({
|
|
920
|
+
containerRef: externalRef
|
|
921
|
+
}) => {
|
|
922
|
+
const [hideAnimation, setHideAnimation] = useState6(false);
|
|
923
|
+
const [dateChanged, setDateChanged] = useState6(null);
|
|
924
|
+
const defaultRef = useRef4(null);
|
|
925
|
+
const containerRef = externalRef || defaultRef;
|
|
926
|
+
const {
|
|
927
|
+
handleChangeDate,
|
|
928
|
+
handleReset
|
|
929
|
+
} = useDateState();
|
|
930
|
+
const {
|
|
931
|
+
singleCalendar,
|
|
932
|
+
expandDirection
|
|
933
|
+
} = useDatePickerConfig();
|
|
934
|
+
const {
|
|
935
|
+
complsOpen,
|
|
936
|
+
isMobile,
|
|
937
|
+
toggleDialog
|
|
938
|
+
} = useUIState();
|
|
939
|
+
const {
|
|
940
|
+
hideDialogHeader,
|
|
941
|
+
hideDialogFooter
|
|
942
|
+
} = useDisplayCustomization();
|
|
943
|
+
const onChangeDate = (date, type) => {
|
|
944
|
+
setDateChanged(date);
|
|
945
|
+
handleChangeDate(date, type);
|
|
946
|
+
};
|
|
947
|
+
useEffect7(() => {
|
|
948
|
+
if (complsOpen && !hideAnimation) {
|
|
949
|
+
setHideAnimation(true);
|
|
950
|
+
}
|
|
951
|
+
if (complsOpen) {
|
|
952
|
+
setTimeout(() => {
|
|
953
|
+
const startDateInput = containerRef.current?.querySelector(
|
|
954
|
+
"#start-date-input-button"
|
|
955
|
+
);
|
|
956
|
+
if (startDateInput) {
|
|
957
|
+
startDateInput.focus();
|
|
958
|
+
}
|
|
959
|
+
}, 50);
|
|
960
|
+
}
|
|
961
|
+
}, [complsOpen, containerRef, hideAnimation]);
|
|
962
|
+
return /* @__PURE__ */ jsxs7(
|
|
963
|
+
"div",
|
|
964
|
+
{
|
|
965
|
+
className: cx6("dialog-date-picker", {
|
|
966
|
+
"open": complsOpen,
|
|
967
|
+
"hide": !complsOpen && hideAnimation,
|
|
968
|
+
"single": singleCalendar && !isMobile,
|
|
969
|
+
"expand-left": expandDirection === "left",
|
|
970
|
+
"expand-right": expandDirection === "right"
|
|
971
|
+
}),
|
|
972
|
+
ref: containerRef,
|
|
973
|
+
children: [
|
|
974
|
+
!hideDialogHeader && /* @__PURE__ */ jsxs7("div", { className: "dialog-header", children: [
|
|
975
|
+
/* @__PURE__ */ jsx14(
|
|
976
|
+
"button",
|
|
977
|
+
{
|
|
978
|
+
type: "button",
|
|
979
|
+
className: "btn-outline back-button",
|
|
980
|
+
onClick: toggleDialog,
|
|
981
|
+
children: /* @__PURE__ */ jsx14(back_default, { viewBox: "0 0 492 492" })
|
|
982
|
+
}
|
|
983
|
+
),
|
|
984
|
+
/* @__PURE__ */ jsx14(
|
|
985
|
+
DateInputGroup,
|
|
986
|
+
{
|
|
987
|
+
showIcon: true,
|
|
988
|
+
nonFocusable: !complsOpen
|
|
989
|
+
}
|
|
990
|
+
),
|
|
991
|
+
/* @__PURE__ */ jsx14(
|
|
992
|
+
"button",
|
|
993
|
+
{
|
|
994
|
+
type: "button",
|
|
995
|
+
className: "btn-outline reset-button",
|
|
996
|
+
onClick: handleReset,
|
|
997
|
+
children: "Reset"
|
|
998
|
+
}
|
|
999
|
+
)
|
|
1000
|
+
] }),
|
|
1001
|
+
/* @__PURE__ */ jsx14("div", { className: "dialog-content", children: isMobile ? /* @__PURE__ */ jsx14(DialogContentMobile, {}) : /* @__PURE__ */ jsx14(
|
|
1002
|
+
DialogContentDesktop,
|
|
1003
|
+
{
|
|
1004
|
+
dateChanged
|
|
1005
|
+
}
|
|
1006
|
+
) }),
|
|
1007
|
+
!hideDialogFooter && /* @__PURE__ */ jsxs7("div", { className: "dialog-footer", children: [
|
|
1008
|
+
/* @__PURE__ */ jsx14(
|
|
1009
|
+
"button",
|
|
1010
|
+
{
|
|
1011
|
+
type: "button",
|
|
1012
|
+
className: "submit-button",
|
|
1013
|
+
onClick: toggleDialog,
|
|
1014
|
+
tabIndex: 0,
|
|
1015
|
+
children: "Done"
|
|
1016
|
+
}
|
|
1017
|
+
),
|
|
1018
|
+
/* @__PURE__ */ jsx14(
|
|
1019
|
+
"button",
|
|
1020
|
+
{
|
|
1021
|
+
type: "button",
|
|
1022
|
+
className: "btn-outline reset-button mobile",
|
|
1023
|
+
onClick: handleReset,
|
|
1024
|
+
children: "Reset"
|
|
1025
|
+
}
|
|
1026
|
+
)
|
|
1027
|
+
] })
|
|
1028
|
+
]
|
|
1029
|
+
}
|
|
1030
|
+
);
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
// src/lib/components/DatePicker/BaseDatePicker.tsx
|
|
1034
|
+
import { jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1035
|
+
dayjs8.extend(localeData);
|
|
1036
|
+
var BaseDatePicker = ({
|
|
1037
|
+
startDate = null,
|
|
1038
|
+
endDate = null,
|
|
1039
|
+
className = "",
|
|
1040
|
+
disabled = false,
|
|
1041
|
+
startDatePlaceholder,
|
|
1042
|
+
endDatePlaceholder,
|
|
1043
|
+
onChange,
|
|
1044
|
+
onFocus = () => {
|
|
1045
|
+
},
|
|
1046
|
+
startWeekDay = "monday",
|
|
1047
|
+
minDate = null,
|
|
1048
|
+
maxDate = null,
|
|
1049
|
+
weekDayFormat = "dd",
|
|
1050
|
+
dateFormat = "",
|
|
1051
|
+
monthFormat = "",
|
|
1052
|
+
highlightToday = false,
|
|
1053
|
+
dateInputSeperator = null,
|
|
1054
|
+
hideDialogHeader = false,
|
|
1055
|
+
hideDialogFooter = false,
|
|
1056
|
+
hideDialogAfterSelectEndDate = false,
|
|
1057
|
+
isOpen = false,
|
|
1058
|
+
onCloseCalendar,
|
|
1059
|
+
tooltip = "",
|
|
1060
|
+
subTextDict = null,
|
|
1061
|
+
expandDirection = "right",
|
|
1062
|
+
locale = "en",
|
|
1063
|
+
isSingle = false,
|
|
1064
|
+
singleCalendar = false
|
|
1065
|
+
}) => {
|
|
1066
|
+
const [complsOpen, setComplsOpen] = useState7(isOpen);
|
|
1067
|
+
const [inputFocus, setInputFocus] = useState7(
|
|
1068
|
+
isSingle ? "from" : null
|
|
1069
|
+
);
|
|
1070
|
+
const [fromDate, setFromDate] = useState7(
|
|
1071
|
+
startDate ? dayjs8(startDate) : void 0
|
|
1072
|
+
);
|
|
1073
|
+
const [toDate, setToDate] = useState7(
|
|
1074
|
+
endDate ? dayjs8(endDate) : void 0
|
|
1075
|
+
);
|
|
1076
|
+
const [hoverDate, setHoverDate] = useState7();
|
|
1077
|
+
const [isMobile, setIsMobile] = useState7(false);
|
|
1078
|
+
const [isFirstTime, setIsFirstTime] = useState7(false);
|
|
1079
|
+
const isClient = useClientSide();
|
|
1080
|
+
const containerRef = useRef5(null);
|
|
1081
|
+
const fromDateRef = useRef5(null);
|
|
1082
|
+
const toDateRef = useRef5(null);
|
|
1083
|
+
const handleResize = useCallback4(() => {
|
|
1084
|
+
if (!isClient) return;
|
|
1085
|
+
setIsMobile(window.innerWidth < 768);
|
|
1086
|
+
}, [isClient]);
|
|
1087
|
+
const notifyChange = () => {
|
|
1088
|
+
const _startDate = fromDateRef.current ? fromDateRef.current.toDate() : null;
|
|
1089
|
+
const _endDate = !isSingle && toDateRef.current ? toDateRef.current.toDate() : null;
|
|
1090
|
+
if (isSingle) {
|
|
1091
|
+
onChange(_startDate, null);
|
|
1092
|
+
} else {
|
|
1093
|
+
onChange(_startDate, _endDate);
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
const debounceNotifyChange = debounce(notifyChange, 20);
|
|
1097
|
+
const updateFromDate = (dateValue, shouldNotifyChange = false) => {
|
|
1098
|
+
setFromDate(dateValue || void 0);
|
|
1099
|
+
fromDateRef.current = dateValue || null;
|
|
1100
|
+
if (shouldNotifyChange) {
|
|
1101
|
+
debounceNotifyChange();
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
const updateToDate = (dateValue, shouldNotifyChange = false) => {
|
|
1105
|
+
if (!isSingle) {
|
|
1106
|
+
setToDate(dateValue || void 0);
|
|
1107
|
+
toDateRef.current = dateValue || null;
|
|
1108
|
+
if (shouldNotifyChange) {
|
|
1109
|
+
debounceNotifyChange();
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
useLayoutEffect(() => {
|
|
1114
|
+
if (!isClient) return;
|
|
1115
|
+
handleResize();
|
|
1116
|
+
window.addEventListener("resize", handleResize);
|
|
1117
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
1118
|
+
}, [isClient, handleResize]);
|
|
1119
|
+
useEffect8(() => {
|
|
1120
|
+
if (!isClient) return;
|
|
1121
|
+
setIsFirstTime(true);
|
|
1122
|
+
const handleDocumentClick = (e) => {
|
|
1123
|
+
if (containerRef.current && e.target instanceof Node && !containerRef.current.contains(e.target) && window.innerWidth >= 768) {
|
|
1124
|
+
setComplsOpen(false);
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
document.addEventListener("click", handleDocumentClick);
|
|
1128
|
+
return () => document.removeEventListener("click", handleDocumentClick);
|
|
1129
|
+
}, [isClient]);
|
|
1130
|
+
useEffect8(() => {
|
|
1131
|
+
const _startDateJs = startDate ? dayjs8(startDate) : null;
|
|
1132
|
+
fromDateRef.current = _startDateJs;
|
|
1133
|
+
updateFromDate(_startDateJs, false);
|
|
1134
|
+
}, [startDate]);
|
|
1135
|
+
useEffect8(() => {
|
|
1136
|
+
if (!isSingle) {
|
|
1137
|
+
const _endDateJs = endDate ? dayjs8(endDate) : null;
|
|
1138
|
+
toDateRef.current = _endDateJs;
|
|
1139
|
+
updateToDate(_endDateJs, false);
|
|
1140
|
+
}
|
|
1141
|
+
}, [endDate, isSingle]);
|
|
1142
|
+
useEffect8(() => {
|
|
1143
|
+
if (!complsOpen && isFirstTime) {
|
|
1144
|
+
const _startDate = fromDateRef.current?.toDate() || null;
|
|
1145
|
+
const _endDate = toDateRef.current?.toDate() || null;
|
|
1146
|
+
if (isSingle) {
|
|
1147
|
+
onCloseCalendar(_startDate, null);
|
|
1148
|
+
} else {
|
|
1149
|
+
onCloseCalendar(_startDate, _endDate);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}, [complsOpen, isFirstTime, isSingle, onCloseCalendar]);
|
|
1153
|
+
useEffect8(() => {
|
|
1154
|
+
setComplsOpen(isOpen);
|
|
1155
|
+
}, [isOpen]);
|
|
1156
|
+
useEffect8(() => {
|
|
1157
|
+
if (isFirstTime) {
|
|
1158
|
+
const input = inputFocus === "from" ? "Start Date" : inputFocus === "to" ? "End Date" : "";
|
|
1159
|
+
onFocus(input);
|
|
1160
|
+
}
|
|
1161
|
+
}, [inputFocus, isFirstTime, onFocus]);
|
|
1162
|
+
const toggleDialog = () => {
|
|
1163
|
+
setComplsOpen(!complsOpen);
|
|
1164
|
+
};
|
|
1165
|
+
const handleClickDateInput = (focusInput) => {
|
|
1166
|
+
if (disabled || !isSingle && focusInput === "to" && !fromDate) {
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
if (!complsOpen) {
|
|
1170
|
+
setComplsOpen(true);
|
|
1171
|
+
}
|
|
1172
|
+
setInputFocus(focusInput);
|
|
1173
|
+
};
|
|
1174
|
+
const onSelectDate = useCallback4(
|
|
1175
|
+
(date) => {
|
|
1176
|
+
const minDayjs = minDate ? dayjs8(minDate) : null;
|
|
1177
|
+
const maxDayjs = maxDate ? dayjs8(maxDate) : null;
|
|
1178
|
+
if (minDayjs && minDayjs.isAfter(date, "date") || maxDayjs && maxDayjs.isBefore(date, "date")) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
if (isSingle) {
|
|
1182
|
+
updateFromDate(date, true);
|
|
1183
|
+
if (hideDialogAfterSelectEndDate) {
|
|
1184
|
+
setTimeout(() => setComplsOpen(false), 50);
|
|
1185
|
+
}
|
|
1186
|
+
} else if (inputFocus === "from" || fromDate && date.isBefore(fromDate, "date")) {
|
|
1187
|
+
updateFromDate(date, true);
|
|
1188
|
+
if (toDate && date.isAfter(toDate, "date")) {
|
|
1189
|
+
updateToDate(null, true);
|
|
1190
|
+
}
|
|
1191
|
+
setInputFocus("to");
|
|
1192
|
+
} else {
|
|
1193
|
+
updateToDate(date, true);
|
|
1194
|
+
setInputFocus(null);
|
|
1195
|
+
if (hideDialogAfterSelectEndDate) {
|
|
1196
|
+
setTimeout(() => setComplsOpen(false), 50);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
},
|
|
1200
|
+
[
|
|
1201
|
+
minDate,
|
|
1202
|
+
maxDate,
|
|
1203
|
+
isSingle,
|
|
1204
|
+
hideDialogAfterSelectEndDate,
|
|
1205
|
+
inputFocus,
|
|
1206
|
+
fromDate,
|
|
1207
|
+
toDate
|
|
1208
|
+
]
|
|
1209
|
+
);
|
|
1210
|
+
const onHoverDate = (date) => {
|
|
1211
|
+
setHoverDate(date);
|
|
1212
|
+
};
|
|
1213
|
+
const handleReset = () => {
|
|
1214
|
+
setHoverDate(void 0);
|
|
1215
|
+
updateFromDate(null, true);
|
|
1216
|
+
if (!isSingle) {
|
|
1217
|
+
updateToDate(null, true);
|
|
1218
|
+
}
|
|
1219
|
+
setInputFocus("from");
|
|
1220
|
+
};
|
|
1221
|
+
const handleChangeDate = useCallback4(
|
|
1222
|
+
(date, type) => {
|
|
1223
|
+
const minDayjs = minDate ? dayjs8(minDate) : null;
|
|
1224
|
+
const maxDayjs = maxDate ? dayjs8(maxDate) : null;
|
|
1225
|
+
if (minDayjs && minDayjs.isAfter(date, "date") || maxDayjs && maxDayjs.isBefore(date, "date")) {
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
if (type === "from" || isSingle) {
|
|
1229
|
+
setInputFocus("from");
|
|
1230
|
+
updateFromDate(date, true);
|
|
1231
|
+
if (!isSingle && toDate && date.isAfter(toDate, "date")) {
|
|
1232
|
+
updateToDate(null, true);
|
|
1233
|
+
}
|
|
1234
|
+
} else {
|
|
1235
|
+
setInputFocus("to");
|
|
1236
|
+
updateToDate(date, true);
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1239
|
+
[minDate, maxDate, isSingle, toDate, inputFocus]
|
|
1240
|
+
);
|
|
1241
|
+
const dateState = {
|
|
1242
|
+
fromDate,
|
|
1243
|
+
toDate,
|
|
1244
|
+
hoverDate,
|
|
1245
|
+
inputFocus,
|
|
1246
|
+
onSelectDate,
|
|
1247
|
+
onHoverDate,
|
|
1248
|
+
handleChangeDate,
|
|
1249
|
+
handleReset,
|
|
1250
|
+
handleClickDateInput
|
|
1251
|
+
};
|
|
1252
|
+
const config = {
|
|
1253
|
+
isSingle,
|
|
1254
|
+
startWeekDay,
|
|
1255
|
+
minDate: minDate ? dayjs8(minDate).toDate() : null,
|
|
1256
|
+
maxDate: maxDate ? dayjs8(maxDate).toDate() : null,
|
|
1257
|
+
weekDayFormat,
|
|
1258
|
+
dateFormat,
|
|
1259
|
+
monthFormat,
|
|
1260
|
+
highlightToday,
|
|
1261
|
+
singleCalendar,
|
|
1262
|
+
expandDirection,
|
|
1263
|
+
locale
|
|
1264
|
+
};
|
|
1265
|
+
const uiState = {
|
|
1266
|
+
complsOpen,
|
|
1267
|
+
isMobile,
|
|
1268
|
+
disabled,
|
|
1269
|
+
toggleDialog
|
|
1270
|
+
};
|
|
1271
|
+
const display = {
|
|
1272
|
+
startDatePlaceholder,
|
|
1273
|
+
endDatePlaceholder,
|
|
1274
|
+
dateInputSeperator,
|
|
1275
|
+
hideDialogHeader,
|
|
1276
|
+
hideDialogFooter,
|
|
1277
|
+
hideDialogAfterSelectEndDate,
|
|
1278
|
+
tooltip,
|
|
1279
|
+
subTextDict
|
|
1280
|
+
};
|
|
1281
|
+
return /* @__PURE__ */ jsx15("div", { className: "react-google-flight-datepicker", children: /* @__PURE__ */ jsx15(
|
|
1282
|
+
"div",
|
|
1283
|
+
{
|
|
1284
|
+
className: cx7("date-picker", className, {
|
|
1285
|
+
disabled
|
|
1286
|
+
}),
|
|
1287
|
+
ref: containerRef,
|
|
1288
|
+
children: /* @__PURE__ */ jsxs8(
|
|
1289
|
+
DatePickerProvider,
|
|
1290
|
+
{
|
|
1291
|
+
dateState,
|
|
1292
|
+
config,
|
|
1293
|
+
uiState,
|
|
1294
|
+
display,
|
|
1295
|
+
locale,
|
|
1296
|
+
children: [
|
|
1297
|
+
/* @__PURE__ */ jsx15(DateInputGroup, {}),
|
|
1298
|
+
/* @__PURE__ */ jsx15(DialogWrapper_default, { children: /* @__PURE__ */ jsx15(Dialog, {}) })
|
|
1299
|
+
]
|
|
1300
|
+
}
|
|
1301
|
+
)
|
|
1302
|
+
}
|
|
1303
|
+
) });
|
|
1304
|
+
};
|
|
1305
|
+
var BaseDatePicker_default = BaseDatePicker;
|
|
1306
|
+
|
|
1307
|
+
// src/lib/components/DatePicker/ClientOnly.tsx
|
|
1308
|
+
import { useState as useState8, useEffect as useEffect9 } from "react";
|
|
1309
|
+
import { Fragment, jsx as jsx16 } from "react/jsx-runtime";
|
|
1310
|
+
var ClientOnly = ({ children }) => {
|
|
1311
|
+
const [hasMounted, setHasMounted] = useState8(false);
|
|
1312
|
+
useEffect9(() => {
|
|
1313
|
+
setHasMounted(true);
|
|
1314
|
+
}, []);
|
|
1315
|
+
if (!hasMounted) return null;
|
|
1316
|
+
return /* @__PURE__ */ jsx16(Fragment, { children });
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
// src/lib/components/DatePicker/RangeDatePicker.tsx
|
|
1320
|
+
import { jsx as jsx17 } from "react/jsx-runtime";
|
|
1321
|
+
var RangeDatePicker = ({
|
|
1322
|
+
onChange = () => {
|
|
1323
|
+
},
|
|
1324
|
+
onCloseCalendar = () => {
|
|
1325
|
+
},
|
|
1326
|
+
startDatePlaceholder = "Start date",
|
|
1327
|
+
endDatePlaceholder = "End date",
|
|
1328
|
+
...props
|
|
1329
|
+
}) => /* @__PURE__ */ jsx17(ClientOnly, { children: /* @__PURE__ */ jsx17(
|
|
1330
|
+
BaseDatePicker_default,
|
|
1331
|
+
{
|
|
1332
|
+
...props,
|
|
1333
|
+
isSingle: false,
|
|
1334
|
+
startDate: props.startDate,
|
|
1335
|
+
endDate: props.endDate,
|
|
1336
|
+
startDatePlaceholder,
|
|
1337
|
+
endDatePlaceholder,
|
|
1338
|
+
onChange,
|
|
1339
|
+
onCloseCalendar
|
|
1340
|
+
}
|
|
1341
|
+
) });
|
|
1342
|
+
|
|
1343
|
+
// src/lib/components/DatePicker/SingleDatePicker.tsx
|
|
1344
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
1345
|
+
var SingleDatePicker = ({
|
|
1346
|
+
onChange = () => {
|
|
1347
|
+
},
|
|
1348
|
+
onCloseCalendar = () => {
|
|
1349
|
+
},
|
|
1350
|
+
startDatePlaceholder = "Date",
|
|
1351
|
+
...props
|
|
1352
|
+
}) => /* @__PURE__ */ jsx18(ClientOnly, { children: /* @__PURE__ */ jsx18(
|
|
1353
|
+
BaseDatePicker_default,
|
|
1354
|
+
{
|
|
1355
|
+
...props,
|
|
1356
|
+
endDate: null,
|
|
1357
|
+
isSingle: true,
|
|
1358
|
+
startDate: props.startDate,
|
|
1359
|
+
startDatePlaceholder,
|
|
1360
|
+
onChange: (date) => onChange(date),
|
|
1361
|
+
onCloseCalendar: (date) => onCloseCalendar(date)
|
|
1362
|
+
}
|
|
1363
|
+
) });
|
|
1364
|
+
export {
|
|
1365
|
+
RangeDatePicker,
|
|
1366
|
+
SingleDatePicker
|
|
1367
|
+
};
|
|
2
1368
|
//# sourceMappingURL=index.mjs.map
|