Calendar
完整而紧凑的日历中的日程安排和活动。
何时使用
日历按日历日显示计划、事件或指标。在月份模式下,您可以看到该月的天数,在年模式下,您可以看到一年中的月份。要在紧凑字段中选择日期,请使用 DatePicker。
fullscreen=false 将迷你日历嵌入到卡中。几天的事件和柱线是从应用程序数据中提取的;它们不会将单个日历值更改为范围。
视口宽度不超过 480 px 时,月视图中的年份和月份选择器位于同一行,模式切换按钮位于下方。
日期和面板模式
常规日历可与 Dayjs 配合使用。有了 value,应用程序通过 onChange 接受新日期;如果没有 value,则使用 defaultValue 或当前日期。托管 mode 与值分开更新。
| 问题 | 设置 | 示例 |
|---|---|---|
| 显示完整日历 | defaultValue |
基本日历 |
| 将所选日期与状态相关联 | value、onChange、onSelect |
引导选择 |
| 嵌入迷你日历 | fullscreen={false} |
卡片中的日历 |
| 显示周数 | showWeek |
周数 |
| 限制可用日期 | validRange、disabledDate |
有效工作日期 |
onChange 报告日期更改,onPanelChange 报告日期或面板模式,onSelect 报告带有源 date/月/年/自定义的选择。再次选择相同的日期仍然会调用 onSelect。要专门对日期单元格做出反应,请检查 info.source=date 而不是任何标题更改。
value 不支持 bind:value。通过 callback 保存 Dayjs;该组件不会标准化其时间、毫秒或时区。另一种日期类型通过公共 generateCalendar 和 CalendarGenerateConfig 连接,而不是通过将任意 Date 传递给标准日历。
事件和自己的标头
cellRender - 带有日期和 info.type=date/month 的 Svelte 代码片段。它补充了标准内容。 日历上的活动 显示当日徽章和当月总数; 连续几天的事件 根据示例数据构建条带。
fullCellRender 替换单元格的全部内部内容。 info.originNode 包含原始内部标记的片段,您可以将其保存在合成中。对于周数列,不会调用 render 片段。
headerRender 获取 value、type、onChange 和 onTypeChange。对于您自己的标头,请调用这些处理程序来保存选择和模式切换。标头的 onChange 报告 source=customize; onTypeChange 更改面板模式,无需单独的日期选择器。 标头示例 使用公共 Svelte 组件作为交换机。
限制、语言和设计
validRange 比较包含时间戳精度的边界。对于整个日历日,请指定 startOf('day') 和 endOf('day'),如约束示例中所示。 disabledDate 标识不可用的单元格;不要修改谓词内传递的日期对象。
ConfigProvider 与 ruRU/enUS 指定一个字典,locale.lang 指定一个单独的日历。对于另一种语言,还加载 Day.js 区域设置并将其与组件的日期和设置相匹配。区域设置决定一周的开始;全局 dayjs.locale 不足以翻译所有控件。
农历 通过 Intl 接收签名。这是对没有太阳季节和假期指南的显示的改编。必要的象形文字的存在取决于页面字体;所选日期类型仍为 Dayjs。
classNames/styles 接受来自 props 的对象或函数; styles 包含 CSS 字符串。使用 fullCellRender 和 headerRender,内容属于您的代码片段。 Semantic styles 显示有效的插槽和 ConfigProvider.calendar。 theme.components.Calendar 组件设计令牌(design tokens)适用于日历、其标题及其单元格。
日历 CSS 前缀 显示全局 ConfigProvider.prefixCls 和本地 prefixCls。本地值是完整的基本Picker前缀:日历根添加 -calendar,单元格和 originNode 直接使用它。 cellRender/fullCellRender 在 info.prefixCls 中获取此名称。空字符串/undefined 返回带有 -picker 的公共提供程序前缀。 Select 和 Radio 标头继承公共命名空间,无论本地 Calendar.prefixCls 是什么; theme.cssVar.prefix 单独设置主题变量。更改前缀会保留根、带有原始时间的日期、焦点和打开的标题列表。
这些单元保留了标准面板的键盘导航。 bind:nativeElement 挂载后返回根 div,卸载时清除;日历没有导出 focus/blur。
示例
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
基本日历
完整的日历,具有年和月之间的过渡。 defaultValue 指定开始日期。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
</script>
<Calendar defaultValue={dayjs('2026-10-15')} />
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
日历上的活动
cellRender 用事件列表补充日,用事件数量补充月。 Svelte 片段用于单元格内容。
<script lang="ts">
import dayjs from 'dayjs';
import { Badge, Calendar } from '@woodger/antd';
const events = [
{ date: '2026-10-15', status: 'success', text: "发布" },
{ date: '2026-10-20', status: 'warning', text: "考试" },
{ date: '2026-10-20', status: 'processing', text: "集会" }
] as const;
</script>
<style>
.events {
margin: 0;
padding: 0;
list-style: none;
text-align: start;
}
li {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
<Calendar defaultValue={dayjs('2026-10-15')}>
{#snippet cellRender(date, info)}
{#if info.type === 'date'}
<ul class="events">
{#each events.filter(event => event.date === date.format('YYYY-MM-DD')) as event (event.text)}
<li title={(event.text)}><Badge status={event.status} text={(event.text)} /></li>
{/each}
</ul>
{:else}
{@const count = events.filter(event => event.date.startsWith(date.format('YYYY-MM'))).length}
{#if count}<span>{(count)}{(" 事件")}</span>{/if}
{/if}
{/snippet}
</Calendar>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
连续几天的活动
cellRender 绘制开始、中间、结束和一日事件条。范围指的是示例数据;日历值仍然是单个日期。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
const events = [
{ title: "检查布局", start: '2026-10-12', end: '2026-10-15', color: '#722ed1' },
{ title: "开发", start: '2026-10-14', end: '2026-10-18', color: '#237804' },
{ title: "发布", start: '2026-10-20', end: '2026-10-20', color: '#ad4e00' }
];
</script>
<style>
.bands {
display: grid;
gap: 3px;
text-align: start;
}
.band {
height: 18px;
margin-inline: calc(-1 * var(--ant-padding-xs) - var(--ant-margin-xs) / 2);
padding-inline: 4px;
overflow: hidden;
color: white;
font-size: 11px;
line-height: 18px;
white-space: nowrap;
}
.start {
margin-inline-start: 0;
border-radius: 9px 0 0 9px;
}
.end {
margin-inline-end: 0;
border-radius: 0 9px 9px 0;
}
.single {
margin-inline: 0;
border-radius: 9px;
}
.legend {
display: grid;
gap: 8px;
margin-top: 16px;
font-size: 12px;
line-height: 1.6;
}
</style>
<Calendar defaultValue={dayjs('2026-10-15')} styles={{ itemContent: 'overflow:visible' }}>
{#snippet cellRender(date, info)}
{#if info.type === 'date'}
{@const key = date.format('YYYY-MM-DD')}
<div class="bands">
{#each events as event (event.title)}
{@const active = key >= event.start && key <= event.end}
{@const position = key === event.start
? key === event.end ? 'single' : 'start'
: key === event.end
? 'end'
: 'middle'}
<div class={['band', position]} title={(active ? event.title : undefined)}
style:background={(active ? event.color : 'transparent')}>
{#if active && (position === 'start' || position === 'single')}{(event.title)}{/if}
</div>
{/each}
</div>
{/if}
{/snippet}
</Calendar>
<div class="legend" aria-label={("每日活动")}>
{#each events as event (event.title)}
<span>{(event.title)}: {(event.start)} — {(event.end)}</span>
{/each}
</div>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
卡片中的日历
fullscreen=false 启用迷你日历。容器的宽度限制为 320 px,并随页面缩小。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
</script>
<style>.card {
max-width: 320px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
}</style>
<div class="card"><Calendar fullscreen={false} defaultValue={dayjs('2026-10-15')} /></div>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
引导选择
value 通过 onChange 更新,onSelect 报告源并重新选择。所选日期显示在其旁边。
<script lang="ts">
import dayjs from 'dayjs';
import { Alert, Calendar } from '@woodger/antd';
const initial = dayjs('2026-10-15');
let value = $state(initial);
let selected = $state(initial);
let source = $state('—');
</script>
<style>
.example {
display: grid;
gap: 16px;
}
output {
overflow-wrap: anywhere;
}
</style>
<div class="example">
<Alert type="info" role="status" title={("选定日期: " + String((selected.format('YYYY-MM-DD'))) + "")} />
<Calendar {value} onChange={date => { value = date; }}
onSelect={(date, info) => { selected = date; source = info.source; }} />
<output
aria-label={("日历选择")}
>{(selected.format('YYYY-MM-DD'))}{(";来源: ")}{source}</output>
</div>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 八月18日 | 29 八月19日 | 30 八月20日 | 1 八月21日 | 2 八月22日 | 3 八月23日 | 4 八月24日 |
5 八月25日 | 6 八月26日 | 7 八月27日 | 8 八月28日 | 9 八月29日 | 10 九月1日 | 11 九月2日 |
12 九月3日 | 13 九月4日 | 14 九月5日 | 15 九月6日 | 16 九月7日 | 17 九月8日 | 18 九月9日 |
19 九月10日 | 20 九月11日 | 21 九月12日 | 22 九月13日 | 23 九月14日 | 24 九月15日 | 25 九月16日 |
26 九月17日 | 27 九月18日 | 28 九月19日 | 29 九月20日 | 30 九月21日 | 31 九月22日 | 1 九月23日 |
2 九月24日 | 3 九月25日 | 4 九月26日 | 5 九月27日 | 6 九月28日 | 7 九月29日 | 8 九月30日 |
通过 Intl 农历日期
fullCellRender 通过内置的 Intl 显示中国农历日期。此处未计算原始示例中的太阳季节。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
const lunar = new Intl.DateTimeFormat('zh-CN-u-ca-chinese', { month: 'long', day: 'numeric' });
</script>
<style>
.cell {
padding: 8px 2px;
text-align: center;
}
small {
display: block;
margin-top: 4px;
color: var(--ant-color-text-secondary);
font-size: 12px;
overflow-wrap: anywhere;
}
</style>
<Calendar defaultValue={dayjs('2026-10-15')}>
{#snippet fullCellRender(date, info)}
<div class="cell">
{@render info.originNode()}
{#if info.type === 'date'}<small>{(lunar.format(date.toDate()))}</small>{/if}
</div>
{/snippet}
</Calendar>
| 周 | 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|---|
40 | 28 | 29 | 30 | 01 | 02 | 03 | 04 |
41 | 05 | 06 | 07 | 08 | 09 | 10 | 11 |
42 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
43 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
44 | 26 | 27 | 28 | 29 | 30 | 31 | 01 |
45 | 02 | 03 | 04 | 05 | 06 | 07 | 08 |
周数
showWeek 添加周数。选择一个数字将发布日历行的开头。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
let value = $state(dayjs('2026-10-15'));
</script>
<style>
.example {
display: grid;
gap: 16px;
}
</style>
<div class="example">
<Calendar {value} showWeek onChange={date => { value = date; }} />
<output aria-label={("带周数的日期")}>{(value.format('YYYY-MM-DD'))}</output>
</div>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
你自己的帽子
headerRender 获取值、模式和回调。 Public Select/RadioGroup 控制年、月和模式。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar, RadioGroup, Select, type CalendarMode } from '@woodger/antd';
let value = $state(dayjs('2026-10-15'));
let mode = $state<CalendarMode>('month');
let source = $state('—');
</script>
<style>
.header {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding: 12px 0;
}
output {
display: block;
margin-top: 16px;
overflow-wrap: anywhere;
}
</style>
<Calendar {value} {mode} fullscreen={false} onChange={date => { value = date; }}
onPanelChange={(_date, next) => { mode = next; }} onSelect={(
_date,
info
) => { source = info.source; }}>
{#snippet headerRender(header)}
<div class="header">
<RadioGroup aria-label={("自定义日历模式")} value={header.type}
options={([{ value: 'month', label: "月" }, {
value: 'year',
label: "年"
}])}
onValueChange={next => header.onTypeChange(next as CalendarMode)} />
<Select
aria-label={("您的日历年份")}
value={header.value.year()}
style="width:100px"
options={([2025, 2026, 2027].map(year => ({
value: year,
label: String(year)
})))}
onValueChange={year => {
if (typeof year === 'number') {
header.onChange(header.value.year(year));
}
}}
/>
{#if header.type === 'month'}
<Select
aria-label={("您日历中的月份")}
value={header.value.month()}
style="width:120px"
options={(Array.from({ length: 12 }, (_, month) => ({
value: month,
label: `${month + 1} 月`
})))}
onValueChange={month => {
if (typeof month === 'number') {
header.onChange(header.value.month(month));
}
}}
/>
{/if}
</div>
{/snippet}
</Calendar>
<output
aria-label={("您自己的日历标题")}
>{(value.format('YYYY-MM-DD'))}{(";模式: ")}{mode}{(";来源: ")}{source}</output>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
Semantic styles
类对象和 styles 函数应用于实际的插槽;该函数接收日历属性。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
</script>
<Calendar fullscreen={false} defaultValue={dayjs('2026-10-15')}
classNames={{ root: 'calendar-semantic-root' }}
styles={({ props }) => ({
root: `
border: 2px dashed ${props.fullscreen ? '#722ed1' : '#52c41a'};
border-radius: 8px;
`,
header: 'padding-inline:12px',
itemContent: 'font-weight:600'
})} />
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
有效工作日期
validRange 限制精确时间戳(包括在内);边界延长了一整天。 disabledDate 不包括周末。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
let value = $state(dayjs('2026-10-15'));
</script>
<style>
.example {
display: grid;
gap: 16px;
}
</style>
<div class="example">
<Calendar {value} fullscreen={false}
validRange={[dayjs('2026-10-10').startOf('day'), dayjs('2026-10-20').endOf('day')]}
disabledDate={date => date.day() === 0 || date.day() === 6}
onChange={date => { value = date; }} />
<output aria-label={("限定日期日历")}>{(value.format('YYYY-MM-DD'))}</output>
</div>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
评论中的交互式日历
保存的示例:切换完整视图、周数和受控日期。
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar } from '@woodger/antd';
let value = $state(dayjs('2026-10-29'));
let fullscreen = $state(false);
let showWeek = $state(false);
</script>
<style>
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.controls label {
display: flex;
align-items: center;
gap: 8px;
}
.calendar {
box-sizing: border-box;
width: 360px;
max-width: 100%;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
overflow: hidden;
}
.calendar.full { width: 780px; }
output {
display: block;
margin-top: 16px;
}
</style>
<div class="controls">
<label><input
type="checkbox"
bind:checked={fullscreen}
/>{(" 全日历")}</label>
<label><input type="checkbox" bind:checked={showWeek} />{(" 周数")}</label>
</div>
<div class="calendar" class:full={fullscreen}>
<Calendar
{value}
{fullscreen}
{showWeek}
onChange={next => { value = next; }}
/>
</div>
<output
aria-label={("日历上的日期")}
>{(value.format('DD.MM.YYYY'))}</output>
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
PrefixCls指定Picker的基本名称; Calendar 将 -calendar 附加到根目录。 CellRender 和 fullCellRender 通过 info.prefixCls 接收相同的前缀,originNode 将其用于其类。 Select 和 Radio 标头分别继承公共命名空间。两个日历在不同的主题区域使用相同的本地类;日期与原始时间一起存储为 Dayjs。
<script lang="ts">
import dayjs, { type Dayjs } from 'dayjs';
import {
Calendar, Checkbox, ConfigProvider, type CalendarCellRenderInfo, type CalendarMode
} from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
let rtl = $state(false);
let fullscreen = $state(false);
let showWeek = $state(false);
let withVariables = $state(true);
let value = $state.raw(dayjs('2026-10-15T12:34:56.789'));
let mode = $state<CalendarMode>('month');
let changes = $state(0);
let nativeElement = $state<HTMLDivElement>();
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-picker' : '');
</script>
<style>
.example,
section {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
{#snippet marker(date: Dayjs, info: CalendarCellRenderInfo)}
<span data-render-prefix={info.prefixCls} aria-hidden="true">
{(info.type === 'date' && date.date() === 15 ? '•' : '')}
</span>
{/snippet}
{#snippet original(_date: Dayjs, info: CalendarCellRenderInfo)}
<div data-render-prefix={info.prefixCls}>{@render info.originNode()}</div>
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("通用前缀日历套件")}</Checkbox>
<Checkbox bind:checked={local}>{("日历本地前缀")}</Checkbox>
<Checkbox bind:checked={rtl}>{("带前缀的 RTL 日历")}</Checkbox>
<Checkbox bind:checked={fullscreen}>{("带前缀的完整日历")}</Checkbox>
<Checkbox
bind:checked={showWeek}
>{("带前缀的日历周数")}</Checkbox>
<Checkbox bind:checked={withVariables}>CSS variables Calendar</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} direction={rtl ? 'rtl' : 'ltr'}
theme={withVariables ? { cssVar: { prefix: 'calendar-theme' } } : undefined}>
<section aria-label={("带前缀的主日历")}>
<Calendar prefixCls={localPrefix} bind:nativeElement class="prefix-calendar-main"
{value} {mode} {fullscreen} {showWeek} cellRender={marker}
onChange={next => {
value = next;
changes++;
}}
onPanelChange={(_date, next) => { mode = next; }} />
<output aria-label={("带前缀的日历日期")}>{(value.format('YYYY-MM-DD HH:mm:ss.SSS'))}</output>
<output aria-label={("日历更改带有前缀")}>{("变化: ")}{changes}</output>
</section>
<ConfigProvider prefixCls="neighbor" theme={{ cssVar: { prefix: 'neighbor-calendar-theme' } }}>
<section aria-label={("带前缀的相邻日历")}>
<Calendar prefixCls={localPrefix} class="prefix-calendar-neighbor"
defaultValue={dayjs('2026-10-15T12:34:56.789')} fullscreen={false}
fullCellRender={original} />
</section>
</ConfigProvider>
</ConfigProvider>
<output aria-label={("日历 CSS 前缀")}>
Picker: {(localPrefix || prefix + '-picker')}{(";根: ")}{(localPrefix
|| prefix + '-picker')}-calendar
</output>
<output aria-label={("带前缀的根日历")}>{(nativeElement ? "已连接" : "等待挂载")}</output>
<p>
{("PrefixCls指定Picker的基本名称; Calendar 将 -calendar 附加到根目录。 CellRender 和 fullCellRender 通过 info.prefixCls 接收相同的前缀,originNode 将其用于其类。 Select 和 Radio 标头分别继承公共命名空间。两个日历在不同的主题区域使用相同的本地类;日期与原始时间一起存储为 Dayjs。")}
</p>
</div>
覆盖示例
整理了九个 ant.design 6.7 实时页面主题。卡片排列在一列中:事件和范围栏需要宽度空间。
| 主题 | 状态 | 苗条的例子 |
|---|---|---|
| Basic | 实施的 | 基本日历 |
| Notice Calendar | 通过cellRender实现 | 日历上的活动 |
| Event Range | 通过cellRender实现 | 连续几天的活动 |
| Card | 实施的 | 卡片中的日历 |
| Selectable Calendar | 实施的 | 引导选择 |
| Lunar Calendar | 部分:来自 Intl 的农历日期,无太阳季节 | 通过 Intl 农历日期 |
| Show Week | 实施的 | 周数 |
| Customize Header | 通过 Svelte 代码片段实现 | 你自己的帽子 |
| Custom semantic dom styling | 实施的 | Semantic styles |
通过 Intl 改编的农历示例:显示中国农历日期,没有太阳季节和假期指南。这是显示数据;模型仍然是 Dayjs。
API
主要参数根据公共 CalendarProps 进行检查。常规日历可与 Dayjs 配合使用。对于其日期类型,generateCalendar 是通过 CalendarGenerateConfig 适配器导出的。
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 完整的基础选择器前缀;根日历添加 -calendar。空字符串/undefined 继承ConfigProvider。 Cells、originNode 和 info.prefixCls 遵循此名称; Select/Radio 标头使用独立的公共前缀。主题的命名空间是单独设置的。 | string | ConfigProvider.prefixCls + "-picker" |
value | 通过 onChange 管理日期。没有 bind:value;时间和时区未标准化。 | Dayjs | undefined |
defaultValue | 当地州的开始日期。 | Dayjs | 当前日期 |
mode | 托管模式。在 onPanelChange 中更新它以启用切换。 | month | year | month |
fullscreen | false 启用迷你日历和小标题控件。 | boolean | true |
showWeek | 月份模式下的周列。选择一个数字将发布该行的开头。 | boolean | false |
validRange | 包含时间戳精度的边界;他们还限制上限。对于全天,请使用 startOf/endOf。 | [Dayjs, Dayjs] | undefined |
disabledDate | 限制面板单元格。如果一个月的第一天和最后一天被禁用,则该月被禁用。 | (date: Dayjs) => boolean | undefined |
onChange | 更改日历日;重新选择同一天不会调用 onChange。 | (date: Dayjs) => void | — |
onPanelChange | 面板转换或模式更改。在受控模式下,采用新的外部 mode。 | (date, mode: CalendarMode) => void | — |
onSelect | 每一个选择,包括重复的选择。 source=date/month/year/customize 报告来源。 | (date, info: CalendarSelectInfo) => void | — |
locale | Lang 与通用语言环境和基本词汇相结合。 | CalendarLocale | 来自配置提供者 |
headerRender | 获取 value、type、onChange 和 onTypeChange。 onChange 调用具有 source=customize。 | Snippet<[CalendarHeaderRenderInfo]> | 标准帽子 |
cellRender | 将内容添加到标准单元格。 info.type=date/月份, prefixCls — 允许的 Picker 前缀; originNode - 带有此前缀的内部标记片段。 | Snippet<[Dayjs, CalendarCellRenderInfo]> | 空加法 |
fullCellRender | 替换单元格的内容。没有要求提供周数。 | Snippet<[Dayjs, CalendarCellRenderInfo]> | 标准电池 |
classNames | 类 root/header/body/content/item/itemContent、带有 props 的对象或函数。 | CalendarSemantic | undefined |
styles | 相同插槽的 CSS 行。本地样式在提供者配置之后出现。 | CalendarSemantic | undefined |
nativeElement | bind:nativeElement 在挂载后给出 root 并在卸载时清除 ref。 | HTMLDivElement | undefined |
cellRender 完成单元格的内容,fullCellRender 替换它。这两个参数都接受 Svelte 片段。
事件和参考
onChange 报告日期变化。再次选择时也会调用 onSelect; info.source 区分 date、月份、年份和自定义。 onPanelChange 报告面板或模式的更改。
在托管模式下,将新 value 存储在 onChange 中,将新 mode 存储在 onPanelChange 中。 headerRender.onChange 选择带有 source=customize 的日期; onTypeChange 通过 onPanelChange 切换模式。
日历没有导出 focus()/blur() 。 bind:nativeElement 在挂载后给出根 div,并在卸载时清除 ref;这是 CalendarRef.nativeElement 的 Svelte 等效项。
Semantic DOM
该表具有网格、日期和月份的角色 - gridcell。所选日期标记为 aria-selected,禁用日期标记为 aria-disabled,当前日期标记为 aria-current=date。箭头移动焦点,Home/End 移动到行边界,Enter/Space 选择单元格。
下面突出显示的是实际插槽。在 RTL 中,水平箭头考虑了接口的方向。
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
| Slot | 目的 |
|---|---|
root | 根 div 日历。 |
header | 标准标题,可选择年、月和模式。 |
body | 表容器。 |
content | 表具有网格作用。 |
item | 日或月单元;周数被排除在外。 |
itemContent | 标准单元的附加内容;使用 fullCellRender 这个包装器被替换。 |
styles 接受 CSS 字符串,classNames 接受类;两种形式都支持带有 props 的回调。使用自定义 headerRender,标题由您的代码片段创建,使用 fullCellRender 您可以控制单元格的内部内容。
注册令牌
六个组件令牌对应于官方表和公共 ComponentTokenMap.Calendar。 theme.components.Calendar 将标记应用于日历。语义 styles 和 ConfigProvider.calendar 阐明了设计。
| 代币 | 目的 |
|---|---|
fullBg | 完整的日历背景。 |
fullPanelBg | 面板背景。 |
itemActiveBg | 选定的日子。 |
miniContentHeight | 迷你日历高度。 |
monthControlWidth | 月份选择宽度。 |
yearControlWidth | 年份选择宽度。 |
当前主题的常用标记
根据 ant.design 表检查名称;这些值是通过 theme.useToken() 反应式读取的。
| 代币 | 意义 |
|---|---|
colorBgContainer | #ffffff |
colorFillSecondary | rgba(0,0,0,0.06) |
colorIcon | rgba(0,0,0,0.45) |
colorIconHover | rgba(0,0,0,0.88) |
colorPrimary | #2f54eb |
colorSplit | rgba(5,5,5,0.06) |
colorText | rgba(0,0,0,0.88) |
colorTextDisabled | rgba(0,0,0,0.25) |
colorTextHeading | rgba(0,0,0,0.88) |
colorTextLightSolid | #fff |
colorTextTertiary | rgba(0,0,0,0.45) |
borderRadiusLG | 8 |
borderRadiusSM | 4 |
controlHeightLG | 40 |
controlHeightSM | 24 |
controlItemBgActive | #f0f5ff |
controlItemBgHover | rgba(0,0,0,0.04) |
fontFamily | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 14 |
fontWeightStrong | 600 |
lineHeight | 1.5714285714285714 |
lineType | solid |
lineWidth | 1 |
lineWidthBold | 2 |
marginXS | 8 |
marginXXS | 4 |
motionDurationMid | 0.2s |
motionDurationSlow | 0.3s |
padding | 16 |
paddingSM | 12 |
paddingXS | 8 |
paddingXXS | 4 |
screenXS | 480 |
ConfigProvider.calendar
支持 class、style、classNames 和 styles。局部语义 styles 先于上下文;根的 style 具有最终优先权。嵌套日历对象替换整个父对象。
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
|---|---|---|---|---|---|---|
28 | 29 | 30 | 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 | 06 | 07 | 08 |
<script lang="ts">
import dayjs from 'dayjs';
import { Calendar, ConfigProvider } from '@woodger/antd';
</script>
<ConfigProvider calendar={{
styles: {
root: `
border: 2px solid #722ed1;
border-radius: 8px;
`,
header: 'padding-inline:12px'
}
}}>
<Calendar fullscreen={false} defaultValue={dayjs('2026-10-15')} />
</ConfigProvider>
FAQ
如何从单元格中获取具体日期?
将 onSelect 与 info.source=date 结合使用。 onChange 也会在标头发生更改时调用,并且重新选择日期只能由 onSelect 报告。
如何设置语言和一周的开始时间?
将 locale 或 ConfigProvider.locale 与 Day.js 区域设置相匹配。一周的第一天由相应的语言设置决定。
cellRender 更换一整天?
它完成了细胞。要替换内部内容,请使用 fullCellRender;原始标记可通过 info.originNode 获得。
为什么 validRange 使用 startOf/endOf?
边界作为时间戳进行比较,不会自动丢弃时间。如果需要全天,请明确扩展它们。
几天的事件会改变 value 的类型吗?
不,value 仍然是一个日期。这些条带是由示例根据应用程序自己的数据构建的。
是否可以使用其他日期库?
generateCalendar 接受 CalendarGenerateConfig 适配器并为您的日期类型创建一个组件。标准日历使用 Dayjs。