From 41640210f42ace67a61b097232f9e165a9cb84eb Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Wed, 7 Mar 2018 12:09:22 +0100 Subject: [PATCH] Refactored notification animations --- src/app/shared/animations/fade.ts | 14 +- src/app/shared/animations/fromBottom.ts | 26 ++++ src/app/shared/animations/fromLeft.ts | 26 ++++ src/app/shared/animations/fromRight.ts | 26 ++++ src/app/shared/animations/fromTop.ts | 26 ++++ src/app/shared/animations/rotate.ts | 26 ++++ src/app/shared/animations/scale.ts | 26 ++++ .../models/notification-animations-type.ts | 16 +++ .../models/notification-options.model.ts | 6 +- .../notification/notification.component.html | 13 +- .../notification/notification.component.scss | 11 +- .../notification/notification.component.ts | 128 ++++-------------- .../notifications-board.component.html | 7 - .../notifications-board.component.ts | 30 ++-- 14 files changed, 232 insertions(+), 149 deletions(-) create mode 100644 src/app/shared/animations/fromBottom.ts create mode 100644 src/app/shared/animations/fromLeft.ts create mode 100644 src/app/shared/animations/fromRight.ts create mode 100644 src/app/shared/animations/fromTop.ts create mode 100644 src/app/shared/animations/rotate.ts create mode 100644 src/app/shared/animations/scale.ts create mode 100644 src/app/shared/notifications/models/notification-animations-type.ts diff --git a/src/app/shared/animations/fade.ts b/src/app/shared/animations/fade.ts index 09a0be66ba..187a482746 100644 --- a/src/app/shared/animations/fade.ts +++ b/src/app/shared/animations/fade.ts @@ -1,14 +1,24 @@ -import { animate, style, transition, trigger } from '@angular/animations'; +import { animate, state, style, transition, trigger } from '@angular/animations'; +export const fadeInState = state('fadeIn', style({opacity: 1})); +export const fadeInEnter = transition('* => fadeIn', [ + style({ opacity: 0 }), + animate(300, style({ opacity: 1 })) +]); const fadeEnter = transition(':enter', [ style({ opacity: 0 }), animate(300, style({ opacity: 1 })) ]); -const fadeLeave = transition(':leave', [ +export const fadeOutState = state('fadeOut', style({opacity: 0})); +export const fadeOutLeave = transition('fadeIn => fadeOut', [ style({ opacity: 1 }), animate(400, style({ opacity: 0 })) ]); +const fadeLeave = transition(':leave', [ + style({ opacity: 0 }), + animate(300, style({ opacity: 1 })) +]); export const fadeIn = trigger('fadeIn', [ fadeEnter diff --git a/src/app/shared/animations/fromBottom.ts b/src/app/shared/animations/fromBottom.ts new file mode 100644 index 0000000000..e2c6f44728 --- /dev/null +++ b/src/app/shared/animations/fromBottom.ts @@ -0,0 +1,26 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; + +export const fromBottomInState = state('fromBottomIn', style({opacity: 1, transform: 'translateY(0)'})); +export const fromBottomEnter = transition('* => fromBottomIn', [ + style({opacity: 0, transform: 'translateY(5%)'}), + animate('400ms ease-in-out') +]); + +export const fromBottomOutState = state('fromBottomOut', style({opacity: 0, transform: 'translateY(-5%)'})); +export const fromBottomLeave = transition('fromBottomIn => fromBottomOut', [ + style({opacity: 1, transform: 'translateY(0)'}), + animate('300ms ease-in-out') +]); + +export const fromBottomIn = trigger('fromBottomIn', [ + fromBottomEnter +]); + +export const fromBottomOut = trigger('fromBottomOut', [ + fromBottomLeave +]); + +export const fromBottomInOut = trigger('fromBottomInOut', [ + fromBottomEnter, + fromBottomLeave +]); diff --git a/src/app/shared/animations/fromLeft.ts b/src/app/shared/animations/fromLeft.ts new file mode 100644 index 0000000000..07fe5bcde5 --- /dev/null +++ b/src/app/shared/animations/fromLeft.ts @@ -0,0 +1,26 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; + +export const fromLeftInState = state('fromLeftIn', style({opacity: 1, transform: 'translateX(0)'})); +export const fromLeftEnter = transition('* => fromLeftIn', [ + style({opacity: 0, transform: 'translateX(-5%)'}), + animate('400ms ease-in-out') +]); + +export const fromLeftOutState = state('fromLeftOut', style({opacity: 0, transform: 'translateX(5%)'})); +export const fromLeftLeave = transition('fromLeftIn => fromLeftOut', [ + style({opacity: 1, transform: 'translateX(0)'}), + animate('300ms ease-in-out') +]); + +export const fromLeftIn = trigger('fromLeftIn', [ + fromLeftEnter +]); + +export const fromLeftOut = trigger('fromLeftOut', [ + fromLeftLeave +]); + +export const fromLeftInOut = trigger('fromLeftInOut', [ + fromLeftEnter, + fromLeftLeave +]); diff --git a/src/app/shared/animations/fromRight.ts b/src/app/shared/animations/fromRight.ts new file mode 100644 index 0000000000..10b36d12ec --- /dev/null +++ b/src/app/shared/animations/fromRight.ts @@ -0,0 +1,26 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; + +export const fromRightInState = state('fromRightIn', style({opacity: 1, transform: 'translateX(0)'})); +export const fromRightEnter = transition('* => fromRightIn', [ + style({opacity: 0, transform: 'translateX(5%)'}), + animate('400ms ease-in-out') +]); + +export const fromRightOutState = state('fromRightOut', style({opacity: 0, transform: 'translateX(-5%)'})); +export const fromRightLeave = transition('fromRightIn => fromRightOut', [ + style({opacity: 1, transform: 'translateX(0)'}), + animate('300ms ease-in-out') +]); + +export const fromRightIn = trigger('fromRightIn', [ + fromRightEnter +]); + +export const fromRightOut = trigger('fromRightOut', [ + fromRightLeave +]); + +export const fromRightInOut = trigger('fromRightInOut', [ + fromRightEnter, + fromRightLeave +]); diff --git a/src/app/shared/animations/fromTop.ts b/src/app/shared/animations/fromTop.ts new file mode 100644 index 0000000000..a33beed163 --- /dev/null +++ b/src/app/shared/animations/fromTop.ts @@ -0,0 +1,26 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; + +export const fromTopInState = state('fromTopIn', style({opacity: 1, transform: 'translateY(0)'})); +export const fromTopEnter = transition('* => fromTopIn', [ + style({opacity: 0, transform: 'translateY(-5%)'}), + animate('400ms ease-in-out') +]); + +export const fromTopOutState = state('fromTopOut', style({opacity: 0, transform: 'translateY(5%)'})); +export const fromTopLeave = transition('fromTopIn => fromTopOut', [ + style({opacity: 1, transform: 'translateY(0)'}), + animate('300ms ease-in-out') +]); + +export const fromTopIn = trigger('fromTopIn', [ + fromTopEnter +]); + +export const fromTopOut = trigger('fromTopOut', [ + fromTopLeave +]); + +export const fromTopInOut = trigger('fromTopInOut', [ + fromTopEnter, + fromTopLeave +]); diff --git a/src/app/shared/animations/rotate.ts b/src/app/shared/animations/rotate.ts new file mode 100644 index 0000000000..00f8b01452 --- /dev/null +++ b/src/app/shared/animations/rotate.ts @@ -0,0 +1,26 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; + +export const rotateInState = state('rotateIn', style({opacity: 1, transform: 'rotate(0deg)'})); +export const rotateEnter = transition('* => rotateIn', [ + style({opacity: 0, transform: 'rotate(5deg)'}), + animate('400ms ease-in-out') +]); + +export const rotateOutState = state('rotateOut', style({opacity: 0, transform: 'rotate(5deg)'})); +export const rotateLeave = transition('rotateIn => rotateOut', [ + style({opacity: 1, transform: 'rotate(0deg)'}), + animate('400ms ease-in-out') +]); + +export const rotateIn = trigger('rotateIn', [ + rotateEnter +]); + +export const rotateOut = trigger('rotateOut', [ + rotateLeave +]); + +export const rotateInOut = trigger('rotateInOut', [ + rotateEnter, + rotateLeave +]); diff --git a/src/app/shared/animations/scale.ts b/src/app/shared/animations/scale.ts new file mode 100644 index 0000000000..ca749ceeef --- /dev/null +++ b/src/app/shared/animations/scale.ts @@ -0,0 +1,26 @@ +import { animate, state, style, transition, trigger } from '@angular/animations'; + +export const scaleInState = state('scaleIn', style({opacity: 1, transform: 'scale(1)'})); +export const scaleEnter = transition('* => scaleIn', [ + style({opacity: 0, transform: 'scale(0)'}), + animate('400ms ease-in-out') +]); + +export const scaleOutState = state('scaleOut', style({opacity: 0, transform: 'scale(0)'})); +export const scaleLeave = transition('scaleIn => scaleOut', [ + style({opacity: 1, transform: 'scale(1)'}), + animate('400ms ease-in-out') +]); + +export const scaleIn = trigger('scaleIn', [ + scaleEnter +]); + +export const scaleOut = trigger('scaleOut', [ + scaleLeave +]); + +export const scaleInOut = trigger('scaleInOut', [ + scaleEnter, + scaleLeave +]); diff --git a/src/app/shared/notifications/models/notification-animations-type.ts b/src/app/shared/notifications/models/notification-animations-type.ts new file mode 100644 index 0000000000..6654dccfe3 --- /dev/null +++ b/src/app/shared/notifications/models/notification-animations-type.ts @@ -0,0 +1,16 @@ +// 'fade' | 'fromTop' | 'fromRight' | 'fromBottom' | 'fromLeft' | 'rotate' | 'scale' + +export enum NotificationAnimationsType { + Fade = 'fade', + FromTop = 'fromTop', + FromRight = 'fromRight', + FromBottom = 'fromBottom', + FromLeft = 'fromLeft', + Rotate = 'rotate', + Scale = 'scale' +} + +export enum NotificationAnimationsStatus { + In = 'In', + Out = 'Out' +} diff --git a/src/app/shared/notifications/models/notification-options.model.ts b/src/app/shared/notifications/models/notification-options.model.ts index b8357f5269..3520727ec3 100644 --- a/src/app/shared/notifications/models/notification-options.model.ts +++ b/src/app/shared/notifications/models/notification-options.model.ts @@ -1,8 +1,10 @@ +import { NotificationAnimationsType } from './notification-animations-type'; + export interface INotificationOptions { timeOut: number; clickToClose: boolean; rtl: boolean; - animate: 'fade' | 'fromTop' | 'fromRight' | 'fromBottom' | 'fromLeft' | 'rotate' | 'scale'; + animate: NotificationAnimationsType; position: ['top' | 'bottom' | 'middle', 'right' | 'left' | 'center']; } @@ -15,7 +17,7 @@ export class NotificationOptions implements INotificationOptions { constructor(timeOut = 0, clickToClose = true, - animate = 'scale', + animate = NotificationAnimationsType.Scale, position = ['top' , 'right'], rtl = false) { diff --git a/src/app/shared/notifications/notification/notification.component.html b/src/app/shared/notifications/notification/notification.component.html index 1d35b6f931..2de7045be5 100644 --- a/src/app/shared/notifications/notification/notification.component.html +++ b/src/app/shared/notifications/notification/notification.component.html @@ -1,8 +1,6 @@