-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Custom Header component implementation
- Loading branch information
Yahima Duarte
committed
Sep 9, 2018
1 parent
d8c70d5
commit bb2c482
Showing
11 changed files
with
178 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,45 @@ Action button can be of two types: | |
- without return value | ||
Has no direct effect on dialog. Can be used to trigger some arbitrary functionality (e.g. copy values to clipboard) | ||
|
||
Custom Header | ||
1. Create a custom header component that implements `IModalHeaderDialog`. | ||
|
||
```ts | ||
import {Component} from '@angular/core'; | ||
import {IModalHeaderDialog} from '../../../../src/modal-dialog.interface'; | ||
|
||
@Component({ | ||
selector: 'app-custom-header-modal', | ||
template: ` | ||
<p>This component is a custom header.</p> | ||
<p><strong>Written By: </strong><b>{{data}}</b></p> | ||
` | ||
}) | ||
export class CustomHeaderModalComponent implements IModalHeaderDialog { | ||
data: string; | ||
|
||
setData(data: any) { | ||
this.data = data; | ||
} | ||
} | ||
``` | ||
|
||
2. Inject the `ModalDialogService` where you want to open the dialog passing the headerComponent as a new parameter instead of the title attribute: | ||
```ts | ||
constructor(modalService: ModalDialogService, viewRef: ViewContainerRef) { } | ||
|
||
openNewDialog() { | ||
this.modalDialogService.openDialog(this.viewContainer, { | ||
headerComponent: CustomHeaderModalComponent, | ||
childComponent: CustomModalComponent, | ||
settings: { | ||
closeButtonClass: 'close theme-icon-close' | ||
}, | ||
data: 'Yahima Duarte <[email protected]>' | ||
}); | ||
} | ||
``` | ||
|
||
## API | ||
|
||
### ModalDialogService | ||
|
@@ -122,6 +161,7 @@ Modal heading text | |
```ts | ||
interface IModalDialogOptions<T> { | ||
title: string; | ||
headerComponent: IModalHeaderDialog; | ||
childComponent: IModalDialog; | ||
onClose: ModalDialogOnAction; | ||
actionButtons: IModalDialogButton[]; | ||
|
@@ -136,6 +176,9 @@ This is generic interface, where `T` is arbitrary type of `data` section. | |
- title: `string` | ||
Modal heading text | ||
|
||
- headerComponent: `any` | ||
Component type that will be rendered as a header of modal dialog. Component must implement `IModalHeaderDialog` interface. | ||
|
||
- childComponent: `any` | ||
Component type that will be rendered as a content of modal dialog. Component must implement `IModalDialog` interface. | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { Component, ViewContainerRef } from '@angular/core'; | ||
import { ModalDialogService, SimpleModalComponent } from 'ngx-modal-dialog'; | ||
import { CustomModalComponent } from './dialogs/custom-modal.component'; | ||
import { DynamicModalComponent } from './dialogs/dynamic-modal.component'; | ||
import {Component, ViewContainerRef} from '@angular/core'; | ||
import {ModalDialogService, SimpleModalComponent} from 'ngx-modal-dialog'; | ||
import {CustomModalComponent} from './dialogs/custom-modal.component'; | ||
import {DynamicModalComponent} from './dialogs/dynamic-modal.component'; | ||
import {CustomHeaderModalComponent} from './dialogs/custom-header-modal.component'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html' | ||
}) | ||
export class AppComponent { | ||
constructor(private modalDialogService: ModalDialogService, private viewContainer: ViewContainerRef) {} | ||
constructor(private modalDialogService: ModalDialogService, private viewContainer: ViewContainerRef) { | ||
} | ||
|
||
openSimpleModal() { | ||
this.modalDialogService.openDialog(this.viewContainer, { | ||
|
@@ -92,6 +94,18 @@ export class AppComponent { | |
}); | ||
} | ||
|
||
openCustomHeaderModal() { | ||
this.modalDialogService.openDialog(this.viewContainer, { | ||
title: 'Custom child component', | ||
headerComponent: CustomHeaderModalComponent, | ||
childComponent: CustomModalComponent, | ||
settings: { | ||
closeButtonClass: 'close theme-icon-close' | ||
}, | ||
data: 'Yahima Duarte <[email protected]>' | ||
}); | ||
} | ||
|
||
openDynamicModal() { | ||
this.modalDialogService.openDialog(this.viewContainer, { | ||
title: 'Dynamic child component', | ||
|
@@ -106,30 +120,34 @@ export class AppComponent { | |
this.modalDialogService.openDialog(this.viewContainer, { | ||
title: 'Dialog 1', | ||
childComponent: SimpleModalComponent, | ||
settings: { closeButtonClass: 'close theme-icon-close' }, | ||
settings: {closeButtonClass: 'close theme-icon-close'}, | ||
placeOnTop: true, | ||
data: { text: ` | ||
data: { | ||
text: ` | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, | ||
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | ||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. | ||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.` } | ||
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.` | ||
} | ||
}); | ||
this.modalDialogService.openDialog(this.viewContainer, { | ||
title: 'Dialog 2', | ||
childComponent: SimpleModalComponent, | ||
settings: { closeButtonClass: 'close theme-icon-close' }, | ||
settings: {closeButtonClass: 'close theme-icon-close'}, | ||
placeOnTop: true, | ||
data: { text: ` | ||
data: { | ||
text: ` | ||
Lorem ipsum is placeholder text commonly used in the graphic, print, | ||
and publishing industries for previewing layouts and visual mockups.` } | ||
and publishing industries for previewing layouts and visual mockups.` | ||
} | ||
}); | ||
this.modalDialogService.openDialog(this.viewContainer, { | ||
title: 'Dialog 3', | ||
childComponent: SimpleModalComponent, | ||
settings: { closeButtonClass: 'close theme-icon-close' }, | ||
settings: {closeButtonClass: 'close theme-icon-close'}, | ||
placeOnTop: true, | ||
data: { text: 'Some text content' } | ||
data: {text: 'Some text content'} | ||
}); | ||
} | ||
} |
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,18 +1,20 @@ | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {NgModule} from '@angular/core'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { CustomModalComponent } from './dialogs/custom-modal.component'; | ||
import { ModalDialogModule } from 'ngx-modal-dialog'; | ||
import { DynamicModalComponent } from './dialogs/dynamic-modal.component'; | ||
import {AppComponent} from './app.component'; | ||
import {CustomModalComponent} from './dialogs/custom-modal.component'; | ||
import {ModalDialogModule} from 'ngx-modal-dialog'; | ||
import {DynamicModalComponent} from './dialogs/dynamic-modal.component'; | ||
import {CustomHeaderModalComponent} from './dialogs/custom-header-modal.component'; | ||
|
||
@NgModule({ | ||
declarations: [AppComponent, CustomModalComponent, DynamicModalComponent], | ||
declarations: [AppComponent, CustomModalComponent, DynamicModalComponent, CustomHeaderModalComponent], | ||
imports: [ | ||
BrowserModule, | ||
ModalDialogModule.forRoot() | ||
], | ||
entryComponents: [CustomModalComponent, DynamicModalComponent], | ||
entryComponents: [CustomModalComponent, DynamicModalComponent, CustomHeaderModalComponent], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
export class AppModule { | ||
} |
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,17 @@ | ||
import {Component} from '@angular/core'; | ||
import {IModalHeaderDialog} from '../../../../src/modal-dialog.interface'; | ||
|
||
@Component({ | ||
selector: 'app-custom-header-modal', | ||
template: ` | ||
<p>This component is a custom header.</p> | ||
<p>Written By: <b>{{data}}</b></p> | ||
` | ||
}) | ||
export class CustomHeaderModalComponent implements IModalHeaderDialog { | ||
data: string; | ||
|
||
setData(data: any) { | ||
this.data = data; | ||
} | ||
} |
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
Oops, something went wrong.