Skip to content

Commit 815e1dd

Browse files
authoredMar 3, 2023
feat: Add generic for payload in IndividualConfig (#980)
1 parent efaf809 commit 815e1dd

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed
 

‎src/lib/toastr/toast.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ import { ToastrService } from './toastr.service';
5353
],
5454
preserveWhitespaces: false
5555
})
56-
export class Toast implements OnDestroy {
56+
export class Toast<ConfigPayload = any> implements OnDestroy {
5757
message?: string | null;
5858
title?: string;
59-
options: IndividualConfig;
59+
options: IndividualConfig<ConfigPayload>;
6060
duplicatesCount!: number;
6161
originalTimeout: number;
6262
/** width of progress bar */

‎src/lib/toastr/toastr-config.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type DisableTimoutType = boolean | 'timeOut' | 'extendedTimeOut';
1111
/**
1212
* Configuration for an individual toast.
1313
*/
14-
export interface IndividualConfig {
14+
export interface IndividualConfig<ConfigPayload = any> {
1515
/**
1616
* disable both timeOut and extendedTimeOut
1717
* default: false
@@ -101,10 +101,9 @@ export interface IndividualConfig {
101101
newestOnTop: boolean;
102102

103103
/**
104-
* payload to pass to the toastComponent
105-
* default: null
104+
* Payload to pass to the toast component
106105
*/
107-
payload: any;
106+
payload?: ConfigPayload;
108107
}
109108

110109
export interface ToastrIconClasses {
@@ -157,13 +156,13 @@ export interface GlobalConfig extends IndividualConfig {
157156
/**
158157
* Everything a toast needs to launch
159158
*/
160-
export class ToastPackage {
159+
export class ToastPackage<ConfigPayload = any> {
161160
private _onTap = new Subject<void>();
162161
private _onAction = new Subject<any>();
163162

164163
constructor(
165164
public toastId: number,
166-
public config: IndividualConfig,
165+
public config: IndividualConfig<ConfigPayload>,
167166
public message: string | null | undefined,
168167
public title: string | undefined,
169168
public toastType: string,
@@ -237,8 +236,6 @@ export const DefaultNoComponentGlobalConfig: GlobalConfig = {
237236
tapToDismiss: true,
238237
onActivateTick: false,
239238
progressAnimation: 'decreasing',
240-
241-
payload: null
242239
};
243240

244241
export interface ToastToken {

‎src/lib/toastr/toastr.service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,26 @@ export class ToastrService {
6464
}
6565
}
6666
/** show toast */
67-
show(message?: string, title?: string, override: Partial<IndividualConfig> = {}, type = '') {
67+
show<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}, type = '') {
6868
return this._preBuildNotification(type, message, title, this.applyConfig(override));
6969
}
7070
/** show successful toast */
71-
success(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
71+
success<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
7272
const type = this.toastrConfig.iconClasses.success || '';
7373
return this._preBuildNotification(type, message, title, this.applyConfig(override));
7474
}
7575
/** show error toast */
76-
error(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
76+
error<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
7777
const type = this.toastrConfig.iconClasses.error || '';
7878
return this._preBuildNotification(type, message, title, this.applyConfig(override));
7979
}
8080
/** show info toast */
81-
info(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
81+
info<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
8282
const type = this.toastrConfig.iconClasses.info || '';
8383
return this._preBuildNotification(type, message, title, this.applyConfig(override));
8484
}
8585
/** show warning toast */
86-
warning(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
86+
warning<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
8787
const type = this.toastrConfig.iconClasses.warning || '';
8888
return this._preBuildNotification(type, message, title, this.applyConfig(override));
8989
}

0 commit comments

Comments
 (0)
Please sign in to comment.