• Stars
    star
    3,515
  • Rank 12,645 (Top 0.3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ultimate calendar for your React app.

npm downloads CI

React-Calendar

Ultimate calendar for your React app.

  • Pick days, months, years, or even decades
  • Supports range selection
  • Supports virtually any language
  • No moment.js needed

tl;dr

  • Install by executing npm install react-calendar or yarn add react-calendar.
  • Import by adding import Calendar from 'react-calendar'.
  • Use by adding <Calendar />. Use onChange prop for getting new values.

Demo

A minimal demo page can be found in sample directory.

Online demo is also available!

Before you continue

React-Calendar is under constant development. This documentation is written for React-Calendar 4.x branch. If you want to see documentation for other versions of React-Calendar, use dropdown on top of GitHub page to switch to an appropriate tag. Here are quick links to the newest docs from each branch:

Getting started

Compatibility

Your project needs to use React 16.8 or later.

React-Calendar uses modern web technologies. That's why it's so fast, lightweight and easy to style. This, however, comes at a cost of supporting only modern browsers.

Legacy browsers

If you need to support legacy browsers like Internet Explorer 10, you will need to use Intl.js or another Intl polyfill along with React-Calendar.

My locale isn't supported! What can I do?

If your locale isn't supported, you can use Intl.js or another Intl polyfill along with React-Calendar.

Installation

Add React-Calendar to your project by executing npm install react-calendar or yarn add react-calendar.

Usage

Here's an example of basic usage:

import React, { useState } from 'react';
import Calendar from 'react-calendar';

function MyApp() {
  const [value, onChange] = useState(new Date());

  return (
    <div>
      <Calendar onChange={onChange} value={value} />
    </div>
  );
}

Check the sample directory in this repository for a full working example. For more examples and more advanced use cases, check Recipes in React-Calendar Wiki.

Custom styling

If you want to use default React-Calendar styling to build upon it, you can import React-Calendar's styles by using:

import 'react-calendar/dist/Calendar.css';

User guide

Calendar

Displays a complete, interactive calendar.

Props

Prop name Description Default value Example values
activeStartDate The beginning of a period that shall be displayed. If you wish to use React-Calendar in an uncontrolled way, use defaultActiveStartDate instead. (today) new Date(2017, 0, 1)
allowPartialRange Whether to call onChange with only partial result given selectRange prop. false true
calendarType Type of calendar that should be used. Can be "ISO 8601", "US", "Arabic", or "Hebrew". Setting to "US" or "Hebrew" will change the first day of the week to Sunday. Setting to "Arabic" will change the first day of the week to Saturday. Setting to "Arabic" or "Hebrew" will make weekends appear on Friday to Saturday. Type of calendar most commonly used in a given locale "ISO 8601"
className Class name(s) that will be added along with "react-calendar" to the main React-Calendar <div> element. n/a
  • String: "class1 class2"
  • Array of strings: ["class1", "class2 class3"]
defaultActiveStartDate The beginning of a period that shall be displayed by default. If you wish to use React-Calendar in a controlled way, use activeStartDate instead. (today) new Date(2017, 0, 1)
defaultValue Calendar value that shall be selected initially. Can be either one value or an array of two values. If you wish to use React-Calendar in a controlled way, use value instead. n/a
  • Date: new Date()
  • An array of dates: [new Date(2017, 0, 1), new Date(2017, 7, 1)]
defaultView Determines which calendar view shall be opened initially. Does not disable navigation. Can be "month", "year", "decade" or "century". If you wish to use React-Calendar in a controlled way, use view instead. The most detailed view allowed "year"
formatDay Function called to override default formatting of day tile labels. Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'd')
formatLongDate Function called to override default formatting of day tile abbr labels. Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'dd MMM YYYY')
formatMonth Function called to override default formatting of month names. Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'MMM')
formatMonthYear Function called to override default formatting of months and years. Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'MMMM YYYY')
formatShortWeekday Function called to override default formatting of weekday names (shortened). Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'dd')
formatWeekday Function called to override default formatting of weekday names. Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'dd')
formatYear Function called to override default formatting of year in the top navigation section. Can be used to use your own formatting function. (default formatter) (locale, date) => formatDate(date, 'YYYY')
goToRangeStartOnSelect Whether to go to the beginning of the range when selecting the end of the range. true false
inputRef A prop that behaves like ref, but it's passed to main <div> rendered by <Calendar> component. n/a
  • Function:
    (ref) => { this.myCalendar = ref; }
  • Ref created using React.createRef:
    this.ref = React.createRef();
    …
    inputRef={this.ref}
  • Ref created using React.useRef:
    const ref = React.useRef();
    …
    inputRef={ref}
locale Locale that should be used by the calendar. Can be any IETF language tag. User's browser settings "hu-HU"
maxDate Maximum date that the user can select. Periods partially overlapped by maxDate will also be selectable, although React-Calendar will ensure that no later date is selected. n/a Date: new Date()
maxDetail The most detailed view that the user shall see. View defined here also becomes the one on which clicking an item will select a date and pass it to onChange. Can be "month", "year", "decade" or "century". "month" "year"
minDate Minimum date that the user can select. Periods partially overlapped by minDate will also be selectable, although React-Calendar will ensure that no earlier date is selected. n/a Date: new Date()
minDetail The least detailed view that the user shall see. Can be "month", "year", "decade" or "century". "century" "decade"
navigationAriaLabel aria-label attribute of a label rendered on calendar navigation bar. n/a "Go up"
navigationAriaLive aria-live attribute of a label rendered on calendar navigation bar. undefined "polite"
navigationLabel Content of a label rendered on calendar navigation bar. (default label) ({ date, label, locale, view }) => `Current view: ${view}, date: ${date.toLocaleDateString(locale)}`
nextAriaLabel aria-label attribute of the "next" button on the navigation pane. n/a "Next"
nextLabel Content of the "next" button on the navigation pane. Setting the value explicitly to null will hide the icon. "β€Ί"
  • String: "β€Ί"
  • React element: <NextIcon />
next2AriaLabel aria-label attribute of the "next on higher level" button on the navigation pane. n/a "Jump forwards"
next2Label Content of the "next on higher level" button on the navigation pane. Setting the value explicitly to null will hide the icon. "Β»"
  • String: "Β»"
  • React element: <DoubleNextIcon />
onActiveStartDateChange Function called when the user navigates from one view to another using previous/next button. Note that this function will not be called when e.g. drilling up from January 2021 to 2021 or drilling down the other way around.
action signifies the reason for active start date change and can be one of the following values: "prev", "prev2", "next", "next2", "drillUp", "drillDown", "onChange".
n/a ({ action, activeStartDate, value, view }) => alert('Changed view to: ', activeStartDate, view)
onChange Function called when the user clicks an item (day on month view, month on year view and so on) on the most detailed view available. n/a (value, event) => alert('New date is: ', value)
onViewChange Function called when the user navigates from one view to another using drill up button or by clicking a tile.
action signifies the reason for view change and can be one of the following values: "prev", "prev2", "next", "next2", "drillUp", "drillDown", "onChange".
n/a ({ action, activeStartDate, value, view }) => alert('New view is: ', view)
onClickDay Function called when the user clicks a day. n/a (value, event) => alert('Clicked day: ', value)
onClickDecade Function called when the user clicks a decade. n/a (value, event) => alert('Clicked decade: ', value)
onClickMonth Function called when the user clicks a month. n/a (value, event) => alert('Clicked month: ', value)
onClickWeekNumber Function called when the user clicks a week number. n/a (weekNumber, date, event) => alert('Clicked week: ', weekNumber, 'that starts on: ', date)
onClickYear Function called when the user clicks a year. n/a (value, event) => alert('Clicked year: ', value)
onDrillDown Function called when the user drills down by clicking a tile. n/a ({ activeStartDate, view }) => alert('Drilled down to: ', activeStartDate, view)
onDrillUp Function called when the user drills up by clicking drill up button. n/a ({ activeStartDate, view }) => alert('Drilled up to: ', activeStartDate, view)
prevAriaLabel aria-label attribute of the "previous" button on the navigation pane. n/a "Previous"
prevLabel Content of the "previous" button on the navigation pane. Setting the value explicitly to null will hide the icon. "β€Ή"
  • String: "β€Ή"
  • React element: <PreviousIcon />
prev2AriaLabel aria-label attribute of the "previous on higher level" button on the navigation pane. n/a "Jump backwards"
prev2Label Content of the "previous on higher level" button on the navigation pane. Setting the value explicitly to null will hide the icon. "Β«"
  • String: "Β«"
  • React element: <DoublePreviousIcon />
returnValue Which dates shall be passed by the calendar to the onChange function and onClick{Period} functions. Can be "start", "end" or "range". The latter will cause an array with start and end values to be passed. "start" "range"
showDoubleView Whether to show two months/years/… at a time instead of one. Defaults showFixedNumberOfWeeks prop to be true. false true
showFixedNumberOfWeeks Whether to always show fixed number of weeks (6). Forces showNeighboringMonth prop to be true. false true
showNavigation Whether a navigation bar with arrows and title shall be rendered. true false
showNeighboringMonth Whether days from previous or next month shall be rendered if the month doesn't start on the first day of the week or doesn't end on the last day of the week, respectively. true false
selectRange Whether the user shall select two dates forming a range instead of just one. Note: This feature will make React-Calendar return array with two dates regardless of returnValue setting. false true
showWeekNumbers Whether week numbers shall be shown at the left of MonthView or not. false true
tileClassName Class name(s) that will be applied to a given calendar item (day on month view, month on year view and so on). n/a
  • String: "class1 class2"
  • Array of strings: ["class1", "class2 class3"]
  • Function: ({ activeStartDate, date, view }) => view === 'month' && date.getDay() === 3 ? 'wednesday' : null
tileContent Allows to render custom content within a given calendar item (day on month view, month on year view and so on). n/a
  • String: "Sample"
  • React element: <TileContent />
  • Function: ({ activeStartDate, date, view }) => view === 'month' && date.getDay() === 0 ? <p>It's Sunday!</p> : null
tileDisabled Pass a function to determine if a certain day should be displayed as disabled. n/a
  • Function: ({activeStartDate, date, view }) => date.getDay() === 0
value Calendar value. Can be either one value or an array of two values. If you wish to use React-Calendar in an uncontrolled way, use defaultValue instead. n/a
  • Date: new Date()
  • String: 2017-01-01
  • An array of dates: [new Date(2017, 0, 1), new Date(2017, 7, 1)]
  • An array of strings: ['2017-01-01', '2017-08-01']
view Determines which calendar view shall be opened. Does not disable navigation. Can be "month", "year", "decade" or "century". If you wish to use React-Calendar in an uncontrolled way, use defaultView instead. The most detailed view allowed "year"

MonthView, YearView, DecadeView, CenturyView

Displays a given month, year, decade and a century, respectively.

Props

Prop name Description Default value Example values
activeStartDate The beginning of a period that shall be displayed. n/a new Date(2017, 0, 1)
hover The date over which the user is hovering. Used only when selectRange is enabled, to render a β€œWIP” range when the user is selecting range. n/a new Date(2017, 0, 1)
maxDate Maximum date that the user can select. Periods partially overlapped by maxDate will also be selectable, although react-calendar will ensure that no later date is selected. n/a Date: new Date()
minDate Minimum date that the user can select. Periods partially overlapped by minDate will also be selectable, although react-calendar will ensure that no earlier date is selected. n/a Date: new Date()
onClick Function called when the user clicks an item (day on month view, month on year view and so on). n/a (value) => alert('New date is: ', value)
tileClassName Class name(s) that will be applied to a given calendar item (day on month view, month on year view and so on). n/a
  • String: "class1 class2"
  • Array of strings: ["class1", "class2 class3"]
  • Function: ({ date, view }) => view === 'month' && date.getDay() === 3 ? 'wednesday' : null
tileContent Allows to render custom content within a given item (day on month view, month on year view and so on). Note: For tiles with custom content you might want to set fixed height of react-calendar__tile to ensure consistent layout. n/a ({ date, view }) => view === 'month' && date.getDay() === 0 ? <p>It's Sunday!</p> : null
value Calendar value. Can be either one value or an array of two values. n/a
  • Date: new Date()
  • An array of dates: [new Date(2017, 0, 1), new Date(2017, 7, 1)]
  • String: 2017-01-01
  • An array of strings: ['2017-01-01', '2017-08-01']

Useful links

License

The MIT License.

Author

Wojciech Maj
[email protected]
https://wojtekmaj.pl

Thank you

Sponsors

Thank you to all our sponsors! Become a sponsor and get your image on our README on GitHub.

Backers

Thank you to all our backers! Become a backer and get your image on our README on GitHub.

Top Contributors

Thank you to all our contributors that helped on this project!

Top Contributors

More Repositories

1

react-pdf

Display PDFs in your React app as easily as if they were images.
TypeScript
9,148
star
2

react-lifecycle-methods-diagram

Interactive React Lifecycle Methods diagram.
TypeScript
3,870
star
3

react-date-picker

A date picker for your React app.
TypeScript
1,255
star
4

react-datetime-picker

A datetime picker for your React app.
TypeScript
543
star
5

react-daterange-picker

A date range picker for your React app.
TypeScript
519
star
6

react-clock

An analog clock for your React app.
TypeScript
335
star
7

react-time-picker

A time picker for your React app.
TypeScript
322
star
8

enzyme-adapter-react-17

Unofficial adapter for React 17 for Enzyme.
JavaScript
297
star
9

react-datetimerange-picker

A datetime range picker for your React app.
TypeScript
169
star
10

react-timerange-picker

A time range picker for your React app.
TypeScript
87
star
11

react-hooks

A collection of React Hooks.
TypeScript
69
star
12

get-user-locale

A function that returns user's locale as an IETF language tag, based on all available sources.
TypeScript
58
star
13

country-code-to-flag-emoji

A function that returns a flag emoji given IETF language tag.
TypeScript
55
star
14

make-cancellable-promise

Make any Promise cancellable.
TypeScript
28
star
15

merge-refs

A function that merges React refs into one.
TypeScript
25
star
16

react-fit

Fit a popover element on the screen.
TypeScript
22
star
17

detect-element-overflow

A function that tells you whether a given element is overflowing its container or not. Useful for creating dropdowns and tooltips.
TypeScript
21
star
18

date-utils

A collection of date-related utilities.
TypeScript
20
star
19

yarn-plugin-nolyfill

Yarn Berry plugin that replaces unnecessary polyfills with native implementations.
TypeScript
18
star
20

opening-hours-utils

A collection of opening hours-related utilities.
TypeScript
13
star
21

merge-class-names

A function that merges given class names, no matter their format: string with single or multiple class names or an array of class names. Filters out invalid class names as well.
JavaScript
12
star
22

react-t

Simple translation module for React applications.
TypeScript
12
star
23

recreate-from-source-maps

Recreate a Webpack project just by providing an URL.
JavaScript
11
star
24

color-utils

A collection of color-related utilities.
TypeScript
11
star
25

async-array-utils

A collection of array-related async utilities.
TypeScript
11
star
26

react-async-button

A button that handles Promises for your React app.
TypeScript
10
star
27

vite-plugin-simple-html

Vite plugin for HTML processing and minification
TypeScript
10
star
28

i18n-compare

Generates a summary of differences between two i18n files
TypeScript
9
star
29

package-manager-stats

Script to get stats about package managers used in most popular projects on GitHub.
TypeScript
8
star
30

make-event-props

Returns an object with on-event callback props curried with provided args.
TypeScript
8
star
31

predict-input-value

Predicts the input value during KeyDown or KeyPress events, before the input is actually changed
TypeScript
8
star
32

timezone-coworking-tool

A tool to help with coworking with people in different timezones.
TypeScript
7
star
33

eslint-config-wojtekmaj

ESLint configuration by wojtekmaj
TypeScript
5
star
34

next-turbopack-nodenext

Adds module: NodeNext support to Turbopack in Next.js.
TypeScript
4
star
35

is-valid-nip

Check if a number is a valid Numer Identyfikacji Podatkowej (NIP).
TypeScript
3
star
36

update-input-width

A function that given input element, updates its width to fit its content.
TypeScript
3
star
37

uwp-web-framework

Universal Windows Platform web framework
CSS
3
star
38

is-valid-abn

Check if a number is a valid Australian Business Number (ABN).
TypeScript
3
star
39

is-valid-regon

Check if a number is a valid REGON.
TypeScript
2
star
40

eslint-staged-files

Run ESLint on staged files only.
JavaScript
2
star
41

nightmare-advanced-click

Extends Nightmare with .rightClick(), .middleClick(), .ctrlClick() and other actions.
JavaScript
2
star
42

is-valid-pesel

Check if a number is a valid PESEL.
TypeScript
2
star
43

is-valid-australian-postcode

Check if a number is a valid Australian postcode.
TypeScript
1
star
44

is-valid-acn

Check if a number is a valid Australian Company Number (ACN).
TypeScript
1
star
45

webpack-summary-compare

Generates a summary of differences between two Webpack summaries
JavaScript
1
star
46

is-valid-utr

Check if a number is a valid Unique Taxpayer Reference (UTR).
TypeScript
1
star