[ADF-4327] added templating for content dialog (#4549)

* [ADF-4327] added templating for content dialog

* [ADF-4327] added unit test and documentation
This commit is contained in:
Vito
2019-04-04 12:44:47 +01:00
committed by Denys Vuika
parent 4ebc8e2527
commit c5ac798c5b
12 changed files with 286 additions and 22 deletions

View File

@@ -15,29 +15,14 @@
* limitations under the License.
*/
import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { Component, Inject, ViewEncapsulation, SecurityContext } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'adf-confirm-dialog',
template: `
<h1 mat-dialog-title>{{ title | translate }}</h1>
<mat-dialog-content>
<p>{{ message | translate }}</p>
</mat-dialog-content>
<mat-dialog-actions>
<span class="spacer"></span>
<button id="adf-confirm-accept" mat-button color="primary" [mat-dialog-close]="true">{{ yesLabel | translate }}</button>
<button id="adf-confirm-cancel" mat-button [mat-dialog-close]="false" cdkFocusInitial>{{ noLabel | translate }}</button>
</mat-dialog-actions>
`,
styles: [`
.spacer { flex: 1 1 auto; }
.adf-confirm-dialog .mat-dialog-actions .mat-button-wrapper {
text-transform: uppercase;
}
`],
templateUrl: './confirm.dialog.html',
styleUrls: ['./confirm.dialog.scss'],
host: { 'class': 'adf-confirm-dialog' },
encapsulation: ViewEncapsulation.None
})
@@ -47,12 +32,18 @@ export class ConfirmDialogComponent {
message: string;
yesLabel: string;
noLabel: string;
htmlContent: string;
constructor(@Inject(MAT_DIALOG_DATA) data) {
constructor(@Inject(MAT_DIALOG_DATA) data, private sanitizer: DomSanitizer) {
data = data || {};
this.title = data.title || 'ADF_CONFIRM_DIALOG.CONFIRM';
this.message = data.message || 'ADF_CONFIRM_DIALOG.MESSAGE';
this.yesLabel = data.yesLabel || 'ADF_CONFIRM_DIALOG.YES_LABEL';
this.noLabel = data.noLabel || 'ADF_CONFIRM_DIALOG.NO_LABEL';
this.htmlContent = data.htmlContent;
}
public sanitizedHtmlContent() {
return this.sanitizer.sanitize(SecurityContext.HTML, this.htmlContent);
}
}