conversional-big-calendar
v0.0.31
Published
Calendar! with events
Maintainers
Readme
react-big-calendar
An events calendar component built for React and designed for modern browsers (read: not IE) and uses flexbox over the classic tables-caption approach.
Inspired by Full Calendar.
Use and Setup
yarn add react-big-calendar or npm install --save react-big-calendar
Include react-big-calendar/lib/css/react-big-calendar.css for styles, and make sure your calendar's container
element has a height, or the calendar won't be visible. To provide your own custom styling, see the Custom Styling topic.
Starters
- react-big-calendar
- react-big-calendar with drag and drop
- react-big-calendar with TypeScript and React hooks bundled with Vite
Run examples locally
$ git clone [email protected]:jquense/react-big-calendar.git
$ cd react-big-calendar
$ yarn
$ yarn storybookLocalization and Date Formatting
react-big-calendar includes four options for handling the date formatting and culture localization, depending
on your preference of DateTime libraries. You can use either the Moment.js, Globalize.js, date-fns, Day.js localizers.
Regardless of your choice, you must choose a localizer to use this library:
Moment.js
import { Calendar, momentLocalizer } from 'react-big-calendar'
import moment from 'moment'
const localizer = momentLocalizer(moment)
const MyCalendar = (props) => (
<div>
<Calendar
localizer={localizer}
events={myEventsList}
startAccessor="start"
endAccessor="end"
style={{ height: 500 }}
/>
</div>
)Globalize.js v0.1.1
import { Calendar, globalizeLocalizer } from 'react-big-calendar'
import globalize from 'globalize'
const localizer = globalizeLocalizer(globalize)
const MyCalendar = (props) => (
<div>
<Calendar
localizer={localizer}
events={myEventsList}
startAccessor="start"
endAccessor="end"
style={{ height: 500 }}
/>
</div>
)date-fns v2
import { Calendar, dateFnsLocalizer } from 'react-big-calendar'
import format from 'date-fns/format'
import parse from 'date-fns/parse'
import startOfWeek from 'date-fns/startOfWeek'
import getDay from 'date-fns/getDay'
import enUS from 'date-fns/locale/en-US'
const locales = {
'en-US': enUS,
}
const localizer = dateFnsLocalizer({
format,
parse,
startOfWeek,
getDay,
locales,
})
const MyCalendar = (props) => (
<div>
<Calendar
localizer={localizer}
events={myEventsList}
startAccessor="start"
endAccessor="end"
style={{ height: 500 }}
/>
</div>
)Day.js
Note that the dayjsLocalizer extends Day.js with the following plugins:
import { Calendar, dayjsLocalizer } from 'react-big-calendar'
import dayjs from 'dayjs'
const localizer = dayjsLocalizer(dayjs)
const MyCalendar = (props) => (
<div>
<Calendar
localizer={localizer}
events={myEventsList}
startAccessor="start"
endAccessor="end"
style={{ height: 500 }}
/>
</div>
)Virtual Resource Columns
When rendering a large number of resources (hundreds or more) in the day view with resourceGroupingLayout, the default behaviour mounts every resource column in the DOM simultaneously. With 800 resources this creates tens of thousands of DOM nodes and makes the calendar unusably slow.
Pass virtual={true} to opt into horizontal column virtualisation:
<Calendar
localizer={localizer}
events={events}
defaultView="day"
resourceGroupingLayout
resourceGroups={myGroups} // e.g. 4 groups × 200 resources = 800 total
virtual
/>How it works
Fixed column width. In virtual mode every resource column is given a fixed width of 160px (VIRTUAL_COL_WIDTH) instead of the default flex: 1. This makes each column's pixel position predictable from its index alone — no DOM measurement needed.
Scroll tracking. TimeGrid listens to the onScroll event of the .rbc-time-content div. To avoid layout thrashing it defers the state update into a requestAnimationFrame callback (one update per frame, regardless of how fast the user scrolls).
Visible range calculation. On every render, getVirtualRange(totalCols) derives which columns intersect the current viewport:
visibleStart = floor(scrollLeft / VIRTUAL_COL_WIDTH)
visibleEnd = ceil((scrollLeft + clientWidth) / VIRTUAL_COL_WIDTH)Three extra columns are added on each side as an overscan buffer so columns pop into view before they reach the edge of the scroll container.
Spacer divs. Instead of rendering all 800 DayColumn components, only the ~20 visible ones are rendered. Two flex: none spacer divs — one on the left, one on the right — take up the space of the hidden columns and keep the scroll container at the correct total width (800 × 160px).
Header synchronisation. The same virtualStart/virtualEnd range is forwarded to TimeGridHeaderWithResourceGroups. Groups that fall entirely outside the range render as a single empty placeholder div. Visible groups render only their visible resource header cells, also surrounded by spacers. The header element gets overflow: hidden so the browser clips content that has been scrolled out of view when its scrollLeft is updated via the existing sync logic.
Week view. The virtual prop only affects the day view resource columns. If you switch to the week view you should stop passing resourceGroups (so the calendar renders a normal week grid without resource columns):
const [view, setView] = useState('day')
<Calendar
view={view}
onView={setView}
resourceGroups={view === 'day' ? myGroups : undefined}
resourceGroupingLayout={view === 'day'}
virtual
/>Custom Styling
Out of the box, you can include the compiled CSS files and be up and running. But, sometimes, you may want to style Big Calendar to match your application styling. For this reason, SASS files are included with Big Calendar.
@import 'react-big-calendar/lib/sass/styles';
@import 'react-big-calendar/lib/addons/dragAndDrop/styles'; // if using DnDSASS implementation provides a variables file containing color and sizing variables that you can
update to fit your application. Note: Changing and/or overriding styles can cause rendering issues with your
Big Calendar. Carefully test each change accordingly.
Join The Community
Help us improve Big Calendar! Join us on Slack. (Slack invite links do expire. If you can't get in, just file an issue and we'll get a new link.)
