7
7
*/
8
8
9
9
import { FocusMonitor , FocusOrigin } from '@angular/cdk/a11y' ;
10
- import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
11
10
import { Platform } from '@angular/cdk/platform' ;
12
11
import {
13
12
AfterViewInit ,
13
+ booleanAttribute ,
14
14
Directive ,
15
15
ElementRef ,
16
16
inject ,
17
+ Input ,
17
18
NgZone ,
19
+ numberAttribute ,
18
20
OnDestroy ,
19
21
OnInit ,
20
22
} from '@angular/core' ;
21
- import {
22
- CanColor ,
23
- CanDisable ,
24
- CanDisableRipple ,
25
- MatRipple ,
26
- mixinColor ,
27
- mixinDisabled ,
28
- mixinDisableRipple ,
29
- MatRippleLoader ,
30
- } from '@angular/material/core' ;
31
-
32
- /** Inputs common to all buttons. */
33
- export const MAT_BUTTON_INPUTS = [ 'disabled' , 'disableRipple' , 'color' ] ;
23
+ import { MatRipple , MatRippleLoader } from '@angular/material/core' ;
34
24
35
25
/** Shared host configuration for all buttons */
36
26
export const MAT_BUTTON_HOST = {
@@ -43,6 +33,7 @@ export const MAT_BUTTON_HOST = {
43
33
// Add a class that applies to all buttons. This makes it easier to target if somebody
44
34
// wants to target all Material buttons.
45
35
'[class.mat-mdc-button-base]' : 'true' ,
36
+ '[class]' : 'color ? "mat-" + color : ""' ,
46
37
} ;
47
38
48
39
/** List of classes to add to buttons instances based on host attribute selector. */
@@ -77,24 +68,9 @@ const HOST_SELECTOR_MDC_CLASS_PAIR: {selector: string; mdcClasses: string[]}[] =
77
68
} ,
78
69
] ;
79
70
80
- // Boilerplate for applying mixins to MatButton.
81
- /** @docs -private */
82
- export const _MatButtonMixin = mixinColor (
83
- mixinDisabled (
84
- mixinDisableRipple (
85
- class {
86
- constructor ( public _elementRef : ElementRef ) { }
87
- } ,
88
- ) ,
89
- ) ,
90
- ) ;
91
-
92
71
/** Base class for all buttons. */
93
72
@Directive ( )
94
- export class MatButtonBase
95
- extends _MatButtonMixin
96
- implements CanDisable , CanColor , CanDisableRipple , AfterViewInit , OnDestroy
97
- {
73
+ export class MatButtonBase implements AfterViewInit , OnDestroy {
98
74
private readonly _focusMonitor = inject ( FocusMonitor ) ;
99
75
100
76
/**
@@ -118,41 +94,41 @@ export class MatButtonBase
118
94
this . _rippleLoader ?. attachRipple ( this . _elementRef . nativeElement , v ) ;
119
95
}
120
96
121
- // We override `disableRipple` and `disabled` so we can hook into
122
- // their setters and update the ripple disabled state accordingly.
97
+ /** Theme color palette of the button */
98
+ @ Input ( ) color ?: string | null ;
123
99
124
100
/** Whether the ripple effect is disabled or not. */
125
- override get disableRipple ( ) : boolean {
101
+ @Input ( { transform : booleanAttribute } )
102
+ get disableRipple ( ) : boolean {
126
103
return this . _disableRipple ;
127
104
}
128
- override set disableRipple ( value : any ) {
129
- this . _disableRipple = coerceBooleanProperty ( value ) ;
105
+ set disableRipple ( value : any ) {
106
+ this . _disableRipple = value ;
130
107
this . _updateRippleDisabled ( ) ;
131
108
}
132
109
private _disableRipple : boolean = false ;
133
110
134
- override get disabled ( ) : boolean {
111
+ @Input ( { transform : booleanAttribute } )
112
+ get disabled ( ) : boolean {
135
113
return this . _disabled ;
136
114
}
137
- override set disabled ( value : any ) {
138
- this . _disabled = coerceBooleanProperty ( value ) ;
115
+ set disabled ( value : any ) {
116
+ this . _disabled = value ;
139
117
this . _updateRippleDisabled ( ) ;
140
118
}
141
119
private _disabled : boolean = false ;
142
120
143
121
constructor (
144
- elementRef : ElementRef ,
122
+ public _elementRef : ElementRef ,
145
123
public _platform : Platform ,
146
124
public _ngZone : NgZone ,
147
125
public _animationMode ?: string ,
148
126
) {
149
- super ( elementRef ) ;
150
-
151
127
this . _rippleLoader ?. configureRipple ( this . _elementRef . nativeElement , {
152
128
className : 'mat-mdc-button-ripple' ,
153
129
} ) ;
154
130
155
- const classList = ( elementRef . nativeElement as HTMLElement ) . classList ;
131
+ const classList = ( _elementRef . nativeElement as HTMLElement ) . classList ;
156
132
157
133
// For each of the variant selectors that is present in the button's host
158
134
// attributes, add the correct corresponding MDC classes.
@@ -195,9 +171,6 @@ export class MatButtonBase
195
171
}
196
172
}
197
173
198
- /** Shared inputs by buttons using the `<a>` tag */
199
- export const MAT_ANCHOR_INPUTS = [ 'disabled' , 'disableRipple' , 'color' , 'tabIndex' ] ;
200
-
201
174
/** Shared host configuration for buttons using the `<a>` tag. */
202
175
export const MAT_ANCHOR_HOST = {
203
176
'[attr.disabled]' : 'disabled || null' ,
@@ -215,13 +188,19 @@ export const MAT_ANCHOR_HOST = {
215
188
// Add a class that applies to all buttons. This makes it easier to target if somebody
216
189
// wants to target all Material buttons.
217
190
'[class.mat-mdc-button-base]' : 'true' ,
191
+ '[class]' : 'color ? "mat-" + color : ""' ,
218
192
} ;
219
193
220
194
/**
221
195
* Anchor button base.
222
196
*/
223
197
@Directive ( )
224
198
export class MatAnchorBase extends MatButtonBase implements OnInit , OnDestroy {
199
+ @Input ( {
200
+ transform : ( value : unknown ) => {
201
+ return value == null ? undefined : numberAttribute ( value ) ;
202
+ } ,
203
+ } )
225
204
tabIndex : number ;
226
205
227
206
constructor ( elementRef : ElementRef , platform : Platform , ngZone : NgZone , animationMode ?: string ) {
0 commit comments