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.12 to 0.2.13

10

dist/DayCell.d.ts
/// <reference types="react" />
import { DayCellProps } from './types';
export declare const DayCell: ({ date, dayIndexInWeek, weekIndexInCalRange, availsByIndex, selectedDate, handleSelected, moment, utils, theme, overrides, }: DayCellProps & {
export declare const DayCell: ({ date, shouldDisplay, dayIndexInWeek, weekIndexInCalRange, availsByIndex, selectedDate, handleSelected, moment, utils, theme, overrides, }: DayCellProps & {
overrides?: {

@@ -8,4 +8,8 @@ ToolBar: import("./overrides/general").OverridableComponentProps<import("./types").ToolBarProps, {}, {}>;

Weekdays: import("./overrides/general").OverridableComponentProps<{}, {}, {}>;
Weekday: import("./overrides/general").OverridableComponentProps<{
weekday: string;
}, {}, {}>;
DayCells: import("./overrides/general").OverridableComponentProps<import("./types").DayCellsProps, {}, {}>;
DayCell: import("./overrides/general").OverridableComponentProps<DayCellProps, {}, {
date: Date;
isSelected: boolean;

@@ -15,4 +19,6 @@ hasAvail: boolean;

Availabilities: import("./overrides/general").OverridableComponentProps<import("./types").AvailSlotsProps, {}, {}>;
AvailSlot: import("./overrides/general").OverridableComponentProps<import("./types").AvailSlotProps, {}, {}>;
AvailSlot: import("./overrides/general").OverridableComponentProps<import("./types").AvailSlotProps, {}, {
date: Date;
}>;
} | undefined;
}) => JSX.Element;

2

dist/DayCells.d.ts
/// <reference types="react" />
import { DayCellsProps } from './types';
import { Overrides } from './overrides';
export declare function DayCells({ week, selectedDate, weekIndexInCalRange, handleSelected, availsByIndex, moment, utils, theme, overrides, }: DayCellsProps & {
export declare function DayCells({ week, date, selectedDate, weekIndexInCalRange, handleSelected, availsByIndex, moment, utils, theme, overrides, }: DayCellsProps & {
overrides?: Overrides;
}): JSX.Element;

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

Weekdays: import("./overrides/general").OverridableComponentProps<{}, {}, {}>;
Weekday: import("./overrides/general").OverridableComponentProps<{
weekday: string;
}, {}, {}>;
DayCells: import("./overrides/general").OverridableComponentProps<import("./types").DayCellsProps, {}, {}>;
DayCell: import("./overrides/general").OverridableComponentProps<import("./types").DayCellProps, {}, {
date: Date;
isSelected: boolean;

@@ -15,4 +19,6 @@ hasAvail: boolean;

Availabilities: import("./overrides/general").OverridableComponentProps<import("./types").AvailSlotsProps, {}, {}>;
AvailSlot: import("./overrides/general").OverridableComponentProps<import("./types").AvailSlotProps, {}, {}>;
AvailSlot: import("./overrides/general").OverridableComponentProps<import("./types").AvailSlotProps, {}, {
date: Date;
}>;
} | undefined;
}) => JSX.Element;

@@ -11,2 +11,3 @@ import { DayCellProps, DayCellsProps, ToolBarProps, AvailSlotsProps, ToolBarButtonProps, AvailSlotProps } from '../types';

declare const DefaultDayCell: OverridableComponentProps<DayCellProps, {}, {
date: Date;
isSelected: boolean;

@@ -16,3 +17,5 @@ hasAvail: boolean;

declare const DefaultAvailabiliies: OverridableComponentProps<AvailSlotsProps, {}, {}>;
declare const DefaultAvailSlot: OverridableComponentProps<AvailSlotProps, {}, {}>;
declare const DefaultAvailSlot: OverridableComponentProps<AvailSlotProps, {}, {
date: Date;
}>;
declare type ExtractStyleProps<Overridable> = Overridable extends OverridableComponentProps<infer _T, infer _U, infer Z> ? Z : never;

@@ -28,2 +31,3 @@ export declare const defaultComponents: {

DayCell: OverridableComponentProps<DayCellProps, {}, {
date: Date;
isSelected: boolean;

@@ -33,3 +37,5 @@ hasAvail: boolean;

Availabilities: OverridableComponentProps<AvailSlotsProps, {}, {}>;
AvailSlot: OverridableComponentProps<AvailSlotProps, {}, {}>;
AvailSlot: OverridableComponentProps<AvailSlotProps, {}, {
date: Date;
}>;
};

@@ -46,3 +52,3 @@ export declare type Overrides = typeof defaultComponents;

export declare function getAvailsOverride(overrides: Overrides | undefined, defaultSpec: typeof DefaultAvailabiliies): ResolvedOverride<AvailSlotsProps, {}>;
export declare function getAvailOverride(overrides: Overrides | undefined, defaultSpec: typeof DefaultAvailSlot): ResolvedOverride<AvailSlotProps, {}>;
export declare function getAvailOverride(overrides: Overrides | undefined, defaultSpec: typeof DefaultAvailSlot, styleProps?: ExtractStyleProps<typeof DefaultAvailSlot>): ResolvedOverride<AvailSlotProps, {}>;
export {};

@@ -192,2 +192,6 @@ 'use strict';

function sameMonth(d1, d2) {
return datesEqual(moment(d1).startOf('month').toDate(), moment(d2).startOf('month').toDate());
}
function datesEqual(d1, d2) {

@@ -356,2 +360,3 @@ return d1 && d2 && d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();

formatAsMonth: formatAsMonth,
sameMonth: sameMonth,
formatAsDateWithTime: formatAsDateWithTime,

@@ -597,5 +602,5 @@ formatAsDateJustTime: formatAsDateJustTime,

}
function getAvailOverride(overrides, defaultSpec) {
function getAvailOverride(overrides, defaultSpec, styleProps) {
var o = overrides ? overrides.AvailSlot : undefined;
return getOverride(o, defaultSpec, {});
return getOverride(o, defaultSpec, styleProps);
}

@@ -753,7 +758,11 @@

var _getAvailOverride = getAvailOverride(overrides, {
className: theme.slotButtonClass,
style: {
marginBottom: 10
minWidth: 200
}
}, {
date: s.startDate
}),
Root = _getAvailOverride.Root,
className = _getAvailOverride.className,
style = _getAvailOverride.style;

@@ -771,10 +780,10 @@

return React__default.createElement("div", {
style: style
style: {
marginBottom: 10
}
}, React__default.createElement("button", {
className: theme.slotButtonClass,
className: className,
disabled: false,
// variant="contained"
style: {
minWidth: 200
},
style: style,
onClick: function onClick() {

@@ -879,2 +888,3 @@ return onAvailabilitySelected({

var date = _ref.date,
shouldDisplay = _ref.shouldDisplay,
dayIndexInWeek = _ref.dayIndexInWeek,

@@ -905,2 +915,3 @@ weekIndexInCalRange = _ref.weekIndexInCalRange,

}, {
date: date,
isSelected: isSelected,

@@ -915,2 +926,3 @@ hasAvail: hasAvail

return React__default.createElement(Root, Object.assign({}, {
shouldDisplay: shouldDisplay,
date: date,

@@ -928,5 +940,8 @@ dayIndexInWeek: dayIndexInWeek,

var styleWithHiden = shouldDisplay ? style : _extends({}, style, {
visibility: 'hidden'
});
return React__default.createElement("div", {
className: className,
style: style,
style: styleWithHiden,
onClick: function onClick() {

@@ -940,2 +955,3 @@ return handleSelected(date);

var week = _ref.week,
date = _ref.date,
selectedDate = _ref.selectedDate,

@@ -963,2 +979,3 @@ weekIndexInCalRange = _ref.weekIndexInCalRange,

return React__default.createElement(Root, Object.assign({}, {
date: date,
week: week,

@@ -981,2 +998,3 @@ selectedDate: selectedDate,

}, {
shouldDisplay: utils.sameMonth(d, date),
date: d,

@@ -1060,2 +1078,3 @@ selectedDate: selectedDate,

}, React__default.createElement(DayCells, Object.assign({}, {
date: date,
week: w,

@@ -1062,0 +1081,0 @@ selectedDate: selectedDate,

@@ -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.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;
"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;
//# sourceMappingURL=react-availability-calendar.cjs.production.min.js.map

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

function sameMonth(d1, d2) {
return datesEqual(moment(d1).startOf('month').toDate(), moment(d2).startOf('month').toDate());
}
function datesEqual(d1, d2) {

@@ -349,2 +353,3 @@ return d1 && d2 && d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();

formatAsMonth: formatAsMonth,
sameMonth: sameMonth,
formatAsDateWithTime: formatAsDateWithTime,

@@ -590,5 +595,5 @@ formatAsDateJustTime: formatAsDateJustTime,

}
function getAvailOverride(overrides, defaultSpec) {
function getAvailOverride(overrides, defaultSpec, styleProps) {
var o = overrides ? overrides.AvailSlot : undefined;
return getOverride(o, defaultSpec, {});
return getOverride(o, defaultSpec, styleProps);
}

@@ -746,7 +751,11 @@

var _getAvailOverride = getAvailOverride(overrides, {
className: theme.slotButtonClass,
style: {
marginBottom: 10
minWidth: 200
}
}, {
date: s.startDate
}),
Root = _getAvailOverride.Root,
className = _getAvailOverride.className,
style = _getAvailOverride.style;

@@ -764,10 +773,10 @@

return React.createElement("div", {
style: style
style: {
marginBottom: 10
}
}, React.createElement("button", {
className: theme.slotButtonClass,
className: className,
disabled: false,
// variant="contained"
style: {
minWidth: 200
},
style: style,
onClick: function onClick() {

@@ -872,2 +881,3 @@ return onAvailabilitySelected({

var date = _ref.date,
shouldDisplay = _ref.shouldDisplay,
dayIndexInWeek = _ref.dayIndexInWeek,

@@ -898,2 +908,3 @@ weekIndexInCalRange = _ref.weekIndexInCalRange,

}, {
date: date,
isSelected: isSelected,

@@ -908,2 +919,3 @@ hasAvail: hasAvail

return React.createElement(Root, Object.assign({}, {
shouldDisplay: shouldDisplay,
date: date,

@@ -921,5 +933,8 @@ dayIndexInWeek: dayIndexInWeek,

var styleWithHiden = shouldDisplay ? style : _extends({}, style, {
visibility: 'hidden'
});
return React.createElement("div", {
className: className,
style: style,
style: styleWithHiden,
onClick: function onClick() {

@@ -933,2 +948,3 @@ return handleSelected(date);

var week = _ref.week,
date = _ref.date,
selectedDate = _ref.selectedDate,

@@ -956,2 +972,3 @@ weekIndexInCalRange = _ref.weekIndexInCalRange,

return React.createElement(Root, Object.assign({}, {
date: date,
week: week,

@@ -974,2 +991,3 @@ selectedDate: selectedDate,

}, {
shouldDisplay: utils.sameMonth(d, date),
date: d,

@@ -1053,2 +1071,3 @@ selectedDate: selectedDate,

}, React.createElement(DayCells, Object.assign({}, {
date: date,
week: w,

@@ -1055,0 +1074,0 @@ selectedDate: selectedDate,

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

selectedDate: Date | null;
shouldDisplay: boolean;
date: Date;

@@ -100,2 +101,3 @@ dayIndexInWeek: number;

week: Date[];
date: Date;
selectedDate: Date | null;

@@ -102,0 +104,0 @@ weekIndexInCalRange: number;

@@ -7,2 +7,3 @@ import { Range, MsSinceMidnightRange, AvailabilityEvent, Booking } from '../types';

formatAsMonth: (date: Date) => string;
sameMonth: (d1: Date, d2: Date) => boolean;
formatAsDateWithTime: (date: Date) => string;

@@ -9,0 +10,0 @@ formatAsDateJustTime: (date: Date) => string;

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