1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[CL-18] toast component and service (#6490)

Update toast styles and new service to CL.
This commit is contained in:
Will Martin
2024-04-18 13:23:35 -04:00
committed by GitHub
parent 9277465951
commit d5f503a0d6
32 changed files with 440 additions and 534 deletions

View File

@@ -0,0 +1,57 @@
import { Injectable } from "@angular/core";
import { IndividualConfig, ToastrService } from "ngx-toastr";
import type { ToastComponent } from "./toast.component";
import { calculateToastTimeout } from "./utils";
export type ToastOptions = {
/**
* The duration the toast will persist in milliseconds
**/
timeout?: number;
} & Pick<ToastComponent, "message" | "variant" | "title">;
/**
* Presents toast notifications
**/
@Injectable({ providedIn: "root" })
export class ToastService {
constructor(private toastrService: ToastrService) {}
showToast(options: ToastOptions) {
const toastrConfig: Partial<IndividualConfig> = {
payload: {
message: options.message,
variant: options.variant,
title: options.title,
},
timeOut:
options.timeout != null && options.timeout > 0
? options.timeout
: calculateToastTimeout(options.message),
};
this.toastrService.show(null, options.title, toastrConfig);
}
/**
* @deprecated use `showToast` instead
*
* Converts options object from PlatformUtilsService
**/
_showToast(options: {
type: "error" | "success" | "warning" | "info";
title: string;
text: string | string[];
options?: {
timeout?: number;
};
}) {
this.showToast({
message: options.text,
variant: options.type,
title: options.title,
timeout: options.options?.timeout,
});
}
}