bitwarden-estensione-browser/libs/angular/src/components/toastr.component.ts

96 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-12-16 13:36:21 +01:00
import { animate, state, style, transition, trigger } from "@angular/animations";
import { CommonModule } from "@angular/common";
import { Component, ModuleWithProviders, NgModule } from "@angular/core";
2021-12-07 19:15:56 +01:00
import {
2021-12-16 13:36:21 +01:00
DefaultNoComponentGlobalConfig,
GlobalConfig,
Toast as BaseToast,
ToastPackage,
ToastrService,
TOAST_CONFIG,
} from "ngx-toastr";
2021-12-07 19:15:56 +01:00
@Component({
2021-12-16 13:36:21 +01:00
selector: "[toast-component2]",
template: `
<button
*ngIf="options.closeButton"
(click)="remove()"
type="button"
class="toast-close-button"
aria-label="Close"
>
<span aria-hidden="true">&times;</span>
2021-12-07 19:15:56 +01:00
</button>
<div class="icon">
2021-12-16 13:36:21 +01:00
<i></i>
2021-12-07 19:15:56 +01:00
</div>
<div>
2021-12-16 13:36:21 +01:00
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
{{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
</div>
<div
*ngIf="message && options.enableHtml"
role="alertdialog"
aria-live="polite"
[class]="options.messageClass"
[innerHTML]="message"
></div>
<div
*ngIf="message && !options.enableHtml"
role="alertdialog"
aria-live="polite"
[class]="options.messageClass"
[attr.aria-label]="message"
>
{{ message }}
</div>
2021-12-07 19:15:56 +01:00
</div>
<div *ngIf="options.progressBar">
2021-12-16 13:36:21 +01:00
<div class="toast-progress" [style.width]="width + '%'"></div>
2021-12-07 19:15:56 +01:00
</div>
2021-12-16 13:36:21 +01:00
`,
animations: [
trigger("flyInOut", [
state("inactive", style({ opacity: 0 })),
state("active", style({ opacity: 1 })),
state("removed", style({ opacity: 0 })),
transition("inactive => active", animate("{{ easeTime }}ms {{ easing }}")),
transition("active => removed", animate("{{ easeTime }}ms {{ easing }}")),
]),
],
preserveWhitespaces: false,
2021-12-07 19:15:56 +01:00
})
export class BitwardenToast extends BaseToast {
2021-12-16 13:36:21 +01:00
constructor(protected toastrService: ToastrService, public toastPackage: ToastPackage) {
super(toastrService, toastPackage);
}
2021-12-07 19:15:56 +01:00
}
export const BitwardenToastGlobalConfig: GlobalConfig = {
2021-12-16 13:36:21 +01:00
...DefaultNoComponentGlobalConfig,
toastComponent: BitwardenToast,
};
2021-12-07 19:15:56 +01:00
@NgModule({
2021-12-16 13:36:21 +01:00
imports: [CommonModule],
declarations: [BitwardenToast],
exports: [BitwardenToast],
2021-12-07 19:15:56 +01:00
})
export class BitwardenToastModule {
2021-12-16 13:36:21 +01:00
static forRoot(config: Partial<GlobalConfig> = {}): ModuleWithProviders<BitwardenToastModule> {
return {
ngModule: BitwardenToastModule,
providers: [
{
provide: TOAST_CONFIG,
useValue: {
default: BitwardenToastGlobalConfig,
config: config,
},
},
],
};
}
2021-12-07 19:15:56 +01:00
}