Skip to content

Commit 576d1dc

Browse files
committed
fix(material-experimental/mdc-button): split up fab and mini fab
1 parent 71031ca commit 576d1dc

File tree

2 files changed

+95
-10
lines changed

2 files changed

+95
-10
lines changed

src/material-experimental/mdc-button/fab.ts

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,33 @@ import {
2727
MatButtonBase
2828
} from './button-base';
2929
import {ThemePalette} from '@angular/material-experimental/mdc-core';
30+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
3031

3132
/**
3233
* Material Design floating action button (FAB) component. These buttons represent the primary
3334
* or most common action for users to interact with.
3435
* See https://material.io/components/buttons-floating-action-button/
3536
*
36-
* The `MatFabButton` class has two appearances: normal and mini.
37+
* The `MatFabButton` class has two appearances: normal and extended.
3738
*/
3839
@Component({
39-
selector: `button[mat-fab], button[mat-mini-fab]`,
40+
selector: `button[mat-fab]`,
4041
templateUrl: 'button.html',
4142
styleUrls: ['fab.css'],
42-
inputs: [...MAT_BUTTON_INPUTS, 'extended'],
43+
// TODO: change to MAT_BUTTON_INPUTS/MAT_BUTTON_HOST with spread after ViewEngine is deprecated
44+
inputs: ['disabled', 'disableRipple', 'color', 'extended'],
4345
host: {
4446
'[class.mdc-fab--extended]': 'extended',
45-
'[class.mat-mdc-extended-fab]': 'extended', ...MAT_BUTTON_HOST
47+
'[class.mat-mdc-extended-fab]': 'extended',
48+
'[attr.disabled]': 'disabled || null',
49+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
50+
// MDC automatically applies the primary theme color to the button, but we want to support
51+
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
52+
// select and style this "theme".
53+
'[class.mat-unthemed]': '!color',
54+
// Add a class that applies to all buttons. This makes it easier to target if somebody
55+
// wants to target all Material buttons.
56+
'[class.mat-mdc-button-base]': 'true',
4657
},
4758
exportAs: 'matButton',
4859
encapsulation: ViewEncapsulation.None,
@@ -61,22 +72,64 @@ export class MatFabButton extends MatButtonBase {
6172
}
6273
}
6374

75+
/**
76+
* Material Design mini floating action button (FAB) component. These buttons represent the primary
77+
* or most common action for users to interact with.
78+
* See https://material.io/components/buttons-floating-action-button/
79+
*/
80+
@Component({
81+
selector: `button[mat-mini-fab]`,
82+
templateUrl: 'button.html',
83+
styleUrls: ['fab.css'],
84+
inputs: MAT_BUTTON_INPUTS,
85+
host: MAT_BUTTON_HOST,
86+
exportAs: 'matButton',
87+
encapsulation: ViewEncapsulation.None,
88+
changeDetection: ChangeDetectionStrategy.OnPush,
89+
})
90+
export class MatMiniFabButton extends MatButtonBase {
91+
// The FAB by default has its color set to accent.
92+
color = 'accent' as ThemePalette;
93+
94+
constructor(
95+
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
96+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
97+
super(elementRef, platform, ngZone, animationMode);
98+
}
99+
}
100+
64101

65102
/**
66103
* Material Design floating action button (FAB) component for anchor elements. Anchor elements
67104
* are used to provide links for the user to navigate across different routes or pages.
68105
* See https://material.io/components/buttons-floating-action-button/
69106
*
70-
* The `MatFabAnchor` class has two appearances: normal and mini.
107+
* The `MatFabAnchor` class has two appearances: normal and extended.
71108
*/
72109
@Component({
73-
selector: `a[mat-fab], a[mat-mini-fab]`,
110+
selector: `a[mat-fab]`,
74111
templateUrl: 'button.html',
75112
styleUrls: ['fab.css'],
76-
inputs: [...MAT_ANCHOR_INPUTS, 'extended'],
113+
// TODO: change to MAT_ANCHOR_INPUTS/MAT_ANCHOR_HOST with spread after ViewEngine is deprecated
114+
inputs: ['disabled', 'disableRipple', 'color', 'tabIndex', 'extended'],
77115
host: {
78116
'[class.mdc-fab--extended]': 'extended',
79-
'[class.mat-mdc-extended-fab]': 'extended', ...MAT_ANCHOR_HOST
117+
'[class.mat-mdc-extended-fab]': 'extended',
118+
'[attr.disabled]': 'disabled || null',
119+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
120+
121+
// Note that we ignore the user-specified tabindex when it's disabled for
122+
// consistency with the `mat-button` applied on native buttons where even
123+
// though they have an index, they're not tabbable.
124+
'[attr.tabindex]': 'disabled ? -1 : (tabIndex || 0)',
125+
'[attr.aria-disabled]': 'disabled.toString()',
126+
// MDC automatically applies the primary theme color to the button, but we want to support
127+
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
128+
// select and style this "theme".
129+
'[class.mat-unthemed]': '!color',
130+
// Add a class that applies to all buttons. This makes it easier to target if somebody
131+
// wants to target all Material buttons.
132+
'[class.mat-mdc-button-base]': 'true',
80133
},
81134
exportAs: 'matButton, matAnchor',
82135
encapsulation: ViewEncapsulation.None,
@@ -86,11 +139,39 @@ export class MatFabAnchor extends MatAnchor {
86139
// The FAB by default has its color set to accent.
87140
color = 'accent' as ThemePalette;
88141

89-
extended: boolean;
142+
private _extended: boolean;
143+
get extended() { return this._extended; }
144+
set extended(extended: any) { this._extended = coerceBooleanProperty(extended); }
90145

91146
constructor(
92147
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
93148
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
94149
super(elementRef, platform, ngZone, animationMode);
95150
}
96151
}
152+
153+
/**
154+
* Material Design mini floating action button (FAB) component for anchor elements. Anchor elements
155+
* are used to provide links for the user to navigate across different routes or pages.
156+
* See https://material.io/components/buttons-floating-action-button/
157+
*/
158+
@Component({
159+
selector: `a[mat-mini-fab]`,
160+
templateUrl: 'button.html',
161+
styleUrls: ['fab.css'],
162+
inputs: MAT_ANCHOR_INPUTS,
163+
host: MAT_ANCHOR_HOST,
164+
exportAs: 'matButton, matAnchor',
165+
encapsulation: ViewEncapsulation.None,
166+
changeDetection: ChangeDetectionStrategy.OnPush,
167+
})
168+
export class MatMiniFabAnchor extends MatAnchor {
169+
// The FAB by default has its color set to accent.
170+
color = 'accent' as ThemePalette;
171+
172+
constructor(
173+
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
174+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
175+
super(elementRef, platform, ngZone, animationMode);
176+
}
177+
}

src/material-experimental/mdc-button/module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {NgModule} from '@angular/core';
1010
import {MatCommonModule, MatRippleModule} from '@angular/material-experimental/mdc-core';
1111
import {MatAnchor, MatButton} from './button';
12-
import {MatFabAnchor, MatFabButton} from './fab';
12+
import {MatFabAnchor, MatFabButton, MatMiniFabAnchor, MatMiniFabButton} from './fab';
1313
import {MatIconAnchor, MatIconButton} from './icon-button';
1414

1515
@NgModule({
@@ -19,6 +19,8 @@ import {MatIconAnchor, MatIconButton} from './icon-button';
1919
MatButton,
2020
MatIconAnchor,
2121
MatIconButton,
22+
MatMiniFabAnchor,
23+
MatMiniFabButton,
2224
MatFabAnchor,
2325
MatFabButton,
2426
MatCommonModule,
@@ -27,6 +29,8 @@ import {MatIconAnchor, MatIconButton} from './icon-button';
2729
MatAnchor,
2830
MatButton,
2931
MatIconAnchor,
32+
MatMiniFabAnchor,
33+
MatMiniFabButton,
3034
MatIconButton,
3135
MatFabAnchor,
3236
MatFabButton,

0 commit comments

Comments
 (0)