Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
feat(dialog): support basic alert and confirm dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
justindujardin committed Dec 25, 2015
1 parent 72e8381 commit 7236279
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 233 deletions.
2 changes: 2 additions & 0 deletions examples/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import CardBasicUsage from './components/card/basic_usage';
import CardInlineActions from './components/card/inline_actions';
import ButtonBasicUsage from './components/button/basic_usage';
import CardActionButtons from './components/card/action_buttons';
import DialogBasicUsage from './components/dialog/basic_usage';
import ToolbarBasicUsage from './components/toolbar/basic_usage';
import ToolbarScrollShrink from './components/toolbar/scroll_shrink';
import ProgressLinearBasicUsage from './components/progress_linear/basic_usage';
Expand All @@ -21,6 +22,7 @@ import TabsDynamicTabs from './components/tabs/dynamic_tabs';
export const DEMO_DIRECTIVES: Type[] = CONST_EXPR([
CardBasicUsage, CardInlineActions, CardActionButtons,
ButtonBasicUsage,
DialogBasicUsage,
RadioBasicUsage,
SwitchBasicUsage,
TabsDynamicHeight,
Expand Down
33 changes: 33 additions & 0 deletions examples/components/dialog/basic_usage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="md-padding" id="popupContainer">
<p class="inset">
Open a dialog over the app's content. Press escape or click outside to close the dialog and
send focus back to the triggering button.
</p>

<div class="dialog-demo-content" layout="row" layout-wrap layout-margin>
<button md-raised-button class="md-primary" (click)="showAlert($event)" flex="100" flex-gt-md="auto">
Alert Dialog
</button>
<button md-raised-button class="md-primary" (click)="showConfirm($event)" flex="100" flex-gt-md="auto">
Confirm Dialog
</button>
<button md-raised-button class="md-primary" (click)="showAdvanced($event)" flex="100" flex-gt-md="auto">
Custom Dialog
</button>
<div hide-gt-sm layout="row" layout-align="center center" flex="100">
<md-checkbox [(checked)]="customFullscreen" aria-label="Fullscreen Custom Dialog">Custom Dialog Fullscreen</md-checkbox>
</div>
<button md-raised-button class="md-primary" (click)="showTabDialog($event)" flex="100" flex-gt-md="auto">
Tab Dialog
</button>
</div>
<p class="footer">Note: The <b>Confirm</b> dialog does not use <code>config.clickOutsideToClose(true)</code>.</p>

<div *ngIf="status">
<br/>
<b layout="row" layout-align="center center" class="md-padding">
{{status}}
</b>
</div>

</div>
14 changes: 14 additions & 0 deletions examples/components/dialog/basic_usage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#popupContainer {
position:relative;
}

.footer {
width:100%;
text-align: center;
margin-left:20px;
}
.footer, .footer > code {
font-size: 0.8em;
margin-top:50px;
}

117 changes: 117 additions & 0 deletions examples/components/dialog/basic_usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {View, Component} from 'angular2/core';
import {MATERIAL_DIRECTIVES,MdDialog} from 'ng2-material/all';
import {ElementRef} from "angular2/core";
import {Input} from "angular2/core";
import {DOM} from "angular2/src/platform/dom/dom_adapter";
import {MdDialogConfig} from "ng2-material/components/dialog/dialog_config";
import {MdDialogBasic} from "ng2-material/components/dialog/dialog_basic";
import {MdDialogRef} from "ng2-material/components/dialog/dialog_ref";


function hasMedia(size: string) {
// TODO: Implement as $mdMedia
return true;
}

@Component({selector: 'dialog-basic-usage'})
@View({
templateUrl: 'examples/components/dialog/basic_usage.html',
styleUrls: ['examples/components/dialog/basic_usage.css'],
directives: [MATERIAL_DIRECTIVES]
})
export default class DialogBasicUsage {

status = ' ';
customFullscreen = hasMedia('xs') || hasMedia('sm');

constructor(public dialog: MdDialog, public element: ElementRef) {

}

showAlert(ev) {
let config = new MdDialogConfig()
.parent(DOM.query('#popupContainer'))
.textContent('You can specify some description text in here')
.title('This is an alert title')
.ok('Got it!')
.targetEvent(ev);
this.dialog.open(MdDialogBasic, this.element, config);
//// Appending dialog to document.body to cover sidenav in docs app
//// Modal dialogs should fully cover application
//// to prevent interaction outside of dialog
//this.dialog.show(
// this.dialog.alert()
// .parent(angular.element(document.querySelector('#popupContainer')))
// .clickOutsideToClose(true)
// .title('This is an alert title')
// .textContent('You can specify some description text in here.')
// .ariaLabel('Alert Dialog Demo')
// .ok('Got it!')
// .targetEvent(ev)
//);
};

showConfirm(ev) {
let config = new MdDialogConfig()
.textContent('All of the banks have agreed to forgive you your debts.')
.clickOutsideToClose(false)
.title('Would you like to delete your debt?')
.ariaLabel('Lucky day')
.ok('Please do it!')
.cancel('Sounds like a scam')
.targetEvent(ev);
this.dialog
.open(MdDialogBasic, this.element, config)
.then((ref: MdDialogRef) => {
ref.whenClosed.then((result) => {
if (result) {
this.status = 'You decided to get rid of your debt.';
}
else {
this.status = 'You decided to keep your debt.';
}
})
});
};

showAdvanced(ev) {
//var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && this.customFullscreen;
//
//this.dialog.show({
// controller: DialogController,
// templateUrl: 'dialog1.tmpl.html',
// parent: angular.element(document.body),
// targetEvent: ev,
// clickOutsideToClose: true,
// fullscreen: useFullScreen
// })
// .then((answer) => {
// $scope.status = 'You said the information was "' + answer + '".';
// }, () =>{
// $scope.status = 'You cancelled the dialog.';
// });
//
//
//$scope.$watch(() =>{
// return $mdMedia('xs') || $mdMedia('sm');
//}, (wantsFullScreen) => {
// this.customFullscreen = (wantsFullScreen === true);
//});

};

showTabDialog(ev) {
//this.dialog.show({
// controller: DialogController,
// templateUrl: 'tabDialog.tmpl.html',
// parent: angular.element(document.body),
// targetEvent: ev,
// clickOutsideToClose: true
// })
// .then((answer) => {
// this.status = 'You said the information was "' + answer + '".';
// }, () =>{
// this.status = 'You cancelled the dialog.';
// });
};
}
1 change: 1 addition & 0 deletions ng2-material/all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import "core/style/default-theme";


@import "components/backdrop/backdrop";
@import "components/button/button";
@import "components/card/card";
@import "components/content/content";
Expand Down
2 changes: 2 additions & 0 deletions ng2-material/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {MdContent} from './components/content/content';
export * from './components/content/content';

export * from './components/dialog/dialog';
import {MdDialog} from './components/dialog/dialog';

import {MdDivider} from './components/divider/divider';
export * from './components/divider/divider';
Expand Down Expand Up @@ -109,6 +110,7 @@ export class MaterialTemplateResolver extends UrlResolver {
* Collection of Material Design component providers.
*/
export const MATERIAL_PROVIDERS: any[] = [
MdDialog,
MdRadioDispatcher,
provide(UrlResolver, {useValue: new MaterialTemplateResolver()})
];
94 changes: 79 additions & 15 deletions ng2-material/components/dialog/dialog.scss
Original file line number Diff line number Diff line change
@@ -1,27 +1,91 @@
@import "../../core/style/variables";
@import "../../core/style/shadows";
@import "../../core/style/default-theme";

.md-dialog {
position: absolute;
position: fixed;
z-index: 80;

/** Center the dialog. */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 300px;
min-height: 100px;

padding: $baseline-grid * 3;

box-shadow: $whiteframe-shadow-13dp;
display: flex;
flex-direction: column;

opacity: 0;
transition: $swift-ease-out;
transform: translate3d(-50%, -50%, 0) scale(0.2);

order: 1;
overflow: auto;
-webkit-overflow-scrolling: touch;

&:not([layout=row]) > * > *:first-child:not(.md-subheader) {
margin-top: 0;
}

&:focus {
outline: none;
}

&.md-active {
opacity: 1;
transition: $swift-ease-out;
transform: translate3d(-50%, -50%, 0) scale(1.0);
}

&.md-dialog-absolute {
position: absolute;
}

width: 300px;
height: 300px;
.md-actions, md-dialog-actions {
display: flex;
order: 2;
box-sizing: border-box;
align-items: center;
justify-content: flex-end;
padding-top: $baseline-grid * 3;
padding-right: $baseline-grid;
padding-left: $baseline-grid * 2;

background-color: white;
border: 1px solid black;
box-shadow: 0 4px 4px;;
// Align md-actions outside of the padding of .md-dialog
margin-bottom: -$baseline-grid * 3;
margin-left: -$baseline-grid * 3;
margin-right: -$baseline-grid * 3;

right: -$baseline-grid * 3;
min-height: $baseline-grid * 6.5;
overflow: hidden;

[md-button], [md-raised-button] {
margin-bottom: $baseline-grid;
margin-left: $baseline-grid;
margin-right: 0;
margin-top: $baseline-grid;
}
}

padding: 20px;
}

.md-backdrop {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.12);
// Theme

$dialog-border-radius: 4px !default;

.md-dialog {
border-radius: $dialog-border-radius;
background-color: md-color($md-background, lighter); //'{{background-color}}';

&.md-content-overflow {
.md-actions, md-dialog-actions {
border-top-color: md-color($md-foreground, divider); //'{{foreground-4}}';
}
}
}


Loading

0 comments on commit 7236279

Please sign in to comment.