Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit af40e25

Browse files
dansandersonThomasBurleson
authored andcommitted
fix(toast): Updated toast styles, added rtl features, added custom demo
* Also adds test for md-toast-text class in simple toast Fixes #6649, #breaking Closes #7099
1 parent 658bc2b commit af40e25

File tree

11 files changed

+112
-40
lines changed

11 files changed

+112
-40
lines changed

src/components/button/button.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ $button-fab-border-radius: 50% !default;
33
$button-icon-border-radius: $button-fab-border-radius;
44

55
$button-line-height: rem(3.60) !default;
6-
$button-padding: 0 rem(0.600) !default;
76
$button-margin: rem(0.600) rem(0.800) !default;
87
$button-min-width: rem(8.800) !default;
8+
$button-padding: 0 $button-left-right-padding !default;
9+
910

1011
// Fab buttons
1112
$button-fab-line-height: rem(5.600) !default;

src/components/toast/demoBasicUsage/index.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
<div ng-controller="AppCtrl" layout-fill layout="column" class="inset" ng-cloak>
1+
<div ng-controller="AppCtrl" layout-fill layout="column" class="inset" ng-cloak paddi>
22
<p>
33
Toast can be dismissed with a swipe, a timer, or a button.<br/>
4-
<span style="font-size:0.8em">Notice the 'Show Custom' toast will not nudge the FABs positions since a custom parent was specified.</span>
54
</p>
65

76

8-
<div layout="row" layout-sm="column" layout-align="space-around">
7+
<div layout="row" layout-align="space-around">
98
<div style="width:50px"></div>
109
<md-button ng-click="showSimpleToast()">
1110
Show Simple
1211
</md-button>
1312
<md-button class="md-raised" ng-click="showActionToast()">
1413
Show With Action
1514
</md-button>
16-
<md-button ng-click="showCustomToast()">
17-
Show Custom
18-
</md-button>
1915
<div style="width:50px"></div>
2016
</div>
2117

2218
<div layout="row" id="toastBounds">
2319

2420
<div>
25-
<br/>
26-
<b>Toast Position: "{{getToastPosition()}}"</b>
27-
<br/>
21+
<p><b>Toast Position: "{{getToastPosition()}}"</b></p>
2822
<md-checkbox ng-repeat="(name, isSelected) in toastPosition"
2923
ng-model="toastPosition[name]">
3024
{{name}}

src/components/toast/demoBasicUsage/script.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
angular.module('toastDemo1', ['ngMaterial'])
33

4-
.controller('AppCtrl', function($scope, $mdToast, $document) {
4+
.controller('AppCtrl', function($scope, $mdToast) {
55
var last = {
66
bottom: false,
77
top: true,
@@ -30,31 +30,24 @@ angular.module('toastDemo1', ['ngMaterial'])
3030
last = angular.extend({},current);
3131
}
3232

33-
$scope.showCustomToast = function() {
34-
$mdToast.show({
35-
controller: 'ToastCtrl',
36-
templateUrl: 'toast-template.html',
37-
parent : $document[0].querySelector('#toastBounds'),
38-
hideDelay: 6000,
39-
position: $scope.getToastPosition()
40-
});
41-
};
42-
4333
$scope.showSimpleToast = function() {
34+
var pinTo = $scope.getToastPosition();
35+
4436
$mdToast.show(
4537
$mdToast.simple()
4638
.textContent('Simple Toast!')
47-
.position($scope.getToastPosition())
39+
.position(pinTo )
4840
.hideDelay(3000)
4941
);
5042
};
5143

5244
$scope.showActionToast = function() {
45+
var pinTo = $scope.getToastPosition();
5346
var toast = $mdToast.simple()
5447
.textContent('Action Toast!')
5548
.action('OK')
5649
.highlightAction(false)
57-
.position($scope.getToastPosition());
50+
.position(pinTo);
5851

5952
$mdToast.show(toast).then(function(response) {
6053
if ( response == 'ok' ) {

src/components/toast/demoBasicUsage/toast-template.html

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div ng-controller="AppCtrl" class="inset" ng-cloak style="height:300px; padding: 25px;">
2+
<div layout="row">
3+
4+
<p>
5+
Toast can have multiple actions:
6+
</p>
7+
8+
<md-button ng-click="showCustomToast()" class="md-raised" style="padding-left: 10px;padding-right: 10px;">
9+
Show Custom Toast
10+
</md-button>
11+
12+
</div>
13+
</div>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
(function() {
2+
3+
var isDlgOpen;
4+
5+
angular
6+
.module('toastDemo2', ['ngMaterial'])
7+
.controller('AppCtrl', function($scope, $mdToast) {
8+
$scope.showCustomToast = function() {
9+
$mdToast.show({
10+
hideDelay : 3000,
11+
position : 'top right',
12+
controller : 'ToastCtrl',
13+
templateUrl : 'toast-template.html'
14+
});
15+
};
16+
})
17+
.controller('ToastCtrl', function($scope, $mdToast, $mdDialog) {
18+
19+
$scope.closeToast = function() {
20+
if (isDlgOpen) return;
21+
22+
$mdToast
23+
.hide()
24+
.then(function() {
25+
isDlgOpen = false;
26+
});
27+
};
28+
29+
$scope.openMoreInfo = function(e) {
30+
if ( isDlgOpen ) return;
31+
isDlgOpen = true;
32+
33+
$mdDialog
34+
.show($mdDialog
35+
.alert()
36+
.title('More info goes here.')
37+
.textContent('Something witty.')
38+
.ariaLabel('More info')
39+
.ok('Got it')
40+
.targetEvent(e)
41+
)
42+
.then(function() {
43+
isDlgOpen = false;
44+
})
45+
};
46+
});
47+
48+
})();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<md-toast>
2+
<span class="md-toast-text" flex>Custom toast!</span>
3+
<md-button class="md-highlight" ng-click="openMoreInfo($event)">
4+
More info
5+
</md-button>
6+
<md-button ng-click="closeToast()">
7+
Close
8+
</md-button>
9+
</md-toast>

src/components/toast/toast.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,18 @@ function MdToastProvider($$interimElementProvider) {
228228
var activeToastContent;
229229
var $mdToast = $$interimElementProvider('$mdToast')
230230
.setDefaults({
231-
methods: ['position', 'hideDelay', 'capsule', 'parent' ],
231+
methods: ['position', 'hideDelay', 'capsule', 'parent', 'position' ],
232232
options: toastDefaultOptions
233233
})
234234
.addPreset('simple', {
235235
argOption: 'textContent',
236-
methods: ['textContent', 'content', 'action', 'highlightAction', 'theme', 'parent'],
236+
methods: ['textContent', 'content', 'action', 'highlightAction', 'theme', 'parent' ],
237237
options: /* @ngInject */ function($mdToast, $mdTheming) {
238238
var opts = {
239239
template:
240240
'<md-toast md-theme="{{ toast.theme }}" ng-class="{\'md-capsule\': toast.capsule}">' +
241241
' <div class="md-toast-content">' +
242-
' <span flex role="alert" aria-relevant="all" aria-atomic="true">' +
242+
' <span flex class="md-toast-text" role="alert" aria-relevant="all" aria-atomic="true">' +
243243
' {{ toast.content }}' +
244244
' </span>' +
245245
' <md-button class="md-action" ng-if="toast.action" ng-click="toast.resolve()" ng-class="{\'md-highlight\': toast.highlightAction}">' +
@@ -366,7 +366,8 @@ function MdToastProvider($$interimElementProvider) {
366366
}
367367

368368
function toastOpenClass(position) {
369-
if (!$mdMedia('gt-sm')) {
369+
// For mobile, always open full-width on bottom
370+
if (!$mdMedia('gt-xs')) {
370371
return 'md-toast-open-bottom';
371372
}
372373

src/components/toast/toast.scss

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// See height set globally, depended on by buttons
22

3+
$md-toast-content-padding: 3 * $baseline-grid - $button-left-right-padding;
4+
$md-toast-button-left-margin: 3 * $baseline-grid - 2 * $button-left-right-padding;
5+
$md-toast-text-padding: $button-left-right-padding;
6+
7+
8+
.md-toast-text {
9+
padding: 0 $md-toast-text-padding;
10+
}
11+
312
md-toast {
413
position: absolute;
514
z-index: $z-index-toast;
@@ -23,8 +32,7 @@ md-toast {
2332
max-height: 7 * $toast-height;
2433
max-width: 100%;
2534
min-height: 48px;
26-
padding-left: 24px;
27-
padding-right: 24px;
35+
padding: 0 $md-toast-content-padding;
2836

2937
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
3038
border-radius: 2px;
@@ -35,6 +43,8 @@ md-toast {
3543
// Setup for transform transitions on inner content
3644
transform: translate3d(0, 0, 0) rotateZ(0deg);
3745
transition: $swift-ease-out;
46+
47+
@include rtl(justify-content, flex-start, flex-end);
3848
}
3949

4050
&.md-capsule {
@@ -112,10 +122,12 @@ md-toast {
112122
cursor: pointer;
113123
text-transform: uppercase;
114124
float: right;
125+
}
115126

116-
&.md-button {
117-
min-width: 0;
118-
}
127+
.md-button {
128+
min-width: 0;
129+
@include rtl(margin-right, 0, $md-toast-button-left-margin);
130+
@include rtl(margin-left, $md-toast-button-left-margin, 0);
119131
}
120132
}
121133

src/components/toast/toast.spec.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('$mdToast service', function() {
4444
$material.flushOutstandingAnimations();
4545

4646
expect(parent.find('span').text().trim()).toBe('Do something');
47+
expect(parent.find('span')).toHaveClass('md-toast-text');
4748
expect(parent.find('md-toast')).toHaveClass('md-capsule');
4849
expect(parent.find('md-toast').attr('md-theme')).toBe('some-theme');
4950

@@ -177,8 +178,11 @@ describe('$mdToast service', function() {
177178
$timeout.flush();
178179

179180
expect(toast.children.length).toBe(1);
180-
expect(toast.children[0].classList.contains('md-toast-content'));
181-
expect(toast.children[0].textContent).toMatch('Charmander');
181+
var toastContent = toast.children[0];
182+
var contentSpan = toastContent.children[0];
183+
expect(toastContent.classList.contains('md-toast-content'));
184+
expect(toastContent.textContent).toMatch('Charmander');
185+
expect(contentSpan).not.toHaveClass('md-toast-text');
182186
}));
183187

184188

0 commit comments

Comments
 (0)