优化result组件

master
yutent 2023-11-16 15:25:15 +08:00
parent a156c9a236
commit 63a7892344
1 changed files with 42 additions and 67 deletions

View File

@ -9,83 +9,68 @@ import '../icon/index.js'
class Result extends Component { class Result extends Component {
static props = { static props = {
title: { title: 'str!',
type: String, subTitle: '',
default: '', type: 'success',
attribute: false icon: ''
},
subTitle: { type: String, default: '' },
type: {
type: String,
default: 'success'
},
icon: {
type: String,
default: ''
}
} }
static styles = [ static styles = [
css` css`
:host { :host {
position: relative; display: inline-flex;
display: inline-block; }
text-align: center;
:host([type='success']) .icon {
background: var(--color-teal-1);
} }
:host([type='warning']) .icon { :host([type='warning']) .icon {
background: #e6a23c; background: var(--color-orange-1);
wc-icon {
transform: translateY(-2px);
}
} }
:host([type='error']) .icon { :host([type='error']) .icon {
--wc-icon-size: 24px; background: var(--color-red-1);
background: #f56c6c;
} }
:host([type='info']) .icon { :host([type='info']) .icon {
background: #909399; background: var(--color-blue-1);
} }
.result {
.container {
display: flex; display: flex;
justify-content: center;
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
text-align: center; text-align: center;
box-sizing: border-box; max-width: 440px;
padding: 40px 30px; padding: 36px 32px;
} line-height: 1.5;
.icon-wrapper { font-size: 14px;
display: flex; color: var(--color-dark-1);
align-items: center;
justify-content: center;
} }
.icon { .icon {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 53px; width: 52px;
height: 53px; height: 52px;
line-height: 1;
border-radius: 50%; border-radius: 50%;
background: var(--wc-result-icon-color, var(--color-dark-1));
color: #fff; color: #fff;
background: #67c23a;
} }
.title { .title {
margin-top: 20px; margin-top: 16px;
font-size: 18px;
} }
.sub-title { .sub-title {
margin-top: 10px; margin-top: 6px;
} }
.extra { .extra {
margin-top: 30px; margin-top: 12px;
}
span {
font-size: 14px;
color: #5e6d82;
line-height: 1.5em;
} }
` `
] ]
get iconName() {
get #icon() {
if (this.icon) { if (this.icon) {
return this.icon return this.icon
} }
@ -93,38 +78,28 @@ class Result extends Component {
return 'get' return 'get'
} }
if (this.type === 'error') { if (this.type === 'error') {
return 'close' return 'deny'
} }
return this.type return this.type
} }
render() { render() {
return html` return html`
<div class="result"> <main class="container">
<div class="icon-wrapper">
<slot name="icon">
<div class="icon"> <div class="icon">
<wc-icon name=${this.iconName}></wc-icon> <slot name="icon"><wc-icon name=${this.#icon}></wc-icon></slot>
</div>
</slot>
</div> </div>
<div class="title"> <h3 class="title">
<slot name="title"> <slot name="title">${this.title}</slot>
<span>${this.title}</span> </h3>
</slot>
</div>
<div class="sub-title"> <section class="sub-title">
<slot name="sub-title"> <slot name="sub-title">${this.subTitle}</slot>
<span>${this.subTitle}</span> </section>
</slot>
</div>
<div class="extra"> <cite class="extra"><slot></slot></cite>
<slot name="extra"></slot> </main>
</div>
</div>
` `
} }
} }