kopia lustrzana https://github.com/shoelace-style/shoelace
69 wiersze
2.0 KiB
TypeScript
69 wiersze
2.0 KiB
TypeScript
import { html, LitElement } from 'lit';
|
|
import { customElement } from 'lit/decorators.js';
|
|
import { classMap } from 'lit/directives/class-map.js';
|
|
import { HasSlotController } from '~/internal/slot';
|
|
import styles from './card.styles';
|
|
|
|
/**
|
|
* @since 2.0
|
|
* @status stable
|
|
*
|
|
* @slot - The card's body.
|
|
* @slot header - The card's header.
|
|
* @slot footer - The card's footer.
|
|
* @slot image - The card's image.
|
|
*
|
|
* @csspart base - The component's internal wrapper.
|
|
* @csspart image - The card's image, if present.
|
|
* @csspart header - The card's header, if present.
|
|
* @csspart body - The card's body.
|
|
* @csspart footer - The card's footer, if present.
|
|
*
|
|
* @cssproperty --border-color - The card's border color, including borders that occur inside the card.
|
|
* @cssproperty --border-radius - The border radius for card edges.
|
|
* @cssproperty --border-width - The width of card borders.
|
|
* @cssproperty --padding - The padding to use for card sections.*
|
|
*/
|
|
@customElement('sl-card')
|
|
export default class SlCard extends LitElement {
|
|
static styles = styles;
|
|
|
|
private readonly hasSlotController = new HasSlotController(this, 'footer', 'header', 'image');
|
|
|
|
render() {
|
|
return html`
|
|
<div
|
|
part="base"
|
|
class=${classMap({
|
|
card: true,
|
|
'card--has-footer': this.hasSlotController.test('footer'),
|
|
'card--has-image': this.hasSlotController.test('image'),
|
|
'card--has-header': this.hasSlotController.test('header')
|
|
})}
|
|
>
|
|
<div part="image" class="card__image">
|
|
<slot name="image"></slot>
|
|
</div>
|
|
|
|
<div part="header" class="card__header">
|
|
<slot name="header"></slot>
|
|
</div>
|
|
|
|
<div part="body" class="card__body">
|
|
<slot></slot>
|
|
</div>
|
|
|
|
<div part="footer" class="card__footer">
|
|
<slot name="footer"></slot>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'sl-card': SlCard;
|
|
}
|
|
}
|