Skip to content

feat(date-picker): 添加 date slot 支持自定义日期单元格内容#7382

Open
LouisLau-art wants to merge 4 commits intotusen-ai:mainfrom
LouisLau-art:feat/date-picker-date-slot
Open

feat(date-picker): 添加 date slot 支持自定义日期单元格内容#7382
LouisLau-art wants to merge 4 commits intotusen-ai:mainfrom
LouisLau-art:feat/date-picker-date-slot

Conversation

@LouisLau-art
Copy link

功能描述

为 DatePicker 组件添加 `date` 插槽,允许用户自定义日期单元格的内容,例如添加农历、节日等信息。

关联 Issue

Closes #6751

修改内容

  • 在 `DatePickerSlots` 接口中添加 `date` 插槽定义,接受 `{ year, month, date }` 参数
  • 在 `public-types.ts` 中导出 `DatePickerDateSlotProps` 类型
  • 在以下面板文件中支持 date 插槽:
    • `date.tsx`
    • `datetime.tsx`
    • `daterange.tsx`(两处)
    • `datetimerange.tsx`(两处)
  • 添加中英文演示文件
  • 更新中英文文档

用法示例

```vue

<template #date="{ year, month, date }">


{{ date }}

{{ getLunarDate(year, month, date) }}




```

- Add date slot to DatePickerSlots interface with year, month, date parameters
- Support date slot in date, datetime, daterange, datetimerange panels
- Add DatePickerDateSlotProps to public-types
- Add demo files for both English and Chinese
- Update documentation with slot description

Closes tusen-ai#6751

export type DatePickerSetupProps = ExtractPropTypes<typeof datePickerProps>

export interface DatePickerDateSlotProps {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/date-picker/src/public-types.ts 里的重复定义了

>
<div class={`${mergedClsPrefix}-date-panel-date__trigger`} />
{dateItem.dateObject.date}
{datePickerSlots.date
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这几段逻辑完全一致 你可以抽一个 renderDateutil 复用

| prev-month | `()` | 日期面板的 `上一个` 图标 | 2.33.4 |
| prev-year | `()` | 日期面板的 `快速上一个` 图标 | 2.33.4 |
| separator | `()` | 日期范围分隔符号 | 2.29.0 |
| 名称 | 参数 | 说明 | 版本 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the `date` slot to customize the content of date cells, such as adding lunar calendar dates or holidays.
</markdown>

<script lang="ts">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新写的 demo 没有特殊原因的话都用 script setup 语法吧

@LouisLau-art
Copy link
Author

@Sepush 谢谢 review,收到:

  1. 我会复用 src/date-picker/src/public-types.ts 的定义,移除重复声明。
  2. 我会抽一个 renderDate 的 util 来复用这些重复逻辑。
  3. demo 文档我会按 CONTRIBUTING.zh-CN.md 的格式补齐/调整。
  4. 新 demo 我会改成 script setup 写法(除非后续发现必须用 Options API)。

@LouisLau-art
Copy link
Author

@Sepush 感谢 review!我按你提的点做了跟进:

  • 去掉 DatePicker.tsx 里重复的 DatePickerDateSlotProps 定义,统一复用 src/date-picker/src/public-types.ts
  • 把多处重复的 date slot 渲染逻辑抽成 renderDate util,并在 date / daterange / datetime / datetimerange 面板里复用。
  • zhCN/index.demo-entry.md 的版本占位修正为 NEXT_VERSION(对齐 enUS)。
  • 新增 demo 改为 script setup 写法。

麻烦你再看下是否符合预期~

使用 `date` 插槽可以自定义日期单元格的内容,例如添加农历、节日等信息。
</markdown>

<script lang="ts">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也要改

@filusilia
Copy link

这个功能很需要, 现在日历上一个月与下个月的日期颜色和禁用颜色是一样的,会造成上个月,下个月日期也是禁用的错觉。如果能给日期自定义问题可以稍微避免这样的误会

@LouisLau-art
Copy link
Author

感谢反馈,这个问题很有价值。我会接手把这个场景也纳入这次 PR:区分上/下月日期与禁用日期的视觉表现,避免“非当月看起来像禁用”的误解。处理完我会在这里同步截图/说明。

@Gahotx
Copy link

Gahotx commented Feb 24, 2026

请问这个PR有进展吗,有同样的自定义日期单元格需求

@LouisLau-art
Copy link
Author

感谢关注,这个 PR 目前在等待 maintainer review。
如果 maintainer 希望我补充/调整实现,我会第一时间跟进并更新。

@Gahotx
Copy link

Gahotx commented Feb 27, 2026

@LouisLau-art 我把 eslint 报错和上面要求的 script setup 语法完善了,你看下你仓库的 pr,没问题的话合并然后再麻烦 @Sepush review一遍

@LouisLau-art
Copy link
Author

收到,感谢你帮忙补了 eslintscript setup 🙏

我这边可以跟进合并到当前 PR,但请你把你那个 PR / 分支链接贴一下(或直接告诉我 fork 仓库名 + 分支名)。
我拿到链接后会尽快同步并 @Sepush 再看一轮。

@Gahotx
Copy link

Gahotx commented Mar 3, 2026

我之前在你的仓库提交了 PR LouisLau-art#3,按理说你合并之后就会自动同步到现在这个 PR 上的,
不过我看你没有合并,因为我比较着急使用这个功能,所以我后来自己提交了一个 PR #7514 到 naive-ui 的仓库,
我看你仓库的分支太久没有同步官方的 main 分支代码,所以不太方便修改官方的 CHANGELOG
不过我现在已经自己发布了一个到 npm 上了,因为等不了官方合并 PR了,项目着急上线😂

@LouisLau-art
Copy link
Author

已跟进修复当前 CI 的 lint 失败并推送到本分支:2753e98a6

修复内容(对应 lint 日志):

  • DatePicker.tsx:合并重复的 ./public-types type import,修正 import 排序冲突。
  • panel/datetimerange.tsx:修复两处 JSX 片段中的 tab/缩进/closing tag 对齐问题。
  • panel/renderDate.ts:去掉文件末尾多余空行。

本地验证:

  • pnpm run lint ✅(含 lint:code + lint:type

可以触发新一轮 CI 了,辛苦再看下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

日期选择器添加日期slot

4 participants