Skip to content

Commit 0b23fbd

Browse files
committed
style(button): polished icon buttons ripples
1 parent b939cd8 commit 0b23fbd

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

src/lib/button/_button-base.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ $mat-button-min-width: 88px !default;
99
$mat-button-margin: 0 !default;
1010
$mat-button-line-height: 36px !default;
1111
$mat-button-border-radius: 2px !default;
12-
$mat-button-focus-transition: opacity 200ms $swift-ease-in-out-timing-function !default;
12+
$mat-button-focus-transition: opacity 200ms $swift-ease-in-out-timing-function,
13+
background-color 200ms $swift-ease-in-out-timing-function !default;
1314

1415
// Icon Button standards
1516
$mat-icon-button-size: 40px !default;

src/lib/button/_button-theme.scss

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@import '../core/theming/theming';
22

3-
43
// Applies a focus style to an md-button element for each of the supported palettes.
54
@mixin _mat-button-focus-color($theme) {
65
$primary: map-get($theme, primary);
@@ -20,6 +19,24 @@
2019
}
2120
}
2221

22+
@mixin _mat-button-ripple-color($theme) {
23+
$primary: map-get($theme, primary);
24+
$accent: map-get($theme, accent);
25+
$warn: map-get($theme, warn);
26+
27+
&.mat-primary .mat-ripple-element {
28+
background-color: mat-color($primary, 0.26);
29+
}
30+
31+
&.mat-accent .mat-ripple-element {
32+
background-color: mat-color($accent, 0.26);
33+
}
34+
35+
&.mat-warn .mat-ripple-element {
36+
background-color: mat-color($warn, 0.26);
37+
}
38+
}
39+
2340
// Applies a property to an md-button element for each of the supported palettes.
2441
@mixin _mat-button-theme-color($theme, $property, $color: 'default') {
2542
$primary: map-get($theme, primary);
@@ -70,6 +87,10 @@
7087
}
7188
}
7289

90+
.mat-icon-button {
91+
@include _mat-button-ripple-color($theme);
92+
}
93+
7394
.mat-raised-button, .mat-fab, .mat-mini-fab {
7495
// Default properties when not using any [color] value.
7596
color: mat-color($foreground, text);

src/lib/button/button.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<span class="mat-button-wrapper"><ng-content></ng-content></span>
22
<div md-ripple *ngIf="!_isRippleDisabled()" class="mat-button-ripple"
3-
[class.mat-button-ripple-round]="_isRoundButton()"
4-
[mdRippleTrigger]="_getHostElement()"></div>
3+
[mdRippleCentered]="_isIconButton()"
4+
[class.mat-button-ripple-round]="_isRoundButton() || _isIconButton()"
5+
[mdRippleTrigger]="_getHostElement()"></div>
56
<!-- the touchstart handler prevents the overlay from capturing the initial tap on touch devices -->
67
<div class="mat-button-focus-overlay" (touchstart)="$event.preventDefault()"></div>

src/lib/button/button.scss

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77
.mat-button, .mat-icon-button {
88
@extend %mat-button-base;
99

10-
// Only flat buttons and icon buttons (not raised or fabs) have a hover style.
11-
&:hover {
12-
// Use the same visual treatment for hover as for focus.
10+
&[disabled]:hover {
11+
&.mat-primary, &.mat-accent, &.mat-warn, .mat-button-focus-overlay {
12+
background-color: transparent;
13+
}
14+
1315
.mat-button-focus-overlay {
14-
opacity: 1;
16+
transition: none;
17+
opacity: 0;
1518
}
1619
}
20+
}
1721

18-
&[disabled]:hover {
19-
&.mat-primary, &.mat-accent, &.mat-warn, .mat-button-focus-overlay {
20-
background-color: transparent;
22+
.mat-button {
23+
// Only flat buttons (not raised, fabs or icon buttons) have a hover style.
24+
&:hover {
25+
// Use the same visual treatment for hover as for focus.
26+
.mat-button-focus-overlay {
27+
opacity: 1;
2128
}
2229
}
2330
}

src/lib/button/button.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ export class MdButton {
167167

168168
_isRoundButton() {
169169
const el = this._getHostElement();
170-
return el.hasAttribute('md-icon-button') ||
171-
el.hasAttribute('md-fab') ||
172-
el.hasAttribute('md-mini-fab');
170+
return el.hasAttribute('md-fab') ||
171+
el.hasAttribute('md-mini-fab');
172+
}
173+
174+
_isIconButton() {
175+
const el = this._getHostElement();
176+
return el.hasAttribute('md-icon-button');
173177
}
174178

175179
_isRippleDisabled() {

0 commit comments

Comments
 (0)