2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2018-11-04 16:20:35 +08:00
|
|
|
|
type: 数据展示
|
2016-09-21 11:28:38 +08:00
|
|
|
|
subtitle: 日历
|
2016-03-31 14:17:09 +08:00
|
|
|
|
cols: 1
|
2016-09-21 11:28:38 +08:00
|
|
|
|
title: Calendar
|
2020-05-31 11:48:34 +08:00
|
|
|
|
cover: https://gw.alipayobjects.com/zos/antfincdn/dPQmLq08DI/Calendar.svg
|
2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
2015-11-11 00:15:12 +08:00
|
|
|
|
|
2015-11-13 18:20:22 +08:00
|
|
|
|
按照日历形式展示数据的容器。
|
2015-11-11 00:15:12 +08:00
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
2015-11-13 18:20:22 +08:00
|
|
|
|
当数据是日期或按照日期划分时,例如日程、课表、价格日历等,农历等。目前支持年/月切换。
|
|
|
|
|
|
2015-11-11 00:15:12 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2022-06-13 14:03:43 +08:00
|
|
|
|
**注意:**Calendar 部分 locale 是从 value 中读取,所以请先正确设置 dayjs 的 locale。
|
2017-02-23 15:57:05 +08:00
|
|
|
|
|
|
|
|
|
```jsx
|
2017-09-26 23:12:47 +08:00
|
|
|
|
// 默认语言为 en-US,所以如果需要使用其他语言,推荐在入口文件全局设置 locale
|
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
|
|
|
|
|
2015-11-13 19:56:34 +08:00
|
|
|
|
<Calendar
|
|
|
|
|
dateCellRender={dateCellRender}
|
|
|
|
|
monthCellRender={monthCellRender}
|
2015-11-15 21:40:01 +08:00
|
|
|
|
onPanelChange={onPanelChange}
|
2017-03-03 15:26:23 +08:00
|
|
|
|
onSelect={onSelect}
|
2015-11-13 19:56:34 +08:00
|
|
|
|
/>
|
2015-11-11 00:15:12 +08:00
|
|
|
|
```
|
|
|
|
|
|
2019-05-26 13:09:06 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
2022-06-13 14:03:43 +08:00
|
|
|
|
| dateCellRender | 自定义渲染日期单元格,返回内容会被追加到单元格 | function(date: Dayjs): ReactNode | - | |
|
|
|
|
|
| dateFullCellRender | 自定义渲染日期单元格,返回内容覆盖单元格 | function(date: Dayjs): ReactNode | - | |
|
|
|
|
|
| defaultValue | 默认展示的日期 | [dayjs](https://day.js.org/) | - | |
|
|
|
|
|
| disabledDate | 不可选择的日期,参数为当前 `value`,注意使用时[不要直接修改](https://github.com/ant-design/ant-design/issues/30987) | (currentDate: Dayjs) => boolean | - | |
|
2019-05-26 13:09:06 +08:00
|
|
|
|
| fullscreen | 是否全屏显示 | boolean | true | |
|
2022-06-13 14:03:43 +08:00
|
|
|
|
| headerRender | 自定义头部内容 | function(object:{value: Dayjs, type: string, onChange: f(), onTypeChange: f()}) | - | |
|
2020-07-01 22:37:55 +08:00
|
|
|
|
| locale | 国际化配置 | object | [(默认配置)](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json) | |
|
|
|
|
|
| mode | 初始模式 | `month` \| `year` | `month` | |
|
2022-06-13 14:03:43 +08:00
|
|
|
|
| monthCellRender | 自定义渲染月单元格,返回内容会被追加到单元格 | function(date: Dayjs): ReactNode | - | |
|
|
|
|
|
| monthFullCellRender | 自定义渲染月单元格,返回内容覆盖单元格 | function(date: Dayjs): ReactNode | - | |
|
|
|
|
|
| validRange | 设置可以显示的日期 | \[[dayjs](https://day.js.org/), [dayjs](https://day.js.org/)] | - | |
|
|
|
|
|
| value | 展示日期 | [dayjs](https://day.js.org/) | - | |
|
|
|
|
|
| onChange | 日期变化回调 | function(date: Dayjs) | - | |
|
|
|
|
|
| onPanelChange | 日期面板变化回调 | function(date: Dayjs, mode: string) | - | |
|
|
|
|
|
| onSelect | 点击选择日期回调 | function(date: Dayjs) | - | |
|
2020-01-02 16:05:59 +08:00
|
|
|
|
|
|
|
|
|
## FAQ
|
|
|
|
|
|
2022-06-13 14:03:43 +08:00
|
|
|
|
- [如何在 Calendar 中使用自定义日期库](/docs/react/use-custom-date-library#Calendar)
|