forked from scttcper/ngx-toastr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add provider function, convert to standalone and use inject (sc…
- Loading branch information
Showing
9 changed files
with
75 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import { | ||
Directive, | ||
ElementRef, | ||
NgModule, | ||
} from '@angular/core'; | ||
import { Directive, ElementRef } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[toastContainer]', | ||
exportAs: 'toastContainer', | ||
standalone: true | ||
}) | ||
export class ToastContainerDirective { | ||
constructor(private el: ElementRef) { } | ||
getContainerElement(): HTMLElement { | ||
return this.el.nativeElement; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [ToastContainerDirective], | ||
exports: [ToastContainerDirective], | ||
}) | ||
export class ToastContainerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DefaultNoComponentGlobalConfig, GlobalConfig, TOAST_CONFIG } from './toastr-config'; | ||
import { EnvironmentProviders, makeEnvironmentProviders, Provider } from '@angular/core'; | ||
import { Toast } from './toast.component'; | ||
|
||
export const DefaultGlobalConfig: GlobalConfig = { | ||
...DefaultNoComponentGlobalConfig, | ||
toastComponent: Toast, | ||
}; | ||
|
||
/** | ||
* @description | ||
* Provides the `TOAST_CONFIG` token with the given config. | ||
* | ||
* @param config The config to configure toastr. | ||
* @returns The environment providers. | ||
* | ||
* @example | ||
* ```ts | ||
* import { provideToastr } from 'ngx-toastr'; | ||
* | ||
* bootstrap(AppComponent, { | ||
* providers: [ | ||
* provideToastr({ | ||
* timeOut: 2000, | ||
* positionClass: 'toast-top-right', | ||
* }), | ||
* ], | ||
* }) | ||
*/ | ||
export const provideToastr = (config: Partial<GlobalConfig> = {}): EnvironmentProviders => { | ||
const providers: Provider[] = [ | ||
{ | ||
provide: TOAST_CONFIG, | ||
useValue: { | ||
default: DefaultGlobalConfig, | ||
config, | ||
} | ||
} | ||
]; | ||
|
||
return makeEnvironmentProviders(providers); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters