* // Individual module import
* import { ToastNotificationModule } from 'patternfly-ng/notification';
* // Or
* import { ToastNotificationModule } from 'patternfly-ng';
*
* // NGX Bootstrap
* import { BsDropdownConfig, BsDropdownModule } from 'ngx-bootstrap/dropdown';
*
* @NgModule({
* imports: [ToastNotificationModule, BsDropdownModule.forRoot(),...],
* providers: [BsDropdownConfig]
* })
* export class AppModule(){}
*
*
* Optional:
*
* import { Notification, NotificationEvent, NotificationType } from 'patternfly-ng/notification';
*
*/
@Component({
encapsulation: ViewEncapsulation.None,
selector: 'pfng-toast-notification',
templateUrl: './toast-notification.component.html'
})
export class ToastNotificationComponent implements DoCheck, OnInit {
/**
* The notification header
*/
@Input() header: string;
/**
* The notification message
*/
@Input() message: string;
/**
* The notification kebab actions
*/
@Input() moreActions: Action[];
/**
* An object containing notifications properties
*/
@Input() notification: Notification;
/**
* The primary action
*/
@Input() primaryAction: Action;
/**
* Set to true to show close button
*/
@Input() showClose: boolean;
/**
* The notification type (e.g., NotificationType.SUCCESS, NotificationType.INFO, etc.)
*/
@Input() type: string;
/**
* The event emitted when an action has been selected
*/
@Output('onActionSelect') onActionSelect = new EventEmitter();
/**
* The event emitted when the close button has been selected
*/
@Output('onCloseSelect') onCloseSelect = new EventEmitter();
/**
* The event emitted when the mouse hovers over and leaves a notification
*/
@Output('onViewingChange') onViewingChange = new EventEmitter();
private _showCloseButton: boolean = false;
/**
* The default constructor
*/
constructor() {
}
// Initialization
/**
* Setup component configuration upon initialization
*/
ngOnInit(): void {
}
/**
* Check if the component config has changed
*/
ngDoCheck(): void {
this._showCloseButton = (this.showClose === true)
&& (this.moreActions === undefined || this.moreActions === null || this.moreActions.length === 0);
}
// Accessors
/**
* Get the flag indicating that the close button should be shown
*
* @returns {FilterField} The flag indicating that the close button should be shown
*/
get showCloseButton(): boolean {
return this._showCloseButton;
}
// Actions
handleEnter($event: MouseEvent): void {
this.onViewingChange.emit({
notification: this.notification,
isViewing: true
} as NotificationEvent);
}
handleLeave($event: MouseEvent): void {
this.onViewingChange.emit({
notification: this.notification,
isViewing: false
} as NotificationEvent);
}
// Private
private handleAction(action: Action): void {
if (action && action.disabled !== true) {
this.onActionSelect.emit({
action: action,
notification: this.notification
} as NotificationEvent);
}
}
private handleClose($event: MouseEvent): void {
this.onCloseSelect.emit({ notification: this.notification } as NotificationEvent);
}
}