react-availability-calendar
Advanced tools
Comparing version 0.2.13 to 0.2.14
@@ -5,1 +5,3 @@ export { AvailabilityCalendar } from './AvailabilityCalendar'; | ||
export { defaultComponents } from './overrides'; | ||
export { AvailSlot } from './AvailSlot'; | ||
export { AvailSlots } from './AvailSlots'; |
@@ -1179,2 +1179,4 @@ 'use strict'; | ||
exports.AvailSlot = AvailSlot; | ||
exports.AvailSlots = AvailSlots; | ||
exports.AvailabilityCalendar = AvailabilityCalendar; | ||
@@ -1181,0 +1183,0 @@ exports.createUtils = createUtils; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}function r(e){function t(e){return e.endDate.getTime()-e.startDate.getTime()}function a(e,t){t=t>0?Math.min(864e5,t):Math.max(-864e5,t);var a=(e=Math.min(864e5,Math.max(0,e)))-t;return a<0?a+864e5:a}function n(e,t){return e&&t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function r(e,t,n,r,o){for(var l=function(e,t){var n=e.map((function(e){return[a(e[0],t)%864e5,a(e[1],t)%864e5]})),r=n.map((function(e,t){return e[1]<e[0]?t:-1})).filter((function(e){return e>=0})),o=Array.isArray(r),l=0;for(r=o?r:r[Symbol.iterator]();;){var s;if(o){if(l>=r.length)break;s=r[l++]}else{if((l=r.next()).done)break;s=l.value}var i=n[s];n[s]=[-1,-1],n.push([i[0],864e5]),n.push([0,i[1]])}var u=n.filter((function(e){return e[0]>=0}));return u.sort((function(e,t){return e[0]-t[0]})),u}(e,function(e){if(!e)return 0;var t=new Date,a=new Date(t.toLocaleString("en-US",{timeZone:e}));return 36e5*Math.floor((a.getTime()-t.getTime())/36e5+.5)}(t)),s=[].concat(n),i=new Date(r.getFullYear(),r.getMonth(),r.getDate()).getTime(),u=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),m=i;m<=u;m+=864e5){var d=new Date(m),c=l,f=Array.isArray(c),v=0;for(c=f?c:c[Symbol.iterator]();;){var h;if(f){if(v>=c.length)break;h=c[v++]}else{if((v=c.next()).done)break;h=v.value}var y=h,D=Math.floor(y[0]/36e5),g=Math.floor(y[1]/36e5),b=Math.floor(y[0]/6e4)%60,p=Math.floor(y[1]/6e4)%60;s.push({startDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),D,b),endDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),g,p)})}s.push({startDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),23,59),endDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),24)})}return s}return{msInHour:36e5,datesEqual:n,formatAsMonth:function(t){return e(t).format("MMM YYYY")},sameMonth:function(t,a){return n(e(t).startOf("month").toDate(),e(a).startOf("month").toDate())},formatAsDateWithTime:function(t){return e(t).format("ddd, MMM Do h:mma")},formatAsDateJustTime:function(t){return e(t).format("h:mma")},formatAsDate:function(t){return e(t).format("ddd, MMM Do YYYY")},shouldHideWeek:function(t,a,r){return t&&(o=a[0],!n(e(t).startOf("week").toDate(),e(o).startOf("week").toDate()))&&r.length>0;var o},availByIndex:function(e,t){return(e||[]).map((function(e){return{hasAvail:t.some((function(t){return n(t.startDate,e)}))}}))},addBlockOutBookings:r,availabilitiesFromBookings:function(e,t,a,n,o,l){var s,i=Math.max((s=n.getTime(),36e5*Math.floor(s/36e5)+36e5),o.getTime()),u=new Date(i);if(l.getTime()<=u.getTime())return[];var m=[{startDate:u,endDate:l}],d=r(e,t,a,u,l).sort((function(e,t){return e.startDate.getTime()-t.startDate.getTime()})),c=Array.isArray(d),f=0;for(d=c?d:d[Symbol.iterator]();;){var v;if(c){if(f>=d.length)break;v=d[f++]}else{if((f=d.next()).done)break;v=f.value}var h=v,y=m[m.length-1],D=h.startDate.getTime(),g=h.endDate.getTime();if(h.startDate&&h.endDate&&!(D>=g))if(D<y.startDate.getTime())y.startDate=new Date(Math.max(y.startDate.getTime(),g));else if(D<y.endDate.getTime()){var b=y.endDate;y.endDate=new Date(D),g<b.getTime()&&m.push({startDate:new Date(g),endDate:b})}}return m},toStartAndEnd:function(e){var t={startDate:e.start||e[0],endDate:e.end||e[e.length-1]};return t.startDate.getTime()===t.endDate.getTime()&&(t.endDate=new Date(t.endDate.getTime()+864e5)),t},monthRangeForDate:function(t){return{start:e(t).startOf("month").toDate(),end:e(t).endOf("month").toDate()}},monthDaysForDate:function(t){for(var a=e(t).startOf("month"),n=e(t).endOf("month"),r=a.startOf("week"),o=n.endOf("week").diff(r,"days")+1,l=[],s=[],i=r,u=Math.floor(o/7),m=0;m<u;++m){var d=[];l.push(d);for(var c=0;c<7;++c)d.push(i.toDate()),s.push(i.toDate()),i.add(1,"day")}return{weeks:l,days:s}},chunkify:function(e,a,n){var r=[],o=e,l=Array.isArray(o),s=0;for(o=l?o:o[Symbol.iterator]();;){var i;if(l){if(s>=o.length)break;i=o[s++]}else{if((s=o.next()).done)break;i=s.value}for(var u=i,m=u.endDate.getTime(),d=u.startDate.getTime();d<m;d+=n){var c=d,f={startDate:new Date(c),endDate:new Date(Math.min(m,c+a))};t(f)>=a&&r.push(f)}}return r}}}var o={dayClassBase:"rounded-circle",dayClassSelected:"border-primary",dayClassHasAvailability:"border-info",dayClassDefault:"border border-default",slotsContainerStyleShow:{transition:"transform 300ms",transform:"scale(1)"},slotsContainerStyleHide:{transition:"transform 300ms",transform:"scale(0)"},slotContainerCloseClass:"close",slotButtonClass:"btn btn-primary",toolBarStyle:{flexWrap:"nowrap",width:350,minHeight:50},toolBarButtonsContainerClass:"border btn-group w-100",toolBarButtonClass:"btn",toolBarLabelClass:"btn btn-link",requestAppointmentLabel:"Request Appointment"},l={format:function(e){throw new Error("not implemented")},startOf:function(e){throw new Error("not implemented")},endOf:function(e){throw new Error("not implemented")},add:function(e,t){throw new Error("not implemented")},diff:function(e,t,a){throw new Error("not implemented")},toDate:function(){throw new Error("not implemented")}},s=a.createContext({moment:function(){return l},utils:r((function(){return l})),theme:o}),i=function(){return t.useContext(s)},u=function(e){var n=e.moment,o=e.theme,l=e.children,i=t.useMemo((function(){return r(n)}),[n]);return a.createElement(s.Provider,{value:{moment:n,utils:i,theme:o}},l)};function m(e,t){return"function"==typeof e?e(t||{}):e}function d(e,t){return"function"==typeof e?e(t||{}):e}function c(e,t,a,r,o,l){return void 0===e?{Root:t.Root,className:d(t.className,a),style:n({},m(t.style,a)),internalProps:t.internalProps}:{Root:e.Root||t.Root,className:d(e.className,a)||d(t.className,a),style:n({},m(t.style,a),{},m(e.style,a)),internalProps:n({},t.internalProps,{},e.internalProps)}}var f=function(e){var t=e.localizer.messages,n=e.label,r=e.onNavigate,o=e.overrides,l=i().theme,s=function(e,t){return c(e?e.ToolBar:void 0,t,{})}(o,{style:l.toolBarStyle,className:l.toolBarButtonsContainerClass}),u=s.Root,m=s.style,d=s.className;return u?a.createElement(u,Object.assign({},{localizer:{messages:t},label:n,onNavigate:r})):a.createElement("div",{style:m,className:d,role:"group"},a.createElement(v,{theme:l,overrides:o,onClick:function(){return r("TODAY")},message:t.today}),a.createElement(v,{theme:l,overrides:o,onClick:function(){return r("PREV")},message:t.previous}),a.createElement(v,{theme:l,overrides:o,onClick:function(){return r("NEXT")},message:t.next}),a.createElement("button",{disabled:!0,className:l.toolBarLabelClass,style:{width:110}},a.createElement("span",null,n)))};function v(e){var t,n=e.message,r=e.onClick,o=c((t=e.overrides)?t.ToolBarButton:void 0,{className:e.theme.toolBarButtonClass},{}),l=o.Root,s=o.style,i=o.internalProps,u=o.className;return void 0!==l?a.createElement(l,{message:n,onClicked:r}):a.createElement("button",Object.assign({className:u,onClick:r,style:s},i),n)}var h=["S","M","T","W","Th","F","Sa"],y=function(e){var t=e.overrides,n=function(e,t){return c(e?e.Weekdays:void 0,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}},{})}(t),r=n.Root,o=n.style;if(r)return a.createElement(r,null);var l=function(e,t){return c(e?e.Weekday:void 0,{className:"border border-default",style:{flex:1,height:50,marginBottom:10,display:"flex",justifyContent:"center",alignItems:"center"}},{})}(t),s=l.Root,i=l.className,u=l.style;return a.createElement("div",{style:o},h.map((function(e){return s?a.createElement(s,{weekday:e}):a.createElement("div",{className:i,key:e,style:u},e)})))};function D(e){var t,n=e.theme,r=e.onAvailabilitySelected,o=e.s,l=e.formatAsDateJustTime,s=c((t=e.overrides)?t.AvailSlot:void 0,{className:n.slotButtonClass,style:{minWidth:200}},{date:o.startDate}),i=s.Root,u=s.className,m=s.style;return i?a.createElement(i,Object.assign({},{theme:n,onAvailabilitySelected:r,s:o,formatAsDateJustTime:l})):a.createElement("div",{style:{marginBottom:10}},a.createElement("button",{className:u,disabled:!1,style:m,onClick:function(){return r({startDate:new Date(o.startDate),endDate:new Date(o.endDate)})}},l(new Date(o.startDate))))}var g=function(e){var t=e.viewingDayAvailabilities,n=e.handleUnselect,r=e.onAvailabilitySelected,o=e.show,l=e.slotStepMs,s=e.slotLengthMs,i=e.utils,u=e.theme,m=e.overrides,d=function(e,t){return c(e?e.Availabilities:void 0,t,{})}(m,{style:o?u.slotsContainerStyleShow:u.slotsContainerStyleHide}),f=d.Root,v=d.style;return f?a.createElement(f,Object.assign({},{viewingDayAvailabilities:t,handleUnselect:n,onAvailabilitySelected:r,show:o,slotStepMs:l,slotLengthMs:s,utils:i,theme:u})):a.createElement("div",{style:v},o&&a.createElement("div",{className:"mt-2 mr-1"},a.createElement("button",{type:"button",className:u.slotContainerCloseClass,"aria-label":"Close",style:{outline:"none"},onClick:n},a.createElement("span",{"aria-hidden":"true"},"×")),a.createElement(b,{theme:u,durationMinutes:60,avails:t,onAvailabilitySelected:r,slotLengthMs:s,slotStepMs:l,utils:i,overrides:m})))},b=function(e){var n=e.avails,r=e.slotLengthMs,o=e.slotStepMs,l=e.onAvailabilitySelected,s=e.theme,i=e.utils,u=e.overrides,m=i.chunkify,d=i.msInHour,c=i.formatAsDate,f=i.formatAsDateJustTime,v=t.useMemo((function(){return m(n.map((function(e){return{startDate:e.startDate,endDate:e.endDate}})),r||1*d,o||.5*d)}),[n,d,m,r,o]);return a.createElement("div",null,a.createElement("h4",null,s.requestAppointmentLabel),a.createElement("h5",null,n&&n.length>0?c(n[0].startDate):""),v.map((function(e,t){return a.createElement(D,Object.assign({key:"b_"+t},{theme:s,onAvailabilitySelected:l,s:e,formatAsDateJustTime:f,overrides:u}))})))},p=function(e){var t=e.date,r=e.shouldDisplay,o=e.dayIndexInWeek,l=e.weekIndexInCalRange,s=e.availsByIndex,i=e.selectedDate,u=e.handleSelected,m=e.moment,d=e.utils,f=e.theme,v=e.overrides,h=7*l+o,y=!!i&&d.datesEqual(t,i),D=s[h].hasAvail,g=function(e,t,a){return c(e?e.DayCell:void 0,t,a)}(v,{className:f.dayClassBase+" "+(i&&d.datesEqual(t,i)?f.dayClassSelected:s[h].hasAvail?f.dayClassHasAvailability:f.dayClassDefault),style:{cursor:"pointer",border:i&&d.datesEqual(t,i)?"4px solid":s[h].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{date:t,isSelected:y,hasAvail:D}),b=g.Root,p=g.style,w=g.className;if(b)return a.createElement(b,Object.assign({},{shouldDisplay:r,date:t,dayIndexInWeek:o,weekIndexInCalRange:l,availsByIndex:s,selectedDate:i,handleSelected:u,moment:m,utils:d,theme:f}));var E=r?p:n({},p,{visibility:"hidden"});return a.createElement("div",{className:w,style:E,onClick:function(){return u(t)}},m(t).format("D"))};function w(e){var t=e.week,n=e.date,r=e.selectedDate,o=e.weekIndexInCalRange,l=e.handleSelected,s=e.availsByIndex,i=e.moment,u=e.utils,m=e.theme,d=e.overrides,f=function(e,t){return c(e?e.DayCells:void 0,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}},{})}(d),v=f.Root,h=f.style;return v?a.createElement(v,Object.assign({},{date:n,week:t,selectedDate:r,weekIndexInCalRange:o,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m})):a.createElement("div",{style:h},t.map((function(e,t){return a.createElement(p,Object.assign({key:"d_"+t},{shouldDisplay:u.sameMonth(e,n),date:e,selectedDate:r,weekIndexInCalRange:o,dayIndexInWeek:t,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m,overrides:d}))})))}var E=function(e){var r=e.availabilities,o=e.onAvailabilitySelected,l=e.slotLengthMs,s=e.slotStepMs,u=e.date,m=e.style,d=e.overrides,c=i(),f=c.moment,v=c.theme,h=c.utils,D=t.useState(null),b=D[0],p=D[1];t.useEffect((function(){p(null)}),[u]);var E=function(e){b&&h.datesEqual(e,b)?p(null):p(e)},M=t.useMemo((function(){return h.monthDaysForDate(u)}),[u,h]),C=M.days,k=M.weeks,S=t.useMemo((function(){return h.availByIndex(C,r)}),[C,r,h]),A=t.useMemo((function(){return null!==b?(r||[]).filter((function(e){return h.datesEqual(e.startDate,b)})):[]}),[b,r,h]);return a.createElement("div",{style:n({minHeight:368},m)},a.createElement(y,{overrides:d}),k.map((function(e,t){return h.shouldHideWeek(b,e,A)?null:a.createElement(a.Fragment,{key:"w_"+t},a.createElement(w,Object.assign({},{date:u,week:e,selectedDate:b,weekIndexInCalRange:t,handleSelected:E,availsByIndex:S,moment:f,utils:h,theme:v,overrides:d})))})),a.createElement(g,Object.assign({},{show:!!b&&A.length>0,onAvailabilitySelected:o,viewingDayAvailabilities:A,handleUnselect:function(){p(null)},slotLengthMs:l,slotStepMs:s,utils:h,theme:v,overrides:d})))},M=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.blockOutPeriods,l=e.providerTimeZone,s=e.bookings,u=e.avails,m=e.onCalRangeChange,d=e.slotLengthMs,c=e.slotStepMs,v=e.overrides,h=i(),y=h.moment,D=h.utils,g=t.useState(n||new Date)[0],b=t.useState(D.monthRangeForDate(g)),p=b[0],w=b[1],M=t.useState(g),C=M[0],k=M[1],S=t.useRef(null);t.useEffect((function(){S.current!==p&&(m&&m(p),S.current=p)}),[p,m]);var A=t.useMemo((function(){if(u)return u;var e=D.toStartAndEnd(p);return D.availabilitiesFromBookings(o||[],l,s,g,e.startDate,e.endDate)}),[u,s,l,p,g,o,D]);return a.createElement("div",null,a.createElement(f,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return k(t),void w(D.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=y(C).add("NEXT"===e?1:-1,"month").toDate();k(a),w(D.monthRangeForDate(a))}},label:D.formatAsMonth(C),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:v}),a.createElement(E,{availabilities:A,date:C,onAvailabilitySelected:r,slotLengthMs:d,slotStepMs:c,overrides:v}))};exports.AvailabilityCalendar=function(e){var t=e.moment,r=e.theme,l=function(e,t){if(null==e)return{};var a,n,r={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(a=o[n])>=0||(r[a]=e[a]);return r}(e,["moment","theme"]);return a.createElement(u,{moment:t,theme:r?n({},o,{},r):o},a.createElement(M,Object.assign({},l)))},exports.createUtils=r,exports.defaultComponents={ToolBar:{},ToolBarButton:{},Weekdays:{},Weekday:{},DayCells:{},DayCell:{},Availabilities:{},AvailSlot:{}},exports.defaultTheme=o; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),a=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e}).apply(this,arguments)}function r(e){function t(e){return e.endDate.getTime()-e.startDate.getTime()}function a(e,t){t=t>0?Math.min(864e5,t):Math.max(-864e5,t);var a=(e=Math.min(864e5,Math.max(0,e)))-t;return a<0?a+864e5:a}function n(e,t){return e&&t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function r(e,t,n,r,o){for(var l=function(e,t){var n=e.map((function(e){return[a(e[0],t)%864e5,a(e[1],t)%864e5]})),r=n.map((function(e,t){return e[1]<e[0]?t:-1})).filter((function(e){return e>=0})),o=Array.isArray(r),l=0;for(r=o?r:r[Symbol.iterator]();;){var s;if(o){if(l>=r.length)break;s=r[l++]}else{if((l=r.next()).done)break;s=l.value}var i=n[s];n[s]=[-1,-1],n.push([i[0],864e5]),n.push([0,i[1]])}var u=n.filter((function(e){return e[0]>=0}));return u.sort((function(e,t){return e[0]-t[0]})),u}(e,function(e){if(!e)return 0;var t=new Date,a=new Date(t.toLocaleString("en-US",{timeZone:e}));return 36e5*Math.floor((a.getTime()-t.getTime())/36e5+.5)}(t)),s=[].concat(n),i=new Date(r.getFullYear(),r.getMonth(),r.getDate()).getTime(),u=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),m=i;m<=u;m+=864e5){var d=new Date(m),c=l,f=Array.isArray(c),v=0;for(c=f?c:c[Symbol.iterator]();;){var h;if(f){if(v>=c.length)break;h=c[v++]}else{if((v=c.next()).done)break;h=v.value}var y=h,D=Math.floor(y[0]/36e5),g=Math.floor(y[1]/36e5),p=Math.floor(y[0]/6e4)%60,b=Math.floor(y[1]/6e4)%60;s.push({startDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),D,p),endDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),g,b)})}s.push({startDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),23,59),endDate:new Date(d.getFullYear(),d.getMonth(),d.getDate(),24)})}return s}return{msInHour:36e5,datesEqual:n,formatAsMonth:function(t){return e(t).format("MMM YYYY")},sameMonth:function(t,a){return n(e(t).startOf("month").toDate(),e(a).startOf("month").toDate())},formatAsDateWithTime:function(t){return e(t).format("ddd, MMM Do h:mma")},formatAsDateJustTime:function(t){return e(t).format("h:mma")},formatAsDate:function(t){return e(t).format("ddd, MMM Do YYYY")},shouldHideWeek:function(t,a,r){return t&&(o=a[0],!n(e(t).startOf("week").toDate(),e(o).startOf("week").toDate()))&&r.length>0;var o},availByIndex:function(e,t){return(e||[]).map((function(e){return{hasAvail:t.some((function(t){return n(t.startDate,e)}))}}))},addBlockOutBookings:r,availabilitiesFromBookings:function(e,t,a,n,o,l){var s,i=Math.max((s=n.getTime(),36e5*Math.floor(s/36e5)+36e5),o.getTime()),u=new Date(i);if(l.getTime()<=u.getTime())return[];var m=[{startDate:u,endDate:l}],d=r(e,t,a,u,l).sort((function(e,t){return e.startDate.getTime()-t.startDate.getTime()})),c=Array.isArray(d),f=0;for(d=c?d:d[Symbol.iterator]();;){var v;if(c){if(f>=d.length)break;v=d[f++]}else{if((f=d.next()).done)break;v=f.value}var h=v,y=m[m.length-1],D=h.startDate.getTime(),g=h.endDate.getTime();if(h.startDate&&h.endDate&&!(D>=g))if(D<y.startDate.getTime())y.startDate=new Date(Math.max(y.startDate.getTime(),g));else if(D<y.endDate.getTime()){var p=y.endDate;y.endDate=new Date(D),g<p.getTime()&&m.push({startDate:new Date(g),endDate:p})}}return m},toStartAndEnd:function(e){var t={startDate:e.start||e[0],endDate:e.end||e[e.length-1]};return t.startDate.getTime()===t.endDate.getTime()&&(t.endDate=new Date(t.endDate.getTime()+864e5)),t},monthRangeForDate:function(t){return{start:e(t).startOf("month").toDate(),end:e(t).endOf("month").toDate()}},monthDaysForDate:function(t){for(var a=e(t).startOf("month"),n=e(t).endOf("month"),r=a.startOf("week"),o=n.endOf("week").diff(r,"days")+1,l=[],s=[],i=r,u=Math.floor(o/7),m=0;m<u;++m){var d=[];l.push(d);for(var c=0;c<7;++c)d.push(i.toDate()),s.push(i.toDate()),i.add(1,"day")}return{weeks:l,days:s}},chunkify:function(e,a,n){var r=[],o=e,l=Array.isArray(o),s=0;for(o=l?o:o[Symbol.iterator]();;){var i;if(l){if(s>=o.length)break;i=o[s++]}else{if((s=o.next()).done)break;i=s.value}for(var u=i,m=u.endDate.getTime(),d=u.startDate.getTime();d<m;d+=n){var c=d,f={startDate:new Date(c),endDate:new Date(Math.min(m,c+a))};t(f)>=a&&r.push(f)}}return r}}}var o={dayClassBase:"rounded-circle",dayClassSelected:"border-primary",dayClassHasAvailability:"border-info",dayClassDefault:"border border-default",slotsContainerStyleShow:{transition:"transform 300ms",transform:"scale(1)"},slotsContainerStyleHide:{transition:"transform 300ms",transform:"scale(0)"},slotContainerCloseClass:"close",slotButtonClass:"btn btn-primary",toolBarStyle:{flexWrap:"nowrap",width:350,minHeight:50},toolBarButtonsContainerClass:"border btn-group w-100",toolBarButtonClass:"btn",toolBarLabelClass:"btn btn-link",requestAppointmentLabel:"Request Appointment"},l={format:function(e){throw new Error("not implemented")},startOf:function(e){throw new Error("not implemented")},endOf:function(e){throw new Error("not implemented")},add:function(e,t){throw new Error("not implemented")},diff:function(e,t,a){throw new Error("not implemented")},toDate:function(){throw new Error("not implemented")}},s=a.createContext({moment:function(){return l},utils:r((function(){return l})),theme:o}),i=function(){return t.useContext(s)},u=function(e){var n=e.moment,o=e.theme,l=e.children,i=t.useMemo((function(){return r(n)}),[n]);return a.createElement(s.Provider,{value:{moment:n,utils:i,theme:o}},l)};function m(e,t){return"function"==typeof e?e(t||{}):e}function d(e,t){return"function"==typeof e?e(t||{}):e}function c(e,t,a,r,o,l){return void 0===e?{Root:t.Root,className:d(t.className,a),style:n({},m(t.style,a)),internalProps:t.internalProps}:{Root:e.Root||t.Root,className:d(e.className,a)||d(t.className,a),style:n({},m(t.style,a),{},m(e.style,a)),internalProps:n({},t.internalProps,{},e.internalProps)}}var f=function(e){var t=e.localizer.messages,n=e.label,r=e.onNavigate,o=e.overrides,l=i().theme,s=function(e,t){return c(e?e.ToolBar:void 0,t,{})}(o,{style:l.toolBarStyle,className:l.toolBarButtonsContainerClass}),u=s.Root,m=s.style,d=s.className;return u?a.createElement(u,Object.assign({},{localizer:{messages:t},label:n,onNavigate:r})):a.createElement("div",{style:m,className:d,role:"group"},a.createElement(v,{theme:l,overrides:o,onClick:function(){return r("TODAY")},message:t.today}),a.createElement(v,{theme:l,overrides:o,onClick:function(){return r("PREV")},message:t.previous}),a.createElement(v,{theme:l,overrides:o,onClick:function(){return r("NEXT")},message:t.next}),a.createElement("button",{disabled:!0,className:l.toolBarLabelClass,style:{width:110}},a.createElement("span",null,n)))};function v(e){var t,n=e.message,r=e.onClick,o=c((t=e.overrides)?t.ToolBarButton:void 0,{className:e.theme.toolBarButtonClass},{}),l=o.Root,s=o.style,i=o.internalProps,u=o.className;return void 0!==l?a.createElement(l,{message:n,onClicked:r}):a.createElement("button",Object.assign({className:u,onClick:r,style:s},i),n)}var h=["S","M","T","W","Th","F","Sa"],y=function(e){var t=e.overrides,n=function(e,t){return c(e?e.Weekdays:void 0,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}},{})}(t),r=n.Root,o=n.style;if(r)return a.createElement(r,null);var l=function(e,t){return c(e?e.Weekday:void 0,{className:"border border-default",style:{flex:1,height:50,marginBottom:10,display:"flex",justifyContent:"center",alignItems:"center"}},{})}(t),s=l.Root,i=l.className,u=l.style;return a.createElement("div",{style:o},h.map((function(e){return s?a.createElement(s,{weekday:e}):a.createElement("div",{className:i,key:e,style:u},e)})))};function D(e){var t,n=e.theme,r=e.onAvailabilitySelected,o=e.s,l=e.formatAsDateJustTime,s=c((t=e.overrides)?t.AvailSlot:void 0,{className:n.slotButtonClass,style:{minWidth:200}},{date:o.startDate}),i=s.Root,u=s.className,m=s.style;return i?a.createElement(i,Object.assign({},{theme:n,onAvailabilitySelected:r,s:o,formatAsDateJustTime:l})):a.createElement("div",{style:{marginBottom:10}},a.createElement("button",{className:u,disabled:!1,style:m,onClick:function(){return r({startDate:new Date(o.startDate),endDate:new Date(o.endDate)})}},l(new Date(o.startDate))))}var g=function(e){var t=e.viewingDayAvailabilities,n=e.handleUnselect,r=e.onAvailabilitySelected,o=e.show,l=e.slotStepMs,s=e.slotLengthMs,i=e.utils,u=e.theme,m=e.overrides,d=function(e,t){return c(e?e.Availabilities:void 0,t,{})}(m,{style:o?u.slotsContainerStyleShow:u.slotsContainerStyleHide}),f=d.Root,v=d.style;return f?a.createElement(f,Object.assign({},{viewingDayAvailabilities:t,handleUnselect:n,onAvailabilitySelected:r,show:o,slotStepMs:l,slotLengthMs:s,utils:i,theme:u})):a.createElement("div",{style:v},o&&a.createElement("div",{className:"mt-2 mr-1"},a.createElement("button",{type:"button",className:u.slotContainerCloseClass,"aria-label":"Close",style:{outline:"none"},onClick:n},a.createElement("span",{"aria-hidden":"true"},"×")),a.createElement(p,{theme:u,durationMinutes:60,avails:t,onAvailabilitySelected:r,slotLengthMs:s,slotStepMs:l,utils:i,overrides:m})))},p=function(e){var n=e.avails,r=e.slotLengthMs,o=e.slotStepMs,l=e.onAvailabilitySelected,s=e.theme,i=e.utils,u=e.overrides,m=i.chunkify,d=i.msInHour,c=i.formatAsDate,f=i.formatAsDateJustTime,v=t.useMemo((function(){return m(n.map((function(e){return{startDate:e.startDate,endDate:e.endDate}})),r||1*d,o||.5*d)}),[n,d,m,r,o]);return a.createElement("div",null,a.createElement("h4",null,s.requestAppointmentLabel),a.createElement("h5",null,n&&n.length>0?c(n[0].startDate):""),v.map((function(e,t){return a.createElement(D,Object.assign({key:"b_"+t},{theme:s,onAvailabilitySelected:l,s:e,formatAsDateJustTime:f,overrides:u}))})))},b=function(e){var t=e.date,r=e.shouldDisplay,o=e.dayIndexInWeek,l=e.weekIndexInCalRange,s=e.availsByIndex,i=e.selectedDate,u=e.handleSelected,m=e.moment,d=e.utils,f=e.theme,v=e.overrides,h=7*l+o,y=!!i&&d.datesEqual(t,i),D=s[h].hasAvail,g=function(e,t,a){return c(e?e.DayCell:void 0,t,a)}(v,{className:f.dayClassBase+" "+(i&&d.datesEqual(t,i)?f.dayClassSelected:s[h].hasAvail?f.dayClassHasAvailability:f.dayClassDefault),style:{cursor:"pointer",border:i&&d.datesEqual(t,i)?"4px solid":s[h].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{date:t,isSelected:y,hasAvail:D}),p=g.Root,b=g.style,w=g.className;if(p)return a.createElement(p,Object.assign({},{shouldDisplay:r,date:t,dayIndexInWeek:o,weekIndexInCalRange:l,availsByIndex:s,selectedDate:i,handleSelected:u,moment:m,utils:d,theme:f}));var E=r?b:n({},b,{visibility:"hidden"});return a.createElement("div",{className:w,style:E,onClick:function(){return u(t)}},m(t).format("D"))};function w(e){var t=e.week,n=e.date,r=e.selectedDate,o=e.weekIndexInCalRange,l=e.handleSelected,s=e.availsByIndex,i=e.moment,u=e.utils,m=e.theme,d=e.overrides,f=function(e,t){return c(e?e.DayCells:void 0,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}},{})}(d),v=f.Root,h=f.style;return v?a.createElement(v,Object.assign({},{date:n,week:t,selectedDate:r,weekIndexInCalRange:o,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m})):a.createElement("div",{style:h},t.map((function(e,t){return a.createElement(b,Object.assign({key:"d_"+t},{shouldDisplay:u.sameMonth(e,n),date:e,selectedDate:r,weekIndexInCalRange:o,dayIndexInWeek:t,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m,overrides:d}))})))}var E=function(e){var r=e.availabilities,o=e.onAvailabilitySelected,l=e.slotLengthMs,s=e.slotStepMs,u=e.date,m=e.style,d=e.overrides,c=i(),f=c.moment,v=c.theme,h=c.utils,D=t.useState(null),p=D[0],b=D[1];t.useEffect((function(){b(null)}),[u]);var E=function(e){p&&h.datesEqual(e,p)?b(null):b(e)},M=t.useMemo((function(){return h.monthDaysForDate(u)}),[u,h]),C=M.days,k=M.weeks,S=t.useMemo((function(){return h.availByIndex(C,r)}),[C,r,h]),A=t.useMemo((function(){return null!==p?(r||[]).filter((function(e){return h.datesEqual(e.startDate,p)})):[]}),[p,r,h]);return a.createElement("div",{style:n({minHeight:368},m)},a.createElement(y,{overrides:d}),k.map((function(e,t){return h.shouldHideWeek(p,e,A)?null:a.createElement(a.Fragment,{key:"w_"+t},a.createElement(w,Object.assign({},{date:u,week:e,selectedDate:p,weekIndexInCalRange:t,handleSelected:E,availsByIndex:S,moment:f,utils:h,theme:v,overrides:d})))})),a.createElement(g,Object.assign({},{show:!!p&&A.length>0,onAvailabilitySelected:o,viewingDayAvailabilities:A,handleUnselect:function(){b(null)},slotLengthMs:l,slotStepMs:s,utils:h,theme:v,overrides:d})))},M=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.blockOutPeriods,l=e.providerTimeZone,s=e.bookings,u=e.avails,m=e.onCalRangeChange,d=e.slotLengthMs,c=e.slotStepMs,v=e.overrides,h=i(),y=h.moment,D=h.utils,g=t.useState(n||new Date)[0],p=t.useState(D.monthRangeForDate(g)),b=p[0],w=p[1],M=t.useState(g),C=M[0],k=M[1],S=t.useRef(null);t.useEffect((function(){S.current!==b&&(m&&m(b),S.current=b)}),[b,m]);var A=t.useMemo((function(){if(u)return u;var e=D.toStartAndEnd(b);return D.availabilitiesFromBookings(o||[],l,s,g,e.startDate,e.endDate)}),[u,s,l,b,g,o,D]);return a.createElement("div",null,a.createElement(f,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return k(t),void w(D.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=y(C).add("NEXT"===e?1:-1,"month").toDate();k(a),w(D.monthRangeForDate(a))}},label:D.formatAsMonth(C),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:v}),a.createElement(E,{availabilities:A,date:C,onAvailabilitySelected:r,slotLengthMs:d,slotStepMs:c,overrides:v}))};exports.AvailSlot=D,exports.AvailSlots=g,exports.AvailabilityCalendar=function(e){var t=e.moment,r=e.theme,l=function(e,t){if(null==e)return{};var a,n,r={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(a=o[n])>=0||(r[a]=e[a]);return r}(e,["moment","theme"]);return a.createElement(u,{moment:t,theme:r?n({},o,{},r):o},a.createElement(M,Object.assign({},l)))},exports.createUtils=r,exports.defaultComponents={ToolBar:{},ToolBarButton:{},Weekdays:{},Weekday:{},DayCells:{},DayCell:{},Availabilities:{},AvailSlot:{}},exports.defaultTheme=o; | ||
//# sourceMappingURL=react-availability-calendar.cjs.production.min.js.map |
@@ -1172,3 +1172,3 @@ import React, { useMemo, useContext, useState, useEffect, useRef } from 'react'; | ||
export { AvailabilityCalendar, createUtils, defaultComponents, defaultTheme }; | ||
export { AvailSlot, AvailSlots, AvailabilityCalendar, createUtils, defaultComponents, defaultTheme }; | ||
//# sourceMappingURL=react-availability-calendar.esm.js.map |
{ | ||
"version": "0.2.13", | ||
"version": "0.2.14", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
356442
2718