Files
shopit-front/src/app/shared/components/toast-container/toast-container.component.ts

39 lines
1.2 KiB
TypeScript

import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { NgClass } from '@angular/common';
import { ToastService, Toast } from '../../../core/services/toast.service';
@Component({
selector: 'app-toast-container',
imports: [NgClass],
templateUrl: './toast-container.component.html',
styleUrl: './toast-container.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ToastContainerComponent {
private readonly toastService = inject(ToastService);
readonly toasts = this.toastService.toasts;
dismiss(id: string): void {
this.toastService.dismiss(id);
}
getToastIconClass(type: Toast['type']): string {
const icons: Record<Toast['type'], string> = {
success: 'fa-solid fa-circle-check',
danger: 'fa-solid fa-circle-exclamation',
info: 'fa-solid fa-circle-info'
};
return icons[type] || 'fa-solid fa-bell';
}
getToastBgClass(type: Toast['type']): string {
const classes: Record<Toast['type'], string> = {
success: 'text-bg-success',
danger: 'text-bg-danger',
info: 'text-bg-primary'
};
return classes[type] || 'text-bg-primary';
}
}