2016-05-22 11:03:07 +08:00
---
category: Components
2022-11-09 12:28:04 +08:00
group: Data Display
2016-05-22 11:03:07 +08:00
title: Calendar
2024-03-22 14:22:42 +08:00
description: A container that displays data in calendar form.
2022-11-30 20:14:41 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*nF6_To7pDSAAAAAAAAAAAAAADrJ8AQ/original
2023-02-09 22:17:31 +08:00
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*-p-wQLik200AAAAAAAAAAAAADrJ8AQ/original
2016-05-22 11:03:07 +08:00
---
2016-09-10 13:43:30 +08:00
## When To Use
2016-05-22 11:03:07 +08:00
2017-09-16 11:29:05 +08:00
When data is in the form of dates, such as schedules, timetables, prices calendar, lunar calendar. This component also supports Year/Month switch.
2016-05-22 11:03:07 +08:00
2022-11-09 12:28:04 +08:00
## Examples
2022-11-17 17:31:26 +08:00
<!-- prettier - ignore -->
2023-03-21 13:00:34 +08:00
< code src = "./demo/basic.tsx" clientOnly > Basic< / code >
< code src = "./demo/notice-calendar.tsx" clientOnly > Notice Calendar< / code >
< code src = "./demo/card.tsx" clientOnly > Card< / code >
< code src = "./demo/select.tsx" clientOnly > Selectable Calendar< / code >
2023-08-17 17:12:51 +08:00
< code src = "./demo/lunar.tsx" clientOnly > Lunar Calendar< / code >
2023-03-21 13:00:34 +08:00
< code src = "./demo/customize-header.tsx" clientOnly > Customize Header< / code >
2023-05-18 16:12:41 +08:00
< code src = "./demo/component-token.tsx" debug > Component Token< / code >
2022-11-09 12:28:04 +08:00
2016-05-22 11:03:07 +08:00
## API
2023-08-08 18:27:48 +08:00
Common props ref: [Common props](/docs/react/common-props)
2022-06-13 14:03:43 +08:00
**Note:** Part of the Calendar's locale is read from `value` . So, please set the locale of `dayjs` correctly.
2017-02-23 15:57:05 +08:00
```jsx
2018-11-09 20:05:18 +08:00
// The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
2022-02-14 14:40:40 +08:00
// import dayjs from 'dayjs';
// import 'dayjs/locale/zh-cn';
// dayjs.locale('zh-cn');
2017-02-23 15:57:05 +08:00
2024-10-07 10:04:44 +08:00
< Calendar cellRender = {cellRender} onPanelChange = {onPanelChange} onSelect = {onSelect} / >
2016-05-22 11:03:07 +08:00
```
2019-05-26 13:09:06 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2024-11-11 12:15:54 +08:00
| cellRender | Customize cell content | function(current: dayjs, info: { prefixCls: string, originNode: React.ReactElement, today: dayjs, range?: 'start' \| 'end', type: PanelMode, locale?: Locale, subType?: 'hour' \| 'minute' \| 'second' \| 'meridiem' }) => React.ReactNode | - | 5.4.0 |
2022-06-13 14:03:43 +08:00
| dateFullCellRender | Customize the display of the date cell, the returned content will override the cell | function(date: Dayjs): ReactNode | - | |
2024-11-11 12:15:54 +08:00
| fullCellRender | Customize cell content | function(current: dayjs, info: { prefixCls: string, originNode: React.ReactElement, today: dayjs, range?: 'start' \| 'end', type: PanelMode, locale?: Locale, subType?: 'hour' \| 'minute' \| 'second' \| 'meridiem' }) => React.ReactNode | - | 5.4.0 |
2022-06-13 14:03:43 +08:00
| defaultValue | The date selected by default | [dayjs ](https://day.js.org/ ) | - | |
| disabledDate | Function that specifies the dates that cannot be selected, `currentDate` is same dayjs object as `value` prop which you shouldn't mutate it](https://github.com/ant-design/ant-design/issues/30987) | (currentDate: Dayjs) => boolean | - | |
2020-06-17 23:18:14 +08:00
| fullscreen | Whether to display in full-screen | boolean | true | |
2022-06-13 14:03:43 +08:00
| headerRender | Render custom header in panel | function(object:{value: Dayjs, type: string, onChange: f(), onTypeChange: f()}) | - | |
2020-07-01 22:37:55 +08:00
| locale | The calendar's locale | object | [(default) ](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json ) | |
2019-05-26 13:09:06 +08:00
| mode | The display mode of the calendar | `month` \| `year` | `month` | |
2022-06-13 14:03:43 +08:00
| validRange | To set valid range | \[[dayjs ](https://day.js.org/ ), [dayjs ](https://day.js.org/ )] | - | |
| value | The current selected date | [dayjs ](https://day.js.org/ ) | - | |
| onChange | Callback for when date changes | function(date: Dayjs) | - | |
| onPanelChange | Callback for when panel changes | function(date: Dayjs, mode: string) | - | |
2023-05-17 21:18:51 +08:00
| onSelect | Callback for when a date is selected, include source info | function(date: Dayjs, info: { source: 'year' \| 'month' \| 'date' \| 'customize' }) | - | `info` : 5.6.0 |
2020-01-02 16:05:59 +08:00
2023-04-11 10:25:24 +08:00
## Design Token
< ComponentTokenTable component = "Calendar" > < / ComponentTokenTable >
2020-01-02 16:05:59 +08:00
## FAQ
2022-07-12 17:09:43 +08:00
### How to use Calendar with customize date library?
2022-07-12 13:10:20 +08:00
2022-12-22 14:12:26 +08:00
See [Use custom date library ](/docs/react/use-custom-date-library#calendar )
2022-07-12 13:10:20 +08:00
### How to set locale for date-related components?
2022-12-22 14:12:26 +08:00
See [How to set locale for date-related components ](/components/date-picker/#localization )
2022-07-12 13:10:20 +08:00
### Date-related components locale is not working?
2022-12-22 14:12:26 +08:00
See FAQ [Date-related-components-locale-is-not-working? ](/docs/react/faq#date-related-components-locale-is-not-working )
2023-05-17 21:18:51 +08:00
### How to get date from panel click?
`onSelect` provide `info.source` to help on this:
```tsx
< Calendar
onSelect={(date, { source }) => {
if (source === 'date') {
console.log('Panel Select:', source);
}
}}
/>
```