Skip to content

Commit e89632c

Browse files
committed
create extendable fab
1 parent cd12561 commit e89632c

23 files changed

+431
-100
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<button mat-fab>Btn</button>
99
<a mat-fab routerLink=".">Link</a>
1010
<a mat-fab routerLink="."><mat-icon>check</mat-icon></a>
11-
<button mat-mini-fab>
11+
<button mat-mini-fab extended="true">
1212
<mat-icon>check</mat-icon>
1313
</button>
1414
<button mat-mini-fab>Btn</button>

src/demo-app/button/button-demo.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
.demo-button {
33
button, a {
44
margin: 8px;
5-
text-transform: uppercase;
65
}
76

87
section {
@@ -16,3 +15,9 @@
1615
}
1716
}
1817

18+
.demo-button-zip {
19+
button {
20+
display: block;
21+
margin: 3px 0;
22+
}
23+
}

src/demo-app/button/button-demo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export class ButtonDemo {
1111
isDisabled: boolean = false;
1212
clickCounter: number = 0;
1313
toggleDisable: boolean = false;
14+
expanded = false;
1415
}

src/demo-app/demo-material-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
MatToolbarModule,
3131
MatTooltipModule,
3232
MatStepperModule,
33+
MatFabModule,
3334
} from '@angular/material';
3435
import {MatNativeDateModule, MatRippleModule} from '@angular/material';
3536
import {CdkTableModule} from '@angular/cdk/table';
@@ -46,6 +47,7 @@ import {PortalModule} from '@angular/cdk/portal';
4647
*/
4748
@NgModule({
4849
exports: [
50+
MatFabModule,
4951
MatAutocompleteModule,
5052
MatButtonModule,
5153
MatButtonToggleModule,

src/demo-app/system-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ System.config({
5757
'@angular/material/datepicker': 'dist/packages/material/datepicker/index.js',
5858
'@angular/material/dialog': 'dist/packages/material/dialog/index.js',
5959
'@angular/material/expansion': 'dist/packages/material/expansion/index.js',
60+
'@angular/material/fab': 'dist/packages/material/fab/index.js',
6061
'@angular/material/form-field': 'dist/packages/material/form-field/index.js',
6162
'@angular/material/grid-list': 'dist/packages/material/grid-list/index.js',
6263
'@angular/material/icon': 'dist/packages/material/icon/index.js',

src/lib/button/_button-base.scss

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ $mat-icon-button-size: 40px !default;
1717
$mat-icon-button-border-radius: 50% !default;
1818
$mat-icon-button-line-height: 24px !default;
1919

20-
// Fab standards
21-
$mat-fab-border-radius: 50% !default;
22-
$mat-fab-size: 56px !default;
23-
$mat-fab-padding: 16px !default;
24-
25-
$mat-mini-fab-size: 40px !default;
26-
$mat-mini-fab-padding: 8px !default;
27-
2820
// Applies base styles to all button types.
2921
%mat-button-base {
3022
box-sizing: border-box;
@@ -62,7 +54,7 @@ $mat-mini-fab-padding: 8px !default;
6254
}
6355
}
6456

65-
// Applies styles to buttons with backgrounds: raised, fab, and mini-fab
57+
// Applies styles to buttons with raised backgrounds.
6658
%mat-raised-button {
6759
@extend %mat-button-base;
6860

@@ -83,30 +75,3 @@ $mat-mini-fab-padding: 8px !default;
8375
box-shadow: none;
8476
}
8577
}
86-
87-
// Applies styles to fab and mini-fab button types only
88-
@mixin mat-fab($size, $padding) {
89-
@extend %mat-raised-button;
90-
91-
@include mat-overridable-elevation(6);
92-
93-
// Reset the min-width from the button base.
94-
min-width: 0;
95-
96-
border-radius: $mat-fab-border-radius;
97-
width: $size;
98-
height: $size;
99-
padding: 0;
100-
101-
flex-shrink: 0;
102-
103-
&:not([disabled]):active {
104-
@include mat-overridable-elevation(12);
105-
}
106-
107-
.mat-button-wrapper {
108-
padding: $padding 0;
109-
display: inline-block;
110-
line-height: $mat-icon-button-line-height;
111-
}
112-
}

src/lib/button/_button-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
@include _mat-button-theme-color($theme, 'color');
8383
}
8484

85-
.mat-raised-button, .mat-fab, .mat-mini-fab {
85+
.mat-raised-button {
8686
// Default properties when not using any [color] value.
8787
color: mat-color($foreground, text);
8888
background-color: mat-color($background, raised-button);
@@ -107,7 +107,7 @@
107107
}
108108

109109
@mixin mat-button-typography($config) {
110-
.mat-button, .mat-raised-button, .mat-icon-button, .mat-fab, .mat-mini-fab {
110+
.mat-button, .mat-raised-button, .mat-icon-button {
111111
font: {
112112
family: mat-font-family($config, button);
113113
size: mat-font-size($config, button);

src/lib/button/button-module.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import {A11yModule} from '@angular/cdk/a11y';
1313
import {
1414
MatAnchor,
1515
MatButton,
16-
MatMiniFab,
1716
MatButtonCssMatStyler,
18-
MatFab,
1917
MatIconButtonCssMatStyler,
2018
MatRaisedButtonCssMatStyler
2119
} from './button';
@@ -31,8 +29,6 @@ import {
3129
exports: [
3230
MatButton,
3331
MatAnchor,
34-
MatMiniFab,
35-
MatFab,
3632
MatCommonModule,
3733
MatButtonCssMatStyler,
3834
MatRaisedButtonCssMatStyler,
@@ -41,8 +37,6 @@ import {
4137
declarations: [
4238
MatButton,
4339
MatAnchor,
44-
MatMiniFab,
45-
MatFab,
4640
MatButtonCssMatStyler,
4741
MatRaisedButtonCssMatStyler,
4842
MatIconButtonCssMatStyler,

src/lib/button/button.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<span class="mat-button-wrapper"><ng-content></ng-content></span>
22
<div matRipple class="mat-button-ripple"
3-
[class.mat-button-ripple-round]="_isRoundButton || _isIconButton"
3+
[class.mat-button-ripple-round]="_isIconButton"
44
[matRippleDisabled]="_isRippleDisabled()"
55
[matRippleCentered]="_isIconButton"
66
[matRippleTrigger]="_getHostElement()"></div>

src/lib/button/button.scss

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

16-
// Only flat buttons (not raised, FABs or icon buttons) have a hover style.
16+
// Only flat buttons (not raised or icon buttons) have a hover style.
1717
// Use the same visual treatment for hover as for focus.
1818
.mat-button:hover .mat-button-focus-overlay {
1919
opacity: 1;
@@ -23,14 +23,6 @@
2323
@extend %mat-raised-button;
2424
}
2525

26-
.mat-fab {
27-
@include mat-fab($mat-fab-size, $mat-fab-padding);
28-
}
29-
30-
.mat-mini-fab {
31-
@include mat-fab($mat-mini-fab-size, $mat-mini-fab-padding);
32-
}
33-
3426
.mat-icon-button {
3527
padding: 0;
3628

@@ -70,7 +62,7 @@
7062

7163
// Element that overlays the button to show focus and hover effects.
7264
.mat-button-focus-overlay {
73-
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
65+
// The button spec calls for focus on raised buttons to be indicated with a
7466
// black, 12% opacity shade over the normal color (for both light and dark themes).
7567
background-color: rgba(black, 0.12);
7668
border-radius: inherit;
@@ -96,7 +88,7 @@
9688

9789
// Add an outline to make it more visible in high contrast mode.
9890
@include cdk-high-contrast {
99-
.mat-button, .mat-raised-button, .mat-icon-button, .mat-fab, .mat-mini-fab {
91+
.mat-button, .mat-raised-button, .mat-icon-button {
10092
outline: solid 1px;
10193
}
10294
}

src/lib/button/button.ts

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ import {
3333

3434
// TODO(kara): Convert attribute selectors to classes when attr maps become available
3535

36-
/** Default color palette for round buttons (mat-fab and mat-mini-fab) */
37-
const DEFAULT_ROUND_BUTTON_COLOR = 'accent';
38-
3936

4037
/**
4138
* Directive whose purpose is to add the mat- CSS styling to this selector.
@@ -67,39 +64,6 @@ export class MatRaisedButtonCssMatStyler {}
6764
})
6865
export class MatIconButtonCssMatStyler {}
6966

70-
/**
71-
* Directive whose purpose is to add the mat- CSS styling to this selector.
72-
* @docs-private
73-
*/
74-
@Directive({
75-
selector: 'button[mat-fab], a[mat-fab]',
76-
host: {'class': 'mat-fab'}
77-
})
78-
export class MatFab {
79-
constructor(@Self() @Optional() @Inject(forwardRef(() => MatButton)) button: MatButton,
80-
@Self() @Optional() @Inject(forwardRef(() => MatAnchor)) anchor: MatAnchor) {
81-
// Set the default color palette for the mat-fab components.
82-
(button || anchor).color = DEFAULT_ROUND_BUTTON_COLOR;
83-
}
84-
}
85-
86-
/**
87-
* Directive that targets mini-fab buttons and anchors. It's used to apply the `mat-` class
88-
* to all mini-fab buttons and also is responsible for setting the default color palette.
89-
* @docs-private
90-
*/
91-
@Directive({
92-
selector: 'button[mat-mini-fab], a[mat-mini-fab]',
93-
host: {'class': 'mat-mini-fab'}
94-
})
95-
export class MatMiniFab {
96-
constructor(@Self() @Optional() @Inject(forwardRef(() => MatButton)) button: MatButton,
97-
@Self() @Optional() @Inject(forwardRef(() => MatAnchor)) anchor: MatAnchor) {
98-
// Set the default color palette for the mat-mini-fab components.
99-
(button || anchor).color = DEFAULT_ROUND_BUTTON_COLOR;
100-
}
101-
}
102-
10367

10468
// Boilerplate for applying mixins to MatButton.
10569
/** @docs-private */
@@ -114,8 +78,7 @@ export const _MatButtonMixinBase = mixinColor(mixinDisabled(mixinDisableRipple(M
11478
*/
11579
@Component({
11680
moduleId: module.id,
117-
selector: `button[mat-button], button[mat-raised-button], button[mat-icon-button],
118-
button[mat-fab], button[mat-mini-fab]`,
81+
selector: `button[mat-button], button[mat-raised-button], button[mat-icon-button]`,
11982
exportAs: 'matButton',
12083
host: {
12184
'[disabled]': 'disabled || null',
@@ -130,9 +93,6 @@ export const _MatButtonMixinBase = mixinColor(mixinDisabled(mixinDisableRipple(M
13093
export class MatButton extends _MatButtonMixinBase
13194
implements OnDestroy, CanDisable, CanColor, CanDisableRipple {
13295

133-
/** Whether the button is round. */
134-
_isRoundButton: boolean = this._hasHostAttributes('mat-fab', 'mat-mini-fab');
135-
13696
/** Whether the button is icon button. */
13797
_isIconButton: boolean = this._hasHostAttributes('mat-icon-button');
13898

@@ -179,7 +139,7 @@ export class MatButton extends _MatButtonMixinBase
179139
*/
180140
@Component({
181141
moduleId: module.id,
182-
selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab], a[mat-mini-fab]`,
142+
selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button]`,
183143
exportAs: 'matButton, matAnchor',
184144
host: {
185145
'[attr.tabindex]': 'disabled ? -1 : 0',

src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
@import '../../tooltip/tooltip-theme';
3030
@import '../../snack-bar/snack-bar-theme';
3131
@import '../../form-field/form-field-theme';
32+
@import '../../fab/fab-theme';
3233

3334

3435
// Create a theme.
@@ -63,4 +64,5 @@
6364
@include mat-toolbar-theme($theme);
6465
@include mat-tooltip-theme($theme);
6566
@include mat-snack-bar-theme($theme);
67+
@include mat-fab-theme($theme);
6668
}

src/lib/core/typography/_all-typography.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@import '../option/option-theme';
3131
@import '../option/optgroup-theme';
3232
@import '../../form-field/form-field-theme';
33+
@import '../../fab/fab-theme';
3334

3435

3536
// Includes all of the typographic styles.
@@ -70,4 +71,5 @@
7071
@include mat-option-typography($config);
7172
@include mat-optgroup-typography($config);
7273
@include mat-snack-bar-typography($config);
74+
@include mat-fab-typography($config);
7375
}

src/lib/fab/_fab-theme.scss

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@import '../core/theming/theming';
2+
@import '../core/typography/typography-utils';
3+
4+
@mixin mat-fab-theme($theme) {
5+
$primary: map-get($theme, primary);
6+
$accent: map-get($theme, accent);
7+
$warn: map-get($theme, warn);
8+
$foreground: map-get($theme, foreground);
9+
$background: map-get($theme, background);
10+
11+
.mat-fab {
12+
// Default properties when not using any [color] value.
13+
color: mat-color($primary, default-contrast);
14+
background-color: mat-color($primary, 1);
15+
16+
&.mat-primary {
17+
color: mat-color($primary, default-contrast);
18+
background-color: mat-color($primary, 1);
19+
20+
.mat-ripple-element {
21+
background-color: mat-color($primary, default-contrast, 0.2);
22+
}
23+
}
24+
25+
&.mat-accent {
26+
color: mat-color($accent, default-contrast);
27+
background-color: mat-color($accent, 1);
28+
29+
.mat-ripple-element {
30+
background-color: mat-color($accent, default-contrast, 0.2);
31+
}
32+
}
33+
34+
&.mat-warn {
35+
color: mat-color($warn, default-contrast);
36+
background-color: mat-color($warn, 1);
37+
38+
.mat-ripple-element {
39+
background-color: mat-color($warn, default-contrast, 0.2);
40+
}
41+
}
42+
43+
&[disabled] {
44+
color: rgba(white, 0.62);
45+
46+
.mat-fab-focus-overlay {
47+
background-color: transparent;
48+
}
49+
.mat-ripple-element {
50+
background-color: transparent;
51+
}
52+
}
53+
}
54+
}
55+
56+
@mixin mat-fab-typography($config) {
57+
.mat-fab {
58+
font: {
59+
family: mat-font-family($config, button);
60+
size: mat-font-size($config, button);
61+
weight: mat-font-weight($config, button);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)