ui/src/card/index.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-03-06 15:24:17 +08:00
/**
* {卡片组件}
* @author yutent<yutent.io@gmail.com>
* @date 2023/03/06 15:17:25
*/
2023-03-15 11:27:16 +08:00
import { css, html, Component } from '@bd/core'
2023-03-06 15:24:17 +08:00
class Card extends Component {
static props = {
2023-03-15 11:27:16 +08:00
header: ''
2023-03-06 15:24:17 +08:00
}
static styles = css`
:host {
display: flex;
border-radius: 3px;
}
.card-box {
display: flex;
flex-direction: column;
position: relative;
width: 100%;
border: 1px solid var(--color-plain-2);
2023-03-15 11:27:16 +08:00
border-radius: inherit;
2023-03-06 15:24:17 +08:00
background: #fff;
color: var(--color-dark-1);
transition: box-shadow 0.2s ease-in-out;
box-shadow: 0 0 12px rgba(0, 0, 0, 0.12);
2023-03-15 11:27:16 +08:00
.header {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
min-height: 52px;
padding: var(--card-padding, 8px 16px);
border-bottom: 1px solid var(--color-plain-2);
font-size: 16px;
user-select: none;
}
.content {
flex: 1;
min-height: 64px;
padding: var(--card-padding, 8px 16px);
font-size: 14px;
color: var(--color-dark-1);
}
2023-03-06 15:24:17 +08:00
}
:host([shadow='never']) .card-box,
:host([shadow='hover']) .card-box {
box-shadow: none;
}
:host([shadow='hover']:hover) .card-box {
box-shadow: 0 0 12px rgba(0, 0, 0, 0.12);
}
`
render() {
return html`
<div class="card-box">
2023-03-15 11:27:16 +08:00
<div class="header">${this.header || html`<slot name="header" />`}</div>
2023-03-06 15:24:17 +08:00
<div class="content"><slot /></div>
</div>
`
}
}
customElements.define('wc-card', Card)