vlcsolutions's picture
Alert Messages :Download Fact Sheet : fail email means give me : Could not send an email! Please try again later, success_email means give me meeage : We have sent you an email. Please check your inbox. If you cannot view it in your primary inbox, please check your Spam or Junk folder.
a8ef119 verified
class NotificationComponent extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
position: fixed;
top: 1rem;
right: 1rem;
max-width: 24rem;
width: 90%;
padding: 1rem;
border-radius: 0.5rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 9999;
display: flex;
align-items: center;
opacity: 0;
transform: translateY(-20px);
transition: opacity 0.3s ease, transform 0.3s ease;
}
:host(.show) {
opacity: 1;
transform: translateY(0);
}
:host(.success) {
background-color: #f0fdf4;
border-left: 4px solid #10b981;
color: #065f46;
}
:host(.error) {
background-color: #fef2f2;
border-left: 4px solid #ef4444;
color: #991b1b;
}
.icon {
margin-right: 0.75rem;
flex-shrink: 0;
}
.content {
flex-grow: 1;
}
.close-btn {
margin-left: 0.75rem;
cursor: pointer;
background: none;
border: none;
padding: 0;
color: inherit;
}
</style>
<div class="icon">
<i data-feather="check-circle"></i>
</div>
<div class="content">
<slot></slot>
</div>
<button class="close-btn" aria-label="Close notification">
<i data-feather="x"></i>
</button>
`;
}
connectedCallback() {
this.closeBtn = this.shadowRoot.querySelector('.close-btn');
this.closeBtn.addEventListener('click', () => this.hide());
}
show(type, message, duration = 5000) {
this.setAttribute('class', type);
// Custom messages for email notifications
if (type === 'error') {
message = 'Could not send an email! Please try again later.';
} else if (type === 'success') {
message = 'We have sent you an email. Please check your inbox. If you cannot view it in your primary inbox, please check your Spam or Junk folder.';
}
this.innerHTML = message;
const icon = this.shadowRoot.querySelector('.icon i');
icon.setAttribute('data-feather', type === 'success' ? 'check-circle' : 'alert-triangle');
this.classList.add('show');
if (duration > 0) {
setTimeout(() => this.hide(), duration);
}
}
hide() {
this.classList.remove('show');
setTimeout(() => this.remove(), 300);
}
}
customElements.define('notification-component', NotificationComponent);