Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | 1x 42x 42x 42x 39x 23x 46x 46x 46x 23x 23x 8x 3x 8x 8x 8x 5x 5x 9x 8x 7x | import { Component, OnInit, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NotificationService, Notification } from '../services/notification.service';
import { Subscription } from 'rxjs';
@Component({
selector: 'app-notification',
standalone: true,
imports: [CommonModule],
template: `
<div class="notification-container">
<div
*ngFor="let notification of notifications"
[class]="'notification notification-' + notification.type"
>
<div class="notification-content">
<div class="notification-icon">
<span *ngIf="notification.type === 'success'">✅</span>
<span *ngIf="notification.type === 'error'">❌</span>
<span *ngIf="notification.type === 'info'">ℹ️</span>
<span *ngIf="notification.type === 'warning'">⚠️</span>
</div>
<div class="notification-text">
<div class="notification-title" *ngIf="notification.title">
{{ notification.title }}
</div>
<div class="notification-message">{{ notification.message }}</div>
</div>
<button
class="notification-close"
(click)="removeNotification(notification.id)"
aria-label="Fermer"
>
×
</button>
</div>
</div>
</div>
`,
styles: [`
.notification-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 10000;
display: flex;
flex-direction: column;
gap: 12px;
max-width: 400px;
pointer-events: none;
}
.notification {
background: white;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
padding: 16px 20px;
display: flex;
align-items: flex-start;
gap: 12px;
pointer-events: auto;
animation: slideIn 0.3s ease-out;
border-left: 4px solid;
transition: transform 0.3s ease-out, opacity 0.3s ease-out;
}
.notification:hover {
transform: translateX(-4px);
}
.notification-success {
border-left-color: #4CAF50;
background: linear-gradient(to right, #E8F5E9 0%, #ffffff 10%);
}
.notification-error {
border-left-color: #F44336;
background: linear-gradient(to right, #FFEBEE 0%, #ffffff 10%);
}
.notification-info {
border-left-color: #2196F3;
background: linear-gradient(to right, #E3F2FD 0%, #ffffff 10%);
}
.notification-warning {
border-left-color: #FF9800;
background: linear-gradient(to right, #FFF3E0 0%, #ffffff 10%);
}
.notification-content {
display: flex;
align-items: flex-start;
gap: 12px;
flex: 1;
}
.notification-icon {
font-size: 24px;
line-height: 1;
flex-shrink: 0;
}
.notification-text {
flex: 1;
min-width: 0;
}
.notification-title {
font-weight: 600;
font-size: 14px;
color: #333;
margin-bottom: 4px;
}
.notification-message {
font-size: 14px;
color: #666;
line-height: 1.5;
word-wrap: break-word;
}
.notification-close {
background: none;
border: none;
font-size: 24px;
color: #999;
cursor: pointer;
padding: 0;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
transition: color 0.2s;
line-height: 1;
}
.notification-close:hover {
color: #333;
}
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(100%);
opacity: 0;
}
}
.notification.removing {
animation: slideOut 0.3s ease-out forwards;
}
/* Responsive */
@media (max-width: 768px) {
.notification-container {
top: 10px;
right: 10px;
left: 10px;
max-width: none;
}
.notification {
padding: 12px 16px;
}
}
`],
animations: []
})
export class NotificationComponent implements OnInit, OnDestroy {
notifications: Notification[] = [];
private subscription?: Subscription;
private timers: Map<number, any> = new Map();
constructor(private notificationService: NotificationService) {}
ngOnInit(): void {
this.subscription = this.notificationService.getNotifications().subscribe(
(notification) => {
this.addNotification(notification);
}
);
}
ngOnDestroy(): void {
this.subscription?.unsubscribe();
this.timers.forEach(timer => clearTimeout(timer));
this.timers.clear();
}
private addNotification(notification: Notification): void {
this.notifications.push(notification);
// Auto-remove après la durée spécifiée (si duration > 0)
if (notification.duration && notification.duration > 0) {
const timer = setTimeout(() => {
this.removeNotification(notification.id);
}, notification.duration);
this.timers.set(notification.id, timer);
}
}
removeNotification(id: number): void {
const timer = this.timers.get(id);
if (timer) {
clearTimeout(timer);
this.timers.delete(id);
}
const index = this.notifications.findIndex(n => n.id === id);
if (index !== -1) {
this.notifications.splice(index, 1);
}
}
}
|