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

Commit

Permalink
feat(toast): add ability to specify theme for simple preset
Browse files Browse the repository at this point in the history
closes #955
  • Loading branch information
rschmukler committed Feb 8, 2015
1 parent c97f48b commit 2fef220
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/components/dialog/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ 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 @@ -259,20 +258,20 @@ function MdDialogProvider($$interimElementProvider) {

return $$interimElementProvider('$mdDialog')
.setDefaults({
methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent', 'theme'],
methods: ['disableParentScroll', 'hasBackdrop', 'clickOutsideToClose', 'escapeToClose', 'targetEvent'],
options: dialogDefaultOptions
})
.addPreset('alert', {
methods: ['title', 'content', 'ariaLabel', 'ok'],
methods: ['title', 'content', 'ariaLabel', 'ok', 'theme'],
options: advancedDialogOptions
})
.addPreset('confirm', {
methods: ['title', 'content', 'ariaLabel', 'ok', 'cancel'],
methods: ['title', 'content', 'ariaLabel', 'ok', 'cancel', 'theme'],
options: advancedDialogOptions
});

/* @ngInject */
function advancedDialogOptions($mdDialog) {
function advancedDialogOptions($mdDialog, $mdTheming) {
return {
template: [
'<md-dialog md-theme="{{ dialog.theme }}" aria-label="{{ dialog.ariaLabel }}">',
Expand All @@ -299,15 +298,15 @@ function MdDialogProvider($$interimElementProvider) {
};
},
controllerAs: 'dialog',
bindToController: true
bindToController: true,
theme: $mdTheming.defaultTheme()
};
}

/* @ngInject */
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
10 changes: 6 additions & 4 deletions src/components/toast/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function MdToastDirective() {
* - $mdToastPreset#action(string) - adds an action button, which resolves the promise returned from `show()` if clicked.
* - $mdToastPreset#highlightAction(boolean) - sets action button to be highlighted
* - $mdToastPreset#capsule(boolean) - adds 'md-capsule' class to the toast (curved corners)
* - $mdToastPreset#theme(boolean) - sets the theme on the toast to theme (default is `$mdThemingProvider`'s default theme)
*/

/**
Expand Down Expand Up @@ -173,11 +174,11 @@ function MdToastProvider($$interimElementProvider) {
})
.addPreset('simple', {
argOption: 'content',
methods: ['content', 'action', 'highlightAction'],
options: /* @ngInject */ function($mdToast) {
methods: ['content', 'action', 'highlightAction', 'theme'],
options: /* @ngInject */ function($mdToast, $mdTheming) {
return {
template: [
'<md-toast ng-class="{\'md-capsule\': toast.capsule}">',
'<md-toast md-theme="{{ toast.theme }}" ng-class="{\'md-capsule\': toast.capsule}">',
'<span flex>{{ toast.content }}</span>',
'<md-button class="md-action" ng-if="toast.action" ng-click="toast.resolve()" ng-class="{\'md-highlight\': toast.highlightAction}">',
'{{ toast.action }}',
Expand All @@ -193,6 +194,7 @@ function MdToastProvider($$interimElementProvider) {
$mdToast.hide();
};
},
theme: $mdTheming.defaultTheme(),
controllerAs: 'toast',
bindToController: true
};
Expand All @@ -205,7 +207,7 @@ function MdToastProvider($$interimElementProvider) {
return $mdToast;

/* @ngInject */
function toastDefaultOptions($timeout, $animate, $mdTheming, $mdToast) {
function toastDefaultOptions($timeout, $animate, $mdToast) {
return {
onShow: onShow,
onRemove: onRemove,
Expand Down
4 changes: 3 additions & 1 deletion src/components/toast/toast.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('$mdToast service', function() {
}

describe('simple()', function() {
hasConfigMethods(['content', 'action', 'capsule', 'highlightAction']);
hasConfigMethods(['content', 'action', 'capsule', 'highlightAction', 'theme']);

it('supports a basic toast', inject(function($mdToast, $rootScope, $timeout, $animate) {
var rejected = false;
Expand All @@ -21,6 +21,7 @@ describe('$mdToast service', function() {
$mdToast.simple({
parent: parent,
content: 'Do something',
theme: 'some-theme',
capsule: true
})
).catch(function() {
Expand All @@ -29,6 +30,7 @@ describe('$mdToast service', function() {
$rootScope.$digest();
expect(parent.find('span').text()).toBe('Do something');
expect(parent.find('md-toast')).toHaveClass('md-capsule');
expect(parent.find('md-toast').attr('md-theme')).toBe('some-theme');
$animate.triggerCallbacks();
$timeout.flush();
$animate.triggerCallbacks();
Expand Down

0 comments on commit 2fef220

Please sign in to comment.