2021-03-24 14:21:21 +00:00
|
|
|
import { LitElement, html, unsafeCSS } from 'lit';
|
|
|
|
import { customElement, state } from 'lit/decorators';
|
2021-03-06 17:01:39 +00:00
|
|
|
import { classMap } from 'lit-html/directives/class-map';
|
2021-02-26 14:09:13 +00:00
|
|
|
import { hasSlot } from '../../internal/slot';
|
2021-05-03 19:08:17 +00:00
|
|
|
import styles from 'sass:./card.scss';
|
2020-07-22 20:02:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @part base - The component's base wrapper.
|
|
|
|
* @part image - The card's image, if present.
|
|
|
|
* @part header - The card's header, if present.
|
|
|
|
* @part body - The card's body.
|
|
|
|
* @part footer - The card's footer, if present.
|
|
|
|
*/
|
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 {
|
2021-03-06 17:01:39 +00:00
|
|
|
static styles = unsafeCSS(styles);
|
2020-07-22 20:02:49 +00:00
|
|
|
|
2021-03-24 14:21:21 +00:00
|
|
|
@state() private hasFooter = false;
|
|
|
|
@state() private hasImage = false;
|
|
|
|
@state() private hasHeader = false;
|
2020-07-22 20:02:49 +00:00
|
|
|
|
2021-03-06 17:01:39 +00:00
|
|
|
connectedCallback() {
|
|
|
|
super.connectedCallback();
|
2020-12-22 22:08:19 +00:00
|
|
|
this.handleSlotChange();
|
|
|
|
}
|
|
|
|
|
2020-10-15 20:35:11 +00:00
|
|
|
handleSlotChange() {
|
2021-02-26 14:09:13 +00:00
|
|
|
this.hasFooter = hasSlot(this, 'footer');
|
|
|
|
this.hasImage = hasSlot(this, 'image');
|
|
|
|
this.hasHeader = hasSlot(this, 'header');
|
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.hasFooter,
|
|
|
|
'card--has-image': this.hasImage,
|
|
|
|
'card--has-header': this.hasHeader
|
2021-02-26 14:09:13 +00:00
|
|
|
})}
|
2020-07-22 20:02:49 +00:00
|
|
|
>
|
|
|
|
<div part="image" class="card__image">
|
2021-03-06 17:01:39 +00:00
|
|
|
<slot name="image" onslotchange=${this.handleSlotChange}></slot>
|
2020-07-22 20:02:49 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div part="header" class="card__header">
|
2021-03-06 17:01:39 +00:00
|
|
|
<slot name="header" onslotchange=${this.handleSlotChange}></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">
|
2021-03-06 17:01:39 +00:00
|
|
|
<slot name="footer" onslotchange=${this.handleSlotChange}></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;
|
|
|
|
}
|
|
|
|
}
|