Back to Ant Design

Calendar

components/calendar/index.en-US.md

6.3.74.9 KB
Original Source

When To Use

When data is in the form of dates, such as schedules, timetables, prices calendar, lunar calendar. This component also supports Year/Month switch.

Examples

<!-- prettier-ignore -->

<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> <code src="./demo/lunar.tsx" clientOnly>Lunar Calendar</code> <code src="./demo/week.tsx" clientOnly version="5.23.0">Show Week</code> <code src="./demo/customize-header.tsx" clientOnly>Customize Header</code> <code src="./demo/style-class.tsx" clientOnly version="6.0.0">Custom semantic dom styling</code> <code src="./demo/component-token.tsx" debug>Component Token</code>

API

Common props ref:Common props

Note: Part of the Calendar's locale is read from value. So, please set the locale of dayjs correctly.

jsx
// The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
// import dayjs from 'dayjs';
// import 'dayjs/locale/zh-cn';
// dayjs.locale('zh-cn');

<Calendar cellRender={cellRender} onPanelChange={onPanelChange} onSelect={onSelect} />
PropertyDescriptionTypeDefaultVersion
cellRenderCustomize cell contentfunction(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
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-
dateFullCellRenderCustomize the display of the date cell, the returned content will override the cellfunction(date: Dayjs): ReactNode-
fullCellRenderCustomize cell contentfunction(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
defaultValueThe date selected by defaultdayjs-
disabledDateFunction 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-
fullscreenWhether to display in full-screenbooleantrue
showWeekWhether to display week numberbooleanfalse5.23.0
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
headerRenderRender custom header in panelfunction(object:{value: Dayjs, type: 'year' | 'month', onChange: f(), onTypeChange: f()})-
localeThe calendar's localeobject(default)
modeThe display mode of the calendarmonth | yearmonth
validRangeTo set valid range[dayjs, dayjs]-
valueThe current selected datedayjs-
onChangeCallback for when date changesfunction(date: Dayjs)-
onPanelChangeCallback for when panel changesfunction(date: Dayjs, mode: string)-
onSelectCallback for when a date is selected, include source infofunction(date: Dayjs, info: { source: 'year' | 'month' | 'date' | 'customize' })-info: 5.6.0

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Calendar"></ComponentTokenTable>

FAQ

How to use Calendar with customize date library? {#faq-customize-date-library}

See Use custom date library

See How to set locale for date-related components

See FAQ Date-related-components-locale-is-not-working?

How to get date from panel click? {#faq-get-date-panel-click}

onSelect provide info.source to help on this:

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