feat(Calendar): add top-info、bottom-info slot (#8847)

This commit is contained in:
neverland 2021-06-10 19:20:22 +08:00 committed by GitHub
parent 5454fef6cf
commit 83e051f621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 19 deletions

View File

@ -305,10 +305,12 @@ Following props are supported when the type is multiple
### Slots ### Slots
| Name | Description | | Name | Description | SlotProps |
| ------ | ------------- | | ---------------------- | ------------------------- | ---------- |
| title | Custom title | | title | Custom title | - |
| footer | Custom fotter | | 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 ### Methods

View File

@ -311,10 +311,12 @@ export default {
### Slots ### Slots
| 名称 | 说明 | | 名称 | 说明 | 参数 |
| ------ | ------------------ | | ---------------------- | ------------------------ | ---------- |
| title | 自定义标题 | | title | 自定义标题 | - |
| footer | 自定义底部区域内容 | | footer | 自定义底部区域内容 | - |
| top-info `v2.12.22` | 自定义日期上方的提示信息 | _day: Day_ |
| bottom-info `v2.12.22` | 自定义日期下方的提示信息 | _day: Day_ |
### 方法 ### 方法

View File

@ -266,8 +266,28 @@ export default createComponent({
); );
}, },
genTopInfo(item) {
const slot = this.$scopedSlots['top-info'];
if (item.topInfo || slot) {
return (
<div class={bem('top-info')}>{slot ? slot(item) : item.topInfo}</div>
);
}
},
genBottomInfo(item) {
const slot = this.$scopedSlots['bottom-info'];
if (item.bottomInfo || slot) {
return (
<div class={bem('bottom-info')}>
{slot ? slot(item) : item.bottomInfo}
</div>
);
}
},
genDay(item, index) { genDay(item, index) {
const { type, topInfo, bottomInfo } = item; const { type } = item;
const style = this.getDayStyle(type, index); const style = this.getDayStyle(type, index);
const disabled = type === 'disabled'; const disabled = type === 'disabled';
@ -277,12 +297,6 @@ export default createComponent({
} }
}; };
const TopInfo = topInfo && <div class={bem('top-info')}>{topInfo}</div>;
const BottomInfo = bottomInfo && (
<div class={bem('bottom-info')}>{bottomInfo}</div>
);
if (type === 'selected') { if (type === 'selected') {
return ( return (
<div <div
@ -300,9 +314,9 @@ export default createComponent({
background: this.color, background: this.color,
}} }}
> >
{TopInfo} {this.genTopInfo(item)}
{item.text} {item.text}
{BottomInfo} {this.genBottomInfo(item)}
</div> </div>
</div> </div>
); );
@ -316,9 +330,9 @@ export default createComponent({
tabindex={disabled ? null : -1} tabindex={disabled ? null : -1}
onClick={onClick} onClick={onClick}
> >
{TopInfo} {this.genTopInfo(item)}
{item.text} {item.text}
{BottomInfo} {this.genBottomInfo(item)}
</div> </div>
); );
}, },

View File

@ -432,6 +432,10 @@ export default createComponent({
allowSameDay={this.allowSameDay} allowSameDay={this.allowSameDay}
showMonthTitle={showMonthTitle} showMonthTitle={showMonthTitle}
firstDayOfWeek={this.dayOffset} firstDayOfWeek={this.dayOffset}
scopedSlots={{
'top-info': this.$scopedSlots['top-info'],
'bottom-info': this.$scopedSlots['bottom-info'],
}}
onClick={this.onClickDay} onClick={this.onClickDay}
/> />
); );