shoelace/src/components/card/card.ts

70 wiersze
2.0 KiB
TypeScript
Czysty Zwykły widok Historia

import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
2021-09-29 12:40:26 +00:00
import { classMap } from 'lit/directives/class-map.js';
2022-03-24 12:01:09 +00:00
import { HasSlotController } from '../../internal/slot';
2021-07-10 00:45:44 +00:00
import styles from './card.styles';
import type { CSSResultGroup } from 'lit';
2020-07-22 20:02:49 +00:00
/**
* @since 2.0
* @status stable
*
2021-06-25 20:25:46 +00:00
* @slot - The card's body.
* @slot header - The card's header.
* @slot footer - The card's footer.
* @slot image - The card's image.
2020-07-22 20:02:49 +00:00
*
2022-03-09 20:54:18 +00:00
* @csspart base - The component's internal wrapper.
2021-06-25 20:25:46 +00:00
* @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.
*
2021-06-25 20:25:46 +00:00
* @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.*
2020-07-22 20:02:49 +00:00
*/
2021-03-18 13:04:23 +00:00
@customElement('sl-card')
2021-03-09 00:14:32 +00:00
export default class SlCard extends LitElement {
static styles: CSSResultGroup = styles;
2020-07-22 20:02:49 +00:00
private readonly hasSlotController = new HasSlotController(this, 'footer', 'header', 'image');
2020-07-22 20:02:49 +00:00
render() {
2021-02-26 14:09:13 +00:00
return html`
2020-07-22 20:02:49 +00:00
<div
part="base"
2021-02-26 14:09:13 +00:00
class=${classMap({
2020-07-22 20:02:49 +00:00
card: true,
'card--has-footer': this.hasSlotController.test('footer'),
'card--has-image': this.hasSlotController.test('image'),
'card--has-header': this.hasSlotController.test('header')
2021-02-26 14:09:13 +00:00
})}
2020-07-22 20:02:49 +00:00
>
<div part="image" class="card__image">
<slot name="image"></slot>
2020-07-22 20:02:49 +00:00
</div>
<div part="header" class="card__header">
<slot name="header"></slot>
2020-07-22 20:02:49 +00:00
</div>
<div part="body" class="card__body">
2021-03-06 17:01:39 +00:00
<slot></slot>
2020-07-22 20:02:49 +00:00
</div>
<div part="footer" class="card__footer">
<slot name="footer"></slot>
2020-07-22 20:02:49 +00:00
</div>
</div>
2021-02-26 14:09:13 +00:00
`;
2020-07-22 20:02:49 +00:00
}
}
2021-03-12 14:09:08 +00:00
declare global {
interface HTMLElementTagNameMap {
'sl-card': SlCard;
}
}