Skip to content

docs(demos): add dialog demos #5666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/lib/dialog/dialog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The `MdDialog` service can be used to open modal dialogs with Material Design styling and
animations.

<!-- example(dialog-overview) -->
<!-- example(dialog-basic) -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be dialog-overview?

I think we should probably get rid of this "dialog-basic" example because it is too basic; it doesn't really show anything. The first example really needs to showcase the component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Moved the first demo to the complex overview example.


A dialog is opened by calling the `open` method with a component to be loaded and an optional
config object. The `open` method will return an instance of `MdDialogRef`:
Expand Down Expand Up @@ -45,25 +45,27 @@ If you want to share data with your dialog, you can use the `data` option to pas

```ts
let dialogRef = dialog.open(YourDialog, {
data: 'your data',
data: { name: 'austin' },
});
```

To access the data in your dialog component, you have to use the MD_DIALOG_DATA injection token:

```ts
import {Component, Inject} from '@angular/core';
import {MD_DIALOG_DATA} from '@angular/material';

@Component({
selector: 'your-dialog',
template: 'passed in {{ data }}',
template: 'passed in {{ data.name }}',
})

export class YourDialog {
constructor(@Inject(MD_DIALOG_DATA) public data: any) { }
}
```

<!-- example(dialog-data) -->

### Dialog content
Several directives are available to make it easier to structure your dialog content:

Expand Down Expand Up @@ -93,6 +95,8 @@ You can control which elements are tab stops with the `tabindex` attribute
<button md-button tabindex="-1">Not Tabbable</button>
```

<!-- example(dialog-content) -->

### AOT Compilation

Due to the dynamic nature of the `MdDialog`, and its usage of `ViewContainerRef#createComponent()`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p> Hi, I'm a dialog! </p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button md-button (click)="openDialog()">Open dialog</button>
23 changes: 23 additions & 0 deletions src/material-examples/dialog-basic/dialog-basic-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Component} from '@angular/core';
import {MdDialog} from '@angular/material';

/**
* @title Basic Dialog
*/
@Component({
selector: 'dialog-basic-example',
templateUrl: 'dialog-basic-example.html',
})
export class DialogBasicExample {
constructor(private dialog: MdDialog) {}

openDialog() {
this.dialog.open(DialogBasicExampleDialog);
}
}

@Component({
selector: 'dialog-basic-example-dialog',
templateUrl: 'dialog-basic-example-dialog.html',
})
export class DialogBasicExampleDialog {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h2 md-dialog-title>Delete all</h2>
<md-dialog-content>Are you sure?</md-dialog-content>
<md-dialog-actions>
<button md-button tabindex="-1">Not Tabbable</button>
<button md-button [md-dialog-close]="true" tabindex="1">Yes</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more realistic example for this case would be to have an input and have the md-dialog-close pass the input value back to the afterClosed.

Copy link
Contributor Author

@amcdnl amcdnl Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crisbeto - I have this demo in the overview, do you think we need to do it here too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I must've missed the one below.

<button md-button md-dialog-close tabindex="2">No</button>
</md-dialog-actions>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button md-button (click)="openDialog()">Open dialog</button>
26 changes: 26 additions & 0 deletions src/material-examples/dialog-content/dialog-content-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Component} from '@angular/core';
import {MdDialog} from '@angular/material';

/**
* @title Dialog Content
*/
@Component({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Dialog content" by itself doesn't really communicate what this example is for. It should be something like
"Dialog with header, scrollable content, and actions". The content should be long enough to cause scrolling and wide enough that the actions are aligned to either the right or left of the dialog.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed the scrolling and title, can you expand on what you had in mind for the button alignment?

selector: 'dialog-content-example',
templateUrl: 'dialog-content-example.html',
})
export class DialogContentExample {
constructor(public dialog: MdDialog) {}

openDialog() {
const dialogRef = this.dialog.open(DialogContentExampleDialog);
dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`);
});
}
}

@Component({
selector: 'dialog-content-example-dialog',
templateUrl: 'dialog-content-example-dialog.html',
})
export class DialogContentExampleDialog {}
15 changes: 15 additions & 0 deletions src/material-examples/dialog-data/dialog-data-example-dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1 md-dialog-title>Favorite Animal</h1>
<div md-dialog-content>
My favorite animal is:
<ul>
<li>
<span *ngIf="data.animal === 'panda'">&#10003;</span> Panda
</li>
<li>
<span *ngIf="data.animal === 'unicorn'">&#10003;</span> Unicorn
</li>
<li>
<span *ngIf="data.animal === 'lion'">&#10003;</span> Lion
</li>
</ul>
</div>
1 change: 1 addition & 0 deletions src/material-examples/dialog-data/dialog-data-example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No CSS for this example */
1 change: 1 addition & 0 deletions src/material-examples/dialog-data/dialog-data-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button md-button (click)="openDialog()">Open dialog</button>
29 changes: 29 additions & 0 deletions src/material-examples/dialog-data/dialog-data-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {Component, Inject} from '@angular/core';
import {MdDialog, MD_DIALOG_DATA} from '@angular/material';

/**
* @title Dialog Data Sharing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this "Injecting data when opening a dialog"

*/
@Component({
selector: 'dialog-data-example',
templateUrl: 'dialog-data-example.html',
})
export class DialogDataExample {
constructor(public dialog: MdDialog) {}

openDialog() {
this.dialog.open(DialogDataExampleDialog, {
data: {
animal: 'panda'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data should come from an <input> next to the dialog open button, to demonstrate the value coming from the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our conversation, we discussed using the example of the overview to demonstrate this and keeping this demo basic.

}
});
}
}

@Component({
selector: 'dialog-data-example-dialog',
templateUrl: 'dialog-data-example-dialog.html',
})
export class DialogDataExampleDialog {
constructor(@Inject(MD_DIALOG_DATA) public data: any) {}
}
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<p> Hi, I'm a dialog! </p>
<h1 md-dialog-title>Hi {{data.name}}</h1>
<div md-dialog-content>
<p>What's your favorite animal?</p>
<md-input-container>
<input mdInput tabindex="1" [(ngModel)]="data.animal">
</md-input-container>
</div>
<div md-dialog-actions>
<button md-button [md-dialog-close]="data.animal" tabindex="2">Ok</button>
<button md-button (click)="onNoClick()" tabindex="-1">No Thanks</button>
</div>
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
<button md-button (click)="openDialog()">Open dialog</button>
<ol>
<li>
<md-input-container>
<input mdInput [(ngModel)]="name" placeholder="What's your name?">
</md-input-container>
</li>
<li>
<button md-raised-button (click)="openDialog()">Pick one</button>
</li>
<li *ngIf="animal">
You chose: <i>{{animal}}</i>
</li>
</ol>
36 changes: 29 additions & 7 deletions src/material-examples/dialog-overview/dialog-overview-example.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import {Component} from '@angular/core';
import {MdDialog} from '@angular/material';
import {Component, Inject} from '@angular/core';
import {MdDialog, MdDialogRef, MD_DIALOG_DATA} from '@angular/material';

/**
* @title Dialog Overview
*/
@Component({
selector: 'dialog-overview-example',
templateUrl: 'dialog-overview-example.html',
templateUrl: 'dialog-overview-example.html'
})
export class DialogOverviewExample {

animal: string;
name: string;

constructor(public dialog: MdDialog) {}

openDialog() {
this.dialog.open(DialogOverviewExampleDialog);
openDialog(): void {
let dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: { name: this.name, animal: this.animal }
});

dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
}

}

@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog {}
export class DialogOverviewExampleDialog {

constructor(
public dialogRef: MdDialogRef<DialogOverviewExampleDialog>,
@Inject(MD_DIALOG_DATA) public data: any) { }

onNoClick(): void {
this.dialogRef.close();
}

}

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions src/material-examples/dialog-result/dialog-result-example.ts

This file was deleted.

32 changes: 24 additions & 8 deletions src/material-examples/example-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import {DatepickerMinMaxExample} from './datepicker-min-max/datepicker-min-max-e
import {DatepickerOverviewExample} from './datepicker-overview/datepicker-overview-example';
import {DatepickerStartViewExample} from './datepicker-start-view/datepicker-start-view-example';
import {DatepickerTouchExample} from './datepicker-touch/datepicker-touch-example';
import {DialogBasicExampleDialog,DialogBasicExample} from './dialog-basic/dialog-basic-example';
import {DialogContentExampleDialog,DialogContentExample} from './dialog-content/dialog-content-example';
import {DialogDataExampleDialog,DialogDataExample} from './dialog-data/dialog-data-example';
import {DialogElementsExampleDialog,DialogElementsExample} from './dialog-elements/dialog-elements-example';
import {DialogOverviewExampleDialog,DialogOverviewExample} from './dialog-overview/dialog-overview-example';
import {DialogResultExampleDialog,DialogResultExample} from './dialog-result/dialog-result-example';
import {GridListDynamicExample} from './grid-list-dynamic/grid-list-dynamic-example';
import {GridListOverviewExample} from './grid-list-overview/grid-list-overview-example';
import {IconOverviewExample} from './icon-overview/icon-overview-example';
Expand Down Expand Up @@ -189,6 +191,24 @@ export const EXAMPLE_COMPONENTS = {
additionalFiles: null,
selectorName: null
},
'dialog-basic': {
title: 'Basic Dialog',
component: DialogBasicExample,
additionalFiles: ["dialog-basic-example-dialog.html"],
selectorName: 'DialogBasicExample, DialogBasicExampleDialog'
},
'dialog-content': {
title: 'Dialog Content',
component: DialogContentExample,
additionalFiles: ["dialog-content-example-dialog.html"],
selectorName: 'DialogContentExample, DialogContentExampleDialog'
},
'dialog-data': {
title: 'Dialog Data Sharing',
component: DialogDataExample,
additionalFiles: ["dialog-data-example-dialog.html"],
selectorName: 'DialogDataExample, DialogDataExampleDialog'
},
'dialog-elements': {
title: 'Dialog elements',
component: DialogElementsExample,
Expand All @@ -201,12 +221,6 @@ export const EXAMPLE_COMPONENTS = {
additionalFiles: ["dialog-overview-example-dialog.html"],
selectorName: 'DialogOverviewExample, DialogOverviewExampleDialog'
},
'dialog-result': {
title: 'Dialog with a result',
component: DialogResultExample,
additionalFiles: ["dialog-result-example-dialog.html"],
selectorName: 'DialogResultExample, DialogResultExampleDialog'
},
'grid-list-dynamic': {
title: 'Dynamic grid-list',
component: GridListDynamicExample,
Expand Down Expand Up @@ -498,9 +512,11 @@ export const EXAMPLE_LIST = [
DatepickerOverviewExample,
DatepickerStartViewExample,
DatepickerTouchExample,
DialogBasicExampleDialog,DialogBasicExample,
DialogContentExampleDialog,DialogContentExample,
DialogDataExampleDialog,DialogDataExample,
DialogElementsExampleDialog,DialogElementsExample,
DialogOverviewExampleDialog,DialogOverviewExample,
DialogResultExampleDialog,DialogResultExample,
GridListDynamicExample,
GridListOverviewExample,
IconOverviewExample,
Expand Down
4 changes: 2 additions & 2 deletions src/material-examples/material-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import {
MdSliderModule,
MdSidenavModule,
MdSnackBarModule,
MdTableModule,
MdTabsModule,
MdToolbarModule,
MdTooltipModule,
MdPaginatorModule,
MdSortModule
MdSortModule,
MdTableModule
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this adds MdTableModule for a second time (it's already defined on line 39).

]
})
export class ExampleMaterialModule {}