React Availability Calendar
A customizable React component for displaying booking availabilities on a calendar.
No moment
dependency required, but accepts a moment
-like prop that needs to implement a subset of Moment
's API.
Props:
export interface AvailabilityCalendarProps {
moment: MomentCtrFunc;
theme?: CalendarThemeProp;
onCalRangeChange?: (range: Range) => any;
providerTimeZone: string;
bookings: Booking[];
initialDate: Date | null;
onAvailabilitySelected: (e: AvailabilityEvent) => any;
blockOutPeriods?: MsSinceMidnightRange[];
slotLengthMs?: number;
slotStepMs?: number;
}
Customize "Request Appointment" label:
pass theme={{requestAppointmentLabel: "Request Booking or other wording"}}
Installation:
npm install react-availability-calendar --save
Demos:
Usage:
import React from 'react';
import {
AvailabilityCalendar,
AvailabilityEvent,
MsSinceMidnightRange,
Booking,
Range,
CalendarThemeProp,
} from 'react-availability-calendar';
import moment from 'moment';
import 'bootstrap/dist/css/bootstrap.min.css';
import './custom.scss';
const msInHour = 60 * 60 * 1000;
const App: React.FC = () => {
const now = new Date();
const onAvailabilitySelected = (a: AvailabilityEvent) =>
console.log('Availability slot selected: ', a);
const onChangedCalRange = (r: Range) =>
console.log('Calendar range selected (fetch bookings here): ', r);
const blockOutPeriods: MsSinceMidnightRange[] = [
[0 * msInHour, 9 * msInHour],
[19 * msInHour, 24 * msInHour],
];
const bookings: Booking[] = [
{
startDate: new Date(2020, 2, 1, 19),
endDate: new Date(2020, 2, 1, 20),
},
{
startDate: new Date(2020, 2, 1, 16, 30),
endDate: new Date(2020, 2, 1, 17),
},
];
const providerTimeZone = 'America/New_York';
return (
<div style={{ width: 350 }}>
<AvailabilityCalendar
bookings={bookings}
providerTimeZone={providerTimeZone}
moment={moment}
initialDate={now}
onAvailabilitySelected={onAvailabilitySelected}
onCalRangeChange={onChangedCalRange}
blockOutPeriods={blockOutPeriods}
/>
</div>
);
};
export default App;
Examples
Running an example
cd example/example1
npm install
npm start
Bootstrapped with TSDX