mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Calendar): add params for subtitle slot (#11168)
* feat(Calendar): add params for subtitle slot * chore: fix
This commit is contained in:
parent
859e5ee32c
commit
6848550243
@ -175,7 +175,10 @@ export default defineComponent({
|
||||
|
||||
const bodyRef = ref<HTMLElement>();
|
||||
|
||||
const subtitle = ref('');
|
||||
const subtitle = ref<{ text: string; date?: Date }>({
|
||||
text: '',
|
||||
date: undefined,
|
||||
});
|
||||
const currentDate = ref(getInitialDate());
|
||||
|
||||
const [monthRefs, setMonthRefs] = useRefs<CalendarMonthInstance>();
|
||||
@ -267,7 +270,10 @@ export default defineComponent({
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (currentMonth) {
|
||||
subtitle.value = currentMonth.getTitle();
|
||||
subtitle.value = {
|
||||
text: currentMonth.getTitle(),
|
||||
date: currentMonth.date,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@ -525,8 +531,9 @@ export default defineComponent({
|
||||
<div class={bem()}>
|
||||
<CalendarHeader
|
||||
v-slots={pick(slots, ['title', 'subtitle'])}
|
||||
date={subtitle.value.date}
|
||||
title={props.title}
|
||||
subtitle={subtitle.value}
|
||||
subtitle={subtitle.value.text}
|
||||
showTitle={props.showTitle}
|
||||
showSubtitle={props.showSubtitle}
|
||||
firstDayOfWeek={dayOffset.value}
|
||||
|
@ -8,6 +8,7 @@ export default defineComponent({
|
||||
name,
|
||||
|
||||
props: {
|
||||
date: Date,
|
||||
title: String,
|
||||
subtitle: String,
|
||||
showTitle: Boolean,
|
||||
@ -30,7 +31,12 @@ export default defineComponent({
|
||||
|
||||
const renderSubtitle = () => {
|
||||
if (props.showSubtitle) {
|
||||
const title = slots.subtitle ? slots.subtitle() : props.subtitle;
|
||||
const title = slots.subtitle
|
||||
? slots.subtitle({
|
||||
date: props.date,
|
||||
text: props.subtitle,
|
||||
})
|
||||
: props.subtitle;
|
||||
return (
|
||||
<div class={bem('header-subtitle')} onClick={onClickSubtitle}>
|
||||
{title}
|
||||
|
@ -331,14 +331,14 @@ Following props are supported when the type is multiple
|
||||
|
||||
### Slots
|
||||
|
||||
| Name | Description | SlotProps |
|
||||
| --------------------- | ------------------------- | ----------------------- |
|
||||
| title | Custom title | - |
|
||||
| subtitle `v3.1.3` | Custom subtitle | - |
|
||||
| footer | Custom footer | - |
|
||||
| confirm-text `v3.2.6` | Custom confirm text | _{ disabled: boolean }_ |
|
||||
| top-info `v3.0.17` | Custom top info of day | _day: Day_ |
|
||||
| bottom-info `v3.0.17` | Custom bottom info of day | _day: Day_ |
|
||||
| Name | Description | SlotProps |
|
||||
| --- | --- | --- |
|
||||
| title | Custom title | - |
|
||||
| subtitle `v3.1.3` | Custom subtitle | _{ text: string, date?: Date }_ |
|
||||
| footer | Custom footer | - |
|
||||
| confirm-text `v3.2.6` | Custom confirm text | _{ disabled: boolean }_ |
|
||||
| top-info `v3.0.17` | Custom top info of day | _day: Day_ |
|
||||
| bottom-info `v3.0.17` | Custom bottom info of day | _day: Day_ |
|
||||
|
||||
### Methods
|
||||
|
||||
|
@ -337,14 +337,14 @@ export default {
|
||||
|
||||
### Slots
|
||||
|
||||
| 名称 | 说明 | 参数 |
|
||||
| --------------------- | ------------------------ | ----------------------- |
|
||||
| title | 自定义标题 | - |
|
||||
| subtitle `v3.1.3` | 自定义日历副标题 | - |
|
||||
| footer | 自定义底部区域内容 | - |
|
||||
| confirm-text `v3.2.6` | 自定义确认按钮的内容 | _{ disabled: boolean }_ |
|
||||
| top-info `v3.0.17` | 自定义日期上方的提示信息 | _day: Day_ |
|
||||
| bottom-info `v3.0.17` | 自定义日期下方的提示信息 | _day: Day_ |
|
||||
| 名称 | 说明 | 参数 |
|
||||
| --- | --- | --- |
|
||||
| title | 自定义标题 | - |
|
||||
| subtitle `v3.1.3` | 自定义日历副标题 | _{ text: string, date?: Date }_ |
|
||||
| footer | 自定义底部区域内容 | - |
|
||||
| confirm-text `v3.2.6` | 自定义确认按钮的内容 | _{ disabled: boolean }_ |
|
||||
| top-info `v3.0.17` | 自定义日期上方的提示信息 | _day: Day_ |
|
||||
| bottom-info `v3.0.17` | 自定义日期下方的提示信息 | _day: Day_ |
|
||||
|
||||
### 方法
|
||||
|
||||
|
@ -934,6 +934,12 @@ exports[`should render confirm-text slot correctly 1`] = `
|
||||
</button>
|
||||
`;
|
||||
|
||||
exports[`should render subtitle slot with params 1`] = `
|
||||
<div class="van-calendar__header-subtitle">
|
||||
Custom Subtitle
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render title、footer、subtitle slot correctly 1`] = `
|
||||
<div class="van-calendar">
|
||||
<div class="van-calendar__header">
|
||||
|
@ -365,6 +365,27 @@ test('should render title、footer、subtitle slot correctly', async () => {
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render subtitle slot with params', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
minDate,
|
||||
maxDate,
|
||||
poppable: false,
|
||||
defaultDate: minDate,
|
||||
lazyRender: false,
|
||||
},
|
||||
slots: {
|
||||
subtitle: ({ text }) => `Custom Subtitle ${text}`,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
|
||||
expect(
|
||||
wrapper.find('.van-calendar__header-subtitle').html()
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should reset when type changed', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user