1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-06 18:43:25 +00:00
Files
browser/libs/components/src/toast/toast.service.ts
Will Martin 827c4c0301 [PM-15847] libs/components strict migration (#15738)
This PR migrates `libs/components` to use strict TypeScript.

- Remove `@ts-strict-ignore` from each file in `libs/components` and resolved any new compilation errors
- Converted ViewChild and ContentChild decorators to use the new signal-based queries using the [Angular signal queries migration](https://angular.dev/reference/migrations/signal-queries)
  - Made view/content children `required` where appropriate, eliminating the need for additional null checking. This helped simplify the strict migration.

---

Co-authored-by: Vicki League <vleague@bitwarden.com>
2025-08-18 15:36:45 -04:00

61 lines
1.5 KiB
TypeScript

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;
message: ReturnType<ToastComponent["message"]>;
variant?: ReturnType<ToastComponent["variant"]>;
title?: ReturnType<ToastComponent["title"]>;
};
/**
* Presents toast notifications
**/
@Injectable({ providedIn: "root" })
export class ToastService {
constructor(private toastrService: ToastrService) {}
showToast(options: ToastOptions): void {
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(undefined, 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,
});
}
}