// Mockup https://www.figma.com/design/zsq2ahat30acTnumyy9aqC/00.Small-System?node-id=504-31645&m=dev import { LitElement, css, html, nothing, unsafeCSS } from "lit"; import { customElement, property } from "lit/decorators.js"; import { classMap } from "lit/directives/class-map.js"; import { ifDefined } from "lit/directives/if-defined.js"; import TemsCardCatalogStyle from "@styles/cards/tems-card-catalog.scss?inline"; import "~icons/material-symbols/rss-feed-rounded"; import "~icons/ic/outline-place"; import "@components/buttons/tems-button"; export type TemsCardCatalogProps = { cardType?: string; isFullSize: boolean; logoOnTop: boolean; backgroundImg?: string; orgLogo?: string; address?: string; language?: string; date?: string; source?: string; header?: string; content?: string; badge?: string; tags: string[] | { name: string; type?: string }[]; }; @customElement("tems-card-catalog") export class TemsCardCatalog extends LitElement { static styles = css` ${unsafeCSS(TemsCardCatalogStyle)}; `; @property({ attribute: "type", type: String, reflect: true }) cardType: TemsCardCatalogProps["cardType"] = "vertical"; @property({ attribute: "address", type: String }) address: TemsCardCatalogProps["address"]; @property({ attribute: "language", type: String }) language: TemsCardCatalogProps["language"]; @property({ attribute: "date", type: String }) date: TemsCardCatalogProps["date"]; @property({ attribute: "source", type: String }) source: TemsCardCatalogProps["source"]; @property({ attribute: "background-img", type: String }) backgroundImg: TemsCardCatalogProps["backgroundImg"]; @property({ attribute: "org-logo", type: String }) orgLogo: TemsCardCatalogProps["orgLogo"]; @property({ attribute: "display-logo", type: Boolean }) logoOnTop: TemsCardCatalogProps["logoOnTop"] = false; @property({ attribute: "full-size", type: Boolean }) isFullSize: TemsCardCatalogProps["isFullSize"] = false; @property({ attribute: "header", type: String }) header: TemsCardCatalogProps["header"]; @property({ attribute: "content", type: String }) content: TemsCardCatalogProps["content"]; @property({ attribute: "badge", type: String }) badge: TemsCardCatalogProps["badge"]; @property({ attribute: false }) tags: TemsCardCatalogProps["tags"] = []; private _getType() { const allowedTypes = ["vertical", "horizontal", "bill-image"]; if (!allowedTypes.includes(String(this.cardType))) { this.cardType = "vertical"; } return { vertical: this.cardType === "vertical", horizontal: this.cardType === "horizontal", billImage: this.cardType === "bill-image", }; } private renderImageHeader() { if (this.isFullSize && (this.backgroundImg || this.badge)) { if (this.backgroundImg) { return html`
${this.badge ? html`` : nothing}
`; } return html`
${this.badge ? html`` : nothing}
`; } return nothing; } private renderLogo() { if (this.logoOnTop && this.orgLogo) { return html``; } return nothing; } private renderTags() { if (!this.tags || this.tags.length === 0) return nothing; return html`
${this.tags .filter((t) => typeof t === "string" || t.name) .map( (tag: string | { name: string; type?: string }) => html`` )}
`; } private renderContent() { if (this.header || this.content) { return html`
${this.header ? html`
` : nothing} ${this.content ? html`
` : nothing}
`; } return nothing; } private renderLangDate() { if (!this.date && !this.language) return nothing; const date = this.date ? html`${this.date}` : nothing; const language = this.language ? html`${this.language}` : nothing; return html`
${this.cardType === "bill-image" ? html`${language}${date}` : html`${date}${language}`}
`; } private renderSource() { if (!this.source) return nothing; return html``; } private renderAddressAndSource() { if (!this.address && !this.source) return nothing; if (this.cardType === "vertical" || this.cardType === "bill-image") { if (!this.address) return nothing; return html`
${this.address}
`; } return html`
${this.address ? html`
${this.address}
` : nothing} ${this.renderSource()}
${this.renderLangDate()}
`; } render() { const classes = { ...this._getType(), }; if (this.cardType === "horizontal") { return html`
${this.renderImageHeader()}
${this.renderLogo()} ${this.renderTags()} ${this.renderContent()} ${this.renderAddressAndSource()}
`; } if (this.cardType === "bill-image") { return html`
${this.renderImageHeader()}
${this.renderLogo()} ${this.renderTags()} ${this.renderSource()} ${this.renderContent()} ${this.renderAddressAndSource()} ${this.renderLangDate()}
`; } return html`
${this.renderImageHeader()}
${this.renderLogo()} ${this.renderLangDate()} ${this.renderContent()} ${this.renderAddressAndSource()} ${this.renderSource()} ${this.renderTags()}
`; } }