aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/toast/toast.component.ts
blob: 6bbae34b60e8c3bbc4dd26d5da89c6cf45f98c22 (plain) (blame)
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
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {ToastType} from '../../services/toasts.service';

@Component({
  selector: 'app-toast',
  standalone: false,
  templateUrl: './toast.component.html',
  styleUrl: './toast.component.css'
})
export class ToastComponent implements OnInit{
    @Input() type!: ToastType
    @Input() message!: string
    @Input() action?: {label: string, onAction: () => void}

    @ViewChild("toastDiv") toastDiv!: ElementRef<HTMLDivElement>

    ngOnInit() {
        setTimeout(() => {
            this.hide();
        }, 3000)
    }

    hide() {
        this.toastDiv.nativeElement.classList.add('hide')
    }

    getColor() {
        switch (this.type) {
            case ToastType.ERROR: return "red";
            case ToastType.INFO: return "";
            case ToastType.WARNING: return "yellow";
        }
    }

    protected readonly ToastType = ToastType;
}