bigpappic's picture
Let's deploy this
1f36718 verified
raw
history blame
2.27 kB
class AuthModal extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
display: none;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background: white;
padding: 2rem;
border-radius: 0.5rem;
width: 100%;
max-width: 400px;
}
.close-btn {
float: right;
cursor: pointer;
}
form {
display: flex;
flex-direction: column;
gap: 1rem;
}
input {
padding: 0.5rem;
border: 1px solid #ccc;
border-radius: 0.25rem;
}
button {
padding: 0.5rem;
background: #4299e1;
color: white;
border: none;
border-radius: 0.25rem;
cursor: pointer;
}
</style>
<div class="modal" id="authModal">
<div class="modal-content">
<span class="close-btn" id="closeModal">&times;</span>
<h2>Sign In</h2>
<form id="authForm">
<input type="email" placeholder="Email" required>
<input type="password" placeholder="Password" required>
<button type="submit">Sign In</button>
</form>
</div>
</div>
`;
const modal = this.shadowRoot.getElementById('authModal');
const closeBtn = this.shadowRoot.getElementById('closeModal');
const authForm = this.shadowRoot.getElementById('authForm');
// Show modal when auth is required
document.addEventListener('auth-required', () => {
modal.style.display = 'flex';
});
closeBtn.addEventListener('click', () => {
modal.style.display = 'none';
});
authForm.addEventListener('submit', (e) => {
e.preventDefault();
// Handle auth logic here
modal.style.display = 'none';
document.dispatchEvent(new CustomEvent('auth-success'));
});
}
}
customElements.define('auth-modal', AuthModal);