Skip to content

feat(date-picker): add date cell slot to customize the content of date cell#7514

Open
Gahotx wants to merge 9 commits intotusen-ai:mainfrom
Gahotx:feat/date-picker-date-slot
Open

feat(date-picker): add date cell slot to customize the content of date cell#7514
Gahotx wants to merge 9 commits intotusen-ai:mainfrom
Gahotx:feat/date-picker-date-slot

Conversation

@Gahotx
Copy link

@Gahotx Gahotx commented Feb 28, 2026

close #6614
close #6751
close #7237

基于 #7382 完善该自定义日期单元格内容的功能,由于原PR的作者好像没空合并代码,所以我单独提交一个新的PR

  1. 修复原PR的 eslint 报错
  2. demo 文档中按官方要求改为 script setup 语法
  3. 重构 date 插槽改为 date-cell 更符合语义化
  4. 完善 demo 文档示例的代码和样式

修改前:

  • 得看代码才知道示例是24年1月份
  • 示例代码样式错乱,会有遮挡问题
image image

修改后:

  • 简单示例标记每月10号,没有样式遮挡问题
image

Copilot AI review requested due to automatic review settings February 28, 2026 03:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new date-cell slot to NDatePicker so consumers can customize the rendered content inside each date cell, and includes updated demos/docs showcasing the feature.

Changes:

  • Introduces DatePickerDateCellSlotProps and a shared renderDateCell helper.
  • Wires the date-cell slot into date-related panels (date, datetime, daterange, datetimerange).
  • Adds new CN/EN demos and updates demo entry documentation to list the new slot.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/date-picker/src/public-types.ts Adds public slot-props type for date-cell.
src/date-picker/src/panel/render-date-cell.ts New helper to render slot content with fallback to date number.
src/date-picker/src/panel/date.tsx Uses renderDateCell to render each day cell.
src/date-picker/src/panel/datetime.tsx Uses renderDateCell for day cells in datetime panel.
src/date-picker/src/panel/daterange.tsx Uses renderDateCell for start/end range calendars.
src/date-picker/src/panel/datetimerange.tsx Uses renderDateCell for start/end range calendars with time.
src/date-picker/src/DatePicker.tsx Extends DatePickerSlots with the new date-cell slot typing.
src/date-picker/demos/zhCN/index.demo-entry.md Registers new demo and documents date-cell slot.
src/date-picker/demos/enUS/index.demo-entry.md Registers new demo and documents date-cell slot.
src/date-picker/demos/zhCN/date-cell-slot.demo.vue New CN demo showcasing date-cell usage and styling.
src/date-picker/demos/enUS/date-cell-slot.demo.vue New EN demo showcasing date-cell usage and styling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

export interface DatePickerDateCellSlotProps {
year: number
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

DatePickerDateCellSlotProps.month is derived from date-fns/getMonth (0-11) in the current implementation, but the type doesn’t document that. Please clarify whether month is 0-based or 1-based (and document it here) to prevent off-by-one usage in slot implementations.

Suggested change
year: number
year: number
/** 0-based month index, as in `date-fns/getMonth` (0 = January, 11 = December). */

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +205
| Name | Parameters | Description | Version |
| --- | --- | --- | --- |
| date-cell | `(props: { year: number, month: number, date: number })` | The content of the date cell. | NEXT_VERSION |
| date-icon | `()` | Date icon of the input box. | 2.29.0 |
| footer | `()` | Extra Footer. | |
| next-month | `()` | Next icon of the date panel. | 2.33.4 |
| next-year | `()` | Fast next icon of the date panel. | 2.33.4 |
| prev-month | `()` | Prev icon of the date panel. | 2.33.4 |
| prev-year | `()` | Fast prev icon of the date panel. | 2.33.4 |
| separator | `()` | Separator of range picker. | 2.29.0 |
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The docs for date-cell don’t clarify whether month is 0-based or 1-based, while the component passes getMonth() (0-11). Please document the month range/indexing in the Parameters column to avoid off-by-one confusion. Also, NEXT_VERSION appears to be a placeholder (no other occurrences in docs); consider replacing it with the actual version number or leaving it blank to match the rest of the tables.

Copilot uses AI. Check for mistakes.
Comment on lines +196 to +205
| 名称 | 参数 | 说明 | 版本 |
| --- | --- | --- | --- |
| date-cell | `(props: { year: number, month: number, date: number })` | 日期单元格的内容 | NEXT_VERSION |
| date-icon | `()` | 日期输入框的图标 | 2.29.0 |
| footer | `()` | 添加额外的页脚 | |
| next-month | `()` | 日期面板的 `下一个` 图标 | 2.33.4 |
| next-year | `()` | 日期面板的 `快速下一个` 图标 | 2.33.4 |
| prev-month | `()` | 日期面板的 `上一个` 图标 | 2.33.4 |
| prev-year | `()` | 日期面板的 `快速上一个` 图标 | 2.33.4 |
| separator | `()` | 日期范围分隔符号 | 2.29.0 |
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

date-cell slot docs should clarify whether month is 0-based or 1-based (implementation uses getMonth() → 0-11). Please update the Parameters/说明 to state the month range/indexing to avoid off-by-one issues. Also, NEXT_VERSION looks like a placeholder (not used elsewhere); consider using the real version number or leaving it empty for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines +165 to +168
{renderDateCell(
datePickerSlots['date-cell'],
dateItem.dateObject
)}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

This introduces new rendering behavior via the date-cell slot, but there’s no corresponding test to verify slot content is rendered for at least type="date" and a range type. Since src/date-picker/tests/DatePicker.spec.tsx already covers many props, please add a regression test that mounts NDatePicker with a date-cell slot and asserts the custom content appears in the panel.

Copilot uses AI. Check for mistakes.
LouisLau-art and others added 7 commits February 28, 2026 15:49
- 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
…ality

* feat: rename the custom date cell variable to the more semantic `date-cell`
* docs: improve the example styles in the demo documentation
@Gahotx Gahotx force-pushed the feat/date-picker-date-slot branch from 59cd07e to ed05d7c Compare February 28, 2026 07:50
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.

DatePicker 增加日期渲染插槽 日期选择器添加日期slot DatePicker: Add cellRender Support to DatePicker

2 participants