2022-08-17 15:37:37 +00:00
|
|
|
import { html } from 'lit';
|
2022-01-05 23:31:41 +00:00
|
|
|
import { customElement } from 'lit/decorators.js';
|
2021-09-29 12:40:26 +00:00
|
|
|
import { classMap } from 'lit/directives/class-map.js';
|
2022-08-17 15:37:37 +00:00
|
|
|
import ShoelaceElement from '../../internal/shoelace-element';
|
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';
|
2022-07-19 12:27:39 +00:00
|
|
|
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-05-17 22:04:28 +00:00
|
|
|
*
|
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')
|
2022-08-17 15:37:37 +00:00
|
|
|
export default class SlCard extends ShoelaceElement {
|
2022-07-19 12:27:39 +00:00
|
|
|
static styles: CSSResultGroup = styles;
|
2020-07-22 20:02:49 +00:00
|
|
|
|
2022-01-16 05:47:14 +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,
|
2022-01-05 23:31:41 +00:00
|
|
|
'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">
|
2022-01-05 23:31:41 +00:00
|
|
|
<slot name="image"></slot>
|
2020-07-22 20:02:49 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div part="header" class="card__header">
|
2022-01-05 23:31:41 +00:00
|
|
|
<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">
|
2022-01-05 23:31:41 +00:00
|
|
|
<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:07:38 +00:00
|
|
|
|
2021-03-12 14:09:08 +00:00
|
|
|
declare global {
|
|
|
|
interface HTMLElementTagNameMap {
|
|
|
|
'sl-card': SlCard;
|
|
|
|
}
|
|
|
|
}
|