Files
milinda-pitch/js/components/category-card.js
2026-01-16 08:20:19 +01:00

107 lines
2.5 KiB
JavaScript

/**
* Category Card Component
* Displays a category with an icon and title
* Icon is centered above the category text
*/
class CategoryCard extends HTMLElement {
static get observedAttributes() {
return ["title", "href", "icon"];
}
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
this.render();
}
attributeChangedCallback() {
if (this.shadowRoot) {
this.render();
}
}
get title() {
return this.getAttribute("title") || "Category";
}
get href() {
return this.getAttribute("href") || "#";
}
get icon() {
return this.getAttribute("icon") || "";
}
render() {
const iconHtml = this.icon
? `<img src="${this.icon}" alt="${this.title}" class="category-icon">`
: `<div class="category-icon placeholder">
<clipboard-icon size="32"></clipboard-icon>
</div>`;
this.shadowRoot.innerHTML = `
<style>
:host {
display: flex;
}
.card {
display: flex;
flex-direction: column;
align-items: center;
flex: 1;
color: inherit;
padding: var(--spacing-md, 0.875rem) var(--spacing-xs, 0.25rem);
text-decoration: none;
transition: transform var(--transition-fast, 150ms ease);
background-color: #F5F4FC;
}
.card:hover {
transform: translateY(-2px);
}
.card:active {
transform: translateY(0);
}
.category-icon {
width: 64px;
height: 64px;
object-fit: contain;
display: block;
}
.category-icon.placeholder {
display: flex;
align-items: center;
justify-content: center;
background-color: var(--color-background-tertiary, #f1f5f9);
border-radius: var(--radius-md, 0.5rem);
color: var(--color-text-light, #64748b);
opacity: 0.5;
}
.category-title {
font-family: var(--font-family-outfit, "Outfit", sans-serif);
font-size: var(--font-size-sm, 0.875rem); /* 14px */
font-weight: var(--font-weight-light, 300);
line-height: var(--line-height-24, 24px);
color: var(--color-text, #1e293b);
text-align: center;
margin: 0;
}
</style>
<a href="${this.href}" class="card">
${iconHtml}
<p class="category-title">${this.title}</p>
</a>
`;
}
}
customElements.define("category-card", CategoryCard);