Skip to content

Commit

Permalink
feat: Add generic for payload in IndividualConfig (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
twittwer authored Mar 3, 2023
1 parent efaf809 commit 815e1dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/lib/toastr/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ import { ToastrService } from './toastr.service';
],
preserveWhitespaces: false
})
export class Toast implements OnDestroy {
export class Toast<ConfigPayload = any> implements OnDestroy {
message?: string | null;
title?: string;
options: IndividualConfig;
options: IndividualConfig<ConfigPayload>;
duplicatesCount!: number;
originalTimeout: number;
/** width of progress bar */
Expand Down
13 changes: 5 additions & 8 deletions src/lib/toastr/toastr-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type DisableTimoutType = boolean | 'timeOut' | 'extendedTimeOut';
/**
* Configuration for an individual toast.
*/
export interface IndividualConfig {
export interface IndividualConfig<ConfigPayload = any> {
/**
* disable both timeOut and extendedTimeOut
* default: false
Expand Down Expand Up @@ -101,10 +101,9 @@ export interface IndividualConfig {
newestOnTop: boolean;

/**
* payload to pass to the toastComponent
* default: null
* Payload to pass to the toast component
*/
payload: any;
payload?: ConfigPayload;
}

export interface ToastrIconClasses {
Expand Down Expand Up @@ -157,13 +156,13 @@ export interface GlobalConfig extends IndividualConfig {
/**
* Everything a toast needs to launch
*/
export class ToastPackage {
export class ToastPackage<ConfigPayload = any> {
private _onTap = new Subject<void>();
private _onAction = new Subject<any>();

constructor(
public toastId: number,
public config: IndividualConfig,
public config: IndividualConfig<ConfigPayload>,
public message: string | null | undefined,
public title: string | undefined,
public toastType: string,
Expand Down Expand Up @@ -237,8 +236,6 @@ export const DefaultNoComponentGlobalConfig: GlobalConfig = {
tapToDismiss: true,
onActivateTick: false,
progressAnimation: 'decreasing',

payload: null
};

export interface ToastToken {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/toastr/toastr.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,26 @@ export class ToastrService {
}
}
/** show toast */
show(message?: string, title?: string, override: Partial<IndividualConfig> = {}, type = '') {
show<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}, type = '') {
return this._preBuildNotification(type, message, title, this.applyConfig(override));
}
/** show successful toast */
success(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
success<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
const type = this.toastrConfig.iconClasses.success || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
}
/** show error toast */
error(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
error<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
const type = this.toastrConfig.iconClasses.error || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
}
/** show info toast */
info(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
info<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
const type = this.toastrConfig.iconClasses.info || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
}
/** show warning toast */
warning(message?: string, title?: string, override: Partial<IndividualConfig> = {}) {
warning<ConfigPayload = any>(message?: string, title?: string, override: Partial<IndividualConfig<ConfigPayload>> = {}) {
const type = this.toastrConfig.iconClasses.warning || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
}
Expand Down

0 comments on commit 815e1dd

Please sign in to comment.