-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
169 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/dbx-web/src/lib/interaction/dialog/dialog.action.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { first, Observable } from 'rxjs'; | ||
import { Directive, OnInit, OnDestroy, Input, ElementRef } from '@angular/core'; | ||
import { DbxActionContextStoreSourceInstance, AbstractDbxActionValueOnTriggerDirective } from '@dereekb/dbx-core'; | ||
import { IsModifiedFunction } from '@dereekb/rxjs'; | ||
import { Maybe } from '@dereekb/util'; | ||
import { MatDialogRef } from '@angular/material/dialog'; | ||
|
||
export type DbxActionDialogFunction<T = any> = () => MatDialogRef<any, Maybe<T>>; | ||
|
||
/** | ||
* Action directive that is used to trigger/display a dialog, then watches that dialog for a value. | ||
*/ | ||
@Directive({ | ||
exportAs: 'dbxActionDialog', | ||
selector: '[dbxActionDialog]' | ||
}) | ||
export class DbxActionDialogDirective<T = any> extends AbstractDbxActionValueOnTriggerDirective<T> implements OnInit, OnDestroy { | ||
|
||
@Input('dbxActionDialog') | ||
fn?: DbxActionDialogFunction<T>; | ||
|
||
@Input() | ||
set dbxActionDialogModified(isModifiedFunction: Maybe<IsModifiedFunction>) { | ||
this.isModifiedFunction = isModifiedFunction; | ||
} | ||
|
||
constructor( | ||
readonly elementRef: ElementRef, | ||
source: DbxActionContextStoreSourceInstance<T, any> | ||
) { | ||
super(source, () => this._getDataFromDialog()); | ||
} | ||
|
||
protected _getDataFromDialog(): Observable<Maybe<T>> { | ||
return this._makeDialogRef().afterClosed().pipe(first()); | ||
} | ||
|
||
protected _makeDialogRef(): MatDialogRef<any, Maybe<T>> { | ||
if (!this.fn) { | ||
throw new Error('dbxActionDialog has no dialog function provided to it.'); | ||
} | ||
|
||
return this.fn(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './abstract.dialog.directive'; | ||
export * from './dialog.content.component'; | ||
export * from './dialog.action.directive'; | ||
export * from './dialog.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ages/demo/src/app/modules/doc/modules/action/component/action.example.dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Component } from '@angular/core'; | ||
import { MatDialog, MatDialogRef } from '@angular/material/dialog'; | ||
import { AbstractDialogDirective } from '@dereekb/dbx-web'; | ||
|
||
export const DEFAULT_INTERACTION_POPUP_COMPOSER_POPUP_KEY = 'popup'; | ||
|
||
@Component({ | ||
template: ` | ||
<dbx-dialog-content> | ||
<p>Pick a value.</p> | ||
<div> | ||
<button mat-raised-button (click)="close(100)">100</button> | ||
<dbx-button-spacer></dbx-button-spacer> | ||
<button mat-raised-button (click)="close(1000)">1000</button> | ||
<dbx-button-spacer></dbx-button-spacer> | ||
<button mat-raised-button (click)="close()">Cancel</button> | ||
</div> | ||
</dbx-dialog-content> | ||
` | ||
}) | ||
export class DocActionExampleDialogComponent extends AbstractDialogDirective { | ||
|
||
static openDialog(matDialog: MatDialog): MatDialogRef<DocActionExampleDialogComponent, boolean> { | ||
const dialogRef = matDialog.open(DocActionExampleDialogComponent, {}); | ||
return dialogRef; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
...es/demo/src/app/modules/doc/modules/interaction/component/interaction.dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters