-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(date-picker): 添加 date slot 支持自定义日期单元格内容 #7382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LouisLau-art
wants to merge
4
commits into
tusen-ai:main
Choose a base branch
from
LouisLau-art:feat/date-picker-date-slot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
877bfee
feat(date-picker): add date slot for custom date cell content
efb15b1
refactor(date-picker): reuse date slot renderer
82bae45
docs(date-picker): align slot docs and demo style
2753e98
fix(date-picker): resolve lint regressions in date slot changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <markdown> | ||
| # Custom Date Cell | ||
|
|
||
| Use the `date` slot to customize the content of date cells, such as adding lunar calendar dates or holidays. | ||
| </markdown> | ||
|
|
||
| <script setup lang="ts"> | ||
| // Simple holiday mapping example (for demonstration only) | ||
| const holidays: Record<string, string> = { | ||
| '2024-1-1': 'NY', | ||
| '2024-12-25': 'Xmas', | ||
| '2024-7-4': 'July 4' | ||
| } | ||
|
|
||
| function getHoliday(year: number, month: number, date: number) { | ||
| const key = `${year}-${month + 1}-${date}` | ||
| return holidays[key] | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <n-space vertical> | ||
| <n-date-picker type="date" :default-value="Date.now()"> | ||
| <template #date="{ year, month, date }"> | ||
| <div style="display: flex; flex-direction: column; align-items: center"> | ||
| <span>{{ date }}</span> | ||
| <span | ||
| v-if="getHoliday(year, month, date)" | ||
| style="font-size: 10px; color: #18a058" | ||
| > | ||
| {{ getHoliday(year, month, date) }} | ||
| </span> | ||
| </div> | ||
| </template> | ||
| </n-date-picker> | ||
| <n-date-picker | ||
| type="daterange" | ||
| :default-value="[Date.now(), Date.now() + 86400000 * 7]" | ||
| > | ||
| <template #date="{ year, month, date }"> | ||
| <div style="display: flex; flex-direction: column; align-items: center"> | ||
| <span>{{ date }}</span> | ||
| <span | ||
| v-if="getHoliday(year, month, date)" | ||
| style="font-size: 10px; color: #18a058" | ||
| > | ||
| {{ getHoliday(year, month, date) }} | ||
| </span> | ||
| </div> | ||
| </template> | ||
| </n-date-picker> | ||
| </n-space> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <markdown> | ||
| # 自定义日期 | ||
|
|
||
| 使用 `date` 插槽可以自定义日期单元格的内容,例如添加农历、节日等信息。 | ||
| </markdown> | ||
|
|
||
| <script lang="ts"> | ||
| import { defineComponent } from 'vue' | ||
|
|
||
| export default defineComponent({ | ||
| setup() { | ||
| // 简单的农历映射示例(仅用于演示) | ||
| const lunarDates: Record<string, string> = { | ||
| '2024-1-1': '廿一', | ||
| '2024-1-15': '初五', | ||
| '2024-2-10': '初一', | ||
| '2024-12-25': '圣诞' | ||
| } | ||
|
|
||
| const getLunarDate = (year: number, month: number, date: number) => { | ||
| const key = `${year}-${month + 1}-${date}` | ||
| return lunarDates[key] | ||
| } | ||
|
|
||
| return { | ||
| getLunarDate | ||
| } | ||
| } | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <n-space vertical> | ||
| <n-date-picker type="date" :default-value="Date.now()"> | ||
| <template #date="{ year, month, date }"> | ||
| <div style="display: flex; flex-direction: column; align-items: center"> | ||
| <span>{{ date }}</span> | ||
| <span | ||
| v-if="getLunarDate(year, month, date)" | ||
| style="font-size: 10px; color: #999" | ||
| > | ||
| {{ getLunarDate(year, month, date) }} | ||
| </span> | ||
| </div> | ||
| </template> | ||
| </n-date-picker> | ||
| <n-date-picker | ||
| type="daterange" | ||
| :default-value="[Date.now(), Date.now() + 86400000 * 7]" | ||
| > | ||
| <template #date="{ year, month, date }"> | ||
| <div style="display: flex; flex-direction: column; align-items: center"> | ||
| <span>{{ date }}</span> | ||
| <span | ||
| v-if="getLunarDate(year, month, date)" | ||
| style="font-size: 10px; color: #999" | ||
| > | ||
| {{ getLunarDate(year, month, date) }} | ||
| </span> | ||
| </div> | ||
| </template> | ||
| </n-date-picker> | ||
| </n-space> | ||
| </template> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ shortcuts.vue | |
| events.vue | ||
| format.vue | ||
| footerslot.vue | ||
| date-slot.vue | ||
| status.vue | ||
| icon.vue | ||
| panel.vue | ||
|
|
@@ -192,15 +193,16 @@ form-debug.vue | |
|
|
||
| ### DatePicker Slots | ||
|
|
||
| | 名称 | 参数 | 说明 | 版本 | | ||
| | ---------- | ---- | ---------------------------- | ------ | | ||
| | 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 | | ||
| | 名称 | 参数 | 说明 | 版本 | | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| | --- | --- | --- | --- | | ||
| | date | `(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 | | ||
|
|
||
| ### Date, Year, QuarterRange, Week Slots | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { VNodeChild } from 'vue' | ||
| import type { DatePickerDateSlotProps } from '../public-types' | ||
|
|
||
| export type DatePickerDateSlot = (props: DatePickerDateSlotProps) => VNodeChild | ||
|
|
||
| export function renderDate( | ||
| dateSlot: DatePickerDateSlot | undefined, | ||
| dateObject: DatePickerDateSlotProps | ||
| ): VNodeChild { | ||
| return dateSlot ? dateSlot(dateObject) : dateObject.date | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个也要改