/** * Push Box Component * A promotional container with logo, title, and CTA * Uses slots for all content to allow easy customization in HTML */ class PushBox extends HTMLElement { static get observedAttributes() { return ["background-color", "text-color"]; } 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 backgroundColor() { return ( this.getAttribute("background-color") || "var(--color-push-box-bg, #EBEEF4)" ); } get textColor() { return this.getAttribute("text-color") || "#951D51"; } render() { this.shadowRoot.innerHTML = `
`; } } customElements.define("push-box", PushBox);