Skip to content

Commit

Permalink
feat(stark-ui): implement Material dialogs presets: alert, confirm an…
Browse files Browse the repository at this point in the history
…d prompt

ISSUES CLOSED: #793
  • Loading branch information
christophercr committed Mar 6, 2019
1 parent 50e9bbe commit 99f5864
Show file tree
Hide file tree
Showing 34 changed files with 627 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/stark-ui/assets/stark-ui-bundle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
@import "../src/modules/collapsible/components/collapsible.component";
@import "../src/modules/collapsible/components/collapsible-theme";
@import "../src/modules/date-range-picker/components/date-range-picker.component";
@import "../src/modules/dialogs/components/alert-dialog.component";
@import "../src/modules/dialogs/components/alert-dialog-theme";
@import "../src/modules/dialogs/components/confirm-dialog.component";
@import "../src/modules/dialogs/components/confirm-dialog-theme";
@import "../src/modules/dialogs/components/prompt-dialog.component";
@import "../src/modules/dialogs/components/prompt-dialog-theme";
@import "../src/modules/generic-search/components/generic-search/generic-search.component";
@import "../src/modules/language-selector/components/language-selector.component";
@import "../src/modules/message-pane/components/message-pane.component";
Expand Down
1 change: 1 addition & 0 deletions packages/stark-ui/src/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from "./modules/breadcrumb";
export * from "./modules/collapsible";
export * from "./modules/date-picker";
export * from "./modules/date-range-picker";
export * from "./modules/dialogs";
export * from "./modules/dropdown";
export * from "./modules/generic-search";
export * from "./modules/input-mask-directives";
Expand Down
2 changes: 2 additions & 0 deletions packages/stark-ui/src/modules/dialogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./dialogs/dialogs.module";
export * from "./dialogs/components";
6 changes: 6 additions & 0 deletions packages/stark-ui/src/modules/dialogs/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./components/alert-dialog.component";
export * from "./components/alert-dialog-content.intf";
export * from "./components/confirm-dialog.component";
export * from "./components/confirm-dialog-content.intf";
export * from "./components/prompt-dialog.component";
export * from "./components/prompt-dialog-content.intf";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { StarkBaseDialogContent } from "./dialog-content.intf";

export interface StarkAlertDialogContent extends StarkBaseDialogContent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.stark-alert-dialog {
.button-ok {
color: mat-color($primary-palette, 500);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2 mat-dialog-title>{{ content.title || "" | translate }}</h2>

<div mat-dialog-content>
{{ content.textContent || "" | translate }}
</div>

<div mat-dialog-actions>
<button mat-button (click)="onOk()" class="button-ok">{{ content.ok || "OK" | translate }}</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.stark-alert-dialog {
[mat-dialog-actions] {
// TODO: remove these 3 lines below when the MatDialogActions is adapted to align with Material Design guidelines: https://github.com/angular/material2/issues/14736
justify-content: flex-end;
align-items: flex-end;
margin-right: -16px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component, Inject, ViewEncapsulation } from "@angular/core";
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
import { StarkAlertDialogContent } from "./alert-dialog-content.intf";

export type StarkAlertDialogResult = "ok" | undefined;

@Component({
selector: "stark-alert-dialog",
templateUrl: "./alert-dialog.component.html",
encapsulation: ViewEncapsulation.None,
// We need to use host instead of @HostBinding: https://github.com/NationalBankBelgium/stark/issues/664
host: {
class: "stark-alert-dialog"
}
})
export class StarkAlertDialogComponent {
public constructor(
public dialogRef: MatDialogRef<StarkAlertDialogComponent, StarkAlertDialogResult>,
@Inject(MAT_DIALOG_DATA) public content: StarkAlertDialogContent
) {
}

public onOk(): void {
this.dialogRef.close("ok");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { StarkBaseDialogContent } from "./dialog-content.intf";

export interface StarkConfirmDialogContent extends StarkBaseDialogContent {
/**
* Label to be set in the "Cancel" button.
*/
cancel?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.stark-confirm-dialog {
.button-ok,
.button-cancel {
color: mat-color($primary-palette, 500);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2 mat-dialog-title>{{ content.title || "" | translate }}</h2>

<div mat-dialog-content>
{{ content.textContent || "" | translate }}
</div>

<div mat-dialog-actions>
<button mat-button (click)="onCancel()" class="button-cancel">{{ content.cancel || "CANCEL" | translate }}</button>
<button mat-button cdkFocusInitial (click)="onOk()" class="button-ok">{{ content.ok || "OK" | translate }}</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.stark-confirm-dialog {
[mat-dialog-actions] {
// TODO: remove these 3 lines below when the MatDialogActions is adapted to align with Material Design guidelines: https://github.com/angular/material2/issues/14736
justify-content: flex-end;
align-items: flex-end;
margin-right: -16px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, Inject, ViewEncapsulation } from "@angular/core";
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
import { StarkConfirmDialogContent } from "./confirm-dialog-content.intf";

export type StarkConfirmDialogResult = "ok" | "cancel" | undefined;

@Component({
selector: "stark-confirm-dialog",
templateUrl: "./confirm-dialog.component.html",
encapsulation: ViewEncapsulation.None,
// We need to use host instead of @HostBinding: https://github.com/NationalBankBelgium/stark/issues/664
host: {
class: "stark-confirm-dialog"
}
})
export class StarkConfirmDialogComponent {
public constructor(
public dialogRef: MatDialogRef<StarkConfirmDialogComponent, StarkConfirmDialogResult>,
@Inject(MAT_DIALOG_DATA) public content: StarkConfirmDialogContent
) {
}

public onCancel(): void {
this.dialogRef.close("cancel");
}

public onOk(): void {
this.dialogRef.close("ok");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface StarkBaseDialogContent {
/**
* Dialog's title.
*/
title?: string;

/**
* Dialog's simple text content.
*/
textContent?: string;

/**
* Label to be set in the "Ok" button.
*/
ok?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { StarkBaseDialogContent } from "./dialog-content.intf";

export interface StarkPromptDialogContent extends StarkBaseDialogContent {
/**
* Text to be shown as label of the prompt input.
*/
label?: string;

/**
* Placeholder text of the prompt input.
*/
placeholder?: string;

/**
* Initial value to be set to the prompt input.
*/
initialValue?: string;

/**
* Label to be set in the "Cancel" button.
*/
cancel?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.stark-prompt-dialog {
.button-ok,
.button-cancel {
color: mat-color($primary-palette, 500);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h2 mat-dialog-title>{{ content.title || "" | translate }}</h2>

<div mat-dialog-content>
{{ content.textContent || "" | translate }}

<mat-form-field class="prompt-text">
<mat-label translate>{{ content.label || content.placeholder }}</mat-label>
<input matInput [placeholder]="content.placeholder || '' | translate" [formControl]="formControl" />
</mat-form-field>
</div>

<div mat-dialog-actions>
<button mat-button (click)="onCancel()" class="button-cancel">{{ content.cancel || "CANCEL" | translate }}</button>
<button mat-button (click)="onOk()" class="button-ok" [disabled]="!formControl.value">{{ content.ok || "OK" | translate }}</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.stark-prompt-dialog {
[mat-dialog-actions] {
// TODO: remove these 3 lines below when the MatDialogActions is adapted to align with Material Design guidelines: https://github.com/angular/material2/issues/14736
justify-content: flex-end;
align-items: flex-end;
margin-right: -16px;
}

.mat-form-field.prompt-text {
display: block;
margin: 16px 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, Inject, ViewEncapsulation } from "@angular/core";
import { FormControl } from "@angular/forms";
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog";
import { StarkPromptDialogContent } from "./prompt-dialog-content.intf";

export type StarkPromptDialogResult = string | "cancel" | undefined;

@Component({
selector: "stark-prompt-dialog",
templateUrl: "./prompt-dialog.component.html",
encapsulation: ViewEncapsulation.None,
// We need to use host instead of @HostBinding: https://github.com/NationalBankBelgium/stark/issues/664
host: {
class: "stark-prompt-dialog"
}
})
export class StarkPromptDialogComponent {
public formControl: FormControl;

public constructor(
public dialogRef: MatDialogRef<StarkPromptDialogComponent, StarkPromptDialogResult>,
@Inject(MAT_DIALOG_DATA) public content: StarkPromptDialogContent
) {
this.formControl = new FormControl(this.content.initialValue);
}

public onCancel(): void {
this.dialogRef.close("cancel");
}

public onOk(): void {
this.dialogRef.close(this.formControl.value);
}
}
15 changes: 15 additions & 0 deletions packages/stark-ui/src/modules/dialogs/dialogs.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NgModule } from "@angular/core";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { MatButtonModule } from "@angular/material/button";
import { MatDialogModule } from "@angular/material/dialog";
import { TranslateModule } from "@ngx-translate/core";
import { StarkAlertDialogComponent, StarkConfirmDialogComponent, StarkPromptDialogComponent } from "./components";
import { MatInputModule } from "@angular/material/input";

@NgModule({
declarations: [StarkAlertDialogComponent, StarkConfirmDialogComponent, StarkPromptDialogComponent],
imports: [FormsModule, ReactiveFormsModule, MatButtonModule, MatDialogModule, MatInputModule, TranslateModule],
exports: [StarkAlertDialogComponent, StarkConfirmDialogComponent, StarkPromptDialogComponent],
entryComponents: [StarkAlertDialogComponent, StarkConfirmDialogComponent, StarkPromptDialogComponent]
})
export class StarkDialogsModule {}
7 changes: 7 additions & 0 deletions showcase/src/app/app-menu.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export const APP_MENU_CONFIG: StarkMenuConfig = {
isEnabled: true,
targetState: "demo-ui.date-range-picker"
},
{
id: "menu-stark-ui-components-dialogs",
label: "SHOWCASE.DEMO.DIALOGS.TITLE",
isVisible: true,
isEnabled: true,
targetState: "demo-ui.dialogs"
},
{
id: "menu-stark-ui-components-dropdown",
label: "SHOWCASE.DEMO.DROPDOWN.TITLE",
Expand Down
9 changes: 7 additions & 2 deletions showcase/src/app/demo-ui/demo-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
StarkCollapsibleModule,
StarkDatePickerModule,
StarkDateRangePickerModule,
StarkDialogsModule,
StarkDropdownModule,
StarkGenericSearchModule,
StarkInputMaskDirectivesModule,
Expand All @@ -51,6 +52,7 @@ import {
DemoCollapsiblePageComponent,
DemoDatePickerPageComponent,
DemoDateRangePickerPageComponent,
DemoDialogsPageComponent,
DemoDropdownPageComponent,
DemoFooterPageComponent,
DemoGenericSearchFormComponent,
Expand Down Expand Up @@ -80,10 +82,10 @@ import {
TableRegularComponent,
TableWithCustomActionsComponent,
TableWithCustomStylingComponent,
TableWithFixedActionsComponent,
TableWithFixedHeaderComponent,
TableWithSelectionComponent,
TableWithTranscludedActionBarComponent,
TableWithFixedActionsComponent
TableWithTranscludedActionBarComponent
} from "./components";

@NgModule({
Expand Down Expand Up @@ -119,6 +121,7 @@ import {
StarkCollapsibleModule,
StarkDatePickerModule,
StarkDateRangePickerModule,
StarkDialogsModule,
StarkDropdownModule,
StarkGenericSearchModule,
StarkInputMaskDirectivesModule,
Expand All @@ -142,6 +145,7 @@ import {
DemoCollapsiblePageComponent,
DemoDatePickerPageComponent,
DemoDateRangePickerPageComponent,
DemoDialogsPageComponent,
DemoDropdownPageComponent,
DemoFooterPageComponent,
DemoGenericSearchPageComponent,
Expand Down Expand Up @@ -177,6 +181,7 @@ import {
DemoCollapsiblePageComponent,
DemoDatePickerPageComponent,
DemoDateRangePickerPageComponent,
DemoDialogsPageComponent,
DemoDropdownPageComponent,
DemoFooterPageComponent,
DemoGenericSearchPageComponent,
Expand Down
24 changes: 24 additions & 0 deletions showcase/src/app/demo-ui/pages/dialogs/dialogs-page.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<h1 class="mat-display-3" translate>SHOWCASE.DEMO.DIALOGS.TITLE</h1>
<section class="stark-section">
<h1 translate>SHOWCASE.DEMO.SHARED.EXAMPLE_VIEWER_LIST</h1>
<example-viewer
[extensions]="['HTML', 'TS']"
filesPath="dialogs/predefined-dialogs"
exampleTitle="SHOWCASE.DEMO.DIALOGS.PREDEFINED_DIALOGS"
>
<div class="dialog-demo-content">
<button mat-raised-button color="alert" (click)="showAlert()">{{ "SHOWCASE.DEMO.DIALOGS.ALERT_DIALOG" | translate }}</button>
<button mat-raised-button color="primary" (click)="showConfirm()">
{{ "SHOWCASE.DEMO.DIALOGS.CONFIRM_DIALOG" | translate }}
</button>
<button mat-stroked-button color="primary" (click)="showPrompt()">
{{ "SHOWCASE.DEMO.DIALOGS.PROMPT_DIALOG" | translate }}
</button>
</div>

<div *ngIf="dialogStatus" class="demo-prompt-dialog-status">
<b>{{ dialogStatus | translate: { result: dialogResult } }}</b>
</div>
</example-viewer>
</section>
<stark-reference-block [links]="referenceList"></stark-reference-block>
16 changes: 16 additions & 0 deletions showcase/src/app/demo-ui/pages/dialogs/dialogs-page.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.dialog-demo-content {
//display: flex;
//flex-direction: row;
//justify-content: space-between;
display: block;
text-align: center;

button {
margin: 10px;
}
}

.demo-prompt-dialog-status {
text-align: center;
padding: 16px 0;
}
Loading

0 comments on commit 99f5864

Please sign in to comment.