@@ -12,6 +12,7 @@ import {
12
12
Component ,
13
13
ElementRef ,
14
14
Inject ,
15
+ InjectionToken ,
15
16
NgZone ,
16
17
Optional ,
17
18
ViewEncapsulation
@@ -29,6 +30,30 @@ import {
29
30
import { ThemePalette } from '@angular/material-experimental/mdc-core' ;
30
31
import { BooleanInput , coerceBooleanProperty } from '@angular/cdk/coercion' ;
31
32
33
+
34
+ /** Default FAB options that can be overridden. */
35
+ export interface MatFabDefaultOptions {
36
+ color ?: ThemePalette ;
37
+ }
38
+
39
+ /** Injection token to be used to override the default options for FAB. */
40
+ export const MAT_FAB_DEFAULT_OPTIONS =
41
+ new InjectionToken < MatFabDefaultOptions > ( 'mat-mdc-fab-default-options' , {
42
+ providedIn : 'root' ,
43
+ factory : MAT_FAB_DEFAULT_OPTIONS_FACTORY
44
+ } ) ;
45
+
46
+ /** @docs -private */
47
+ export function MAT_FAB_DEFAULT_OPTIONS_FACTORY ( ) : MatFabDefaultOptions {
48
+ return {
49
+ // The FAB by default has its color set to accent.
50
+ color : 'accent' ,
51
+ } ;
52
+ }
53
+
54
+ // Default FAB configuration.
55
+ const defaults = MAT_FAB_DEFAULT_OPTIONS_FACTORY ( ) ;
56
+
32
57
/**
33
58
* Material Design floating action button (FAB) component. These buttons represent the primary
34
59
* or most common action for users to interact with.
@@ -60,9 +85,6 @@ import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
60
85
changeDetection : ChangeDetectionStrategy . OnPush ,
61
86
} )
62
87
export class MatFabButton extends MatButtonBase {
63
- // The FAB by default has its color set to accent.
64
- color = 'accent' as ThemePalette ;
65
-
66
88
_isFab = true ;
67
89
68
90
private _extended : boolean ;
@@ -71,8 +93,11 @@ export class MatFabButton extends MatButtonBase {
71
93
72
94
constructor (
73
95
elementRef : ElementRef , platform : Platform , ngZone : NgZone ,
74
- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
96
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
97
+ @Optional ( ) @Inject ( MAT_FAB_DEFAULT_OPTIONS ) private _options ?: MatFabDefaultOptions ) {
75
98
super ( elementRef , platform , ngZone , animationMode ) ;
99
+ this . _options = this . _options || defaults ;
100
+ this . color = this . defaultColor = this . _options ! . color || defaults . color ;
76
101
}
77
102
78
103
static ngAcceptInputType_extended : BooleanInput ;
@@ -94,15 +119,15 @@ export class MatFabButton extends MatButtonBase {
94
119
changeDetection : ChangeDetectionStrategy . OnPush ,
95
120
} )
96
121
export class MatMiniFabButton extends MatButtonBase {
97
- // The FAB by default has its color set to accent.
98
- color = 'accent' as ThemePalette ;
99
-
100
122
_isFab = true ;
101
123
102
124
constructor (
103
125
elementRef : ElementRef , platform : Platform , ngZone : NgZone ,
104
- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
126
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
127
+ @Optional ( ) @Inject ( MAT_FAB_DEFAULT_OPTIONS ) private _options ?: MatFabDefaultOptions ) {
105
128
super ( elementRef , platform , ngZone , animationMode ) ;
129
+ this . _options = this . _options || defaults ;
130
+ this . color = this . defaultColor = this . _options ! . color || defaults . color ;
106
131
}
107
132
}
108
133
@@ -144,9 +169,6 @@ export class MatMiniFabButton extends MatButtonBase {
144
169
changeDetection : ChangeDetectionStrategy . OnPush ,
145
170
} )
146
171
export class MatFabAnchor extends MatAnchor {
147
- // The FAB by default has its color set to accent.
148
- color = 'accent' as ThemePalette ;
149
-
150
172
_isFab = true ;
151
173
152
174
private _extended : boolean ;
@@ -156,8 +178,11 @@ export class MatFabAnchor extends MatAnchor {
156
178
157
179
constructor (
158
180
elementRef : ElementRef , platform : Platform , ngZone : NgZone ,
159
- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
181
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
182
+ @Optional ( ) @Inject ( MAT_FAB_DEFAULT_OPTIONS ) private _options ?: MatFabDefaultOptions ) {
160
183
super ( elementRef , platform , ngZone , animationMode ) ;
184
+ this . _options = this . _options || defaults ;
185
+ this . color = this . defaultColor = this . _options ! . color || defaults . color ;
161
186
}
162
187
163
188
static ngAcceptInputType_extended : BooleanInput ;
@@ -179,14 +204,14 @@ export class MatFabAnchor extends MatAnchor {
179
204
changeDetection : ChangeDetectionStrategy . OnPush ,
180
205
} )
181
206
export class MatMiniFabAnchor extends MatAnchor {
182
- // The FAB by default has its color set to accent.
183
- color = 'accent' as ThemePalette ;
184
-
185
207
_isFab = true ;
186
208
187
209
constructor (
188
210
elementRef : ElementRef , platform : Platform , ngZone : NgZone ,
189
- @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ) {
211
+ @Optional ( ) @Inject ( ANIMATION_MODULE_TYPE ) animationMode ?: string ,
212
+ @Optional ( ) @Inject ( MAT_FAB_DEFAULT_OPTIONS ) private _options ?: MatFabDefaultOptions ) {
190
213
super ( elementRef , platform , ngZone , animationMode ) ;
214
+ this . _options = this . _options || defaults ;
215
+ this . color = this . defaultColor = this . _options ! . color || defaults . color ;
191
216
}
192
217
}
0 commit comments