77 */
88
99import { FocusMonitor , FocusOrigin } from '@angular/cdk/a11y' ;
10- import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1110import { Platform } from '@angular/cdk/platform' ;
1211import {
1312 AfterViewInit ,
13+ booleanAttribute ,
1414 Directive ,
1515 ElementRef ,
1616 inject ,
17+ Input ,
1718 NgZone ,
1819 OnDestroy ,
1920 OnInit ,
2021} 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' ] ;
22+ import { MatRipple , MatRippleLoader , ThemePalette } from '@angular/material/core' ;
3423
3524/** Shared host configuration for all buttons */
3625export const MAT_BUTTON_HOST = {
@@ -43,6 +32,9 @@ export const MAT_BUTTON_HOST = {
4332 // Add a class that applies to all buttons. This makes it easier to target if somebody
4433 // wants to target all Material buttons.
4534 '[class.mat-mdc-button-base]' : 'true' ,
35+ '[class.mat-primary]' : 'color === "primary"' ,
36+ '[class.mat-accent]' : 'color === "accent"' ,
37+ '[class.mat-warn]' : 'color === "warn"' ,
4638} ;
4739
4840/** List of classes to add to buttons instances based on host attribute selector. */
@@ -77,24 +69,9 @@ const HOST_SELECTOR_MDC_CLASS_PAIR: {selector: string; mdcClasses: string[]}[] =
7769 } ,
7870] ;
7971
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-
9272/** Base class for all buttons. */
9373@Directive ( )
94- export class MatButtonBase
95- extends _MatButtonMixin
96- implements CanDisable , CanColor , CanDisableRipple , AfterViewInit , OnDestroy
97- {
74+ export class MatButtonBase implements AfterViewInit , OnDestroy {
9875 private readonly _focusMonitor = inject ( FocusMonitor ) ;
9976
10077 /**
@@ -118,41 +95,41 @@ export class MatButtonBase
11895 this . _rippleLoader ?. attachRipple ( this . _elementRef . nativeElement , v ) ;
11996 }
12097
121- // We override `disableRipple` and `disabled` so we can hook into
122- // their setters and update the ripple disabled state accordingly.
98+ /** Theme color palette of the button */
99+ @ Input ( ) color : ThemePalette ;
123100
124101 /** Whether the ripple effect is disabled or not. */
125- override get disableRipple ( ) : boolean {
102+ @Input ( { transform : booleanAttribute } )
103+ get disableRipple ( ) : boolean {
126104 return this . _disableRipple ;
127105 }
128- override set disableRipple ( value : any ) {
129- this . _disableRipple = coerceBooleanProperty ( value ) ;
106+ set disableRipple ( value : any ) {
107+ this . _disableRipple = value ;
130108 this . _updateRippleDisabled ( ) ;
131109 }
132110 private _disableRipple : boolean = false ;
133111
134- override get disabled ( ) : boolean {
112+ @Input ( { transform : booleanAttribute } )
113+ get disabled ( ) : boolean {
135114 return this . _disabled ;
136115 }
137- override set disabled ( value : any ) {
138- this . _disabled = coerceBooleanProperty ( value ) ;
116+ set disabled ( value : any ) {
117+ this . _disabled = value ;
139118 this . _updateRippleDisabled ( ) ;
140119 }
141120 private _disabled : boolean = false ;
142121
143122 constructor (
144- elementRef : ElementRef ,
123+ protected _elementRef : ElementRef ,
145124 public _platform : Platform ,
146125 public _ngZone : NgZone ,
147126 public _animationMode ?: string ,
148127 ) {
149- super ( elementRef ) ;
150-
151128 this . _rippleLoader ?. configureRipple ( this . _elementRef . nativeElement , {
152129 className : 'mat-mdc-button-ripple' ,
153130 } ) ;
154131
155- const classList = ( elementRef . nativeElement as HTMLElement ) . classList ;
132+ const classList = ( _elementRef . nativeElement as HTMLElement ) . classList ;
156133
157134 // For each of the variant selectors that is present in the button's host
158135 // attributes, add the correct corresponding MDC classes.
@@ -195,9 +172,6 @@ export class MatButtonBase
195172 }
196173}
197174
198- /** Shared inputs by buttons using the `<a>` tag */
199- export const MAT_ANCHOR_INPUTS = [ 'disabled' , 'disableRipple' , 'color' , 'tabIndex' ] ;
200-
201175/** Shared host configuration for buttons using the `<a>` tag. */
202176export const MAT_ANCHOR_HOST = {
203177 '[attr.disabled]' : 'disabled || null' ,
@@ -215,14 +189,17 @@ export const MAT_ANCHOR_HOST = {
215189 // Add a class that applies to all buttons. This makes it easier to target if somebody
216190 // wants to target all Material buttons.
217191 '[class.mat-mdc-button-base]' : 'true' ,
192+ '[class.mat-primary]' : 'color === "primary"' ,
193+ '[class.mat-accent]' : 'color === "accent"' ,
194+ '[class.mat-warn]' : 'color === "warn"' ,
218195} ;
219196
220197/**
221198 * Anchor button base.
222199 */
223200@Directive ( )
224201export class MatAnchorBase extends MatButtonBase implements OnInit , OnDestroy {
225- tabIndex : number ;
202+ @ Input ( ) tabIndex : number ;
226203
227204 constructor ( elementRef : ElementRef , platform : Platform , ngZone : NgZone , animationMode ?: string ) {
228205 super ( elementRef , platform , ngZone , animationMode ) ;
0 commit comments