{}) => { root.classList.add('modal'); root.innerHTML = ` ` /* event listener */ const $close = $('.close', root); const $modalOverlay = $('.modal-overlay', root); $modalOverlay.addEventListener('click', e => root.outerHTML = ``); if($close) $close.addEventListener('click', e => root.outerHTML = ``); func(); $('.root').appendChild(root); } export default Modal;"> {}) => { root.classList.add('modal'); root.innerHTML = ` ` /* event listener */ const $close = $('.close', root); const $modalOverlay = $('.modal-overlay', root); $modalOverlay.addEventListener('click', e => root.outerHTML = ``); if($close) $close.addEventListener('click', e => root.outerHTML = ``); func(); $('.root').appendChild(root); } export default Modal;"> {}) => { root.classList.add('modal'); root.innerHTML = ` ` /* event listener */ const $close = $('.close', root); const $modalOverlay = $('.modal-overlay', root); $modalOverlay.addEventListener('click', e => root.outerHTML = ``); if($close) $close.addEventListener('click', e => root.outerHTML = ``); func(); $('.root').appendChild(root); } export default Modal;">
import { $ } from "./util.js";

const Modal = (root, HTML, func=()=>{}) => {

    root.classList.add('modal');
    root.innerHTML = `
        <div class="modal-overlay"> </div>
        <div class="modal-content f-c"> 
            ${HTML}
        </div>
    `
    /* event listener */
    const $close = $('.close', root);
    const $modalOverlay = $('.modal-overlay', root);

    $modalOverlay.addEventListener('click', e => root.outerHTML = ``);
    if($close)  $close.addEventListener('click', e => root.outerHTML = ``);

    func();
    $('.root').appendChild(root);
}

export default Modal;
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.modal-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
}
.modal-content {
    position: relative;
    width: 300px;
    padding: 30px 50px 20px 50px;
    border-radius: 10px;
    background-color: white;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18), 0, 6px 6px rgba(0, 0, 0, 0.2);
}
.modal-content > * {
    width: 100%;
}
.hidden {
    display: none;
}