Skip to content

Commit

Permalink
feat: 🎸 expose dialog open statuses
Browse files Browse the repository at this point in the history
shaharkazaz committed Jan 1, 2023
1 parent fd63343 commit 030a68d
Showing 6 changed files with 18 additions and 143 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ All notable changes to this project will be documented in this file. See [standa
- Sizes default `height` is now `auto`
- Expose `provideDialogConfig` function
- `dialogClose` should be imported when used
- The `data` property type now infered based on the public ref property in the component (see docs)
- The `data` property type now inferred based on the public ref property in the component (see docs)

### Features

132 changes: 0 additions & 132 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -55,7 +55,6 @@
"prettier": "2.8.0",
"standard-version": "^6.0.1",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.8.4"
},
"config": {
17 changes: 16 additions & 1 deletion projects/ngneat/dialog/src/lib/dialog.service.ts
Original file line number Diff line number Diff line change
@@ -10,12 +10,13 @@ import {
Type,
ViewRef,
} from '@angular/core';
import { Subject } from 'rxjs';
import { BehaviorSubject, startWith, Subject } from 'rxjs';
import { DialogRef, InternalDialogRef } from './dialog-ref';
import { DialogComponent } from './dialog.component';
import { DragOffset } from './draggable.directive';
import { DIALOG_CONFIG, DIALOG_DOCUMENT_REF, GLOBAL_DIALOG_CONFIG, NODES_TO_INSERT } from './providers';
import { AttachOptions, DialogConfig, ExtractData, GlobalDialogConfig, OpenParams } from './types';
import { map } from 'rxjs/operators';

const OVERFLOW_HIDDEN_CLASS = 'ngneat-dialog-hidden';

@@ -26,7 +27,19 @@ export class DialogService {
private document = inject(DIALOG_DOCUMENT_REF);
private globalConfig = inject(GLOBAL_DIALOG_CONFIG);

// Replace with Map in next major version
dialogs: DialogRef[] = [];
// A Stream representing opening & closing dialogs
private hasOpenDialogSub = new BehaviorSubject<boolean>(false);
hasOpenDialogs$ = this.hasOpenDialogSub.asObservable();

hasOpenDialogs() {
return this.dialogs.length > 0;
}

isOpen(id: string) {
return this.dialogs.some((ref) => ref.id === id);
}

closeAll() {
this.dialogs.forEach((dialog) => dialog.close());
@@ -55,6 +68,7 @@ export class DialogService {
};

this.dialogs.push(dialogRef);
this.hasOpenDialogSub.next(true);

if (this.dialogs.length === 1) {
this.document.body.classList.add(OVERFLOW_HIDDEN_CLASS);
@@ -123,6 +137,7 @@ export class DialogService {
const onClose = (result: unknown) => {
this.globalConfig.onClose?.();
this.dialogs = this.dialogs.filter(({ id }) => dialogRef.id !== id);
this.hasOpenDialogSub.next(this.hasOpenDialogs());

container.removeChild(dialog.location.nativeElement);
this.appRef.detachView(dialog.hostView);
2 changes: 1 addition & 1 deletion projects/ngneat/dialog/src/lib/providers.ts
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ export function provideDialogConfig(config: Partial<GlobalDialogConfig>): Provid
useFactory() {
const defaultConfig = defaultGlobalConfig();
return {
...defaultGlobalConfig(),
...defaultConfig,
...config,
sizes: {
...defaultConfig.sizes,
7 changes: 0 additions & 7 deletions projects/ngneat/dialog/tslint.json

This file was deleted.

0 comments on commit 030a68d

Please sign in to comment.