Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-availability-calendar

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-availability-calendar - npm Package Compare versions

Comparing version 0.3.5 to 0.3.6

2

dist/react-availability-calendar.cjs.development.js

@@ -1028,2 +1028,3 @@ 'use strict';

setSelectedDate(null);
onDaySelected && onDaySelected(null);
}, [date]);

@@ -1042,2 +1043,3 @@

var handleUnselect = function handleUnselect() {
onDaySelected && onDaySelected(null);
setSelectedDate(null);

@@ -1044,0 +1046,0 @@ };

2

dist/react-availability-calendar.cjs.production.min.js

@@ -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){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}function r(e,t){if(!t)return 0;var a=new Date(e),n=new Date(a.toLocaleString("en-US",{timeZone:t}));return 36e5*Math.floor((n.getTime()-a.getTime())/36e5+.5)}function o(e,t){return e&&t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function l(e,t,a,o,l){for(var s=[].concat(a),i=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),u=new Date(l.getFullYear(),l.getMonth(),l.getDate()).getTime(),m=i;m<=u;m+=864e5){var d=n(e,r(m,t)),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 y=v;s.push({startDate:new Date(m+y[0]),endDate:new Date(m+y[1])})}s.push({startDate:new Date(m+864e5-1),endDate:new Date(m+864e5)})}return s}return{msInHour:36e5,datesEqual:o,formatAsMonth:function(t){return e(t).format("MMM YYYY")},sameMonth:function(t,a){return o(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,n){return t&&(r=a[0],!o(e(t).startOf("week").toDate(),e(r).startOf("week").toDate()))&&n.length>0;var r},availByIndex:function(e,t){return(e||[]).map((function(e){return{hasAvail:t.some((function(t){return o(t.startDate,e)}))}}))},addBlockOutBookings:l,availabilitiesFromBookings:function(e,t,a,n,r,o){var s,i=Math.max((s=n.getTime(),36e5*Math.floor(s/36e5)+36e5),r.getTime()),u=new Date(i);if(o.getTime()<=u.getTime())return[];var m=[{startDate:u,endDate:o}],d=l(e,t,a,u,o).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 y=v,h=m[m.length-1],D=y.startDate.getTime(),g=y.endDate.getTime();if(y.startDate&&y.endDate&&!(D>=g))if(D<h.startDate.getTime())h.startDate=new Date(Math.max(h.startDate.getTime(),g));else if(D<h.endDate.getTime()){var p=h.endDate;h.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)}}function f(e,t){return c(e?e.ToolBar:void 0,t,{})}function v(e,t){return c(e?e.ToolBarButton:void 0,t,{})}function y(e,t){return c(e?e.Weekdays:void 0,t,{})}function h(e,t){return c(e?e.Weekday:void 0,t,{})}function D(e,t){return c(e?e.DayCells:void 0,t,{})}function g(e,t,a){return c(e?e.DayCell:void 0,t,a)}function p(e,t){return c(e?e.Availabilities:void 0,t,{})}function b(e,t,a){return c(e?e.AvailSlot:void 0,t,a)}var w=function(e){var t=e.localizer.messages,n=e.label,r=e.onNavigate,o=e.overrides,l=i().theme,s=f(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(C,{theme:l,overrides:o,onClick:function(){return r("TODAY")},message:t.today}),a.createElement(C,{theme:l,overrides:o,onClick:function(){return r("PREV")},message:t.previous}),a.createElement(C,{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 C(e){var t=e.message,n=e.onClick,r=v(e.overrides,{className:e.theme.toolBarButtonClass}),o=r.Root,l=r.style,s=r.internalProps,i=r.className;return void 0!==o?a.createElement(o,{message:t,onClicked:n}):a.createElement("button",Object.assign({className:i,onClick:n,style:l},s),t)}var E=["S","M","T","W","Th","F","Sa"],x=function(e){var t=e.overrides,n=y(t,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),r=n.Root,o=n.style;if(r)return a.createElement(r,null);var l=h(t,{className:"border border-default",style:{flex:1,height:50,marginBottom:10,display:"flex",justifyContent:"center",alignItems:"center"}}),s=l.Root,i=l.className,u=l.style;return a.createElement("div",{style:o},E.map((function(e){return s?a.createElement(s,{weekday:e}):a.createElement("div",{className:i,key:e,style:u},e)})))};function k(e){var t=e.theme,n=e.onAvailabilitySelected,r=e.s,o=e.formatAsDateJustTime,l=b(e.overrides,{className:t.slotButtonClass,style:{minWidth:200}},{date:r.startDate}),s=l.Root,i=l.className,u=l.style;return s?a.createElement(s,Object.assign({},{theme:t,onAvailabilitySelected:n,s:r,formatAsDateJustTime:o})):a.createElement("div",{style:{marginBottom:10}},a.createElement("button",{className:i,disabled:!1,style:u,onClick:function(){return n({startDate:new Date(r.startDate),endDate:new Date(r.endDate)})}},o(new Date(r.startDate))))}var S=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=p(m,{style:o?u.slotsContainerStyleShow:u.slotsContainerStyleHide}),c=d.Root,f=d.style;return c?a.createElement(c,Object.assign({},{viewingDayAvailabilities:t,handleUnselect:n,onAvailabilitySelected:r,show:o,slotStepMs:l,slotLengthMs:s,utils:i,theme:u})):a.createElement("div",{style:f},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(A,{theme:u,durationMinutes:60,avails:t,onAvailabilitySelected:r,slotLengthMs:s,slotStepMs:l,utils:i,overrides:m}),t.length>7&&a.createElement("button",{type:"button",className:u.slotContainerCloseClass,"aria-label":"Close",style:{outline:"none"},onClick:n},a.createElement("span",{"aria-hidden":"true"},"×"))))},A=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(k,Object.assign({key:"b_"+t},{theme:s,onAvailabilitySelected:l,s:e,formatAsDateJustTime:f,overrides:u}))})))},M=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,c=e.theme,f=e.overrides,v=7*l+o,y=!!i&&d.datesEqual(t,i),h=s[v].hasAvail,D=g(f,{className:c.dayClassBase+" "+(i&&d.datesEqual(t,i)?c.dayClassSelected:s[v].hasAvail?c.dayClassHasAvailability:c.dayClassDefault),style:{cursor:"pointer",border:i&&d.datesEqual(t,i)?"4px solid":s[v].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{date:t,isSelected:y,hasAvail:h}),p=D.Root,b=D.style,w=D.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:c}));var C=r?b:n({},b,{visibility:"hidden"});return a.createElement("div",{className:w,style:C,onClick:function(){return u(t)}},m(t).format("D"))};function T(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,c=D(d,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),f=c.Root,v=c.style;return f?a.createElement(f,Object.assign({},{date:n,week:t,selectedDate:r,weekIndexInCalRange:o,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m})):a.createElement("div",{style:v},t.map((function(e,t){return a.createElement(M,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 O=function(e){var r=e.availabilities,o=e.onAvailabilitySelected,l=e.onDaySelected,s=e.slotLengthMs,u=e.slotStepMs,m=e.date,d=e.style,c=e.overrides,f=i(),v=f.moment,y=f.theme,h=f.utils,D=t.useState(null),g=D[0],p=D[1];t.useEffect((function(){p(null)}),[m]);var b=function(e){g&&h.datesEqual(e,g)?p(null):p(e),l&&l(e)},w=t.useMemo((function(){return h.monthDaysForDate(m)}),[m,h]),C=w.days,E=w.weeks,k=t.useMemo((function(){return h.availByIndex(C,r)}),[C,r,h]),A=t.useMemo((function(){return null!==g?(r||[]).filter((function(e){return h.datesEqual(e.startDate,g)})):[]}),[g,r,h]);return a.createElement("div",{style:n({minHeight:368},d)},a.createElement(x,{overrides:c}),E.map((function(e,t){return h.shouldHideWeek(g,e,A)?null:a.createElement(a.Fragment,{key:"w_"+t},a.createElement(T,Object.assign({},{date:m,week:e,selectedDate:g,weekIndexInCalRange:t,handleSelected:b,availsByIndex:k,moment:v,utils:h,theme:y,overrides:c})))})),a.createElement(S,Object.assign({},{show:!!g&&A.length>0,onAvailabilitySelected:o,viewingDayAvailabilities:A,handleUnselect:function(){p(null)},slotLengthMs:s,slotStepMs:u,utils:h,theme:y,overrides:c})))},B=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.onDaySelected,l=e.blockOutPeriods,s=e.providerTimeZone,u=e.bookings,m=e.avails,d=e.onCalRangeChange,c=e.slotLengthMs,f=e.slotStepMs,v=e.overrides,y=i(),h=y.moment,D=y.utils,g=t.useState(n||new Date)[0],p=t.useState(D.monthRangeForDate(g)),b=p[0],C=p[1],E=t.useState(g),x=E[0],k=E[1],S=t.useRef(null);t.useEffect((function(){S.current!==b&&(d&&d(b),S.current=b)}),[b,d]);var A=t.useMemo((function(){if(m)return m;var e=D.toStartAndEnd(b);return D.availabilitiesFromBookings(l||[],s,u,new Date,e.startDate,e.endDate)}),[m,u,s,b,g,l,D]);return a.createElement("div",null,a.createElement(w,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return k(t),void C(D.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=h(x).add("NEXT"===e?1:-1,"month").toDate();k(a),C(D.monthRangeForDate(a))}},label:D.formatAsMonth(x),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:v}),a.createElement(O,{availabilities:A,date:x,onAvailabilitySelected:r,onDaySelected:o,slotLengthMs:c,slotStepMs:f,overrides:v}))};exports.AvailSlot=k,exports.AvailSlots=S,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(B,Object.assign({},l)))},exports.createUtils=r,exports.defaultComponents={ToolBar:{},ToolBarButton:{},Weekdays:{},Weekday:{},DayCells:{},DayCell:{},Availabilities:{},AvailSlot:{}},exports.defaultTheme=o,exports.getAvailOverride=b,exports.getAvailsOverride=p,exports.getDayCellOverride=g,exports.getDayCellsOverride=D,exports.getToolBarButtonOverride=v,exports.getToolBarOverride=f,exports.getWeekdayOverride=h,exports.getWeekdaysOverride=y;
"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){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}function r(e,t){if(!t)return 0;var a=new Date(e),n=new Date(a.toLocaleString("en-US",{timeZone:t}));return 36e5*Math.floor((n.getTime()-a.getTime())/36e5+.5)}function o(e,t){return e&&t&&e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function l(e,t,a,o,l){for(var s=[].concat(a),i=new Date(o.getFullYear(),o.getMonth(),o.getDate()).getTime(),u=new Date(l.getFullYear(),l.getMonth(),l.getDate()).getTime(),m=i;m<=u;m+=864e5){var d=n(e,r(m,t)),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 y=v;s.push({startDate:new Date(m+y[0]),endDate:new Date(m+y[1])})}s.push({startDate:new Date(m+864e5-1),endDate:new Date(m+864e5)})}return s}return{msInHour:36e5,datesEqual:o,formatAsMonth:function(t){return e(t).format("MMM YYYY")},sameMonth:function(t,a){return o(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,n){return t&&(r=a[0],!o(e(t).startOf("week").toDate(),e(r).startOf("week").toDate()))&&n.length>0;var r},availByIndex:function(e,t){return(e||[]).map((function(e){return{hasAvail:t.some((function(t){return o(t.startDate,e)}))}}))},addBlockOutBookings:l,availabilitiesFromBookings:function(e,t,a,n,r,o){var s,i=Math.max((s=n.getTime(),36e5*Math.floor(s/36e5)+36e5),r.getTime()),u=new Date(i);if(o.getTime()<=u.getTime())return[];var m=[{startDate:u,endDate:o}],d=l(e,t,a,u,o).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 y=v,h=m[m.length-1],D=y.startDate.getTime(),g=y.endDate.getTime();if(y.startDate&&y.endDate&&!(D>=g))if(D<h.startDate.getTime())h.startDate=new Date(Math.max(h.startDate.getTime(),g));else if(D<h.endDate.getTime()){var p=h.endDate;h.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)}}function f(e,t){return c(e?e.ToolBar:void 0,t,{})}function v(e,t){return c(e?e.ToolBarButton:void 0,t,{})}function y(e,t){return c(e?e.Weekdays:void 0,t,{})}function h(e,t){return c(e?e.Weekday:void 0,t,{})}function D(e,t){return c(e?e.DayCells:void 0,t,{})}function g(e,t,a){return c(e?e.DayCell:void 0,t,a)}function p(e,t){return c(e?e.Availabilities:void 0,t,{})}function b(e,t,a){return c(e?e.AvailSlot:void 0,t,a)}var w=function(e){var t=e.localizer.messages,n=e.label,r=e.onNavigate,o=e.overrides,l=i().theme,s=f(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(C,{theme:l,overrides:o,onClick:function(){return r("TODAY")},message:t.today}),a.createElement(C,{theme:l,overrides:o,onClick:function(){return r("PREV")},message:t.previous}),a.createElement(C,{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 C(e){var t=e.message,n=e.onClick,r=v(e.overrides,{className:e.theme.toolBarButtonClass}),o=r.Root,l=r.style,s=r.internalProps,i=r.className;return void 0!==o?a.createElement(o,{message:t,onClicked:n}):a.createElement("button",Object.assign({className:i,onClick:n,style:l},s),t)}var E=["S","M","T","W","Th","F","Sa"],x=function(e){var t=e.overrides,n=y(t,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),r=n.Root,o=n.style;if(r)return a.createElement(r,null);var l=h(t,{className:"border border-default",style:{flex:1,height:50,marginBottom:10,display:"flex",justifyContent:"center",alignItems:"center"}}),s=l.Root,i=l.className,u=l.style;return a.createElement("div",{style:o},E.map((function(e){return s?a.createElement(s,{weekday:e}):a.createElement("div",{className:i,key:e,style:u},e)})))};function k(e){var t=e.theme,n=e.onAvailabilitySelected,r=e.s,o=e.formatAsDateJustTime,l=b(e.overrides,{className:t.slotButtonClass,style:{minWidth:200}},{date:r.startDate}),s=l.Root,i=l.className,u=l.style;return s?a.createElement(s,Object.assign({},{theme:t,onAvailabilitySelected:n,s:r,formatAsDateJustTime:o})):a.createElement("div",{style:{marginBottom:10}},a.createElement("button",{className:i,disabled:!1,style:u,onClick:function(){return n({startDate:new Date(r.startDate),endDate:new Date(r.endDate)})}},o(new Date(r.startDate))))}var S=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=p(m,{style:o?u.slotsContainerStyleShow:u.slotsContainerStyleHide}),c=d.Root,f=d.style;return c?a.createElement(c,Object.assign({},{viewingDayAvailabilities:t,handleUnselect:n,onAvailabilitySelected:r,show:o,slotStepMs:l,slotLengthMs:s,utils:i,theme:u})):a.createElement("div",{style:f},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(A,{theme:u,durationMinutes:60,avails:t,onAvailabilitySelected:r,slotLengthMs:s,slotStepMs:l,utils:i,overrides:m}),t.length>7&&a.createElement("button",{type:"button",className:u.slotContainerCloseClass,"aria-label":"Close",style:{outline:"none"},onClick:n},a.createElement("span",{"aria-hidden":"true"},"×"))))},A=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(k,Object.assign({key:"b_"+t},{theme:s,onAvailabilitySelected:l,s:e,formatAsDateJustTime:f,overrides:u}))})))},M=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,c=e.theme,f=e.overrides,v=7*l+o,y=!!i&&d.datesEqual(t,i),h=s[v].hasAvail,D=g(f,{className:c.dayClassBase+" "+(i&&d.datesEqual(t,i)?c.dayClassSelected:s[v].hasAvail?c.dayClassHasAvailability:c.dayClassDefault),style:{cursor:"pointer",border:i&&d.datesEqual(t,i)?"4px solid":s[v].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{date:t,isSelected:y,hasAvail:h}),p=D.Root,b=D.style,w=D.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:c}));var C=r?b:n({},b,{visibility:"hidden"});return a.createElement("div",{className:w,style:C,onClick:function(){return u(t)}},m(t).format("D"))};function T(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,c=D(d,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}}),f=c.Root,v=c.style;return f?a.createElement(f,Object.assign({},{date:n,week:t,selectedDate:r,weekIndexInCalRange:o,handleSelected:l,availsByIndex:s,moment:i,utils:u,theme:m})):a.createElement("div",{style:v},t.map((function(e,t){return a.createElement(M,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 O=function(e){var r=e.availabilities,o=e.onAvailabilitySelected,l=e.onDaySelected,s=e.slotLengthMs,u=e.slotStepMs,m=e.date,d=e.style,c=e.overrides,f=i(),v=f.moment,y=f.theme,h=f.utils,D=t.useState(null),g=D[0],p=D[1];t.useEffect((function(){p(null),l&&l(null)}),[m]);var b=function(e){g&&h.datesEqual(e,g)?p(null):p(e),l&&l(e)},w=t.useMemo((function(){return h.monthDaysForDate(m)}),[m,h]),C=w.days,E=w.weeks,k=t.useMemo((function(){return h.availByIndex(C,r)}),[C,r,h]),A=t.useMemo((function(){return null!==g?(r||[]).filter((function(e){return h.datesEqual(e.startDate,g)})):[]}),[g,r,h]);return a.createElement("div",{style:n({minHeight:368},d)},a.createElement(x,{overrides:c}),E.map((function(e,t){return h.shouldHideWeek(g,e,A)?null:a.createElement(a.Fragment,{key:"w_"+t},a.createElement(T,Object.assign({},{date:m,week:e,selectedDate:g,weekIndexInCalRange:t,handleSelected:b,availsByIndex:k,moment:v,utils:h,theme:y,overrides:c})))})),a.createElement(S,Object.assign({},{show:!!g&&A.length>0,onAvailabilitySelected:o,viewingDayAvailabilities:A,handleUnselect:function(){l&&l(null),p(null)},slotLengthMs:s,slotStepMs:u,utils:h,theme:y,overrides:c})))},B=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.onDaySelected,l=e.blockOutPeriods,s=e.providerTimeZone,u=e.bookings,m=e.avails,d=e.onCalRangeChange,c=e.slotLengthMs,f=e.slotStepMs,v=e.overrides,y=i(),h=y.moment,D=y.utils,g=t.useState(n||new Date)[0],p=t.useState(D.monthRangeForDate(g)),b=p[0],C=p[1],E=t.useState(g),x=E[0],k=E[1],S=t.useRef(null);t.useEffect((function(){S.current!==b&&(d&&d(b),S.current=b)}),[b,d]);var A=t.useMemo((function(){if(m)return m;var e=D.toStartAndEnd(b);return D.availabilitiesFromBookings(l||[],s,u,new Date,e.startDate,e.endDate)}),[m,u,s,b,g,l,D]);return a.createElement("div",null,a.createElement(w,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return k(t),void C(D.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=h(x).add("NEXT"===e?1:-1,"month").toDate();k(a),C(D.monthRangeForDate(a))}},label:D.formatAsMonth(x),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:v}),a.createElement(O,{availabilities:A,date:x,onAvailabilitySelected:r,onDaySelected:o,slotLengthMs:c,slotStepMs:f,overrides:v}))};exports.AvailSlot=k,exports.AvailSlots=S,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(B,Object.assign({},l)))},exports.createUtils=r,exports.defaultComponents={ToolBar:{},ToolBarButton:{},Weekdays:{},Weekday:{},DayCells:{},DayCell:{},Availabilities:{},AvailSlot:{}},exports.defaultTheme=o,exports.getAvailOverride=b,exports.getAvailsOverride=p,exports.getDayCellOverride=g,exports.getDayCellsOverride=D,exports.getToolBarButtonOverride=v,exports.getToolBarOverride=f,exports.getWeekdayOverride=h,exports.getWeekdaysOverride=y;
//# sourceMappingURL=react-availability-calendar.cjs.production.min.js.map

@@ -1021,2 +1021,3 @@ import React, { useMemo, useContext, useState, useEffect, useRef } from 'react';

setSelectedDate(null);
onDaySelected && onDaySelected(null);
}, [date]);

@@ -1035,2 +1036,3 @@

var handleUnselect = function handleUnselect() {
onDaySelected && onDaySelected(null);
setSelectedDate(null);

@@ -1037,0 +1039,0 @@ };

@@ -74,3 +74,3 @@ import { MomentCtrFunc } from './moment-types/moment-subset';

onAvailabilitySelected: (e: AvailabilityEvent) => any;
onDaySelected: (d: Date) => any;
onDaySelected: (d: Date | null) => any;
blockOutPeriods?: MsSinceMidnightRange[];

@@ -84,3 +84,3 @@ slotLengthMs?: number;

style?: CSSProperties;
onDaySelected: (d: Date) => any;
onDaySelected: (d: Date | null) => any;
onAvailabilitySelected: (e: AvailabilityEvent) => any;

@@ -87,0 +87,0 @@ slotLengthMs?: number;

{
"version": "0.3.5",
"version": "0.3.6",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc