Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { DaffCartActionTypes } from '@daffodil/cart/state';
import {
DaffModalService,
DaffModalComponent,
DaffModalRef,
} from '@daffodil/design/modal';

import {
Expand All @@ -25,7 +25,7 @@ import { AddToCartNotificationComponent } from '../components/add-to-cart-notifi

@Injectable()
export class AddToCartNotificationEffects {
private notification: DaffModalComponent;
private notification: DaffModalRef;

constructor(
private actions$: Actions,
Expand Down Expand Up @@ -54,7 +54,7 @@ export class AddToCartNotificationEffects {
closeModal$ = createEffect(() => this.actions$.pipe(
ofType(AddToCartNotificationActionTypes.CloseAddToCartNotificationAction),
map((action) => {
this.daffModalService.close(this.notification);
this.notification.close();
}),
), { dispatch: false });
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

import { DaffButtonComponent } from '@daffodil/design/button';
import {
DaffModalComponent,
DaffModalRef,
DAFF_MODAL_COMPONENTS,
DaffModalService,
} from '@daffodil/design/modal';
Expand All @@ -25,7 +25,7 @@ import { BasicModalContentExampleComponent } from './modal-content.component';
],
})
export class BasicModalExampleComponent {
modal: DaffModalComponent;
modal: DaffModalRef;

constructor(private modalService: DaffModalService) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {

import { DaffButtonComponent } from '@daffodil/design/button';
import {
DaffModalComponent,
DaffModalRef,
DAFF_MODAL_COMPONENTS,
DaffModalService,
} from '@daffodil/design/modal';
Expand All @@ -25,7 +25,7 @@ import { PositionConfigModalContentExampleComponent } from './modal-content.comp
],
})
export class PositionConfigModalExampleComponent {
modal: DaffModalComponent;
modal: DaffModalRef;

constructor(private modalService: DaffModalService) {}

Expand Down
32 changes: 32 additions & 0 deletions libs/design/modal/src/modal/interfaces/modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { OverlayRef } from '@angular/cdk/overlay';
import { ComponentRef } from '@angular/core';
import { Observable } from 'rxjs';

import { DaffModalComponent } from '../modal.component';

export interface DaffModal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split this into two files I think to avoid accidental public_api exposure.

/**
* The reference to the modal in question
*/
modal: ComponentRef<DaffModalComponent>;

/**
* The overlay associated with a given modal.
*/
overlay: OverlayRef;
}

/**
* Reference to modal instance.
*/
export interface DaffModalRef {
/**
* Closes the modal.
*/
close(): void;

/**
* Emits when the modal close animation completes.
*/
afterClosed: Observable<boolean>;
}
16 changes: 0 additions & 16 deletions libs/design/modal/src/modal/modal.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/design/modal/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './modal/modal.component';
export { DaffModalModule } from './modal.module';
export { DaffModalService } from './service/modal.service';
export { DaffModal } from './modal/modal';
export { DaffModalRef } from './modal/interfaces/modal';
export { DaffModalHeaderComponent } from './modal-header/modal-header.component';
export { DaffModalTitleDirective } from './modal-title/modal-title.directive';
export { DaffModalContentComponent } from './modal-content/modal-content.component';
Expand Down
13 changes: 10 additions & 3 deletions libs/design/modal/src/service/modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
} from '@angular/core';
import { take } from 'rxjs/operators';

import { DaffModal } from '../modal/modal';
import {
DaffModal,
DaffModalRef,
} from '../modal/interfaces/modal';
import {
DaffModalConfiguration,
DaffModalPosition,
Expand Down Expand Up @@ -99,7 +102,7 @@ export class DaffModalService {
open(
component: Type<any>,
configuration?: Partial<DaffModalConfiguration>,
): DaffModalComponent {
): DaffModalRef {
this._closeAllModals();
const config = { ...this.defaultConfiguration, ...configuration };
const _ref = this._createOverlayRef(config);
Expand All @@ -124,7 +127,11 @@ export class DaffModalService {
? config.onBackdropClicked()
: this.close(modal.modal.instance),
);
return modal.modal.instance;

return {
close: () => this.close(modal.modal.instance),
afterClosed: modal.modal.instance.closedAnimationCompleted$,
};
}

close(component: DaffModalComponent): void {
Expand Down
5 changes: 3 additions & 2 deletions libs/design/modal/src/specs/focus-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { By } from '@angular/platform-browser';
import { DaffFocusStackService } from '@daffodil/design';
import {
DaffModalComponent,
DaffModalRef,
DaffModalService,
} from '@daffodil/design/modal';

Expand All @@ -32,15 +33,15 @@ class ModalContentComponent {}
],
})
class WrapperComponent {
_modal: DaffModalComponent;
_modal: DaffModalRef;
constructor(private modal: DaffModalService) {}

openModal() {
this._modal = this.modal.open(ModalContentComponent);
}

closeModal() {
this.modal.close(this._modal);
this._modal.close();
}
}

Expand Down