Skip to content
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

feat(calendar): add extra slot, closes #6648 #6668

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- Fix `n-date-picker`'s `confirm`, `now`, `clear` slots doesn't work with `'month'`, `'monthrange'`, `'quarter'`, `'quarterrange'`, `'year'` and `'yearrange'` type.
- Fix `n-input`'s `render-count` prop doesn't work when type is not `'textarea'`.

### Features

- `n-calendar` adds `extra` slot, closes [#6648](https://github.com/tusen-ai/naive-ui/issues/6648).

## 2.40.4

`2024-12-20`
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- 修复 `n-date-picker` 的 `confirm`、`now`、`clear` 插槽对 `'month'`、`'monthrange'`、`'quarter'`、`'quarterrange'`、`'year'` 和 `'yearrange'` 类型不生效
- 修复 `n-input` 的 `render-count` 属性在类型非 `'textarea'` 时不生效

### Features

- `n-calendar` 新增 `extra` slot,关闭 [#6648](https://github.com/tusen-ai/naive-ui/issues/6648)

## 2.40.4

`2024-12-20`
Expand Down
1 change: 1 addition & 0 deletions src/calendar/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ basic.vue
| --- | --- | --- | --- |
| default | `({ year: number, month: number, date: number })` | Content to be rendered in each date. | |
| header | `(props: { year: number, month: number })` | Header of the calendar. `month` starts from 1. | 2.29.1 |
| extra | `(props: { year: number, month: number, prev: () => void, next: () => void, today: () => void })` | `month` starts from 1. | NEXT_VERSION |
1 change: 1 addition & 0 deletions src/calendar/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ basic.vue
| --- | --- | --- | --- |
| default | `(props: { year: number, month: number, date: number })` | 每个日期中渲染的内容 | |
| header | `(props: { year: number, month: number })` | 日历的标题,`month` 从 1 开始 | 2.29.1 |
| extra | `(props: { year: number, month: number, prev: () => void, next: () => void, today: () => void })` | `month` 从 1 开始 | NEXT_VERSION |
114 changes: 64 additions & 50 deletions src/calendar/src/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ExtractPublicPropTypes, MaybeArray } from '../../_utils'
import type { CalendarTheme } from '../styles'
import type {
CalendarDefaultSlotProps,
CalendarExtraSlotProps,
CalendarHeaderSlotProps,
DateItem,
OnPanelChange,
Expand Down Expand Up @@ -57,6 +58,7 @@ export type CalendarProps = ExtractPublicPropTypes<typeof calendarProps>
export interface CalendarSlots {
default?: (props: CalendarDefaultSlotProps) => VNode[]
header?: (props: CalendarHeaderSlotProps) => VNode[]
extra?: (props: CalendarExtraSlotProps) => VNode[]
}

export default defineComponent({
Expand Down Expand Up @@ -245,56 +247,68 @@ export default defineComponent({
)}
</div>
<div class={`${mergedClsPrefix}-calendar-header__extra`}>
<NButtonGroup>
{{
default: () => (
<>
<NButton
size="small"
onClick={handlePrevClick}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
>
{{
icon: () => (
<NBaseIcon
clsPrefix={mergedClsPrefix}
class={`${mergedClsPrefix}-calendar-prev-btn`}
>
{{ default: () => <ChevronLeftIcon /> }}
</NBaseIcon>
)
}}
</NButton>
<NButton
size="small"
onClick={handleTodayClick}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
>
{{ default: () => today }}
</NButton>
<NButton
size="small"
onClick={handleNextClick}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
>
{{
icon: () => (
<NBaseIcon
clsPrefix={mergedClsPrefix}
class={`${mergedClsPrefix}-calendar-next-btn`}
>
{{ default: () => <ChevronRightIcon /> }}
</NBaseIcon>
)
}}
</NButton>
</>
)
}}
</NButtonGroup>
{resolveSlotWithTypedProps(
$slots.extra,
{
year,
month: calendarMonth,
prev: handlePrevClick,
next: handleNextClick,
today: handleTodayClick
},
() => [
<NButtonGroup>
{{
default: () => (
<>
<NButton
size="small"
onClick={handlePrevClick}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
>
{{
icon: () => (
<NBaseIcon
clsPrefix={mergedClsPrefix}
class={`${mergedClsPrefix}-calendar-prev-btn`}
>
{{ default: () => <ChevronLeftIcon /> }}
</NBaseIcon>
)
}}
</NButton>
<NButton
size="small"
onClick={handleTodayClick}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
>
{{ default: () => today }}
</NButton>
<NButton
size="small"
onClick={handleNextClick}
theme={mergedTheme.peers.Button}
themeOverrides={mergedTheme.peerOverrides.Button}
>
{{
icon: () => (
<NBaseIcon
clsPrefix={mergedClsPrefix}
class={`${mergedClsPrefix}-calendar-next-btn`}
>
{{ default: () => <ChevronRightIcon /> }}
</NBaseIcon>
)
}}
</NButton>
</>
)
}}
</NButtonGroup>
]
)}
</div>
</div>
<div class={`${mergedClsPrefix}-calendar-dates`}>
Expand Down
8 changes: 8 additions & 0 deletions src/calendar/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export interface CalendarHeaderSlotProps {
year: number
month: number
}

export interface CalendarExtraSlotProps {
year: number
month: number
prev: () => void
next: () => void
today: () => void
}