class PopupElement extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: "open" });
const template = document.createElement("template");
template.innerHTML = /*html*/ `
`;
shadow.appendChild(template.content.cloneNode(true));
}
connectedCallback() {
const shadow = this.shadowRoot;
const id = this.getAttribute("data-id");
const header = this.getAttribute("data-header");
shadow.querySelector(".popup__backdrop").id = id || "";
shadow.querySelector(".popup__header_text").textContent = header || "";
const backdrop = shadow.querySelector(".popup__backdrop");
const closeIcon = shadow.querySelector(".popup__close");
closeIcon.addEventListener("click", () => {
backdrop.style.animation = "fadeOut 0.3s ease-in-out forwards";
setTimeout(() => {
backdrop.remove();
}, 300);
});
}
}
window.customElements.define("popup-element", PopupElement);