File size: 2,686 Bytes
cfdc9e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8ef119
 
 
 
 
 
 
 
d5a3452
a8ef119
 
cfdc9e3
 
 
 
 
 
 
 
d5a3452
cfdc9e3
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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);