File size: 1,952 Bytes
5d90d05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CustomToast extends HTMLElement {
    constructor() {
        super();
        this.attachShadow({ mode: 'open' });
        this.shadowRoot.innerHTML = `
            <style>
                :host {
                    position: fixed;
                    bottom: 1rem;
                    right: 1rem;
                    z-index: 1000;
                }
                .toast {
                    padding: 0.75rem 1.5rem;
                    border-radius: 0.5rem;
                    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
                    color: white;
                    display: flex;
                    align-items: center;
                    gap: 0.5rem;
                    transition: all 0.3s ease;
                    opacity: 0;
                    transform: translateY(20px);
                }
                .toast.visible {
                    opacity: 1;
                    transform: translateY(0);
                }
                .toast.info {
                    background-color: #8b5cf6;
                }
                .toast.success {
                    background-color: #10b981;
                }
                .toast.warning {
                    background-color: #f59e0b;
                }
                .toast.error {
                    background-color: #ef4444;
                }
            </style>
            <div class="toast">
                <slot></slot>
            </div>
        `;
    }

    show(message, type = 'info', duration = 3000) {
        const toast = this.shadowRoot.querySelector('.toast');
        toast.textContent = message;
        toast.className = 'toast ' + type;
        toast.classList.add('visible');
        
        setTimeout(() => {
            toast.classList.remove('visible');
            setTimeout(() => this.remove(), 300);
        }, duration);
    }
}

customElements.define('custom-toast', CustomToast);