Browse Source

feat(theme-shared): add toast-container component

related issue: #2537
pull/2606/head
TheDiaval 7 years ago
parent
commit
78e4429bcc
  1. 11
      npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.html
  2. 12
      npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.scss
  3. 46
      npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts

11
npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.html

@ -0,0 +1,11 @@
<div
class="toast-container"
[style.top]="top || 'auto'"
[style.right]="right || 'auto'"
[style.bottom]="bottom || 'auto'"
[style.left]="left || 'auto'"
[style.display]="toasts.length ? 'flex' : 'none'"
[@toastInOut]="toasts.length - 1 || 0"
>
<abp-toast [toast]="toast" *ngFor="let toast of toasts; trackBy: trackByFunc"></abp-toast>
</div>

12
npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.scss

@ -0,0 +1,12 @@
.toast-container {
position: fixed;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
min-width: 350px;
min-height: 80px;
&.new-on-top {
flex-direction: column-reverse;
}
}

46
npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts

@ -0,0 +1,46 @@
import { Component, Input, OnInit } from '@angular/core';
import { Toaster } from '../../models';
import { toastInOut } from '../../animations';
import { ToasterService } from '../../services/toaster.service';
@Component({
selector: 'abp-toast-container',
templateUrl: './toast-container.component.html',
styleUrls: ['./toast-container.component.scss'],
animations: [toastInOut],
})
export class ToastContainerComponent implements OnInit {
toasts = [] as Toaster.Toast[];
@Input()
top: number;
@Input()
right: number;
@Input()
bottom: number;
@Input()
left: number;
@Input()
toastKey: string;
constructor(private toastService: ToasterService) {}
ngOnInit() {
this.toastService.toasts$.subscribe(toasts => {
this.toasts = this.toastKey
? toasts.filter(t => {
return t.options && t.options.containerKey !== this.toastKey;
})
: toasts;
});
}
trackByFunc(index, toast) {
if (!toast) return null;
return toast.options.id;
}
}
Loading…
Cancel
Save