diff --git a/src/calendar/README.md b/src/calendar/README.md index abd7efc2f..e9a200a58 100644 --- a/src/calendar/README.md +++ b/src/calendar/README.md @@ -305,10 +305,12 @@ Following props are supported when the type is multiple ### Slots -| Name | Description | -| ------ | ------------- | -| title | Custom title | -| footer | Custom fotter | +| Name | Description | SlotProps | +| ---------------------- | ------------------------- | ---------- | +| title | Custom title | - | +| footer | Custom footer | - | +| top-info `v2.12.22` | Custom top info of day | _day: Day_ | +| bottom-info `v2.12.22` | Custom bottom info of day | _day: Day_ | ### Methods diff --git a/src/calendar/README.zh-CN.md b/src/calendar/README.zh-CN.md index b0cc5919b..37925f87d 100644 --- a/src/calendar/README.zh-CN.md +++ b/src/calendar/README.zh-CN.md @@ -311,10 +311,12 @@ export default { ### Slots -| 名称 | 说明 | -| ------ | ------------------ | -| title | 自定义标题 | -| footer | 自定义底部区域内容 | +| 名称 | 说明 | 参数 | +| ---------------------- | ------------------------ | ---------- | +| title | 自定义标题 | - | +| footer | 自定义底部区域内容 | - | +| top-info `v2.12.22` | 自定义日期上方的提示信息 | _day: Day_ | +| bottom-info `v2.12.22` | 自定义日期下方的提示信息 | _day: Day_ | ### 方法 diff --git a/src/calendar/components/Month.js b/src/calendar/components/Month.js index d1d8cc45e..9704a40ea 100644 --- a/src/calendar/components/Month.js +++ b/src/calendar/components/Month.js @@ -266,8 +266,28 @@ export default createComponent({ ); }, + genTopInfo(item) { + const slot = this.$scopedSlots['top-info']; + if (item.topInfo || slot) { + return ( +
{slot ? slot(item) : item.topInfo}
+ ); + } + }, + + genBottomInfo(item) { + const slot = this.$scopedSlots['bottom-info']; + if (item.bottomInfo || slot) { + return ( +
+ {slot ? slot(item) : item.bottomInfo} +
+ ); + } + }, + genDay(item, index) { - const { type, topInfo, bottomInfo } = item; + const { type } = item; const style = this.getDayStyle(type, index); const disabled = type === 'disabled'; @@ -277,12 +297,6 @@ export default createComponent({ } }; - const TopInfo = topInfo &&
{topInfo}
; - - const BottomInfo = bottomInfo && ( -
{bottomInfo}
- ); - if (type === 'selected') { return (
- {TopInfo} + {this.genTopInfo(item)} {item.text} - {BottomInfo} + {this.genBottomInfo(item)}
); @@ -316,9 +330,9 @@ export default createComponent({ tabindex={disabled ? null : -1} onClick={onClick} > - {TopInfo} + {this.genTopInfo(item)} {item.text} - {BottomInfo} + {this.genBottomInfo(item)} ); }, diff --git a/src/calendar/index.js b/src/calendar/index.js index fa7483025..fa8f49bf3 100644 --- a/src/calendar/index.js +++ b/src/calendar/index.js @@ -432,6 +432,10 @@ export default createComponent({ allowSameDay={this.allowSameDay} showMonthTitle={showMonthTitle} firstDayOfWeek={this.dayOffset} + scopedSlots={{ + 'top-info': this.$scopedSlots['top-info'], + 'bottom-info': this.$scopedSlots['bottom-info'], + }} onClick={this.onClickDay} /> );