@televet/kibble-ui 4.0.0-beta.111 → 4.0.0-beta.112
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/chunks/{datePicker.component-C2wNXnG7.js → datePicker.component--6-jJXIm.js} +2 -2
- package/dist/chunks/{datePicker.component-C2wNXnG7.js.map → datePicker.component--6-jJXIm.js.map} +1 -1
- package/dist/chunks/{datePicker.component-DQXEQ7Fw.js → datePicker.component-B6RVRikg.js} +2 -2
- package/dist/chunks/{datePicker.component-DQXEQ7Fw.js.map → datePicker.component-B6RVRikg.js.map} +1 -1
- package/dist/cjs/components/DatePicker/index.cjs +1 -1
- package/dist/cjs/components/index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/components/DatePicker/index.js +1 -1
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
|
@@ -11,5 +11,5 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
11
11
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
12
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */function Y(e,t){y(2,arguments);var n=D(e),r=M(t);return isNaN(r)?new Date(NaN):(r&&n.setDate(n.getDate()+r),n)}function se(e,t){y(1,arguments);var n=e||{},r=D(n.start),a=D(n.end),o=a.getTime();if(!(r.getTime()<=o))throw new RangeError("Invalid interval");var i=[],s=r;s.setHours(0,0,0,0);var u=1;if(isNaN(u))throw new RangeError("`options.step` must be a number greater than 1");for(;s.getTime()<=o;)i.push(D(s)),s.setDate(s.getDate()+u),s.setHours(0,0,0,0);return i}function Qn(e,t){y(1,arguments);var n={},r=n.locale,a=r&&r.options&&r.options.weekStartsOn,o=a==null?0:M(a),i=n.weekStartsOn==null?o:M(n.weekStartsOn);if(!(i>=0&&i<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var s=D(e),u=s.getDay(),d=6+(u<i?-7:0)-(u-i);return s.setDate(s.getDate()+d),s.setHours(23,59,59,999),s}function Ct(e){y(1,arguments);var t=D(e);return t.setDate(1),t.setHours(0,0,0,0),t}function Gn(e,t){y(1,arguments);var n={},r=n.locale,a=r&&r.options&&r.options.weekStartsOn,o=a==null?0:M(a),i=n.weekStartsOn==null?o:M(n.weekStartsOn);if(!(i>=0&&i<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var s=D(e),u=s.getDay(),d=(u<i?7:0)+u-i;return s.setDate(s.getDate()-d),s.setHours(0,0,0,0),s}function Xn(e){var t=e===void 0?{}:e,n=t.firstDayOfWeek,r=n===void 0?1:n,a=t.weekdayLabelFormat,o=a===void 0?function(s){return we(s,"iiiiii")}:a,i=new Date;return se({start:Y(Gn(i),r),end:Y(Qn(i),r)}).reduce(function(s,u){return s.push(o(u)),s},[])}function _n(e){var t=e.year,n=e.month,r=e.firstDayOfWeek,a=r===void 0?1:r,o=e.dayLabelFormat,i=o===void 0?function(l){return we(l,"dd")}:o,s=new Date(t,n),u=Ct(s),d=function(l){y(1,arguments);var m=D(l),c=m.getDay();return c}(u),w=function(l){y(1,arguments);var m=D(l),c=m.getMonth();return m.setFullYear(m.getFullYear(),c+1,0),m.setHours(23,59,59,999),m}(s);return function(){for(var l=0,m=0,c=arguments.length;m<c;m++)l+=arguments[m].length;var h=Array(l),x=0;for(m=0;m<c;m++)for(var E=arguments[m],v=0,k=E.length;v<k;v++,x++)h[x]=E[v];return h}(Array.from(Array(d>=a?d-a:6-a+d+1).keys()).fill(0),se({start:u,end:w}).map(function(l){return{date:l,dayLabel:i(l)}}))}var zn=function(e){return we(e,"dd")},Kn=function(e){return we(e,"eeeeee")},Jn=function(e){return we(e,"MMMM yyyy")};function Vn(e){var t=e.year,n=e.month,r=e.firstDayOfWeek,a=r===void 0?1:r,o=e.dayLabelFormat,i=o===void 0?zn:o,s=e.weekdayLabelFormat,u=s===void 0?Kn:s,d=e.monthLabelFormat,w=d===void 0?Jn:d;return{days:b.useMemo(function(){return _n({year:t,month:n,firstDayOfWeek:a,dayLabelFormat:i})},[t,n,a,i]),weekdayLabels:b.useMemo(function(){return Xn({firstDayOfWeek:a,weekdayLabelFormat:u})},[a,u]),monthLabel:w(new Date(t,n))}}function ne(e,t){y(2,arguments);var n=D(e),r=D(t);return n.getTime()<r.getTime()}function Te(e,t){y(2,arguments);var n=D(e),r=D(t);return n.getTime()>r.getTime()}function he(e,t){y(2,arguments);var n=t||{},r=D(e).getTime(),a=D(n.start).getTime(),o=D(n.end).getTime();if(!(a<=o))throw new RangeError("Invalid interval");return r>=a&&r<=o}function Ye(e){y(1,arguments);var t=D(e);return t.setHours(0,0,0,0),t}function _(e,t){y(2,arguments);var n=Ye(e),r=Ye(t);return n.getTime()===r.getTime()}function Oe(e,t){y(2,arguments);var n=D(e),r=M(t);if(isNaN(r))return new Date(NaN);if(!r)return n;var a=n.getDate(),o=new Date(n.getTime());o.setMonth(n.getMonth()+r+1,0);var i=o.getDate();return a>=i?o:(n.setFullYear(o.getFullYear(),o.getMonth(),a),n)}var Mt=function(e,t){return e===void 0&&(e=[]),e.some(function(n){return _(t,n)})};function $n(e,t,n){return!(!t||!n)&&he(e,{start:t,end:n})}function Zn(e,t,n){return!!(t&&_(e,t)||n&&_(e,n))}function er(e,t){return!(!t||!_(e,t))}function tr(e,t){return!(!t||!_(e,t))}function nr(e){var t=e.date,n=e.minBookingDate,r=e.maxBookingDate,a=e.isDateBlockedFn,o=e.startDate,i=e.endDate,s=e.minBookingDays,u=s===void 0?1:s,d=e.unavailableDates,w=d===void 0?[]:d,l=n&&new Date(n.getFullYear(),n.getMonth(),n.getDate(),0,0,0),m=r&&new Date(r.getFullYear(),r.getMonth(),r.getDate(),0,0,0);return!!(Mt(w,t)||l&&ne(t,l)||m&&Te(t,m)||o&&!i&&u>1&&he(t,{start:o,end:Y(o,u-2)})||a&&a(t))}function Me(e){var t=Ct(e);return{year:function(n){y(1,arguments);var r=D(n),a=r.getFullYear();return a}(t),month:function(n){y(1,arguments);var r=D(n),a=r.getMonth();return a}(t),date:t}}function rr(){return Me(Ye(Date.now()))}function xe(e,t){var n=t?Me(t):rr(),r=n.date,a=[n];return e>1&&(a=Array.from(Array(e-1).keys()).reduce(function(o){return r=Oe(o[o.length-1].date,1),o.concat([Me(r)])},a)),a}function fe(e,t,n,r){var a=e[r?n>0?0:e.length-r:n>0?e.length-1:0].date;return Array.from(Array(t).keys()).reduce(function(o){return a=o.length===0?Oe(a,n):Oe(a,n>=0?1:-1),n>0?o.concat([Me(a)]):[Me(a)].concat(o)},[])}function ct(e,t,n){return e&&typeof t=="string"?we(e,t):e&&typeof t=="function"?t(e):n}function ke(e){var t=e.startDate,n=e.endDate,r=e.isDateBlocked,a=e.minBookingDays,o=e.exactMinBookingDays,i=e.minBookingDate,s=e.maxBookingDate,u=!i||!ne(t,Y(i,-1)),d=!s||!Te(Y(t,a-1),s);return!(!t||a!==1||n||r(t))||(t&&a>1&&!n&&!o||t&&a>0&&o&&u&&d||t&&a>0&&o&&!i&&!s?!se({start:t,end:Y(t,a-1)}).some(function(w){return r(w)}):!(!t||!n||o)&&!ne(n,Y(t,a-1))&&!se({start:t,end:n}).some(function(w){return r(w)}))}function ar(e){var t=e.startDate,n=e.endDate,r=e.focusedInput,a=e.minBookingDate,o=e.maxBookingDate,i=e.onDatesChange,s=e.initialVisibleMonth,u=e.exactMinBookingDays,d=u!==void 0&&u,w=e.minBookingDays,l=w===void 0?1:w,m=e.numberOfMonths,c=m===void 0?2:m,h=e.firstDayOfWeek,x=h===void 0?1:h,E=e.isDateBlocked,v=E===void 0?function(){return!1}:E,k=e.unavailableDates,T=k===void 0?[]:k,I=e.changeActiveMonthOnSelect,q=I===void 0||I,z=b.useState(function(){return xe(c,t||s||null)}),P=z[0],N=z[1],Z=b.useState(null),G=Z[0],K=Z[1],X=b.useState(t),F=X[0],B=X[1];b.useEffect(function(){return typeof window<"u"&&window.addEventListener&&window.addEventListener("keydown",H),function(){window.removeEventListener&&window.removeEventListener("keydown",H)}});var O=function(f){return Mt(T,f)||v(f)},J=function(f){B(f),(!F||F&&!_(f,F))&&N(xe(c,f))},U=function(f){return nr({date:f,minBookingDate:a,maxBookingDate:o,startDate:t,endDate:n,minBookingDays:l,isDateBlockedFn:O})};function H(f){if((f.key==="ArrowRight"||f.key==="ArrowLeft"||f.key==="ArrowDown"||f.key==="ArrowUp")&&!F){var A=P[0];J(A.date),N(xe(c,A.date))}}var ce=b.useCallback(function(){N(fe(P,c,-1)),B(null)},[P,c]),Pe=b.useCallback(function(){N(fe(P,c,-1,1)),B(null)},[P,c]),p=b.useCallback(function(){N(fe(P,c,1)),B(null)},[P,c]),de=b.useCallback(function(){N(fe(P,c,1,1)),B(null)},[P,c]),Ut=b.useCallback(function(f){N(xe(c,f)),B(null)},[c]),jt=b.useCallback(function(f){f===void 0&&(f=1),N(fe(P,c,-(12*f-c+1))),B(null)},[P,c]),Nt=b.useCallback(function(f){f===void 0&&(f=1),N(fe(P,c,12*f-c+1)),B(null)},[P,c]);return{firstDayOfWeek:x,activeMonths:P,isDateSelected:function(f){return $n(f,t,n)},isDateHovered:function(f){return function(A){var le=A.date,W=A.startDate,De=A.endDate,pe=A.isDateBlocked,L=A.hoveredDate,ee=A.minBookingDays,Re=A.exactMinBookingDays;return L&&ee>1&&Re&&he(le,{start:L,end:Y(L,ee-1)})?!se({start:L,end:Y(L,ee-1)}).some(function(re){return pe(re)}):W&&!De&&L&&he(le,{start:W,end:Y(W,ee-1)})&&_(W,L)&&ee>1?!se({start:W,end:Y(W,ee-1)}).some(function(re){return pe(re)}):!(!W||De||!L||ne(L,W)||!he(le,{start:W,end:L}))&&!se({start:W,end:L}).some(function(re){return pe(re)})}({date:f,hoveredDate:G,startDate:t,endDate:n,minBookingDays:l,exactMinBookingDays:d,isDateBlocked:O})},isFirstOrLastSelectedDate:function(f){return Zn(f,t,n)},isStartDate:function(f){return er(f,t)},isEndDate:function(f){return tr(f,n)},isDateBlocked:U,numberOfMonths:c,isDateFocused:function(f){return!!F&&_(f,F)},focusedDate:F,hoveredDate:G,onResetDates:function(){i({startDate:null,endDate:null,focusedInput:"startDate"})},onDateHover:function(f){if(f){if(f){var A=!U(f)||t&&_(f,t),le=!a||!ne(f,Y(a,-1)),W=!o||!Te(f,o),De=Y(f,l-1),pe=!a||!ne(De,a),L=!o||!Te(De,o),ee=d&&l>1&&le&&W&&pe&&L,Re=t&&!n&&!d&&le&&W,re=!(l>1&&t)||he(f,{start:t,end:Y(t,l-2)}),Ft=t&&_(f,t)&&re;A&&(ee||Re||Ft)?K(f):G!==null&&K(null)}}else K(null)},onDateSelect:function(f){(r==="endDate"||r==="startDate")&&l>0&&d&&ke({minBookingDays:l,exactMinBookingDays:d,minBookingDate:a,maxBookingDate:o,isDateBlocked:O,startDate:f,endDate:null})?i({startDate:f,endDate:Y(f,l-1),focusedInput:null}):(r==="endDate"&&t&&ne(f,t)||r==="startDate"&&n&&Te(f,n))&&!d&&ke({minBookingDays:l,isDateBlocked:O,startDate:f,endDate:null})?i({endDate:null,startDate:f,focusedInput:"endDate"}):r==="startDate"&&!d&&ke({minBookingDays:l,isDateBlocked:O,endDate:n,startDate:f})?i({endDate:n,startDate:f,focusedInput:"endDate"}):r==="startDate"&&!d&&ke({minBookingDays:l,isDateBlocked:O,endDate:null,startDate:f})?i({endDate:null,startDate:f,focusedInput:"endDate"}):r==="endDate"&&t&&!ne(f,t)&&!d&&ke({minBookingDays:l,isDateBlocked:O,startDate:t,endDate:f})&&i({startDate:t,endDate:f,focusedInput:null}),r!=="endDate"&&(!F||F&&!_(f,F))&&q&&N(xe(c,f))},onDateFocus:J,goToPreviousMonths:ce,goToPreviousMonthsByOneMonth:Pe,goToNextMonths:p,goToNextMonthsByOneMonth:de,goToDate:Ut,goToPreviousYear:jt,goToNextYear:Nt}}function or(e){var t=e.date,n=e.focusedDate,r=e.isDateSelected,a=e.isDateFocused,o=e.isFirstOrLastSelectedDate,i=e.isDateHovered,s=e.isDateBlocked,u=e.onDateSelect,d=e.onDateFocus,w=e.onDateHover,l=b.useCallback(function(){return u(t)},[t,u]),m=b.useCallback(function(){return w(t)},[t,w]),c=s(t)&&!i(t);return{tabIndex:n===null||a(t)?0:-1,isSelected:r(t),isSelectedStartOrEnd:o(t),isWithinHoverRange:i(t),disabledDate:c,onKeyDown:function(h){h.key==="ArrowRight"?d(Y(t,1)):h.key==="ArrowLeft"?d(Y(t,-1)):h.key==="ArrowUp"?d(Y(t,-7)):h.key==="ArrowDown"&&d(Y(t,7))},onClick:c?function(){}:l,onMouseEnter:m}}var We=(e=>(e.ShortDate="MM/dd/yyyy",e.LongDate="MMM dd yyyy",e.DayOfWeekDayOfMonth="eeee, MMMM do",e))(We||{}),Q=(e=>(e.StartDate="startDate",e.EndDate="endDate",e))(Q||{});const $=new Date,Le=$.getFullYear(),ir=$.getMonth(),sr=$,St=Le-100,Et=Le+5,qe=We.ShortDate,ur={dateFormat:qe,endDate:null,focusedInput:null,withDateRange:!1,maxYear:Et,minYear:St,startDate:null,onClose:()=>{throw new Error("onClose(): boolean not implemented")},setFocusedInput:()=>{throw new Error("setFocusedInput(): boolean not implemented")},focusedDate:$,firstDayOfWeek:void 0,activeMonths:[],isDateFocused:()=>{throw new Error("isDateFocused(): boolean not implemented")},isDateSelected:()=>{throw new Error("isDateSelected(): boolean not implemented")},isDateHovered:()=>{throw new Error("isDateHovered(): boolean not implemented")},isDateBlocked:()=>{throw new Error("isDateBlocked(): boolean not implemented")},isFirstOrLastSelectedDate:()=>{throw new Error("isFirstOrLastSelectedDate(): boolean not implemented")},onDateFocus:()=>{throw new Error("onDateFocus(): boolean not implemented")},onDateHover:()=>{throw new Error("onDateHover(): boolean not implemented")},onDateSelect:()=>{throw new Error("onDateSelect(): boolean not implemented")},goToPreviousMonths:()=>{throw new Error("goToPreviousMonths(): boolean not implemented")},goToNextMonths:()=>{throw new Error("goToNextMonths(): boolean not implemented")},goToDate:()=>{throw new Error("goToDate(): boolean not implemented")},clearDates:()=>{throw new Error("clearDates(): boolean not implemented")}},Pt=b.createContext(ur),ue=()=>b.useContext(Pt);function cr(e,t){const n=S.toDate(e,t?.in);return n.setHours(23,59,59,999),n}function dr(e,t,n){const r=S.toDate(e,n?.in);return isNaN(t)?S.constructFrom(e,NaN):(t&&r.setDate(r.getDate()+t),r)}function lr(e,t,n){const r=S.toDate(e,n?.in);if(isNaN(t))return S.constructFrom(e,NaN);if(!t)return r;const a=r.getDate(),o=S.constructFrom(e,r.getTime());o.setMonth(r.getMonth()+t+1,0);const i=o.getDate();return a>=i?o:(r.setFullYear(o.getFullYear(),o.getMonth(),a),r)}function fr(e,t,n){const{years:r=0,months:a=0,weeks:o=0,days:i=0,hours:s=0,minutes:u=0,seconds:d=0}=t,w=S.toDate(e,n?.in),l=a||r?lr(w,a+r*12):w,m=i||o?dr(l,i+o*7):l,c=u+s*60,x=(d+c*60)*1e3;return S.constructFrom(e,+m+x)}function Rt(e,t){return+S.toDate(e)>+S.toDate(t)}const mr=({children:e,dateFormat:t=qe,endDate:n,inputProps:r,maxDate:a,maxDaysInRange:o,maxYear:i,minDate:s,minYear:u,onDateChange:d,placement:w="bottom",startDate:l,withDateRange:m})=>{const[c,h]=b.useState({startDate:l,endDate:n||l,focusedInput:null}),x=b.useCallback(p=>{if(o&&p)return fr(p,{days:o});if(a)return a},[a,o]),E=p=>{if(!p)return;p.endDate||(p.endDate=p.startDate);const de=x(p.startDate);p.endDate&&de&&Rt(p.endDate,de)&&(p.endDate=null),p.startDate=p.startDate?S.startOfDay(p.startDate):p.startDate,p.endDate=p.endDate?cr(p.endDate):p.endDate,h({...p,focusedInput:p.focusedInput||Q.StartDate}),!m&&d&&d(p)},v=b.useCallback(({open:p})=>{h({startDate:null,endDate:null,focusedInput:p?Q.StartDate:null})},[]),{activeMonths:k,firstDayOfWeek:T,focusedDate:I,goToDate:q,goToNextMonths:z,goToPreviousMonths:P,isDateBlocked:N,isDateFocused:Z,isDateHovered:G,isDateSelected:K,isFirstOrLastSelectedDate:X,onDateFocus:F,onDateHover:B,onDateSelect:O}=ar({endDate:c.endDate,focusedInput:c.focusedInput,initialVisibleMonth:c.startDate||$,maxBookingDate:m&&c.focusedInput===Q.StartDate?void 0:x(c.startDate),minBookingDate:s,minBookingDays:1,numberOfMonths:1,onDatesChange:E,startDate:c.startDate,...!m&&{exactMinBookingDays:!0}}),J=b.useCallback(p=>{p===Q.EndDate&&c.endDate?q(c.endDate):c.startDate&&q(c.startDate)},[q,c.endDate,c.startDate]),U=b.useCallback(p=>{h(de=>({...de,focusedInput:p})),J(p)},[J]),H=()=>{r?.disabled||(!c.startDate||!m)&&U(Q.StartDate)},ce=b.useCallback(()=>{U(null),m&&d&&(console.log("onDateChange called on close"),setTimeout(()=>{console.log("onDateChange called after timeout"),d({startDate:c.startDate,endDate:c.endDate})},200))},[m,d,U,c.endDate,c.startDate]),Pe=b.useMemo(()=>k[0],[k]);return b.useEffect(()=>{h(p=>({...p,startDate:l,endDate:n||l}))},[l,n]),g.jsxRuntimeExports.jsx(Pt.Provider,{value:{activeMonth:Pe,activeMonths:k,dateFormat:t||qe,endDate:c.endDate||null,firstDayOfWeek:T,focusedDate:I||sr,focusedInput:c.focusedInput,goToDate:q,goToNextMonths:z,goToPreviousMonths:P,setFocusedInput:U,isDateBlocked:N,isDateFocused:Z,isDateHovered:G,withDateRange:m||!1,isDateSelected:K,isFirstOrLastSelectedDate:X,maxDate:a,maxYear:i||Et,minDate:s,minYear:u||St,onDateChange:d,onDateFocus:F,onDateHover:B,onDateSelect:O,startDate:c.startDate,onClose:ce,clearDates:v},children:g.jsxRuntimeExports.jsx(te.PopoverRoot,{onOpenChange:({open:p})=>{p?H():U(null)},positioning:{placement:w},onExitComplete:()=>{ce()},children:e})})};function hr(e,t){return+S.toDate(e)<+S.toDate(t)}const gr=(e,t)=>t?Rt(e,t):!0,wr=(e,t)=>t?hr(e,t):!0;function Dr({inputProps:e}){const{setFocusedInput:t,startDate:n,endDate:r,focusedInput:a,dateFormat:o,withDateRange:i,minDate:s,maxDate:u,onDateChange:d,onDateSelect:w,onClose:l}=ue(),{open:m,setOpen:c}=Be.usePopoverContext(),h=e?.size||"md",x=v=>{v.key==="Enter"&&m&&(c(!1),l(),v.preventDefault(),v.stopPropagation())},E=v=>{const k=v.target.value,T=bn(k,o,$);k.length===o.length&&S.isDate(T)&&gr(T,s)&&wr(T,u)&&w(T),!k.length&&d&&d({startDate:null,endDate:null})};return g.jsxRuntimeExports.jsxs(He.HStack,{w:"100%",className:"DatePicker__Trigger","data-testid":"kibble-datepicker-trigger",children:[g.jsxRuntimeExports.jsx(Ae.WrappedTextInput,{className:"DatePicker__Input--Start","data-testid":"kibble-datepicker-input-start",autoComplete:"off",rightElement:g.jsxRuntimeExports.jsx(Ge.Flex,{...!e?.disabled&&{onClick:()=>t(Q.StartDate)},h:"100%",align:"center",children:g.jsxRuntimeExports.jsx(Qe.Icon,{name:"calendarDate",size:h})}),value:ct(n,o,""),onChange:E,onKeyDown:x,...!e?.disabled&&{onFocus:()=>{t(Q.StartDate)}},placeholder:S.format($,o).toString(),...a===Q.StartDate&&{"data-focus":!0},...e}),i&&g.jsxRuntimeExports.jsxs(g.jsxRuntimeExports.Fragment,{children:[g.jsxRuntimeExports.jsx(mt.WrappedText,{children:" - "}),g.jsxRuntimeExports.jsx(Ae.WrappedTextInput,{className:"DatePicker__Input--End","data-testid":"kibble-datepicker-input-end",rightElement:g.jsxRuntimeExports.jsx(Ge.Flex,{...!e?.disabled&&{onClick:()=>t(Q.StartDate)},h:"100%",align:"center",children:g.jsxRuntimeExports.jsx(Qe.Icon,{name:"calendarDate",size:h})}),value:ct(r,o,""),onChange:E,...!e?.disabled&&{onFocus:()=>t(Q.EndDate)},onKeyDown:x,placeholder:S.format($,o).toString(),...a===Q.EndDate&&{"data-focus":!0},...e})]})]})}function pr({buttonText:e="Apply",onSubmit:t,hideResetButton:n}){const{startDate:r,endDate:a,onClose:o,clearDates:i}=ue(),{open:s,setOpen:u}=Be.usePopoverContext(),d=b.useCallback(()=>{u(!1),o(),t&&t({startDate:r,endDate:a})},[u,o,t,r,a]);return g.jsxRuntimeExports.jsxs(He.HStack,{w:"100%",justify:n?"end":"space-between",align:"center",borderTop:"1px",borderColor:"border.default",px:3,py:2,children:[!n&&g.jsxRuntimeExports.jsx(Ce.Button,{size:"sm",variant:"ghostNeutral",onClick:()=>i({open:s}),children:"Clear Dates"}),g.jsxRuntimeExports.jsx(Ce.Button,{size:"sm",onClick:d,children:e})]})}var br=Math.ceil,yr=Math.max;function vr(e,t,n,r){for(var a=-1,o=yr(br((t-e)/(n||1)),0),i=Array(o);o--;)i[++a]=e,e+=n;return i}function xr(e,t,n){if(!oe.isObject(n))return!1;var r=typeof t;return(r=="number"?oe.isArrayLike(n)&&oe.isIndex(t,n.length):r=="string"&&t in n)?oe.eq(n[t],e):!1}var kr=/\s/;function Tr(e){for(var t=e.length;t--&&kr.test(e.charAt(t)););return t}var Cr=/^\s+/;function Mr(e){return e&&e.slice(0,Tr(e)+1).replace(Cr,"")}var dt=NaN,Sr=/^[-+]0x[0-9a-f]+$/i,Er=/^0b[01]+$/i,Pr=/^0o[0-7]+$/i,Rr=parseInt;function Ur(e){if(typeof e=="number")return e;if(oe.isSymbol(e))return dt;if(oe.isObject(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=oe.isObject(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Mr(e);var n=Er.test(e);return n||Pr.test(e)?Rr(e.slice(2),n?2:8):Sr.test(e)?dt:+e}var jr=1/0,Nr=17976931348623157e292;function Fe(e){if(!e)return e===0?e:0;if(e=Ur(e),e===jr||e===-1/0){var t=e<0?-1:1;return t*Nr}return e===e?e:0}function Fr(e){return function(t,n,r){return r&&typeof r!="number"&&xr(t,n,r)&&(n=r=void 0),t=Fe(t),n===void 0?(n=t,t=0):n=Fe(n),r=r===void 0?t<n?1:-1:Fe(r),vr(t,n,r)}}var Yr=Fr();function Or(e,t){const n=S.toDate(e,t?.in),r=n.getFullYear(),a=n.getMonth(),o=S.constructFrom(n,0);return o.setFullYear(r,a+1,0),o.setHours(0,0,0,0),o.getDate()}function qr(e,t,n){const r=S.toDate(e,n?.in),a=r.getFullYear(),o=r.getDate(),i=S.constructFrom(e,0);i.setFullYear(a,t,15),i.setHours(0,0,0,0);const s=Or(i);return r.setMonth(t,Math.min(o,s)),r}function lt(e,t,n){let r=S.toDate(e,n?.in);return isNaN(+r)?S.constructFrom(e,NaN):(t.year!=null&&r.setFullYear(t.year),t.month!=null&&(r=qr(r,t.month)),t.date!=null&&r.setDate(t.date),t.hours!=null&&r.setHours(t.hours),t.minutes!=null&&r.setMinutes(t.minutes),t.seconds!=null&&r.setSeconds(t.seconds),t.milliseconds!=null&&r.setMilliseconds(t.milliseconds),r)}const ft=["January","February","March","April","May","June","July","August","September","October","November","December"];function Br(){const e=b.useRef(null),t=b.useRef(null),{focusedDate:n,activeMonth:r,minYear:a,maxYear:o,goToDate:i,goToNextMonths:s,goToPreviousMonths:u}=ue(),d=b.useMemo(()=>ft.map((h,x)=>{const E=x===r?.month;return{label:h,value:String(x),selected:E,...E&&{ref:e}}}),[r?.month]),w=b.useMemo(()=>Yr(a,o+1).map(h=>{const x=String(h),E=h===r?.year;return{label:x,value:x,selected:E,...E&&{ref:t}}}),[r?.year,o,a]),l=h=>i(lt(n||$,{month:Number(h),year:r?.year})),m=h=>i(lt(n||$,{month:r?.month,year:Number(h)})),c=({type:h})=>{setTimeout(()=>{const x=h==="year"?t?.current:e?.current;x&&x.scrollIntoView({block:"center"})})};return g.jsxRuntimeExports.jsxs(He.HStack,{className:"DatePicker__Header","data-testid":"kibble-datepicker-header",w:"100%",justify:"space-between",borderBottom:"1px",borderColor:"border.default",py:2,px:3,children:[g.jsxRuntimeExports.jsx(Ce.Button,{iconName:"chevronLeft",onClick:u,variant:"ghostNeutral",size:"sm"}),g.jsxRuntimeExports.jsxs(me.Center,{gap:2,h:"100%",children:[g.jsxRuntimeExports.jsx(Xe.Menu,{"data-testid":"kibble-datepicker-month-menu",buttonProps:{variant:"tertiary",text:ft[r?.month||0],size:"sm"},listProps:{menuItems:d,onSelect:l,maxH:250},onOpenChange:({open:h})=>{h&&c({type:"month"})}}),g.jsxRuntimeExports.jsx(Xe.Menu,{"data-testid":"kibble-datepicker-year-menu",buttonProps:{variant:"tertiary",text:String(r?.year),size:"sm"},listProps:{menuItems:w,onSelect:m,maxH:250},onOpenChange:({open:h})=>{h&&c({type:"year"})}})]}),g.jsxRuntimeExports.jsx(Ce.Button,{iconName:"chevronRight",onClick:s,variant:"ghostNeutral",size:"sm"})]})}const Hr=["root","indicator"],Ir={default:{root:{borderColor:"transparent",_hover:{bg:"background.secondaryAlpha.hover"}}},disabled:{root:{bg:"background.subtle",borderColor:"transparent",cursor:"not-allowed",opacity:.4}},inRange:{root:{bg:"background.secondaryAlpha.hover",borderColor:"transparent",borderRadius:"none",color:"text.info"}},selectedEnd:{root:{borderColor:"border.focus",color:"text.info"}},selectedStart:{root:{bg:"background.secondary",borderColor:"border.focus",color:"text.contrast",_hover:{bg:"background.secondary"}}}},Wr=Yt.defineSlotRecipe({slots:Hr,base:{indicator:{position:"absolute",h:6,right:-4,top:-4,transform:"rotate(45deg)",w:6},root:{border:"2px",borderRadius:"4px",color:"text.subtle",cursor:"pointer",fontSize:"sm",fontWeight:"normal !important",position:"relative",px:3,py:1,overflow:"hidden"}},variants:{variant:Ir,isToday:{true:{indicator:{bg:"background.secondary"}},false:{}},withDateRange:{true:{},false:{}}},compoundVariants:[{variant:"selectedStart",isToday:!0,css:{indicator:{bg:"background"}}},{withDateRange:!0,variant:"selectedStart",css:{root:{borderRightRadius:0}}},{withDateRange:!0,variant:"selectedEnd",css:{root:{borderLeftRadius:0}}}],defaultVariants:{}}),Lr=({dayLabel:e,date:t,onDaySelected:n})=>{const r=new Date,a=b.useRef(null),{startDate:o,endDate:i,dateFormat:s,withDateRange:u}=ue(),d=b.useMemo(()=>({currentDay:S.format(t,s),startDate:o&&S.format(o,s),endDate:i&&S.format(i,s)}),[t,s,i,o]),w=d.currentDay===d.startDate,l=d.currentDay===d.endDate,m=d.currentDay===S.format(r,s),{focusedDate:c,isDateFocused:h,isDateSelected:x,isDateHovered:E,isDateBlocked:v,isFirstOrLastSelectedDate:k,onDateSelect:T,onDateFocus:I,onDateHover:q}=ue(),{disabledDate:z,isSelected:P,onClick:N,onKeyDown:Z,onMouseEnter:G,tabIndex:K}=or({date:t,focusedDate:c,isDateFocused:h,isDateSelected:x,isDateHovered:E,isDateBlocked:v,isFirstOrLastSelectedDate:k,onDateFocus:I,onDateSelect:T,onDateHover:q}),X=b.useMemo(()=>{switch(!0){case z:return"disabled";case w:return"selectedStart";case l:return"selectedEnd";case(P&&!w&&!l):return"inRange";default:return"default"}},[z,l,w,P]),B=ht.useSlotRecipe({recipe:Wr})({variant:X,isToday:m,withDateRange:u});if(!e)return g.jsxRuntimeExports.jsx(g.jsxRuntimeExports.Fragment,{});const O=()=>{X!=="disabled"&&(N(),n())};return g.jsxRuntimeExports.jsxs(Ce.Button,{className:"DatePicker__Day","data-testid":`kibble-datepicker-day--${d.currentDay}`,onClick:O,onKeyDown:Z,onMouseEnter:G,tabIndex:K,ref:a,unstyled:!0,css:B.root,children:[m&&g.jsxRuntimeExports.jsx(gt.Box,{css:B.indicator}),e]})},Ar=({onDaySelected:e})=>{const t=b.useRef(null),{firstDayOfWeek:n,activeMonth:r}=ue(),{days:a,weekdayLabels:o}=Vn({year:r?.year||Le,month:r?.month!==void 0?r.month:ir,firstDayOfWeek:n});return g.jsxRuntimeExports.jsxs(gt.Box,{ref:t,className:"DatePicker__Month","data-testid":"kibble-datepicker-month",children:[g.jsxRuntimeExports.jsx(me.Grid,{templateColumns:"repeat(7, 1fr)",my:2,children:o.map(i=>g.jsxRuntimeExports.jsx(me.GridItem,{children:g.jsxRuntimeExports.jsx(me.Center,{children:g.jsxRuntimeExports.jsx(mt.WrappedText,{size:"xs",variant:"subtle",children:i})})},i))}),g.jsxRuntimeExports.jsx(me.Grid,{templateColumns:"repeat(7, 1fr)",children:a.map((i,s)=>typeof i=="object"?g.jsxRuntimeExports.jsx(Lr,{date:i.date,dayLabel:i.dayLabel,onDaySelected:e},i.date.toString()):g.jsxRuntimeExports.jsx("div",{},s))})]})};function Qr(){const{withDateRange:e,activeMonths:t,onClose:n}=ue(),{setOpen:r}=Be.usePopoverContext(),a=()=>{e||(r(!1),n())};return g.jsxRuntimeExports.jsx(me.Grid,{className:"DatePicker__Calendar","data-testid":"kibble-datepicker-calendar",gap:"0 64px",px:3,py:2,children:t.map(o=>g.jsxRuntimeExports.jsx(Ar,{onDaySelected:a},`${o.year}-${o.month}`))})}const Gr=e=>{const{footerProps:t,hideFooter:n=!1,inputProps:r,withDateRange:a=!1}=e,{contentRef:o}=Ot.usePortalContentRef(),s=ht.useSlotRecipe({recipe:te.popoverRecipe})();return g.jsxRuntimeExports.jsxs(mr,{...e,children:[g.jsxRuntimeExports.jsx(te.PopoverTrigger,{children:g.jsxRuntimeExports.jsx(Dr,{inputProps:r})}),g.jsxRuntimeExports.jsx(qt.Portal,{container:o||void 0,children:g.jsxRuntimeExports.jsx(te.PopoverPositioner,{className:"DatePicker","data-testid":"kibble-datepicker",children:g.jsxRuntimeExports.jsxs(te.PopoverContent,{className:"DatePicker__Content","data-testid":"kibble-datepicker-content",css:{...s.content,minW:"340px"},children:[g.jsxRuntimeExports.jsx(te.PopoverArrow,{css:s.arrow,children:g.jsxRuntimeExports.jsx(te.PopoverArrowTip,{css:s.arrowTip})}),g.jsxRuntimeExports.jsxs(te.PopoverBody,{css:{"--popover-padding":0},children:[g.jsxRuntimeExports.jsx(Br,{}),g.jsxRuntimeExports.jsx(Qr,{}),a&&!n&&g.jsxRuntimeExports.jsx(pr,{...t})]})]})})})]})};exports.DateFormats=We;exports.DatePicker=Gr;
|
|
15
|
-
//# sourceMappingURL=datePicker.component-
|
|
14
|
+
***************************************************************************** */function Y(e,t){y(2,arguments);var n=D(e),r=M(t);return isNaN(r)?new Date(NaN):(r&&n.setDate(n.getDate()+r),n)}function se(e,t){y(1,arguments);var n=e||{},r=D(n.start),a=D(n.end),o=a.getTime();if(!(r.getTime()<=o))throw new RangeError("Invalid interval");var i=[],s=r;s.setHours(0,0,0,0);var u=1;if(isNaN(u))throw new RangeError("`options.step` must be a number greater than 1");for(;s.getTime()<=o;)i.push(D(s)),s.setDate(s.getDate()+u),s.setHours(0,0,0,0);return i}function Qn(e,t){y(1,arguments);var n={},r=n.locale,a=r&&r.options&&r.options.weekStartsOn,o=a==null?0:M(a),i=n.weekStartsOn==null?o:M(n.weekStartsOn);if(!(i>=0&&i<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var s=D(e),u=s.getDay(),d=6+(u<i?-7:0)-(u-i);return s.setDate(s.getDate()+d),s.setHours(23,59,59,999),s}function Ct(e){y(1,arguments);var t=D(e);return t.setDate(1),t.setHours(0,0,0,0),t}function Gn(e,t){y(1,arguments);var n={},r=n.locale,a=r&&r.options&&r.options.weekStartsOn,o=a==null?0:M(a),i=n.weekStartsOn==null?o:M(n.weekStartsOn);if(!(i>=0&&i<=6))throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");var s=D(e),u=s.getDay(),d=(u<i?7:0)+u-i;return s.setDate(s.getDate()-d),s.setHours(0,0,0,0),s}function Xn(e){var t=e===void 0?{}:e,n=t.firstDayOfWeek,r=n===void 0?1:n,a=t.weekdayLabelFormat,o=a===void 0?function(s){return we(s,"iiiiii")}:a,i=new Date;return se({start:Y(Gn(i),r),end:Y(Qn(i),r)}).reduce(function(s,u){return s.push(o(u)),s},[])}function _n(e){var t=e.year,n=e.month,r=e.firstDayOfWeek,a=r===void 0?1:r,o=e.dayLabelFormat,i=o===void 0?function(l){return we(l,"dd")}:o,s=new Date(t,n),u=Ct(s),d=function(l){y(1,arguments);var m=D(l),c=m.getDay();return c}(u),w=function(l){y(1,arguments);var m=D(l),c=m.getMonth();return m.setFullYear(m.getFullYear(),c+1,0),m.setHours(23,59,59,999),m}(s);return function(){for(var l=0,m=0,c=arguments.length;m<c;m++)l+=arguments[m].length;var h=Array(l),x=0;for(m=0;m<c;m++)for(var E=arguments[m],v=0,k=E.length;v<k;v++,x++)h[x]=E[v];return h}(Array.from(Array(d>=a?d-a:6-a+d+1).keys()).fill(0),se({start:u,end:w}).map(function(l){return{date:l,dayLabel:i(l)}}))}var zn=function(e){return we(e,"dd")},Kn=function(e){return we(e,"eeeeee")},Jn=function(e){return we(e,"MMMM yyyy")};function Vn(e){var t=e.year,n=e.month,r=e.firstDayOfWeek,a=r===void 0?1:r,o=e.dayLabelFormat,i=o===void 0?zn:o,s=e.weekdayLabelFormat,u=s===void 0?Kn:s,d=e.monthLabelFormat,w=d===void 0?Jn:d;return{days:b.useMemo(function(){return _n({year:t,month:n,firstDayOfWeek:a,dayLabelFormat:i})},[t,n,a,i]),weekdayLabels:b.useMemo(function(){return Xn({firstDayOfWeek:a,weekdayLabelFormat:u})},[a,u]),monthLabel:w(new Date(t,n))}}function ne(e,t){y(2,arguments);var n=D(e),r=D(t);return n.getTime()<r.getTime()}function Te(e,t){y(2,arguments);var n=D(e),r=D(t);return n.getTime()>r.getTime()}function he(e,t){y(2,arguments);var n=t||{},r=D(e).getTime(),a=D(n.start).getTime(),o=D(n.end).getTime();if(!(a<=o))throw new RangeError("Invalid interval");return r>=a&&r<=o}function Ye(e){y(1,arguments);var t=D(e);return t.setHours(0,0,0,0),t}function _(e,t){y(2,arguments);var n=Ye(e),r=Ye(t);return n.getTime()===r.getTime()}function Oe(e,t){y(2,arguments);var n=D(e),r=M(t);if(isNaN(r))return new Date(NaN);if(!r)return n;var a=n.getDate(),o=new Date(n.getTime());o.setMonth(n.getMonth()+r+1,0);var i=o.getDate();return a>=i?o:(n.setFullYear(o.getFullYear(),o.getMonth(),a),n)}var Mt=function(e,t){return e===void 0&&(e=[]),e.some(function(n){return _(t,n)})};function $n(e,t,n){return!(!t||!n)&&he(e,{start:t,end:n})}function Zn(e,t,n){return!!(t&&_(e,t)||n&&_(e,n))}function er(e,t){return!(!t||!_(e,t))}function tr(e,t){return!(!t||!_(e,t))}function nr(e){var t=e.date,n=e.minBookingDate,r=e.maxBookingDate,a=e.isDateBlockedFn,o=e.startDate,i=e.endDate,s=e.minBookingDays,u=s===void 0?1:s,d=e.unavailableDates,w=d===void 0?[]:d,l=n&&new Date(n.getFullYear(),n.getMonth(),n.getDate(),0,0,0),m=r&&new Date(r.getFullYear(),r.getMonth(),r.getDate(),0,0,0);return!!(Mt(w,t)||l&&ne(t,l)||m&&Te(t,m)||o&&!i&&u>1&&he(t,{start:o,end:Y(o,u-2)})||a&&a(t))}function Me(e){var t=Ct(e);return{year:function(n){y(1,arguments);var r=D(n),a=r.getFullYear();return a}(t),month:function(n){y(1,arguments);var r=D(n),a=r.getMonth();return a}(t),date:t}}function rr(){return Me(Ye(Date.now()))}function xe(e,t){var n=t?Me(t):rr(),r=n.date,a=[n];return e>1&&(a=Array.from(Array(e-1).keys()).reduce(function(o){return r=Oe(o[o.length-1].date,1),o.concat([Me(r)])},a)),a}function fe(e,t,n,r){var a=e[r?n>0?0:e.length-r:n>0?e.length-1:0].date;return Array.from(Array(t).keys()).reduce(function(o){return a=o.length===0?Oe(a,n):Oe(a,n>=0?1:-1),n>0?o.concat([Me(a)]):[Me(a)].concat(o)},[])}function ct(e,t,n){return e&&typeof t=="string"?we(e,t):e&&typeof t=="function"?t(e):n}function ke(e){var t=e.startDate,n=e.endDate,r=e.isDateBlocked,a=e.minBookingDays,o=e.exactMinBookingDays,i=e.minBookingDate,s=e.maxBookingDate,u=!i||!ne(t,Y(i,-1)),d=!s||!Te(Y(t,a-1),s);return!(!t||a!==1||n||r(t))||(t&&a>1&&!n&&!o||t&&a>0&&o&&u&&d||t&&a>0&&o&&!i&&!s?!se({start:t,end:Y(t,a-1)}).some(function(w){return r(w)}):!(!t||!n||o)&&!ne(n,Y(t,a-1))&&!se({start:t,end:n}).some(function(w){return r(w)}))}function ar(e){var t=e.startDate,n=e.endDate,r=e.focusedInput,a=e.minBookingDate,o=e.maxBookingDate,i=e.onDatesChange,s=e.initialVisibleMonth,u=e.exactMinBookingDays,d=u!==void 0&&u,w=e.minBookingDays,l=w===void 0?1:w,m=e.numberOfMonths,c=m===void 0?2:m,h=e.firstDayOfWeek,x=h===void 0?1:h,E=e.isDateBlocked,v=E===void 0?function(){return!1}:E,k=e.unavailableDates,T=k===void 0?[]:k,I=e.changeActiveMonthOnSelect,q=I===void 0||I,z=b.useState(function(){return xe(c,t||s||null)}),P=z[0],N=z[1],Z=b.useState(null),G=Z[0],K=Z[1],X=b.useState(t),F=X[0],B=X[1];b.useEffect(function(){return typeof window<"u"&&window.addEventListener&&window.addEventListener("keydown",H),function(){window.removeEventListener&&window.removeEventListener("keydown",H)}});var O=function(f){return Mt(T,f)||v(f)},J=function(f){B(f),(!F||F&&!_(f,F))&&N(xe(c,f))},U=function(f){return nr({date:f,minBookingDate:a,maxBookingDate:o,startDate:t,endDate:n,minBookingDays:l,isDateBlockedFn:O})};function H(f){if((f.key==="ArrowRight"||f.key==="ArrowLeft"||f.key==="ArrowDown"||f.key==="ArrowUp")&&!F){var A=P[0];J(A.date),N(xe(c,A.date))}}var ce=b.useCallback(function(){N(fe(P,c,-1)),B(null)},[P,c]),Pe=b.useCallback(function(){N(fe(P,c,-1,1)),B(null)},[P,c]),p=b.useCallback(function(){N(fe(P,c,1)),B(null)},[P,c]),de=b.useCallback(function(){N(fe(P,c,1,1)),B(null)},[P,c]),Ut=b.useCallback(function(f){N(xe(c,f)),B(null)},[c]),jt=b.useCallback(function(f){f===void 0&&(f=1),N(fe(P,c,-(12*f-c+1))),B(null)},[P,c]),Nt=b.useCallback(function(f){f===void 0&&(f=1),N(fe(P,c,12*f-c+1)),B(null)},[P,c]);return{firstDayOfWeek:x,activeMonths:P,isDateSelected:function(f){return $n(f,t,n)},isDateHovered:function(f){return function(A){var le=A.date,W=A.startDate,De=A.endDate,pe=A.isDateBlocked,L=A.hoveredDate,ee=A.minBookingDays,Re=A.exactMinBookingDays;return L&&ee>1&&Re&&he(le,{start:L,end:Y(L,ee-1)})?!se({start:L,end:Y(L,ee-1)}).some(function(re){return pe(re)}):W&&!De&&L&&he(le,{start:W,end:Y(W,ee-1)})&&_(W,L)&&ee>1?!se({start:W,end:Y(W,ee-1)}).some(function(re){return pe(re)}):!(!W||De||!L||ne(L,W)||!he(le,{start:W,end:L}))&&!se({start:W,end:L}).some(function(re){return pe(re)})}({date:f,hoveredDate:G,startDate:t,endDate:n,minBookingDays:l,exactMinBookingDays:d,isDateBlocked:O})},isFirstOrLastSelectedDate:function(f){return Zn(f,t,n)},isStartDate:function(f){return er(f,t)},isEndDate:function(f){return tr(f,n)},isDateBlocked:U,numberOfMonths:c,isDateFocused:function(f){return!!F&&_(f,F)},focusedDate:F,hoveredDate:G,onResetDates:function(){i({startDate:null,endDate:null,focusedInput:"startDate"})},onDateHover:function(f){if(f){if(f){var A=!U(f)||t&&_(f,t),le=!a||!ne(f,Y(a,-1)),W=!o||!Te(f,o),De=Y(f,l-1),pe=!a||!ne(De,a),L=!o||!Te(De,o),ee=d&&l>1&&le&&W&&pe&&L,Re=t&&!n&&!d&&le&&W,re=!(l>1&&t)||he(f,{start:t,end:Y(t,l-2)}),Ft=t&&_(f,t)&&re;A&&(ee||Re||Ft)?K(f):G!==null&&K(null)}}else K(null)},onDateSelect:function(f){(r==="endDate"||r==="startDate")&&l>0&&d&&ke({minBookingDays:l,exactMinBookingDays:d,minBookingDate:a,maxBookingDate:o,isDateBlocked:O,startDate:f,endDate:null})?i({startDate:f,endDate:Y(f,l-1),focusedInput:null}):(r==="endDate"&&t&&ne(f,t)||r==="startDate"&&n&&Te(f,n))&&!d&&ke({minBookingDays:l,isDateBlocked:O,startDate:f,endDate:null})?i({endDate:null,startDate:f,focusedInput:"endDate"}):r==="startDate"&&!d&&ke({minBookingDays:l,isDateBlocked:O,endDate:n,startDate:f})?i({endDate:n,startDate:f,focusedInput:"endDate"}):r==="startDate"&&!d&&ke({minBookingDays:l,isDateBlocked:O,endDate:null,startDate:f})?i({endDate:null,startDate:f,focusedInput:"endDate"}):r==="endDate"&&t&&!ne(f,t)&&!d&&ke({minBookingDays:l,isDateBlocked:O,startDate:t,endDate:f})&&i({startDate:t,endDate:f,focusedInput:null}),r!=="endDate"&&(!F||F&&!_(f,F))&&q&&N(xe(c,f))},onDateFocus:J,goToPreviousMonths:ce,goToPreviousMonthsByOneMonth:Pe,goToNextMonths:p,goToNextMonthsByOneMonth:de,goToDate:Ut,goToPreviousYear:jt,goToNextYear:Nt}}function or(e){var t=e.date,n=e.focusedDate,r=e.isDateSelected,a=e.isDateFocused,o=e.isFirstOrLastSelectedDate,i=e.isDateHovered,s=e.isDateBlocked,u=e.onDateSelect,d=e.onDateFocus,w=e.onDateHover,l=b.useCallback(function(){return u(t)},[t,u]),m=b.useCallback(function(){return w(t)},[t,w]),c=s(t)&&!i(t);return{tabIndex:n===null||a(t)?0:-1,isSelected:r(t),isSelectedStartOrEnd:o(t),isWithinHoverRange:i(t),disabledDate:c,onKeyDown:function(h){h.key==="ArrowRight"?d(Y(t,1)):h.key==="ArrowLeft"?d(Y(t,-1)):h.key==="ArrowUp"?d(Y(t,-7)):h.key==="ArrowDown"&&d(Y(t,7))},onClick:c?function(){}:l,onMouseEnter:m}}var We=(e=>(e.ShortDate="MM/dd/yyyy",e.LongDate="MMM dd yyyy",e.DayOfWeekDayOfMonth="eeee, MMMM do",e))(We||{}),Q=(e=>(e.StartDate="startDate",e.EndDate="endDate",e))(Q||{});const $=new Date,Le=$.getFullYear(),ir=$.getMonth(),sr=$,St=Le-100,Et=Le+5,qe=We.ShortDate,ur={dateFormat:qe,endDate:null,focusedInput:null,withDateRange:!1,maxYear:Et,minYear:St,startDate:null,onClose:()=>{throw new Error("onClose(): boolean not implemented")},setFocusedInput:()=>{throw new Error("setFocusedInput(): boolean not implemented")},focusedDate:$,firstDayOfWeek:void 0,activeMonths:[],isDateFocused:()=>{throw new Error("isDateFocused(): boolean not implemented")},isDateSelected:()=>{throw new Error("isDateSelected(): boolean not implemented")},isDateHovered:()=>{throw new Error("isDateHovered(): boolean not implemented")},isDateBlocked:()=>{throw new Error("isDateBlocked(): boolean not implemented")},isFirstOrLastSelectedDate:()=>{throw new Error("isFirstOrLastSelectedDate(): boolean not implemented")},onDateFocus:()=>{throw new Error("onDateFocus(): boolean not implemented")},onDateHover:()=>{throw new Error("onDateHover(): boolean not implemented")},onDateSelect:()=>{throw new Error("onDateSelect(): boolean not implemented")},goToPreviousMonths:()=>{throw new Error("goToPreviousMonths(): boolean not implemented")},goToNextMonths:()=>{throw new Error("goToNextMonths(): boolean not implemented")},goToDate:()=>{throw new Error("goToDate(): boolean not implemented")},clearDates:()=>{throw new Error("clearDates(): boolean not implemented")}},Pt=b.createContext(ur),ue=()=>b.useContext(Pt);function cr(e,t){const n=S.toDate(e,t?.in);return n.setHours(23,59,59,999),n}function dr(e,t,n){const r=S.toDate(e,n?.in);return isNaN(t)?S.constructFrom(e,NaN):(t&&r.setDate(r.getDate()+t),r)}function lr(e,t,n){const r=S.toDate(e,n?.in);if(isNaN(t))return S.constructFrom(e,NaN);if(!t)return r;const a=r.getDate(),o=S.constructFrom(e,r.getTime());o.setMonth(r.getMonth()+t+1,0);const i=o.getDate();return a>=i?o:(r.setFullYear(o.getFullYear(),o.getMonth(),a),r)}function fr(e,t,n){const{years:r=0,months:a=0,weeks:o=0,days:i=0,hours:s=0,minutes:u=0,seconds:d=0}=t,w=S.toDate(e,n?.in),l=a||r?lr(w,a+r*12):w,m=i||o?dr(l,i+o*7):l,c=u+s*60,x=(d+c*60)*1e3;return S.constructFrom(e,+m+x)}function Rt(e,t){return+S.toDate(e)>+S.toDate(t)}const mr=({children:e,dateFormat:t=qe,endDate:n,inputProps:r,maxDate:a,maxDaysInRange:o,maxYear:i,minDate:s,minYear:u,onDateChange:d,placement:w="bottom",startDate:l,withDateRange:m})=>{const[c,h]=b.useState({startDate:l,endDate:n||l,focusedInput:null}),x=b.useCallback(p=>{if(o&&p)return fr(p,{days:o});if(a)return a},[a,o]),E=p=>{if(!p)return;p.endDate||(p.endDate=p.startDate);const de=x(p.startDate);p.endDate&&de&&Rt(p.endDate,de)&&(p.endDate=null),p.startDate=p.startDate?S.startOfDay(p.startDate):p.startDate,p.endDate=p.endDate?cr(p.endDate):p.endDate,h({...p,focusedInput:p.focusedInput||Q.StartDate}),!m&&d&&d(p)},v=b.useCallback(({open:p})=>{h({startDate:null,endDate:null,focusedInput:p?Q.StartDate:null})},[]),{activeMonths:k,firstDayOfWeek:T,focusedDate:I,goToDate:q,goToNextMonths:z,goToPreviousMonths:P,isDateBlocked:N,isDateFocused:Z,isDateHovered:G,isDateSelected:K,isFirstOrLastSelectedDate:X,onDateFocus:F,onDateHover:B,onDateSelect:O}=ar({endDate:c.endDate,focusedInput:c.focusedInput,initialVisibleMonth:c.startDate||$,maxBookingDate:m&&c.focusedInput===Q.StartDate?void 0:x(c.startDate),minBookingDate:s,minBookingDays:1,numberOfMonths:1,onDatesChange:E,startDate:c.startDate,...!m&&{exactMinBookingDays:!0}}),J=b.useCallback(p=>{p===Q.EndDate&&c.endDate?q(c.endDate):c.startDate&&q(c.startDate)},[q,c.endDate,c.startDate]),U=b.useCallback(p=>{h(de=>({...de,focusedInput:p})),J(p)},[J]),H=()=>{r?.disabled||(!c.startDate||!m)&&U(Q.StartDate)},ce=b.useCallback(()=>{U(null),m&&d&&(console.log("onDateChange called on close"),setTimeout(()=>{console.log("onDateChange called after timeout"),d({startDate:c.startDate,endDate:c.endDate})},200))},[m,d,U,c.endDate,c.startDate]),Pe=b.useMemo(()=>k[0],[k]);return b.useEffect(()=>{h(p=>({...p,startDate:l,endDate:n||l}))},[l,n]),g.jsxRuntimeExports.jsx(Pt.Provider,{value:{activeMonth:Pe,activeMonths:k,dateFormat:t||qe,endDate:c.endDate||null,firstDayOfWeek:T,focusedDate:I||sr,focusedInput:c.focusedInput,goToDate:q,goToNextMonths:z,goToPreviousMonths:P,setFocusedInput:U,isDateBlocked:N,isDateFocused:Z,isDateHovered:G,withDateRange:m||!1,isDateSelected:K,isFirstOrLastSelectedDate:X,maxDate:a,maxYear:i||Et,minDate:s,minYear:u||St,onDateChange:d,onDateFocus:F,onDateHover:B,onDateSelect:O,startDate:c.startDate,onClose:ce,clearDates:v},children:g.jsxRuntimeExports.jsx(te.PopoverRoot,{onOpenChange:({open:p})=>{p?H():U(null)},positioning:{placement:w},onExitComplete:()=>{ce()},children:e})})};function hr(e,t){return+S.toDate(e)<+S.toDate(t)}const gr=(e,t)=>t?Rt(e,t):!0,wr=(e,t)=>t?hr(e,t):!0;function Dr({inputProps:e}){const{setFocusedInput:t,startDate:n,endDate:r,focusedInput:a,dateFormat:o,withDateRange:i,minDate:s,maxDate:u,onDateChange:d,onDateSelect:w,onClose:l}=ue(),{open:m,setOpen:c}=Be.usePopoverContext(),h=e?.size||"md",x=v=>{v.key==="Enter"&&m&&(c(!1),l(),v.preventDefault(),v.stopPropagation())},E=v=>{const k=v.target.value,T=bn(k,o,$);k.length===o.length&&S.isDate(T)&&gr(T,s)&&wr(T,u)&&w(T),!k.length&&d&&d({startDate:null,endDate:null})};return g.jsxRuntimeExports.jsxs(He.HStack,{w:"100%",className:"DatePicker__Trigger","data-testid":"kibble-datepicker-trigger",children:[g.jsxRuntimeExports.jsx(Ae.WrappedTextInput,{className:"DatePicker__Input--Start","data-testid":"kibble-datepicker-input-start",autoComplete:"off",rightElement:g.jsxRuntimeExports.jsx(Ge.Flex,{...!e?.disabled&&{onClick:()=>t(Q.StartDate)},h:"100%",align:"center",children:g.jsxRuntimeExports.jsx(Qe.Icon,{name:"calendarDate",size:h})}),value:ct(n,o,""),onChange:E,onKeyDown:x,...!e?.disabled&&{onFocus:()=>{t(Q.StartDate)}},placeholder:S.format($,o).toString(),...a===Q.StartDate&&{"data-focus":!0},...e}),i&&g.jsxRuntimeExports.jsxs(g.jsxRuntimeExports.Fragment,{children:[g.jsxRuntimeExports.jsx(mt.WrappedText,{children:" - "}),g.jsxRuntimeExports.jsx(Ae.WrappedTextInput,{className:"DatePicker__Input--End","data-testid":"kibble-datepicker-input-end",rightElement:g.jsxRuntimeExports.jsx(Ge.Flex,{...!e?.disabled&&{onClick:()=>t(Q.StartDate)},h:"100%",align:"center",children:g.jsxRuntimeExports.jsx(Qe.Icon,{name:"calendarDate",size:h})}),value:ct(r,o,""),onChange:E,...!e?.disabled&&{onFocus:()=>t(Q.EndDate)},onKeyDown:x,placeholder:S.format($,o).toString(),...a===Q.EndDate&&{"data-focus":!0},...e})]})]})}function pr({buttonText:e="Apply",onSubmit:t,hideResetButton:n}){const{startDate:r,endDate:a,onClose:o,clearDates:i}=ue(),{open:s,setOpen:u}=Be.usePopoverContext(),d=b.useCallback(()=>{u(!1),o(),t&&t({startDate:r,endDate:a})},[u,o,t,r,a]);return g.jsxRuntimeExports.jsxs(He.HStack,{w:"100%",justify:n?"end":"space-between",align:"center",borderTop:"1px",borderColor:"border.default",px:3,py:2,children:[!n&&g.jsxRuntimeExports.jsx(Ce.Button,{size:"sm",variant:"ghostNeutral",onClick:()=>i({open:s}),children:"Clear Dates"}),g.jsxRuntimeExports.jsx(Ce.Button,{size:"sm",onClick:d,children:e})]})}var br=Math.ceil,yr=Math.max;function vr(e,t,n,r){for(var a=-1,o=yr(br((t-e)/(n||1)),0),i=Array(o);o--;)i[++a]=e,e+=n;return i}function xr(e,t,n){if(!oe.isObject(n))return!1;var r=typeof t;return(r=="number"?oe.isArrayLike(n)&&oe.isIndex(t,n.length):r=="string"&&t in n)?oe.eq(n[t],e):!1}var kr=/\s/;function Tr(e){for(var t=e.length;t--&&kr.test(e.charAt(t)););return t}var Cr=/^\s+/;function Mr(e){return e&&e.slice(0,Tr(e)+1).replace(Cr,"")}var dt=NaN,Sr=/^[-+]0x[0-9a-f]+$/i,Er=/^0b[01]+$/i,Pr=/^0o[0-7]+$/i,Rr=parseInt;function Ur(e){if(typeof e=="number")return e;if(oe.isSymbol(e))return dt;if(oe.isObject(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=oe.isObject(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Mr(e);var n=Er.test(e);return n||Pr.test(e)?Rr(e.slice(2),n?2:8):Sr.test(e)?dt:+e}var jr=1/0,Nr=17976931348623157e292;function Fe(e){if(!e)return e===0?e:0;if(e=Ur(e),e===jr||e===-1/0){var t=e<0?-1:1;return t*Nr}return e===e?e:0}function Fr(e){return function(t,n,r){return r&&typeof r!="number"&&xr(t,n,r)&&(n=r=void 0),t=Fe(t),n===void 0?(n=t,t=0):n=Fe(n),r=r===void 0?t<n?1:-1:Fe(r),vr(t,n,r)}}var Yr=Fr();function Or(e,t){const n=S.toDate(e,t?.in),r=n.getFullYear(),a=n.getMonth(),o=S.constructFrom(n,0);return o.setFullYear(r,a+1,0),o.setHours(0,0,0,0),o.getDate()}function qr(e,t,n){const r=S.toDate(e,n?.in),a=r.getFullYear(),o=r.getDate(),i=S.constructFrom(e,0);i.setFullYear(a,t,15),i.setHours(0,0,0,0);const s=Or(i);return r.setMonth(t,Math.min(o,s)),r}function lt(e,t,n){let r=S.toDate(e,n?.in);return isNaN(+r)?S.constructFrom(e,NaN):(t.year!=null&&r.setFullYear(t.year),t.month!=null&&(r=qr(r,t.month)),t.date!=null&&r.setDate(t.date),t.hours!=null&&r.setHours(t.hours),t.minutes!=null&&r.setMinutes(t.minutes),t.seconds!=null&&r.setSeconds(t.seconds),t.milliseconds!=null&&r.setMilliseconds(t.milliseconds),r)}const ft=["January","February","March","April","May","June","July","August","September","October","November","December"];function Br(){const e=b.useRef(null),t=b.useRef(null),{focusedDate:n,activeMonth:r,minYear:a,maxYear:o,goToDate:i,goToNextMonths:s,goToPreviousMonths:u}=ue(),d=b.useMemo(()=>ft.map((h,x)=>{const E=x===r?.month;return{label:h,value:String(x),selected:E,...E&&{ref:e}}}),[r?.month]),w=b.useMemo(()=>Yr(a,o+1).map(h=>{const x=String(h),E=h===r?.year;return{label:x,value:x,selected:E,...E&&{ref:t}}}),[r?.year,o,a]),l=h=>i(lt(n||$,{month:Number(h),year:r?.year})),m=h=>i(lt(n||$,{month:r?.month,year:Number(h)})),c=({type:h})=>{setTimeout(()=>{const x=h==="year"?t?.current:e?.current;x&&x.scrollIntoView({block:"center"})})};return g.jsxRuntimeExports.jsxs(He.HStack,{className:"DatePicker__Header","data-testid":"kibble-datepicker-header",w:"100%",justify:"space-between",borderBottom:"1px",borderColor:"border.default",py:2,px:3,children:[g.jsxRuntimeExports.jsx(Ce.Button,{iconName:"chevronLeft",onClick:u,variant:"ghostNeutral",size:"sm"}),g.jsxRuntimeExports.jsxs(me.Center,{gap:2,h:"100%",children:[g.jsxRuntimeExports.jsx(Xe.Menu,{"data-testid":"kibble-datepicker-month-menu",buttonProps:{variant:"tertiary",text:ft[r?.month||0],size:"sm"},listProps:{menuItems:d,onSelect:l,maxH:250},onOpenChange:({open:h})=>{h&&c({type:"month"})}}),g.jsxRuntimeExports.jsx(Xe.Menu,{"data-testid":"kibble-datepicker-year-menu",buttonProps:{variant:"tertiary",text:String(r?.year),size:"sm"},listProps:{menuItems:w,onSelect:m,maxH:250},onOpenChange:({open:h})=>{h&&c({type:"year"})}})]}),g.jsxRuntimeExports.jsx(Ce.Button,{iconName:"chevronRight",onClick:s,variant:"ghostNeutral",size:"sm"})]})}const Hr=["root","indicator"],Ir={default:{root:{borderColor:"transparent",_hover:{bg:"background.secondaryAlpha.hover"}}},disabled:{root:{bg:"background.subtle",borderColor:"transparent",cursor:"not-allowed",opacity:.4}},inRange:{root:{bg:"background.secondaryAlpha.hover",borderColor:"transparent",borderRadius:"none",color:"text.info"}},selectedEnd:{root:{borderColor:"border.focus",color:"text.info"}},selectedStart:{root:{bg:"background.secondary",borderColor:"border.focus",color:"text.contrast",_hover:{bg:"background.secondary"}}}},Wr=Yt.defineSlotRecipe({slots:Hr,base:{indicator:{position:"absolute",h:6,right:-4,top:-4,transform:"rotate(45deg)",w:6},root:{border:"2px",borderRadius:"4px",color:"text.subtle",cursor:"pointer",fontSize:"sm",fontWeight:"normal !important",position:"relative",px:3,py:1,overflow:"hidden"}},variants:{variant:Ir,isToday:{true:{indicator:{bg:"background.secondary"}},false:{}},withDateRange:{true:{},false:{}}},compoundVariants:[{variant:"selectedStart",isToday:!0,css:{indicator:{bg:"background"}}},{withDateRange:!0,variant:"selectedStart",css:{root:{borderRightRadius:0}}},{withDateRange:!0,variant:"selectedEnd",css:{root:{borderLeftRadius:0}}}],defaultVariants:{}}),Lr=({dayLabel:e,date:t,onDaySelected:n})=>{const r=new Date,a=b.useRef(null),{startDate:o,endDate:i,dateFormat:s,withDateRange:u}=ue(),d=b.useMemo(()=>({currentDay:S.format(t,s),startDate:o&&S.format(o,s),endDate:i&&S.format(i,s)}),[t,s,i,o]),w=d.currentDay===d.startDate,l=d.currentDay===d.endDate,m=d.currentDay===S.format(r,s),{focusedDate:c,isDateFocused:h,isDateSelected:x,isDateHovered:E,isDateBlocked:v,isFirstOrLastSelectedDate:k,onDateSelect:T,onDateFocus:I,onDateHover:q}=ue(),{disabledDate:z,isSelected:P,onClick:N,onKeyDown:Z,onMouseEnter:G,tabIndex:K}=or({date:t,focusedDate:c,isDateFocused:h,isDateSelected:x,isDateHovered:E,isDateBlocked:v,isFirstOrLastSelectedDate:k,onDateFocus:I,onDateSelect:T,onDateHover:q}),X=b.useMemo(()=>{switch(!0){case z:return"disabled";case w:return"selectedStart";case l:return"selectedEnd";case(P&&!w&&!l):return"inRange";default:return"default"}},[z,l,w,P]),B=ht.useSlotRecipe({recipe:Wr})({variant:X,isToday:m,withDateRange:u});if(!e)return g.jsxRuntimeExports.jsx(g.jsxRuntimeExports.Fragment,{});const O=()=>{X!=="disabled"&&(N(),n())};return g.jsxRuntimeExports.jsxs(Ce.Button,{className:"DatePicker__Day","data-testid":`kibble-datepicker-day--${d.currentDay}`,onClick:O,onKeyDown:Z,onMouseEnter:G,tabIndex:K,ref:a,unstyled:!0,css:B.root,children:[m&&g.jsxRuntimeExports.jsx(gt.Box,{css:B.indicator}),e]})},Ar=({onDaySelected:e})=>{const t=b.useRef(null),{firstDayOfWeek:n,activeMonth:r}=ue(),{days:a,weekdayLabels:o}=Vn({year:r?.year||Le,month:r?.month!==void 0?r.month:ir,firstDayOfWeek:n});return g.jsxRuntimeExports.jsxs(gt.Box,{ref:t,className:"DatePicker__Month","data-testid":"kibble-datepicker-month",children:[g.jsxRuntimeExports.jsx(me.Grid,{templateColumns:"repeat(7, 1fr)",my:2,children:o.map(i=>g.jsxRuntimeExports.jsx(me.GridItem,{children:g.jsxRuntimeExports.jsx(me.Center,{children:g.jsxRuntimeExports.jsx(mt.WrappedText,{size:"xs",variant:"subtle",children:i})})},i))}),g.jsxRuntimeExports.jsx(me.Grid,{templateColumns:"repeat(7, 1fr)",children:a.map((i,s)=>typeof i=="object"?g.jsxRuntimeExports.jsx(Lr,{date:i.date,dayLabel:i.dayLabel,onDaySelected:e},i.date.toString()):g.jsxRuntimeExports.jsx("div",{},s))})]})};function Qr(){const{withDateRange:e,activeMonths:t,onClose:n}=ue(),{setOpen:r}=Be.usePopoverContext(),a=()=>{e||(r(!1),n())};return g.jsxRuntimeExports.jsx(me.Grid,{className:"DatePicker__Calendar","data-testid":"kibble-datepicker-calendar",gap:"0 64px",px:3,py:2,children:t.map(o=>g.jsxRuntimeExports.jsx(Ar,{onDaySelected:a},`${o.year}-${o.month}`))})}const Gr=e=>{const{footerProps:t,hideFooter:n=!1,inputProps:r,withDateRange:a=!1}=e,{contentRef:o}=Ot.usePortalContentRef(),s=ht.useSlotRecipe({recipe:te.popoverRecipe})();return g.jsxRuntimeExports.jsxs(mr,{...e,children:[g.jsxRuntimeExports.jsx(te.PopoverTrigger,{w:"100%",children:g.jsxRuntimeExports.jsx(Dr,{inputProps:r})}),g.jsxRuntimeExports.jsx(qt.Portal,{container:o||void 0,children:g.jsxRuntimeExports.jsx(te.PopoverPositioner,{className:"DatePicker","data-testid":"kibble-datepicker",children:g.jsxRuntimeExports.jsxs(te.PopoverContent,{className:"DatePicker__Content","data-testid":"kibble-datepicker-content",css:{...s.content,minW:"340px"},children:[g.jsxRuntimeExports.jsx(te.PopoverArrow,{css:s.arrow,children:g.jsxRuntimeExports.jsx(te.PopoverArrowTip,{css:s.arrowTip})}),g.jsxRuntimeExports.jsxs(te.PopoverBody,{css:{"--popover-padding":0},children:[g.jsxRuntimeExports.jsx(Br,{}),g.jsxRuntimeExports.jsx(Qr,{}),a&&!n&&g.jsxRuntimeExports.jsx(pr,{...t})]})]})})})]})};exports.DateFormats=We;exports.DatePicker=Gr;
|
|
15
|
+
//# sourceMappingURL=datePicker.component--6-jJXIm.js.map
|