/** * Push Box Component * A promotional container with logo, title, and CTA * Uses slots for all content to allow easy customization in HTML * Supports variant="purple" for purple background with white content */ class PushBox extends HTMLElement { static get observedAttributes() { return ["background-color", "text-color", "variant"]; } constructor() { super(); this.attachShadow({ mode: "open" }); } connectedCallback() { this.render(); // Use requestAnimationFrame to ensure slots are assigned requestAnimationFrame(() => { this.updateLogoVisibility(); }); } attributeChangedCallback() { this.render(); requestAnimationFrame(() => { this.updateLogoVisibility(); }); } updateLogoVisibility() { const logoSlot = this.shadowRoot?.querySelector('slot[name="logo"]'); const logoWrapper = this.shadowRoot?.querySelector(".logo-wrapper"); if (logoSlot && logoWrapper) { const assignedNodes = logoSlot.assignedNodes(); const hasContent = assignedNodes.length > 0 && assignedNodes.some((node) => { return node.nodeType === Node.ELEMENT_NODE && node.tagName === "IMG"; }); if (!hasContent) { logoWrapper.classList.add("hidden"); } else { logoWrapper.classList.remove("hidden"); } } } get variant() { return this.getAttribute("variant") || "default"; } get isPurple() { return this.variant === "purple"; } get backgroundColor() { if (this.isPurple) { return "#951D51"; } return ( this.getAttribute("background-color") || "var(--color-push-box-bg, #EBEEF4)" ); } get textColor() { if (this.isPurple) { return "#FFFFFF"; } return this.getAttribute("text-color") || "#951D51"; } get titleColor() { if (this.isPurple) { return "#FFFFFF"; } return "#000000"; } render() { this.shadowRoot.innerHTML = `
`; } } customElements.define("push-box", PushBox);