|
1 | | -import { Component, Input } from '@angular/core'; |
| 1 | +import { animate, style, transition, trigger } from '@angular/animations'; |
| 2 | +import { Component, EventEmitter, Input, Output } from '@angular/core'; |
2 | 3 |
|
3 | 4 | @Component({ |
4 | 5 | selector: 'alert-errors', |
5 | 6 | template: ` |
6 | | - <div class="p-4 rounded-md bg-red-50" [ngClass]="class"> |
7 | | - <div class="flex"> |
8 | | - <div class="shrink-0"> |
9 | | - <svg |
10 | | - class="w-5 h-5 text-red-400" |
11 | | - xmlns="http://www.w3.org/2000/svg" |
12 | | - viewBox="0 0 20 20" |
13 | | - fill="currentColor" |
14 | | - aria-hidden="true"> |
15 | | - <path |
16 | | - fill-rule="evenodd" |
17 | | - clip-rule="evenodd" |
18 | | - d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM8.28 7.22a.75.75 0 0 0-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 1 0 1.06 1.06L10 11.06l1.72 1.72a.75.75 0 1 0 1.06-1.06L11.06 10l1.72-1.72a.75.75 0 0 0-1.06-1.06L10 8.94 8.28 7.22Z" /> |
19 | | - </svg> |
20 | | - </div> |
21 | | - <div class="ml-3"> |
22 | | - <h3 *ngIf="message" class="text-sm font-medium text-red-800"> |
23 | | - {{ message }} |
24 | | - </h3> |
25 | | - <div *ngIf="errors.length" class="mt-2 text-sm text-red-700"> |
26 | | - <ul role="list" class="pl-5 space-y-1 list-disc"> |
27 | | - <li *ngFor="let error of errors">{{ error }}</li> |
28 | | - </ul> |
| 7 | + <div *ngIf="showAlert" aria-live="assertive" class="pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:items-start sm:p-6"> |
| 8 | + <div class="flex w-full flex-col items-center space-y-4 sm:items-end"> |
| 9 | +
|
| 10 | + <div @showHideNotification class="pointer-events-auto w-full max-w-sm overflow-hidden rounded-lg bg-red-50 shadow-lg ring-1 ring-black ring-opacity-5" [ngClass]="class"> |
| 11 | + <div class="p-4"> |
| 12 | + <div class="flex items-start"> |
| 13 | + <div class="flex-shrink-0"> |
| 14 | + <svg |
| 15 | + class="w-5 h-5 text-red-400" |
| 16 | + xmlns="http://www.w3.org/2000/svg" |
| 17 | + viewBox="0 0 20 20" |
| 18 | + fill="currentColor" |
| 19 | + aria-hidden="true"> |
| 20 | + <path |
| 21 | + fill-rule="evenodd" |
| 22 | + clip-rule="evenodd" |
| 23 | + d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM8.28 7.22a.75.75 0 0 0-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 1 0 1.06 1.06L10 11.06l1.72 1.72a.75.75 0 1 0 1.06-1.06L11.06 10l1.72-1.72a.75.75 0 0 0-1.06-1.06L10 8.94 8.28 7.22Z" /> |
| 24 | + </svg> |
| 25 | + </div> |
| 26 | + <div class="ml-3 w-0 flex-1 pt-0.5"> |
| 27 | + <h3 class="text-sm font-medium text-red-800">{{ message }}</h3> |
| 28 | + <div *ngIf="errors.length" class="mt-2 text-sm text-red-700"> |
| 29 | + <ul role="list" class="pl-5 space-y-1 list-disc"> |
| 30 | + <li *ngFor="let error of errors">{{ error }}</li> |
| 31 | + </ul> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + <div class="ml-4 flex flex-shrink-0"> |
| 35 | + <button (click)="toggle()" type="button" class="inline-flex rounded-md bg-red-50 text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2"> |
| 36 | + <span class="sr-only">Close</span> |
| 37 | + <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> |
| 38 | + <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" /> |
| 39 | + </svg> |
| 40 | + </button> |
| 41 | + </div> |
| 42 | + </div> |
29 | 43 | </div> |
30 | 44 | </div> |
| 45 | +
|
31 | 46 | </div> |
32 | 47 | </div> |
33 | 48 | `, |
| 49 | + animations: [ |
| 50 | + trigger('showHideNotification', [ |
| 51 | + transition('void => *', [ |
| 52 | + style({ transform: "translateX(0.5rem)", opacity: 0 }), |
| 53 | + animate(300, style({ transform: "translateX(0)", opacity: 1 })) |
| 54 | + ]), |
| 55 | + transition('* => void', [ |
| 56 | + animate(100, style({ opacity: 0 })) |
| 57 | + ]) |
| 58 | + ]), |
| 59 | + ], |
34 | 60 | }) |
35 | 61 | export class ErrorComponent { |
36 | 62 | @Input() class!: string; |
| 63 | + |
| 64 | + @Input('isOpen') showAlert!: boolean; |
| 65 | + |
37 | 66 | @Input() message!: string; |
| 67 | + |
| 68 | + @Output() toggleShowAlert: EventEmitter<boolean> = new EventEmitter<boolean>(); |
| 69 | + |
| 70 | + toggle(){ |
| 71 | + setTimeout(() => { |
| 72 | + this.toggleShowAlert.emit(false); |
| 73 | + }, 100); |
| 74 | + } |
38 | 75 | @Input() errors: string[] = []; |
39 | 76 | } |
0 commit comments