Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat(dialog): add ability to specify theme on alert and confirm presets
Browse files Browse the repository at this point in the history
references #955
  • Loading branch information
rschmukler committed Feb 8, 2015
1 parent 89e7cb0 commit c97f48b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function MdDialogDirective($$rAF, $mdTheming) {
* - $mdDialogPreset#title(string) - sets title to string
* - $mdDialogPreset#content(string) - sets content / message to string
* - $mdDialogPreset#ok(string) - sets okay button text to string
* - $mdDialogPreset#theme(string) - sets the theme of the dialog
*
*/

Expand All @@ -185,6 +186,7 @@ function MdDialogDirective($$rAF, $mdTheming) {
* - $mdDialogPreset#content(string) - sets content / message to string
* - $mdDialogPreset#ok(string) - sets okay button text to string
* - $mdDialogPreset#cancel(string) - sets cancel button text to string
* - $mdDialogPreset#theme(string) - sets the theme of the dialog
*
*/

Expand Down Expand Up @@ -225,6 +227,7 @@ function MdDialogDirective($$rAF, $mdTheming) {
* to the root element of the application.
* - `onComplete` `{function=}`: Callback function used to announce when the show() action is
* finished.
* - `theme` `{string=}`: Theme to be applied to the dialog, when using a `$mdDialogPreset`.
*
* @returns {promise} A promise that can be resolved with `$mdDialog.hide()` or
* rejected with `$mdDialog.cancel()`.
Expand Down Expand Up @@ -256,7 +259,7 @@ function MdDialogProvider($$interimElementProvider) {

return $$interimElementProvider('$mdDialog')
.setDefaults({
methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent'],
methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent', 'theme'],
options: dialogDefaultOptions
})
.addPreset('alert', {
Expand All @@ -272,7 +275,7 @@ function MdDialogProvider($$interimElementProvider) {
function advancedDialogOptions($mdDialog) {
return {
template: [
'<md-dialog aria-label="{{ dialog.ariaLabel }}">',
'<md-dialog md-theme="{{ dialog.theme }}" aria-label="{{ dialog.ariaLabel }}">',
'<md-content>',
'<h2>{{ dialog.title }}</h2>',
'<p>{{ dialog.content }}</p>',
Expand Down Expand Up @@ -304,6 +307,7 @@ function MdDialogProvider($$interimElementProvider) {
function dialogDefaultOptions($timeout, $rootElement, $compile, $animate, $mdAria, $document,
$mdUtil, $mdConstant, $mdTheming, $$rAF, $q, $mdDialog) {
return {
theme: $mdTheming.defaultTheme(),
hasBackdrop: true,
isolateScope: true,
onShow: onShow,
Expand Down
9 changes: 7 additions & 2 deletions src/components/dialog/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('$mdDialog', function() {
describe('#alert()', function() {
hasConfigurationMethods('alert', [
'title', 'content', 'ariaLabel',
'ok', 'targetEvent'
'ok', 'targetEvent', 'theme'
]);

it('shows a basic alert dialog', inject(function($animate, $rootScope, $mdDialog, $mdConstant) {
Expand All @@ -28,6 +28,7 @@ describe('$mdDialog', function() {
})
.title('Title')
.content('Hello world')
.theme('some-theme')
.ok('Next')
).then(function() {
resolved = true;
Expand All @@ -45,6 +46,10 @@ describe('$mdDialog', function() {
var buttons = parent.find('md-button');
expect(buttons.length).toBe(1);
expect(buttons.eq(0).text()).toBe('Next');
var theme = parent.find('md-dialog').attr('md-theme');
expect(theme).toBe('some-theme');


buttons.eq(0).triggerHandler('click');
$rootScope.$apply();
parent.find('md-dialog').triggerHandler('transitionend');
Expand All @@ -57,7 +62,7 @@ describe('$mdDialog', function() {
describe('#confirm()', function() {
hasConfigurationMethods('confirm', [
'title', 'content', 'ariaLabel',
'ok', 'cancel', 'targetEvent'
'ok', 'cancel', 'targetEvent', 'theme'
]);

it('shows a basic confirm dialog', inject(function($rootScope, $mdDialog, $animate, $mdConstant) {
Expand Down
3 changes: 3 additions & 0 deletions src/core/services/theming/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ function ThemingProvider($mdColorPalette) {
};

applyTheme.registered = registered;
applyTheme.defaultTheme = function() {
return defaultTheme;
};

return applyTheme;

Expand Down
4 changes: 4 additions & 0 deletions src/core/services/theming/theming.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ describe('$mdTheming service', function() {
expect(child.hasClass('md-dark-theme')).toBe(false);
expect(child.hasClass('md-space-theme')).toBe(true);
}));

it('exposes a getter for the default theme', inject(function($mdTheming) {
expect($mdTheming.defaultTheme()).toBe('default');
}));
});

describe('md-theme directive', function() {
Expand Down

0 comments on commit c97f48b

Please sign in to comment.