Skip to content

Commit e65ce0c

Browse files
committed
feat(button): create stroked and flat button variants
1 parent 303e004 commit e65ce0c

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

src/demo-app/button/button-demo.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<section>
33
<button mat-button>flat</button>
44
<button mat-raised-button>raised</button>
5+
<button mat-stroked-button>stroked</button>
6+
<button mat-flat-button>flat</button>
57
<button mat-fab>
68
<mat-icon>check</mat-icon>
79
</button>
@@ -18,6 +20,8 @@
1820
<section>
1921
<a href="http://www.google.com" mat-button color="primary">SEARCH</a>
2022
<a href="http://www.google.com" mat-raised-button>SEARCH</a>
23+
<a href="http://www.google.com" mat-stroked-button>SEARCH</a>
24+
<a href="http://www.google.com" mat-flat-button>SEARCH</a>
2125
<a href="http://www.google.com" mat-fab>
2226
<mat-icon>check</mat-icon>
2327
</a>
@@ -30,12 +34,28 @@
3034
<button mat-button color="primary">primary</button>
3135
<button mat-button color="accent">accent</button>
3236
<button mat-button color="warn">warn</button>
37+
<button mat-button disabled>disabled</button>
3338
</section>
3439

3540
<section>
3641
<button mat-raised-button color="primary">primary</button>
3742
<button mat-raised-button color="accent">accent</button>
3843
<button mat-raised-button color="warn">warn</button>
44+
<button mat-raised-button disabled>disabled</button>
45+
</section>
46+
47+
<section>
48+
<button mat-stroked-button color="primary">primary</button>
49+
<button mat-stroked-button color="accent">accent</button>
50+
<button mat-stroked-button color="warn">warn</button>
51+
<button mat-stroked-button color="primary" disabled>disabled</button>
52+
</section>
53+
54+
<section>
55+
<button mat-flat-button color="primary">primary</button>
56+
<button mat-flat-button color="accent">accent</button>
57+
<button mat-flat-button color="warn">warn</button>
58+
<button mat-flat-button color="primary" disabled>disabled</button>
3959
</section>
4060

4161
<section>

src/lib/button/_button-base.scss

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,30 @@ $mat-mini-fab-padding: 8px !default;
6262
}
6363
}
6464

65-
// Applies styles to buttons with backgrounds: raised, fab, and mini-fab
66-
%mat-raised-button {
65+
// Applies styles to buttons with stroke styling
66+
%mat-stroked-button {
6767
@extend %mat-button-base;
6868

69-
@include mat-overridable-elevation(2);
69+
@include mat-overridable-elevation(0);
70+
71+
outline: 1px solid currentColor;
72+
}
73+
74+
// Applies styles to buttons with flat styling
75+
%mat-flat-button {
76+
@extend %mat-button-base;
77+
78+
@include mat-overridable-elevation(0);
7079

7180
// Force hardware acceleration.
7281
transform: translate3d(0, 0, 0);
82+
}
83+
84+
// Applies styles to buttons with backgrounds: raised, fab, and mini-fab
85+
%mat-raised-button {
86+
@extend %mat-flat-button;
87+
88+
@include mat-overridable-elevation(2);
7389

7490
// Animation.
7591
transition: background $swift-ease-out-duration $swift-ease-out-timing-function,

src/lib/button/_button-theme.scss

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
$background: map-get($theme, background);
7676
$foreground: map-get($theme, foreground);
7777

78-
.mat-button, .mat-icon-button {
78+
.mat-button, .mat-icon-button, .mat-stroked-button {
7979
background: transparent;
8080

8181
@include _mat-button-focus-color($theme);
@@ -99,6 +99,23 @@
9999
@include _mat-button-ripple-color($theme, default, 0.1);
100100
}
101101

102+
.mat-stroked-button {
103+
color: rgba(0, 0, 0, 0.87);
104+
@include _mat-button-theme-color($theme, 'outline-color');
105+
}
106+
107+
.mat-flat-button {
108+
// Default properties when not using any [color] value.
109+
color: mat-color($foreground, text);
110+
111+
background-color: mat-color($background, raised-button);
112+
@include _mat-button-theme-color($theme, 'color', default-contrast);
113+
@include _mat-button-theme-color($theme, 'background-color');
114+
115+
// Add ripple effect with contrast color to buttons that don't have a focus overlay.
116+
@include _mat-button-ripple-color($theme, default-contrast);
117+
}
118+
102119
// Add ripple effect with default color to the icon button. Ripple color needs to be stronger
103120
// since the icon button doesn't have a focus overlay.
104121
.mat-icon-button {
@@ -107,7 +124,8 @@
107124
}
108125

109126
@mixin mat-button-typography($config) {
110-
.mat-button, .mat-raised-button, .mat-icon-button, .mat-fab, .mat-mini-fab {
127+
.mat-button, .mat-raised-button, .mat-icon-button, .mat-stroked-button, .mat-flat-button,
128+
.mat-fab, .mat-mini-fab {
111129
font: {
112130
family: mat-font-family($config, button);
113131
size: mat-font-size($config, button);

src/lib/button/button-module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
MatButton,
1616
MatMiniFab,
1717
MatButtonCssMatStyler,
18+
MatFlatButtonCssMatStyler,
19+
MatStrokedButtonCssMatStyler,
1820
MatFab,
1921
MatIconButtonCssMatStyler,
2022
MatRaisedButtonCssMatStyler
@@ -35,6 +37,8 @@ import {
3537
MatFab,
3638
MatCommonModule,
3739
MatButtonCssMatStyler,
40+
MatFlatButtonCssMatStyler,
41+
MatStrokedButtonCssMatStyler,
3842
MatRaisedButtonCssMatStyler,
3943
MatIconButtonCssMatStyler,
4044
],
@@ -44,6 +48,8 @@ import {
4448
MatMiniFab,
4549
MatFab,
4650
MatButtonCssMatStyler,
51+
MatFlatButtonCssMatStyler,
52+
MatStrokedButtonCssMatStyler,
4753
MatRaisedButtonCssMatStyler,
4854
MatIconButtonCssMatStyler,
4955
],

src/lib/button/button.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@
1313
}
1414
}
1515

16-
// Only flat buttons (not raised, FABs or icon buttons) have a hover style.
16+
// Only flat and stroked buttons (not raised, FABs or icon buttons) have a hover style.
1717
// Use the same visual treatment for hover as for focus.
18-
.mat-button:hover .mat-button-focus-overlay {
18+
.mat-button:hover .mat-button-focus-overlay,
19+
.mat-stroked-button:hover .mat-button-focus-overlay {
1920
opacity: 1;
2021
}
2122

2223
.mat-raised-button {
2324
@extend %mat-raised-button;
2425
}
2526

27+
.mat-stroked-button {
28+
@extend %mat-stroked-button;
29+
}
30+
31+
.mat-flat-button {
32+
@extend %mat-flat-button;
33+
}
34+
2635
.mat-fab {
2736
@include mat-fab($mat-fab-size, $mat-fab-padding);
2837
}

src/lib/button/button.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ export class MatButtonCssMatStyler {}
5656
})
5757
export class MatRaisedButtonCssMatStyler {}
5858

59+
/**
60+
* Directive whose purpose is to add the mat- CSS styling to this selector.
61+
* @docs-private
62+
*/
63+
@Directive({
64+
selector: 'button[mat-stroked-button], a[mat-stroked-button]',
65+
host: {'class': 'mat-stroked-button'}
66+
})
67+
export class MatStrokedButtonCssMatStyler {}
68+
69+
70+
71+
/**
72+
* Directive whose purpose is to add the mat- CSS styling to this selector.
73+
* @docs-private
74+
*/
75+
@Directive({
76+
selector: 'button[mat-flat-button], a[mat-flat-button]',
77+
host: {'class': 'mat-flat-button'}
78+
})
79+
export class MatFlatButtonCssMatStyler {}
80+
5981
/**
6082
* Directive whose purpose is to add the mat- CSS styling to this selector.
6183
* @docs-private
@@ -114,7 +136,8 @@ export const _MatButtonMixinBase = mixinColor(mixinDisabled(mixinDisableRipple(M
114136
@Component({
115137
moduleId: module.id,
116138
selector: `button[mat-button], button[mat-raised-button], button[mat-icon-button],
117-
button[mat-fab], button[mat-mini-fab]`,
139+
button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],
140+
button[mat-flat-button]`,
118141
exportAs: 'matButton',
119142
host: {
120143
'[disabled]': 'disabled || null',
@@ -177,7 +200,8 @@ export class MatButton extends _MatButtonMixinBase
177200
*/
178201
@Component({
179202
moduleId: module.id,
180-
selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab], a[mat-mini-fab]`,
203+
selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab],
204+
a[mat-mini-fab], a[mat-stroked-button], a[mat-flat-button]`,
181205
exportAs: 'matButton, matAnchor',
182206
host: {
183207
'[attr.tabindex]': 'disabled ? -1 : 0',

0 commit comments

Comments
 (0)