diff --git a/libs/inform/README.md b/libs/inform/README.md index 24665d69..d200480b 100644 --- a/libs/inform/README.md +++ b/libs/inform/README.md @@ -99,17 +99,17 @@ The `NgxModalService` provides a WCAG/ARIA compliant approach to the Angular CDK You can use the `NgxModalService` without any prior setup, but the `ngx-inform` package does provide the ability to provide a global configuration that can be applied for all modals. On top of that, you can provide default modals with your specific configuration. ``` ts - provideNgxModalConfiguration({ - closeOnNavigation: true, - autoClose: true - modals: { - confirm: { - component: ConfirmModalComponent, - role: 'alertdialog', - panelClass: 'panel-confirm', - }, - }, - }), +provideNgxModalConfiguration({ + closeOnNavigation: true, + autoClose: true, + modals: { + confirm: { + component: ConfirmModalComponent, + role: 'alertdialog', + panelClass: 'panel-confirm', + }, + }, +}), ``` Using the above configuration, we can set several properties that will be applied to the modals globally. These properties are: @@ -149,43 +149,43 @@ When opening a modal we can overwrite all the globally and modal-specific config If we set a predefined modal, we can now call said modal using the `open` method on `NgxModalService`. ```ts - this.modalService - .open<'Confirm' | 'Deny'>({ - type: 'confirm', - describedById: 'confirm-button', - labelledById: 'confirm-label', - data: { - title: 'Please confirm your actions!' - } - }) - .pipe( - tap(action => { - if(action === 'Confirm') { - // Perform confirm logic - } - - // Perform non-confirm logic - }) - ) - .subscribe(); +this.modalService + .open<'Confirm' | 'Deny'>({ + type: 'confirm', + describedById: 'confirm-button', + labelledById: 'confirm-label', + data: { + title: 'Please confirm your actions!' + } + }) + .pipe( + tap(action => { + if(action === 'Confirm') { + // Perform confirm logic + } + + // Perform non-confirm logic + }) + ) + .subscribe(); ``` #### Custom modal We can always create a custom modal for feature-specific use-cases. We do this by providing a component. ``` ts - this.modalService - .open<'Test'>({ - component: ModalComponent, - label: 'Modal', - role: 'dialog', - }) - .pipe( - tap((action) => { - if (action === 'Test') { - console.log('Hello!'); - } - }) - ) - .subscribe(); +this.modalService + .open<'Test'>({ + component: ModalComponent, + label: 'Modal', + role: 'dialog', + }) + .pipe( + tap((action) => { + if (action === 'Test') { + console.log('Hello!'); + } + }) + ) + .subscribe(); ``` diff --git a/libs/inform/src/lib/services/modal/modal.service.ts b/libs/inform/src/lib/services/modal/modal.service.ts index 0ca0132a..b4b23399 100644 --- a/libs/inform/src/lib/services/modal/modal.service.ts +++ b/libs/inform/src/lib/services/modal/modal.service.ts @@ -41,8 +41,8 @@ export class NgxModalService { * * @param {NgxModalOptions} options - The modal options */ - public open( - options: NgxModalOptions + public open( + options: NgxModalOptions ): Observable { // Iben: If there still is an active subject running, the modal is still active and we early exit if (!this.modalClosedSubject?.closed) { @@ -58,10 +58,10 @@ export class NgxModalService { // Iben: Fetch the type of component we wish to show const configuration = this.configuration?.modals?.[options.type]; - const component: Type> = + const component: Type> = options.component || (this.configuration?.modals?.[options.type].component as Type< - NgxModalAbstractComponent + NgxModalAbstractComponent >); // Iben: Check if all the correct parameters are set and return NEVER when they're not correctly set @@ -70,7 +70,7 @@ export class NgxModalService { } // Iben: Render the modal - const modal = this.createModalComponent(options, component); + const modal = this.createModalComponent(options, component); // Iben: Return the modal action return combineLatest([ @@ -168,9 +168,9 @@ export class NgxModalService { * @param options - The options of the modal * @param component - The component we wish to render */ - private createModalComponent( + private createModalComponent( options: NgxModalOptions, - component: Type> + component: Type> ): NgxModalAbstractComponent { const configuration = this.configuration?.modals?.[options.type];