import { Component, Element, State, h } from '@stencil/core'; import { hasSlot } from '../../utilities/slot'; /** * @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. */ @Component({ tag: 'sl-card', styleUrl: 'card.scss', shadow: true }) export class Card { @Element() host: HTMLSlCardElement; @State() hasFooter = false; @State() hasImage = false; @State() hasHeader = false; connectedCallback() { this.updateSlots = this.updateSlots.bind(this); } componentWillLoad() { this.updateSlots(); this.host.shadowRoot.addEventListener('slotchange', this.updateSlots); } disconnectedCallback() { this.host.shadowRoot.removeEventListener('slotchange', this.updateSlots); } updateSlots() { this.hasFooter = hasSlot(this.host, 'footer'); this.hasImage = hasSlot(this.host, 'image'); this.hasHeader = hasSlot(this.host, 'header'); } render() { return (
); } }