Calendar
Usage
Calendar component:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
RangeCalendar component (supports the same props as Calendar component):
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Multiple selected dates
Set multiple
on Calendar component to allow multiple dates selection:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Custom day renderer
You can provide your own day renderer function with renderDay
prop.
For example, it can be used to wrap day with Indicator:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Controlled month
Control month that is currently displayed with month
and onMonthChange
props:
Alternatively, set initialMonth
prop to leave it uncontrolled:
Level change
Calendar supports three levels: date, month and year. User can access next level by clicking label between next/previous controls.
To disable that, set allowLevelChange
prop to false:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Localization
All @mantine/dates components are built with dayjs library.
Default locale is en
, to change this follow dayjs localization guide:
Then set locale
prop in component:
Пн | Вт | Ср | Чт | Пт | Сб | Вс |
---|---|---|---|---|---|---|
First day of the week
Change first day of week with firstDayOfWeek
prop. It accepts either sunday
or monday
as values:
Su | Mo | Tu | We | Th | Fr | Sa |
---|---|---|---|---|---|---|
Multiple months
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Label format
By default, Calendar will display dates in human-readable format.
To change that, provide dayjs format string to the labelFormat
prop:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Min and max dates
Set minDate
and maxDate
props to define minimum and maximum possible dates.
Dates which are not included in available interval will be disabled:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Exclude dates
To exclude dates set excludeDate
prop with function that receives date as an argument and returns
true
if date should be disabled. For example, to disable weekends, check if date day is 0 or 6:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Render day as props
You can render a custom component with renderDay
.
The function receives one argument:
date
– date object which is used to render day component
Add styles to days
You can apply styles to any day with dayStyle
or dayClassName
callbacks.
Both functions receive two arguments:
date
– date object which is used to render day componentmodifiers
– modifiers that are applied to the day component
Modifiers
Styles based on date
dayStyle
callback allows you to add inline styles to days. Function must return either styles object or null.
In this example, we will add red background to each Friday 13th based on date (first argument):
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Styles based on modifiers
dayClassName
callback allows you to add className to days. Function must return either className string or null.
In this example, we will hide all outside dates and change color of weekends based on modifiers (second argument):
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Customize with styles API
To customize any part of the calendar use Styles API:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Calendar component props
Name | Type | Description |
---|---|---|
allowLevelChange | boolean | Allow to change level (date – month – year) |
amountOfMonths | number | Amount of months |
dayClassName | (date: Date, modifiers: DayModifiers) => string | Adds className to day button based on date and modifiers |
dayStyle | (date: Date, modifiers: DayModifiers) => CSSProperties | Adds style to day button based on date and modifiers |
disableOutsideEvents | boolean | When true dates that are outside of given month cannot be clicked or focused |
excludeDate | (date: Date) => boolean | Callback function to determine if day should be disabled |
firstDayOfWeek | "sunday" | "monday" | Set first day of the week |
focusable | boolean | Should focusable days have tabIndex={0}? |
fullWidth | boolean | Set to true to make calendar take 100% of container width |
hideOutsideDates | boolean | Remove outside dates |
hideWeekdays | boolean | Set to false to remove weekdays row |
initialLevel | "date" | "month" | "year" | Initial date selection level |
initialMonth | Date | Initial month for uncontrolled calendar |
labelFormat | string | dayjs Calendar month label format |
locale | string | Locale used for labels formatting, defaults to theme.datesLocale |
maxDate | Date | Maximum possible date |
minDate | Date | Minimum possible date |
month | Date | Month for controlled calendar |
multiple | boolean | |
nextDecadeLabel | string | Next decade control aria-label |
nextMonthLabel | string | Next month control aria-label |
nextYearLabel | string | Next year control aria-label |
onChange | (value: Multiple extends true ? Date[] : Date) => void | |
onDayMouseEnter | (date: Date, event: MouseEvent<Element, MouseEvent>) => void | Called when onMouseEnter event fired on day button |
onMonthChange | (month: Date) => void | Called when month changes |
paginateBy | number | Paginate by amount of months |
preventFocus | boolean | Prevent focusing upon clicking |
previousDecadeLabel | string | Previous decade control aria-label |
previousMonthLabel | string | Previous month control aria-label |
previousYearLabel | string | Previous year control aria-label |
range | [Date, Date] | Selected range |
renderDay | (date: Date) => ReactNode | Render day based on the date |
size | "xs" | "sm" | "md" | "lg" | "xl" | Calendar size |
value | Date | Date[] | |
weekdayLabelFormat | string | dayjs label format for weekday heading |
weekendDays | number[] | Indices of weekend days |
yearLabelFormat | string | dayjs Calendar year label format |
RangeCalendar component props
Name | Type | Description |
---|---|---|
allowLevelChange | boolean | Allow to change level (date – month – year) |
allowSingleDateInRange | boolean | Allow one date to be selected as range |
amountOfMonths | number | Amount of months |
dayClassName | (date: Date, modifiers: DayModifiers) => string | Adds className to day button based on date and modifiers |
dayStyle | (date: Date, modifiers: DayModifiers) => CSSProperties | Adds style to day button based on date and modifiers |
disableOutsideEvents | boolean | When true dates that are outside of given month cannot be clicked or focused |
excludeDate | (date: Date) => boolean | Callback function to determine if day should be disabled |
firstDayOfWeek | "sunday" | "monday" | Set first day of the week |
focusable | boolean | Should focusable days have tabIndex={0}? |
fullWidth | boolean | Set to true to make calendar take 100% of container width |
hideOutsideDates | boolean | Remove outside dates |
hideWeekdays | boolean | Set to false to remove weekdays row |
initialLevel | "date" | "month" | "year" | Initial date selection level |
initialMonth | Date | Initial month for uncontrolled calendar |
labelFormat | string | dayjs Calendar month label format |
locale | string | Locale used for labels formatting, defaults to theme.datesLocale |
maxDate | Date | Maximum possible date |
minDate | Date | Minimum possible date |
month | Date | Month for controlled calendar |
nextDecadeLabel | string | Next decade control aria-label |
nextMonthLabel | string | Next month control aria-label |
nextYearLabel | string | Next year control aria-label |
onChange * | (value: [Date, Date]) => void | Called when selected date changes |
onDayMouseEnter | (date: Date, event: MouseEvent<Element, MouseEvent>) => void | Called when onMouseEnter event fired on day button |
onMonthChange | (month: Date) => void | Called when month changes |
paginateBy | number | Paginate by amount of months |
preventFocus | boolean | Prevent focusing upon clicking |
previousDecadeLabel | string | Previous decade control aria-label |
previousMonthLabel | string | Previous month control aria-label |
previousYearLabel | string | Previous year control aria-label |
range | [Date, Date] | Selected range |
renderDay | (date: Date) => ReactNode | Render day based on the date |
size | "xs" | "sm" | "md" | "lg" | "xl" | Calendar size |
value * | [Date, Date] | Selected dates |
weekdayLabelFormat | string | dayjs label format for weekday heading |
weekendDays | number[] | Indices of weekend days |
yearLabelFormat | string | dayjs Calendar year label format |
Calendar component Styles API
Name | Static selector | Description |
---|---|---|
calendarBase | .mantine-Calendar-calendarBase | Root element |
calendarHeader | .mantine-Calendar-calendarHeader | Calendar header, contains next/previous and level change controls |
calendarHeaderControl | .mantine-Calendar-calendarHeaderControl | Next/previous controls |
calendarHeaderLevel | .mantine-Calendar-calendarHeaderLevel | Level change control (year, month, date) |
calendarHeaderLevelIcon | .mantine-Calendar-calendarHeaderLevelIcon | Level control icon (caret) |
yearPicker | .mantine-Calendar-yearPicker | Year picker root element |
yearPickerControls | .mantine-Calendar-yearPickerControls | Year picker controls wrapper |
yearPickerControl | .mantine-Calendar-yearPickerControl | Year picker control button |
yearPickerControlActive | .mantine-Calendar-yearPickerControlActive | Year picker control active modifier (currently selected year) |
monthPicker | .mantine-Calendar-monthPicker | Month picker root element |
monthPickerControls | .mantine-Calendar-monthPickerControls | Month picker controls wrapper |
monthPickerControl | .mantine-Calendar-monthPickerControl | Month picker control button |
monthPickerControlActive | .mantine-Calendar-monthPickerControlActive | Month picker control active modifier (currently selected month) |
month | .mantine-Calendar-month | Root element |
weekdayCell | .mantine-Calendar-weekdayCell | Table th element, wraps weekday |
weekday | .mantine-Calendar-weekday | Weekday title |
cell | .mantine-Calendar-cell | Table cell, wraps day |
day | .mantine-Calendar-day | Day button |
RangeCalendar component Styles API
Name | Static selector | Description |
---|---|---|
calendarBase | .mantine-RangeCalendar-calendarBase | Root element |
calendarHeader | .mantine-RangeCalendar-calendarHeader | Calendar header, contains next/previous and level change controls |
calendarHeaderControl | .mantine-RangeCalendar-calendarHeaderControl | Next/previous controls |
calendarHeaderLevel | .mantine-RangeCalendar-calendarHeaderLevel | Level change control (year, month, date) |
calendarHeaderLevelIcon | .mantine-RangeCalendar-calendarHeaderLevelIcon | Level control icon (caret) |
yearPicker | .mantine-RangeCalendar-yearPicker | Year picker root element |
yearPickerControls | .mantine-RangeCalendar-yearPickerControls | Year picker controls wrapper |
yearPickerControl | .mantine-RangeCalendar-yearPickerControl | Year picker control button |
yearPickerControlActive | .mantine-RangeCalendar-yearPickerControlActive | Year picker control active modifier (currently selected year) |
monthPicker | .mantine-RangeCalendar-monthPicker | Month picker root element |
monthPickerControls | .mantine-RangeCalendar-monthPickerControls | Month picker controls wrapper |
monthPickerControl | .mantine-RangeCalendar-monthPickerControl | Month picker control button |
monthPickerControlActive | .mantine-RangeCalendar-monthPickerControlActive | Month picker control active modifier (currently selected month) |
month | .mantine-RangeCalendar-month | Root element |
weekdayCell | .mantine-RangeCalendar-weekdayCell | Table th element, wraps weekday |
weekday | .mantine-RangeCalendar-weekday | Weekday title |
cell | .mantine-RangeCalendar-cell | Table cell, wraps day |
day | .mantine-RangeCalendar-day | Day button |