Calendar
Calendar component enables users to view and select dates.
#
Importimport Calendar from '@volue/wave-react';
#
Examples#
BasicBy default, Calendar
renders static, visual calendar. It does not include any logic of dates selection.
It may be useful when you want to display data with in calendar view but do not want it to be interactive.
Calendar
component is built on top of React Day Picker.
Majority of the React Day Picker API is available to influence the calendar appearance and behaviour.
#
Single selectionYou can use Calendar
component as a base to create custom date selection experience if Date Picker component does not meet your requirements.
To enable single day selection, set mode
property to single
. Also, it usually makes sense to make Calendar
component controlled using selected
and onSelect
props.
#
Range selectionSet mode
to range
to allow the selection of multiple days.
#
Min/max dateYou can set minimum and/or maximum dates to limit users to choose from a specific period in time.
Use startMonth
and endMonth
props to control time frames.
#
Caption layoutBy default Calendar
can be navigated using buttons for moving forward/backward through months. To enable select dropdowns for choosing the month and the year, use captionLayout="dropdown"
prop.
The following layouts of the month caption are available:
-
label
: displays the month and year as a label (default). -
dropdown
: displays dropdowns for choosing the month and the year. -
dropdown-months
: displays a dropdown with the months only. -
dropdown-years
: displays a dropdown with the years only.
dropdown
is typically recommended as it lets the user easily find the time period they want to choose from without having to click through months.
When explicit timeframe is not provided using startMonth
and endMonth
, showing the dropdown will set the start year to 100 years ago, and end year to the current year.
#
SizesCalendar component comes in two sizes: medium
and small
. By default, it uses medium
size.
#
Disabled stateAmong other modifiers that React Day Picker provides, it's convinient to disable specific days in the calendar.
In addition, you can disable the navigation using disableNavigation
prop or hide it alltogether using hideNavigation
prop.
#
LocaleTo change the locale, pass to the locale
prop a date-fns locale object.
For example, to localize the calendar in German, import the locale object from date-fns and pass it to the component.
import { de } from 'date-fns/locale';// import { enGB, nb, ... } from 'date-fns/locale';
#
Time zoneTo change the time zone, pass IANA time zone identifier or a UTC offset to timeZone
prop.
When working with time zones, make sure to use TZDate
object from date-fns timezone utils instead of the native Date
object.
import { TZDate } from '@date-fns/tz';
#
Inside popoverUsually Calendar
component is placed in a wrapping component such as Card or Popover.
Date Picker component is built using a composition of the Popover
and Calendar
components.
#
Accessibility features-
Calendar
provides deep keyboard interactions. -
Necessary ARIA roles and attributes are provided to give directions to a screen reader user.
#
API ReferenceThe props below show a commonly used subset of React DayPicker API.
Prop | Type | Default |
---|---|---|
mode | enum | No default value |
size | enum | "medium" |
captionLayout | enum | "label" |
selected | Matcher | Matcher[] | No default value |
onSelect | enum | No default value |
className | string | No default value |
defaultMonth | Date | No default value |
startMonth | Date | No default value |
endMonth | Date | No default value |
disabled | Matcher | Matcher[] | No default value |
modifiers | DayModifiers | No default value |
disableNavigation | boolean | No default value |
hideNavigation | boolean | No default value |
numberOfMonths | number | 1 |
locale | Locale | No default value |
timeZone | string | No default value |
footer | React.ReactNode | No default value |
labels | Partial<Labels> | No default value |
showOutsideDays | boolean | true |
today | Date | No default value |