Skip to content

Commit 0875f8c

Browse files
committed
create extendable fab
1 parent cd12561 commit 0875f8c

25 files changed

+706
-103
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/src/lib/datepicker/** @mmalerba
1010
/src/lib/dialog/** @jelbourn @crisbeto
1111
/src/lib/expansion/** @josephperrott @jelbourn
12+
/src/lib/fab/** @josephperrott
1213
/src/lib/form-field/** @mmalerba
1314
/src/lib/grid-list/** @kara @jelbourn
1415
/src/lib/icon/** @jelbourn

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
<a mat-mini-fab routerLink=".">Link</a>
1616
</section>
1717

18+
<section>
19+
<button mat-fab color="primary" extendOnFocus routerLink=".">
20+
Link
21+
<ng-template #label>This is a link</ng-template>
22+
</button>
23+
<a mat-fab extendOnFocus extendOnHover routerLink=".">
24+
Link
25+
<ng-template #label>This is a link</ng-template>
26+
</a>
27+
<button mat-mini-fab extendOnHover>
28+
<ng-template #label><b>Check</b> this one off</ng-template>
29+
<mat-icon>check</mat-icon>
30+
</button>
31+
<button mat-mini-fab extendOnHover="true">
32+
Btn
33+
<ng-template #label>This is a button</ng-template>
34+
</button>
35+
</section>
36+
1837
<section>
1938
<a href="http://www.google.com" mat-button color="primary">SEARCH</a>
2039
<a href="http://www.google.com" mat-raised-button>SEARCH</a>

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/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/e2e-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/bundles/material-datepicker.umd.js',
5858
'@angular/material/dialog': 'dist/bundles/material-dialog.umd.js',
5959
'@angular/material/expansion': 'dist/bundles/material-expansion.umd.js',
60+
'@angular/material/fab': 'dist/packages/material/fab/index.js',
6061
'@angular/material/form-field': 'dist/bundles/material-form-field.umd.js',
6162
'@angular/material/grid-list': 'dist/bundles/material-grid-list.umd.js',
6263
'@angular/material/icon': 'dist/bundles/material-icon.umd.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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import {NgModule} from '@angular/core';
1010
import {CommonModule} from '@angular/common';
1111
import {MatCommonModule, MatRippleModule} from '@angular/material/core';
1212
import {A11yModule} from '@angular/cdk/a11y';
13+
import {MatFabModule} from '@angular/material/fab';
1314
import {
1415
MatAnchor,
1516
MatButton,
16-
MatMiniFab,
1717
MatButtonCssMatStyler,
18-
MatFab,
1918
MatIconButtonCssMatStyler,
2019
MatRaisedButtonCssMatStyler
2120
} from './button';
@@ -26,23 +25,21 @@ import {
2625
CommonModule,
2726
MatRippleModule,
2827
MatCommonModule,
28+
MatFabModule,
2929
A11yModule,
3030
],
3131
exports: [
3232
MatButton,
3333
MatAnchor,
34-
MatMiniFab,
35-
MatFab,
3634
MatCommonModule,
35+
MatFabModule,
3736
MatButtonCssMatStyler,
3837
MatRaisedButtonCssMatStyler,
3938
MatIconButtonCssMatStyler,
4039
],
4140
declarations: [
4241
MatButton,
4342
MatAnchor,
44-
MatMiniFab,
45-
MatFab,
4643
MatButtonCssMatStyler,
4744
MatRaisedButtonCssMatStyler,
4845
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 & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ import {
1313
Component,
1414
Directive,
1515
ElementRef,
16-
forwardRef,
17-
Inject,
1816
OnDestroy,
19-
Optional,
2017
Renderer2,
21-
Self,
2218
ViewEncapsulation,
2319
} from '@angular/core';
2420
import {
@@ -33,9 +29,6 @@ import {
3329

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

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

4033
/**
4134
* Directive whose purpose is to add the mat- CSS styling to this selector.
@@ -67,39 +60,6 @@ export class MatRaisedButtonCssMatStyler {}
6760
})
6861
export class MatIconButtonCssMatStyler {}
6962

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-
10363

10464
// Boilerplate for applying mixins to MatButton.
10565
/** @docs-private */
@@ -114,8 +74,7 @@ export const _MatButtonMixinBase = mixinColor(mixinDisabled(mixinDisableRipple(M
11474
*/
11575
@Component({
11676
moduleId: module.id,
117-
selector: `button[mat-button], button[mat-raised-button], button[mat-icon-button],
118-
button[mat-fab], button[mat-mini-fab]`,
77+
selector: `button[mat-button], button[mat-raised-button], button[mat-icon-button]`,
11978
exportAs: 'matButton',
12079
host: {
12180
'[disabled]': 'disabled || null',
@@ -130,9 +89,6 @@ export const _MatButtonMixinBase = mixinColor(mixinDisabled(mixinDisableRipple(M
13089
export class MatButton extends _MatButtonMixinBase
13190
implements OnDestroy, CanDisable, CanColor, CanDisableRipple {
13291

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

@@ -179,7 +135,7 @@ export class MatButton extends _MatButtonMixinBase
179135
*/
180136
@Component({
181137
moduleId: module.id,
182-
selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button], a[mat-fab], a[mat-mini-fab]`,
138+
selector: `a[mat-button], a[mat-raised-button], a[mat-icon-button]`,
183139
exportAs: 'matButton, matAnchor',
184140
host: {
185141
'[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
}

0 commit comments

Comments
 (0)