Skip to content

Commit

Permalink
feat(angular): add openWithRef to dialog service so dialog reference …
Browse files Browse the repository at this point in the history
…can be obtained by the user (#494)

Co-authored-by: Tim Sielemann <[email protected]>
  • Loading branch information
TimSielemann and Tim Sielemann authored Apr 15, 2024
1 parent 30784b9 commit 7990167
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions angular/projects/catalyst/src/lib/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dialog, DialogConfig } from '@angular/cdk/dialog';
import { Dialog, DialogConfig, DialogRef } from '@angular/cdk/dialog';
import { ComponentType } from '@angular/cdk/portal';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
Expand Down Expand Up @@ -31,6 +31,17 @@ export class CatDialogService {
component: ComponentType<unknown>,
config?: CatDialogConfig<D>
): Observable<R | undefined> {
return this.openWithRef<R, D>(component, config).closed;
}

/**
* Opens a modal dialog containing the given component and returns a reference to the dialog.
*
* @param component - The component to render as dialog content.
* @param config - The dialog configuration.
* @returns A reference to the just opened dialog.
*/
openWithRef<R = unknown, D = unknown>(component: ComponentType<unknown>, config?: CatDialogConfig<D>): DialogRef<R> {
const panelClass = config?.panelClass ?? [];
return this.dialog.open<R, D>(component, {
backdropClass: 'cat-backdrop',
Expand All @@ -41,7 +52,7 @@ export class CatDialogService {
maxHeight: 'calc(100vh - 64px)',
maxWidth: 'calc(100vw - 64px)',
...config
}).closed;
});
}

/**
Expand Down

0 comments on commit 7990167

Please sign in to comment.