-
Notifications
You must be signed in to change notification settings - Fork 3
SED-3222 add custom toast #910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
projects/step-core/src/lib/components/toast-container/toast-container.component.html
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,5 @@ | |||
| <div class="toast-container"> | |||
| @for (toast of toasts; track toast) { | |||
| <step-toast [message]="toast.message" [actions]="toast.actions" [duration]="toast.duration"> </step-toast> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <step-toast [message]="toast.message" [actions]="toast.actions" [duration]="toast.duration"> </step-toast> | |
| <step-toast [message]="toast.message" [actions]="toast.actions" [duration]="toast.duration"/> |
| private toastSubject = new Subject<{ message: string; actions?: NotificationAction[]; duration?: number }[]>(); | ||
| toastMessages = this.toastSubject.asObservable(); | ||
| private toasts: { message: string; actions: NotificationAction[]; duration: number }[] = []; | ||
|
|
||
| showToast(message: string, actions?: NotificationAction[], duration?: number): void { | ||
| this.toasts.push({ message, actions: actions || [], duration: duration || 3000 }); | ||
| this.toastSubject.next(this.toasts); | ||
| } | ||
|
|
||
| removeToast(message: string): void { | ||
| this.toasts = this.toasts.filter((toast) => toast.message !== message); | ||
| this.toastSubject.next(this.toasts); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the usage of signals could simplify this code
| private toastSubject = new Subject<{ message: string; actions?: NotificationAction[]; duration?: number }[]>(); | |
| toastMessages = this.toastSubject.asObservable(); | |
| private toasts: { message: string; actions: NotificationAction[]; duration: number }[] = []; | |
| showToast(message: string, actions?: NotificationAction[], duration?: number): void { | |
| this.toasts.push({ message, actions: actions || [], duration: duration || 3000 }); | |
| this.toastSubject.next(this.toasts); | |
| } | |
| removeToast(message: string): void { | |
| this.toasts = this.toasts.filter((toast) => toast.message !== message); | |
| this.toastSubject.next(this.toasts); | |
| } | |
| private toastsInternal = signal<{ message: string; actions?: NotificationAction[]; duration?: number }[]>([]); | |
| readonly toastMessages = this.toastsInternal.asReadonly(); | |
| showToast(message: string, actions: NotificationAction[] = [], duration: number = 3000): void { | |
| this.toastsInternal.update((toasts) => toasts.concat({message, actions, duration})) ; | |
| } | |
| removeToast(message: string): void { | |
| this.toastsInternal.update((toasts) => toasts.filter((toast) => toast.message !== message)); | |
| } |
| toasts: { message: string; actions?: NotificationAction[]; duration?: number }[] = []; | ||
|
|
||
| constructor(private toastService: ToastService) {} | ||
|
|
||
| ngOnInit(): void { | ||
| this.toastService.toastMessages.subscribe((toasts) => { | ||
| this.toasts = toasts; | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, check the comment below in ToastService. With signal usage the code of current component could look like this
| toasts: { message: string; actions?: NotificationAction[]; duration?: number }[] = []; | |
| constructor(private toastService: ToastService) {} | |
| ngOnInit(): void { | |
| this.toastService.toastMessages.subscribe((toasts) => { | |
| this.toasts = toasts; | |
| }); | |
| } | |
| protected readonly _toasts = inject(ToastService).toastMessages; |
| @@ -0,0 +1,14 @@ | |||
| @if (message) { | |||
| <div class="toast"> | |||
| <span class="success-icon">✓</span> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@neogucky @lukasz-lepa
Shouldn't we use feather-icons here instead of unicode symbols?
projects/step-core/src/lib/components/toast/toast.component.html
Outdated
Show resolved
Hide resolved
…ntainer.component.html Co-authored-by: Vladimir <dragonvladir@gmail.com>
Co-authored-by: Vladimir <dragonvladir@gmail.com>
…tend into SED-3222-duplicate-edit
https://exense.atlassian.net/browse/SED-3304