/**
* CTA Button Component
* Full-width purple button with white underlined text
*/
class CtaButton extends HTMLElement {
static get observedAttributes() {
return ["href"];
}
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
this.render();
}
attributeChangedCallback() {
this.render();
}
get href() {
return this.getAttribute("href") || "#";
}
render() {
const isLink = this.hasAttribute("href");
const tag = isLink ? "a" : "button";
const hrefAttr = isLink ? `href="${this.href}"` : "";
this.shadowRoot.innerHTML = `
<${tag} class="cta-button" ${hrefAttr} type="${isLink ? "" : "button"}">
${tag}>
`;
}
}
customElements.define("cta-button", CtaButton);