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.2.11 to 0.2.12

3

dist/AvailabilityCalendar.d.ts

@@ -8,2 +8,5 @@ /// <reference types="react" />

Weekdays: import("./overrides/general").OverridableComponentProps<{}, {}, {}>;
Weekday: import("./overrides/general").OverridableComponentProps<{
weekday: string;
}, {}, {}>;
DayCells: import("./overrides/general").OverridableComponentProps<import("./types").DayCellsProps, {}, {}>;

@@ -10,0 +13,0 @@ DayCell: import("./overrides/general").OverridableComponentProps<import("./types").DayCellProps, {}, {

4

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

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

bookings = _ref.bookings,
avails = _ref.avails,
onCalRangeChange = _ref.onCalRangeChange,

@@ -1106,5 +1107,6 @@ slotLengthMs = _ref.slotLengthMs,

var availabilities = React.useMemo(function () {
if (avails) return avails;
var startAndEnd = utils.toStartAndEnd(calRange);
return utils.availabilitiesFromBookings(blockOutPeriods || [], providerTimeZone, bookings, now, startAndEnd.startDate, startAndEnd.endDate);
}, [bookings, providerTimeZone, calRange, now, blockOutPeriods, utils]);
}, [avails, bookings, providerTimeZone, calRange, now, blockOutPeriods, utils]);

@@ -1111,0 +1113,0 @@ var handleOnNavigate = function handleOnNavigate(navigate) {

@@ -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")},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,{style:{marginBottom:10}},{}),i=s.Root,u=s.style;return i?a.createElement(i,Object.assign({},{theme:n,onAvailabilitySelected:r,s:o,formatAsDateJustTime:l})):a.createElement("div",{style:u},a.createElement("button",{className:n.slotButtonClass,disabled:!1,style:{minWidth:200},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,n=e.dayIndexInWeek,r=e.weekIndexInCalRange,o=e.availsByIndex,l=e.selectedDate,s=e.handleSelected,i=e.moment,u=e.utils,m=e.theme,d=e.overrides,f=7*r+n,v=!!l&&u.datesEqual(t,l),h=o[f].hasAvail,y=function(e,t,a){return c(e?e.DayCell:void 0,t,a)}(d,{className:m.dayClassBase+" "+(l&&u.datesEqual(t,l)?m.dayClassSelected:o[f].hasAvail?m.dayClassHasAvailability:m.dayClassDefault),style:{cursor:"pointer",border:l&&u.datesEqual(t,l)?"4px solid":o[f].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{isSelected:v,hasAvail:h}),D=y.Root,g=y.style,b=y.className;return D?a.createElement(D,Object.assign({},{date:t,dayIndexInWeek:n,weekIndexInCalRange:r,availsByIndex:o,selectedDate:l,handleSelected:s,moment:i,utils:u,theme:m})):a.createElement("div",{className:b,style:g,onClick:function(){return s(t)}},i(t).format("D"))};function w(e){var t=e.week,n=e.selectedDate,r=e.weekIndexInCalRange,o=e.handleSelected,l=e.availsByIndex,s=e.moment,i=e.utils,u=e.theme,m=e.overrides,d=function(e,t){return c(e?e.DayCells:void 0,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}},{})}(m),f=d.Root,v=d.style;return f?a.createElement(f,Object.assign({},{week:t,selectedDate:n,weekIndexInCalRange:r,handleSelected:o,availsByIndex:l,moment:s,utils:i,theme:u})):a.createElement("div",{style:v},t.map((function(e,t){return a.createElement(p,Object.assign({key:"d_"+t},{date:e,selectedDate:n,weekIndexInCalRange:r,dayIndexInWeek:t,handleSelected:o,availsByIndex:l,moment:s,utils:i,theme:u,overrides:m}))})))}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)},C=t.useMemo((function(){return h.monthDaysForDate(u)}),[u,h]),M=C.days,k=C.weeks,S=t.useMemo((function(){return h.availByIndex(M,r)}),[M,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({},{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})))},C=function(e){var n=e.initialDate,r=e.onAvailabilitySelected,o=e.blockOutPeriods,l=e.providerTimeZone,s=e.bookings,u=e.onCalRangeChange,m=e.slotLengthMs,d=e.slotStepMs,c=e.overrides,v=i(),h=v.moment,y=v.utils,D=t.useState(n||new Date)[0],g=t.useState(y.monthRangeForDate(D)),b=g[0],p=g[1],w=t.useState(D),C=w[0],M=w[1],k=t.useRef(null);t.useEffect((function(){k.current!==b&&(u&&u(b),k.current=b)}),[b,u]);var S=t.useMemo((function(){var e=y.toStartAndEnd(b);return y.availabilitiesFromBookings(o||[],l,s,D,e.startDate,e.endDate)}),[s,l,b,D,o,y]);return a.createElement("div",null,a.createElement(f,{onNavigate:function(e){if("TODAY"===e){var t=new Date;return M(t),void p(y.monthRangeForDate(t))}if("NEXT"===e||"PREV"===e){var a=h(C).add("NEXT"===e?1:-1,"month").toDate();M(a),p(y.monthRangeForDate(a))}},label:y.formatAsMonth(C),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:c}),a.createElement(E,{availabilities:S,date:C,onAvailabilitySelected:r,slotLengthMs:m,slotStepMs:d,overrides:c}))};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(C,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),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")},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,{style:{marginBottom:10}},{}),i=s.Root,u=s.style;return i?a.createElement(i,Object.assign({},{theme:n,onAvailabilitySelected:r,s:o,formatAsDateJustTime:l})):a.createElement("div",{style:u},a.createElement("button",{className:n.slotButtonClass,disabled:!1,style:{minWidth:200},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,n=e.dayIndexInWeek,r=e.weekIndexInCalRange,o=e.availsByIndex,l=e.selectedDate,s=e.handleSelected,i=e.moment,u=e.utils,m=e.theme,d=e.overrides,f=7*r+n,v=!!l&&u.datesEqual(t,l),h=o[f].hasAvail,y=function(e,t,a){return c(e?e.DayCell:void 0,t,a)}(d,{className:m.dayClassBase+" "+(l&&u.datesEqual(t,l)?m.dayClassSelected:o[f].hasAvail?m.dayClassHasAvailability:m.dayClassDefault),style:{cursor:"pointer",border:l&&u.datesEqual(t,l)?"4px solid":o[f].hasAvail?"3px solid":"",height:50,width:50,display:"flex",justifyContent:"center",alignItems:"center"}},{isSelected:v,hasAvail:h}),D=y.Root,g=y.style,b=y.className;return D?a.createElement(D,Object.assign({},{date:t,dayIndexInWeek:n,weekIndexInCalRange:r,availsByIndex:o,selectedDate:l,handleSelected:s,moment:i,utils:u,theme:m})):a.createElement("div",{className:b,style:g,onClick:function(){return s(t)}},i(t).format("D"))};function w(e){var t=e.week,n=e.selectedDate,r=e.weekIndexInCalRange,o=e.handleSelected,l=e.availsByIndex,s=e.moment,i=e.utils,u=e.theme,m=e.overrides,d=function(e,t){return c(e?e.DayCells:void 0,{style:{display:"flex",justifyContent:"flex-start",flexWrap:"nowrap",flexDirection:"row"}},{})}(m),f=d.Root,v=d.style;return f?a.createElement(f,Object.assign({},{week:t,selectedDate:n,weekIndexInCalRange:r,handleSelected:o,availsByIndex:l,moment:s,utils:i,theme:u})):a.createElement("div",{style:v},t.map((function(e,t){return a.createElement(p,Object.assign({key:"d_"+t},{date:e,selectedDate:n,weekIndexInCalRange:r,dayIndexInWeek:t,handleSelected:o,availsByIndex:l,moment:s,utils:i,theme:u,overrides:m}))})))}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)},C=t.useMemo((function(){return h.monthDaysForDate(u)}),[u,h]),M=C.days,k=C.weeks,S=t.useMemo((function(){return h.availByIndex(M,r)}),[M,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({},{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})))},C=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],C=t.useState(g),M=C[0],k=C[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(M).add("NEXT"===e?1:-1,"month").toDate();k(a),w(D.monthRangeForDate(a))}},label:D.formatAsMonth(M),localizer:{messages:{today:"Today",previous:"Previous",next:"Next"}},overrides:v}),a.createElement(E,{availabilities:A,date:M,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(C,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

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

bookings = _ref.bookings,
avails = _ref.avails,
onCalRangeChange = _ref.onCalRangeChange,

@@ -1099,5 +1100,6 @@ slotLengthMs = _ref.slotLengthMs,

var availabilities = useMemo(function () {
if (avails) return avails;
var startAndEnd = utils.toStartAndEnd(calRange);
return utils.availabilitiesFromBookings(blockOutPeriods || [], providerTimeZone, bookings, now, startAndEnd.startDate, startAndEnd.endDate);
}, [bookings, providerTimeZone, calRange, now, blockOutPeriods, utils]);
}, [avails, bookings, providerTimeZone, calRange, now, blockOutPeriods, utils]);

@@ -1104,0 +1106,0 @@ var handleOnNavigate = function handleOnNavigate(navigate) {

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

bookings: Booking[];
avails?: AvailabilityEvent[];
initialDate: Date | null;

@@ -73,0 +74,0 @@ onAvailabilitySelected: (e: AvailabilityEvent) => any;

{
"version": "0.2.11",
"version": "0.2.12",
"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