diff --git a/src/calendar/README.md b/src/calendar/README.md index e1222d6c3..634c3f56a 100644 --- a/src/calendar/README.md +++ b/src/calendar/README.md @@ -249,6 +249,7 @@ Set `poppable` to `false`, the calendar will be displayed directly on the page i | round | Whether to show round corner | *boolean* | `true` | | show-mark | Whether to show background month mark | *boolean* | `true` | | show-title `v2.5.5` | Whether to show title | *boolean* | `true` | +| show-subtitle `v2.5.5` | Whether to show subtitle | *boolean* | `true` | | show-confirm | Whether to show confirm button | *boolean* | `true` | | close-on-popstate `v2.4.4` | Whether to close when popstate | *boolean* | `false` | | close-on-click-overlay | Whether to close when click overlay | *boolean* | `true` | diff --git a/src/calendar/README.zh-CN.md b/src/calendar/README.zh-CN.md index e05d2d430..bac44258e 100644 --- a/src/calendar/README.zh-CN.md +++ b/src/calendar/README.zh-CN.md @@ -251,6 +251,7 @@ export default { | round | 是否显示圆角弹窗 | *boolean* | `true` | | show-mark | 是否显示月份背景水印 | *boolean* | `true` | | show-title `v2.5.5` | 是否展示日历标题 | *boolean* | `true` | +| show-subtitle `v2.5.5` | 是否展示日历副标题(年月) | *boolean* | `true` | | show-confirm | 是否展示确认按钮 | *boolean* | `true` | | close-on-popstate `v2.4.4` | 是否在页面回退时自动关闭 | *boolean* | `false` | | close-on-click-overlay | 是否在点击遮罩层后关闭 | *boolean* | `true` | diff --git a/src/calendar/components/Header.js b/src/calendar/components/Header.js index 772055f4e..b10a6d2b9 100644 --- a/src/calendar/components/Header.js +++ b/src/calendar/components/Header.js @@ -6,22 +6,23 @@ const [createComponent] = createNamespace('calendar-header'); export default createComponent({ props: { title: String, + subtitle: String, showTitle: Boolean, - monthTitle: String, + showSubtitle: Boolean, }, methods: { genTitle() { - if (!this.showTitle) { - return; + if (this.showTitle) { + const title = this.slots('title') || this.title || t('title'); + return
{title}
; } - - const title = this.slots('title') || this.title || t('title'); - return
{title}
; }, - genMonth() { - return
{this.monthTitle}
; + genSubtitle() { + if (this.showSubtitle) { + return
{this.subtitle}
; + } }, genWeekDays() { @@ -41,7 +42,7 @@ export default createComponent({ return (
{this.genTitle()} - {this.genMonth()} + {this.genSubtitle()} {this.genWeekDays()}
); diff --git a/src/calendar/index.js b/src/calendar/index.js index 5724797d0..c1f20ff7e 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -77,6 +77,10 @@ export default createComponent({ type: Boolean, default: true, }, + showSubtitle: { + type: Boolean, + default: true, + }, safeAreaInsetBottom: { type: Boolean, default: true, @@ -93,7 +97,7 @@ export default createComponent({ data() { return { - monthTitle: '', + subtitle: '', currentDate: this.getInitialDate(), }; }, @@ -239,7 +243,7 @@ export default createComponent({ /* istanbul ignore else */ if (currentMonth) { - this.monthTitle = currentMonth.title; + this.subtitle = currentMonth.title; } }, @@ -389,7 +393,8 @@ export default createComponent({
this.slots('title'), }} @@ -410,11 +415,11 @@ export default createComponent({ return (
日历
-
2012年1月
+
2012年1月
diff --git a/src/calendar/test/__snapshots__/index.spec.js.snap b/src/calendar/test/__snapshots__/index.spec.js.snap index fe58c9c40..01688ead1 100644 --- a/src/calendar/test/__snapshots__/index.spec.js.snap +++ b/src/calendar/test/__snapshots__/index.spec.js.snap @@ -4,7 +4,7 @@ exports[`color prop when type is range 1`] = `
日期选择
-
2010年1月
+
2010年1月
@@ -55,7 +55,7 @@ exports[`color prop when type is single 1`] = `
日期选择
-
2010年1月
+
2010年1月
@@ -106,7 +106,7 @@ exports[`formatter prop 1`] = `
日期选择
-
2010年1月
+
2010年1月
@@ -163,7 +163,7 @@ exports[`popup wrapper 2`] = `
日期选择
-
2010年1月
+
2010年1月
@@ -216,7 +216,7 @@ exports[`row-height prop 1`] = `
日期选择
-
2010年1月
+
2010年1月
@@ -267,7 +267,7 @@ exports[`title & footer slot 1`] = `
Custom Title
-
2010年1月
+
2010年1月
diff --git a/src/calendar/test/prop.spec.js b/src/calendar/test/prop.spec.js index 9ac0ffd4f..91797c59d 100644 --- a/src/calendar/test/prop.spec.js +++ b/src/calendar/test/prop.spec.js @@ -25,15 +25,42 @@ test('max-range prop', async () => { expect(wrapper.emitted('confirm')).toBeFalsy(); }); -test('show-title prop', async () => { +test('show-title prop', () => { const wrapper = mount(Calendar, { propsData: { value: true, }, }); - await later(); expect(wrapper.contains('.van-calendar__header-title')).toBeTruthy(); wrapper.setProps({ showTitle: false }); expect(wrapper.contains('.van-calendar__header-title')).toBeFalsy(); }); + +test('show-subtitle prop', () => { + const wrapper = mount(Calendar, { + propsData: { + value: true, + }, + }); + + expect(wrapper.contains('.van-calendar__header-subtitle')).toBeTruthy(); + wrapper.setProps({ showSubtitle: false }); + expect(wrapper.contains('.van-calendar__header-subtitle')).toBeFalsy(); +}); + +test('hide close icon when there is no title', () => { + const wrapper = mount(Calendar, { + propsData: { + value: true, + }, + }); + + expect(wrapper.contains('.van-popup__close-icon')).toBeTruthy(); + + wrapper.setProps({ + showTitle: false, + showSubtitle: false, + }); + expect(wrapper.contains('.van-popup__close-icon')).toBeFalsy(); +}); diff --git a/src/style/var.less b/src/style/var.less index 8d0f09588..fbc2ee284 100644 --- a/src/style/var.less +++ b/src/style/var.less @@ -142,6 +142,7 @@ @calendar-header-box-shadow: 0 2px 10px rgba(125, 126, 128, 0.16); @calendar-header-title-height: 44px; @calendar-header-title-font-size: @font-size-lg; +@calendar-header-subtitle-font-size: @font-size-md; @calendar-weekdays-height: 30px; @calendar-weekdays-font-size: @font-size-sm; @calendar-month-title-font-size: @font-size-md;