Pull request #293: Feature/TV-845 ui dialog
Merge in TEA/mina-sidor-fa-web from feature/TV-845-ui-dialog-2 to develop
Squashed commit of the following:
commit 06ee26ccbe9d2fd5edfd12d7a292f42e3b747fb7
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Thu Dec 16 09:45:23 2021 +0100
refactor
commit e2295202721b58fbd37341d3e02dae5a95cbb0c5
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 14:03:37 2021 +0100
Update ui-dialog-ref.ts
commit c9507cd4579b4e542d0116f5e96b3a911c51600d
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 13:00:05 2021 +0100
cleanup
commit 0e4ded553352414b5ca670897a51f127a5a289b1
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 12:48:25 2021 +0100
cleanup
commit 0a48220c8bcd5704f7436f1c0c84ca25bac4c8e8
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 12:36:16 2021 +0100
Dialog working
commit c4c1e9fb42d99df7ec6c058b7bea30662a03bb33
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 11:14:36 2021 +0100
wip
commit 6668dfb154022b873b0a042087181cd0e6f8994d
Merge: 624b9439 9d96f0d9
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 10:47:27 2021 +0100
Merge branch 'develop' into feature/TV-845-ui-dialog-2
commit 624b94399689bef07178f89c015745c90af1b288
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 10:47:19 2021 +0100
wip
commit 0478638ab0d0f8f62ce8d10489f20e4930099936
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 09:58:49 2021 +0100
wip
commit 12234c22062124165c2da10ff75cc887997172a8
Author: Daniel Appelgren <daniel.appelgren@arbetsformedlingen.se>
Date: Fri Dec 10 09:21:09 2021 +0100
wip
This commit is contained in:
44
libs/ui/src/dialog/ui-dialog.service.ts
Normal file
44
libs/ui/src/dialog/ui-dialog.service.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Injectable, Injector, TemplateRef, Type } from '@angular/core';
|
||||
import { ComponentPortal } from '@angular/cdk/portal';
|
||||
import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
|
||||
import { UiDialogRef } from '@ui/dialog/ui-dialog-ref';
|
||||
import { UiDialogComponent } from './ui-dialog.component';
|
||||
import { UI_DIALOG_DATA, UiDialogConfig } from '@ui/dialog/ui-dialog.model';
|
||||
|
||||
@Injectable()
|
||||
export class UiDialog {
|
||||
constructor(private overlay: Overlay, private injector: Injector) {}
|
||||
|
||||
private static _createInjector(uiDialogRef: UiDialogRef, injector: Injector, config: UiDialogConfig): Injector {
|
||||
return Injector.create({
|
||||
parent: injector,
|
||||
providers: [
|
||||
{ provide: UiDialogRef, useValue: uiDialogRef },
|
||||
{ provide: UI_DIALOG_DATA, useValue: config.data },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
open<DialogContent = unknown, T = unknown>(
|
||||
content: string | TemplateRef<unknown> | Type<unknown>,
|
||||
config: UiDialogConfig<T>
|
||||
): UiDialogRef<DialogContent> {
|
||||
const positionStrategy = this.overlay.position().global().centerHorizontally().centerVertically();
|
||||
const configs = new OverlayConfig({
|
||||
positionStrategy,
|
||||
minWidth: '40rem',
|
||||
minHeight: '40rem',
|
||||
hasBackdrop: true,
|
||||
scrollStrategy: this.overlay.scrollStrategies.close(),
|
||||
backdropClass: 'cdk-overlay-dark-backdrop',
|
||||
});
|
||||
|
||||
const overlayRef = this.overlay.create(configs);
|
||||
const uiDialogRef = new UiDialogRef<DialogContent, T>(overlayRef, content, config);
|
||||
|
||||
const injector = UiDialog._createInjector(uiDialogRef, this.injector, config);
|
||||
overlayRef.attach(new ComponentPortal(UiDialogComponent, null, injector));
|
||||
|
||||
return uiDialogRef;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user