|
1 | | -import { Component, Input } from '@angular/core'; |
| 1 | +import { animate, keyframes, state, style, transition, trigger } from '@angular/animations'; |
| 2 | +import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; |
2 | 3 |
|
3 | 4 | @Component({ |
4 | 5 | selector: 'alert-success', |
5 | 6 | template: ` |
6 | | - <div class="p-4 rounded-md bg-green-50" [ngClass]="class"> |
7 | | - <div class="flex"> |
8 | | - <div class="shrink-0"> |
9 | | - <svg |
10 | | - class="w-5 h-5 text-green-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 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z" /> |
19 | | - </svg> |
20 | | - </div> |
21 | | - <div class="ml-3"> |
22 | | - <p class="text-sm font-medium text-green-800">{{ message }}</p> |
| 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-white 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 class="h-6 w-6 text-green-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"> |
| 15 | + <path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /> |
| 16 | + </svg> |
| 17 | + </div> |
| 18 | + <div class="ml-3 w-0 flex-1 pt-0.5"> |
| 19 | + <p class="text-sm font-medium text-gray-900">{{ message }}</p> |
| 20 | + <p class="mt-1 text-sm text-gray-500">{{ description }}</p> |
| 21 | + </div> |
| 22 | + <div class="ml-4 flex flex-shrink-0"> |
| 23 | + <button (click)="toggle()" type="button" class="inline-flex rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"> |
| 24 | + <span class="sr-only">Close</span> |
| 25 | + <svg class="h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> |
| 26 | + <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" /> |
| 27 | + </svg> |
| 28 | + </button> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + </div> |
23 | 32 | </div> |
| 33 | +
|
24 | 34 | </div> |
25 | 35 | </div> |
26 | 36 | `, |
| 37 | + animations: [ |
| 38 | + trigger('showHideNotification', [ |
| 39 | + transition('void => *', [ |
| 40 | + style({ transform: "translateX(0.5rem)", opacity: 0 }), |
| 41 | + animate(300, style({ transform: "translateX(0)", opacity: 1 })) |
| 42 | + ]), |
| 43 | + transition('* => void', [ |
| 44 | + style({ opacity: 0 }), |
| 45 | + animate(100, style({ opacity: 1 })) |
| 46 | + ]) |
| 47 | + ]), |
| 48 | + ], |
27 | 49 | }) |
28 | 50 | export class SuccessComponent { |
29 | 51 | @Input() class!: string; |
30 | 52 |
|
| 53 | + @Input('isOpen') showAlert!: boolean; |
| 54 | + |
| 55 | + @Output() toggleShowAlert: EventEmitter<boolean> = new EventEmitter<boolean>(); |
| 56 | + |
31 | 57 | @Input() message!: string; |
| 58 | + |
| 59 | + @Input() description!: string; |
| 60 | + |
| 61 | + toggle(){ |
| 62 | + this.toggleShowAlert.emit(false); |
| 63 | + } |
32 | 64 | } |
0 commit comments