5.24.8

Calendar
日历

按照日历形式展示数据的容器。
使用import { Calendar } from "antd";

何时使用

当数据是日期或按照日期划分时,例如日程、课表、价格日历等,农历等。目前支持年/月切换。

代码演示

2025年
4月
31
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
01
02
03
04
05
06
07
08
09
10
11

一个通用的日历面板,支持年/月切换。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
2025年
4月
31
    01
      02
        03
          04
            05
              06
                07
                  08
                  • This is warning event.
                  • This is usual event.
                  09
                    10
                    • This is warning event.
                    • This is usual event.
                    • This is error event.
                    11
                      12
                        13
                          14
                            15
                            • This is warning event
                            • This is very long usual event......
                            • This is error event 1.
                            • This is error event 2.
                            • This is error event 3.
                            • This is error event 4.
                            16
                              17
                                18
                                  19
                                    20
                                      21
                                        22
                                          23
                                            24
                                              25
                                                26
                                                  27
                                                    28
                                                      29
                                                        30
                                                          01
                                                            02
                                                              03
                                                                04
                                                                  05
                                                                    06
                                                                      07
                                                                        08
                                                                        • This is warning event.
                                                                        • This is usual event.
                                                                        09
                                                                          10
                                                                          • This is warning event.
                                                                          • This is usual event.
                                                                          • This is error event.
                                                                          11

                                                                            一个复杂的应用示例,用 dateCellRendermonthCellRender 函数来自定义需要渲染的数据。

                                                                            CodeSandbox Icon
                                                                            codepen icon
                                                                            External Link Icon
                                                                            expand codeexpand code
                                                                            2025年
                                                                            4月
                                                                            31
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11
                                                                            12
                                                                            13
                                                                            14
                                                                            15
                                                                            16
                                                                            17
                                                                            18
                                                                            19
                                                                            20
                                                                            21
                                                                            22
                                                                            23
                                                                            24
                                                                            25
                                                                            26
                                                                            27
                                                                            28
                                                                            29
                                                                            30
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11

                                                                            用于嵌套在空间有限的容器中。

                                                                            CodeSandbox Icon
                                                                            codepen icon
                                                                            External Link Icon
                                                                            expand codeexpand code
                                                                            2017年
                                                                            1月
                                                                            26
                                                                            27
                                                                            28
                                                                            29
                                                                            30
                                                                            31
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11
                                                                            12
                                                                            13
                                                                            14
                                                                            15
                                                                            16
                                                                            17
                                                                            18
                                                                            19
                                                                            20
                                                                            21
                                                                            22
                                                                            23
                                                                            24
                                                                            25
                                                                            26
                                                                            27
                                                                            28
                                                                            29
                                                                            30
                                                                            31
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05

                                                                            一个通用的日历面板,支持年/月切换。

                                                                            CodeSandbox Icon
                                                                            codepen icon
                                                                            External Link Icon
                                                                            expand codeexpand code
                                                                            二〇二五年(乙巳蛇年)
                                                                            4月(三月)
                                                                            31
                                                                            初三
                                                                            1
                                                                            初四
                                                                            2
                                                                            初五
                                                                            3
                                                                            初六
                                                                            4
                                                                            清明节
                                                                            5
                                                                            初八
                                                                            6
                                                                            初九
                                                                            7
                                                                            初十
                                                                            8
                                                                            十一
                                                                            9
                                                                            十二
                                                                            10
                                                                            十三
                                                                            11
                                                                            十四
                                                                            12
                                                                            十五
                                                                            13
                                                                            十六
                                                                            14
                                                                            十七
                                                                            15
                                                                            十八
                                                                            16
                                                                            十九
                                                                            17
                                                                            二十
                                                                            18
                                                                            廿一
                                                                            19
                                                                            廿二
                                                                            20
                                                                            谷雨
                                                                            21
                                                                            廿四
                                                                            22
                                                                            廿五
                                                                            23
                                                                            廿六
                                                                            24
                                                                            廿七
                                                                            25
                                                                            廿八
                                                                            26
                                                                            廿九
                                                                            27
                                                                            三十
                                                                            28
                                                                            初一
                                                                            29
                                                                            初二
                                                                            30
                                                                            初三
                                                                            1
                                                                            劳动节
                                                                            2
                                                                            初五
                                                                            3
                                                                            初六
                                                                            4
                                                                            初七
                                                                            5
                                                                            立夏
                                                                            6
                                                                            初九
                                                                            7
                                                                            初十
                                                                            8
                                                                            十一
                                                                            9
                                                                            十二
                                                                            10
                                                                            十三
                                                                            11
                                                                            十四

                                                                            展示农历、节气等信息。

                                                                            CodeSandbox Icon
                                                                            codepen icon
                                                                            External Link Icon
                                                                            expand codeexpand code
                                                                            2025年
                                                                            4月
                                                                            14
                                                                            31
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            15
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11
                                                                            12
                                                                            13
                                                                            16
                                                                            14
                                                                            15
                                                                            16
                                                                            17
                                                                            18
                                                                            19
                                                                            20
                                                                            17
                                                                            21
                                                                            22
                                                                            23
                                                                            24
                                                                            25
                                                                            26
                                                                            27
                                                                            18
                                                                            28
                                                                            29
                                                                            30
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            19
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11

                                                                            2025年
                                                                            4月
                                                                            14
                                                                            31
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            15
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11
                                                                            12
                                                                            13
                                                                            16
                                                                            14
                                                                            15
                                                                            16
                                                                            17
                                                                            18
                                                                            19
                                                                            20
                                                                            17
                                                                            21
                                                                            22
                                                                            23
                                                                            24
                                                                            25
                                                                            26
                                                                            27
                                                                            18
                                                                            28
                                                                            29
                                                                            30
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            19
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11

                                                                            通过将 showWeek 属性设置为 true,在全屏日历中显示周数。

                                                                            CodeSandbox Icon
                                                                            codepen icon
                                                                            External Link Icon
                                                                            expand codeexpand code
                                                                            5.23.0

                                                                            Custom header

                                                                            2025
                                                                            Apr
                                                                            31
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11
                                                                            12
                                                                            13
                                                                            14
                                                                            15
                                                                            16
                                                                            17
                                                                            18
                                                                            19
                                                                            20
                                                                            21
                                                                            22
                                                                            23
                                                                            24
                                                                            25
                                                                            26
                                                                            27
                                                                            28
                                                                            29
                                                                            30
                                                                            01
                                                                            02
                                                                            03
                                                                            04
                                                                            05
                                                                            06
                                                                            07
                                                                            08
                                                                            09
                                                                            10
                                                                            11

                                                                            自定义日历头部内容。

                                                                            CodeSandbox Icon
                                                                            codepen icon
                                                                            External Link Icon
                                                                            expand codeexpand code

                                                                            API

                                                                            通用属性参考:通用属性

                                                                            注意:Calendar 部分 locale 是从 value 中读取,所以请先正确设置 dayjs 的 locale。

                                                                            jsx
                                                                            // 默认语言为 en-US,所以如果需要使用其他语言,推荐在入口文件全局设置 locale
                                                                            // import dayjs from 'dayjs';
                                                                            // import 'dayjs/locale/zh-cn';
                                                                            // dayjs.locale('zh-cn');
                                                                            <Calendar cellRender={cellRender} onPanelChange={onPanelChange} onSelect={onSelect} />
                                                                            参数说明类型默认值版本
                                                                            cellRender自定义单元格的内容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
                                                                            dateFullCellRender自定义渲染日期单元格,返回内容覆盖单元格,>= 5.4.0 请用 fullCellRenderfunction(date: Dayjs): ReactNode-< 5.4.0
                                                                            fullCellRender自定义单元格的内容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
                                                                            defaultValue默认展示的日期dayjs-
                                                                            disabledDate不可选择的日期,参数为当前 value,注意使用时不要直接修改(currentDate: Dayjs) => boolean-
                                                                            fullscreen是否全屏显示booleantrue
                                                                            showWeek是否显示周数列booleanfalse5.23.0
                                                                            headerRender自定义头部内容function(object:{value: Dayjs, type: 'year' | 'month', onChange: f(), onTypeChange: f()})-
                                                                            locale国际化配置object(默认配置)
                                                                            mode初始模式month | yearmonth
                                                                            validRange设置可以显示的日期[dayjs, dayjs]-
                                                                            value展示日期dayjs-
                                                                            onChange日期变化回调function(date: Dayjs)-
                                                                            onPanelChange日期面板变化回调function(date: Dayjs, mode: string)-
                                                                            onSelect选择日期回调,包含来源信息function(date: Dayjs, info: { source: 'year' | 'month' | 'date' | 'customize' })-info: 5.6.0

                                                                            主题变量(Design Token)

                                                                            组件 Token如何定制?
                                                                            Token 名称描述类型默认值
                                                                            fullBg完整日历背景色string#ffffff
                                                                            fullPanelBg完整日历面板背景色string#ffffff
                                                                            itemActiveBg日期项选中背景色string#e6f4ff
                                                                            miniContentHeight迷你日历内容高度string | number256
                                                                            monthControlWidth月选择器宽度string | number70
                                                                            yearControlWidth年选择器宽度string | number80
                                                                            全局 Token如何定制?

                                                                            FAQ

                                                                            如何在 Calendar 中使用自定义日期库

                                                                            参考 使用自定义日期库

                                                                            如何给日期类组件配置国际化?

                                                                            参考 如何给日期类组件配置国际化

                                                                            为什么时间类组件的国际化 locale 设置不生效?

                                                                            参考 FAQ 为什么时间类组件的国际化 locale 设置不生效?

                                                                            如何仅获取来自面板点击的日期?

                                                                            onSelect 事件提供额外的来源信息,你可以通过 info.source 来判断来源:

                                                                            tsx
                                                                            <Calendar
                                                                            onSelect={(date, { source }) => {
                                                                            if (source === 'date') {
                                                                            console.log('Panel Select:', source);
                                                                            }
                                                                            }}
                                                                            />