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 } from '@angular/material/core' ;
3423
3524/** Shared host configuration for all buttons */
3625export const MAT_BUTTON_HOST = {
@@ -43,6 +32,7 @@ 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]' : 'color ? "mat-" + color : ""' ,
4636} ;
4737
4838/** List of classes to add to buttons instances based on host attribute selector. */
@@ -77,24 +67,9 @@ const HOST_SELECTOR_MDC_CLASS_PAIR: {selector: string; mdcClasses: string[]}[] =
7767 } ,
7868] ;
7969
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-
9270/** Base class for all buttons. */
9371@Directive ( )
94- export class MatButtonBase
95- extends _MatButtonMixin
96- implements CanDisable , CanColor , CanDisableRipple , AfterViewInit , OnDestroy
97- {
72+ export class MatButtonBase implements AfterViewInit , OnDestroy {
9873 private readonly _focusMonitor = inject ( FocusMonitor ) ;
9974
10075 /**
@@ -118,41 +93,41 @@ export class MatButtonBase
11893 this . _rippleLoader ?. attachRipple ( this . _elementRef . nativeElement , v ) ;
11994 }
12095
121- // We override `disableRipple` and `disabled` so we can hook into
122- // their setters and update the ripple disabled state accordingly.
96+ /** Theme color palette of the button */
97+ @ Input ( ) color ?: string | null ;
12398
12499 /** Whether the ripple effect is disabled or not. */
125- override get disableRipple ( ) : boolean {
100+ @Input ( { transform : booleanAttribute } )
101+ get disableRipple ( ) : boolean {
126102 return this . _disableRipple ;
127103 }
128- override set disableRipple ( value : any ) {
129- this . _disableRipple = coerceBooleanProperty ( value ) ;
104+ set disableRipple ( value : any ) {
105+ this . _disableRipple = value ;
130106 this . _updateRippleDisabled ( ) ;
131107 }
132108 private _disableRipple : boolean = false ;
133109
134- override get disabled ( ) : boolean {
110+ @Input ( { transform : booleanAttribute } )
111+ get disabled ( ) : boolean {
135112 return this . _disabled ;
136113 }
137- override set disabled ( value : any ) {
138- this . _disabled = coerceBooleanProperty ( value ) ;
114+ set disabled ( value : any ) {
115+ this . _disabled = value ;
139116 this . _updateRippleDisabled ( ) ;
140117 }
141118 private _disabled : boolean = false ;
142119
143120 constructor (
144- elementRef : ElementRef ,
121+ public _elementRef : ElementRef ,
145122 public _platform : Platform ,
146123 public _ngZone : NgZone ,
147124 public _animationMode ?: string ,
148125 ) {
149- super ( elementRef ) ;
150-
151126 this . _rippleLoader ?. configureRipple ( this . _elementRef . nativeElement , {
152127 className : 'mat-mdc-button-ripple' ,
153128 } ) ;
154129
155- const classList = ( elementRef . nativeElement as HTMLElement ) . classList ;
130+ const classList = ( _elementRef . nativeElement as HTMLElement ) . classList ;
156131
157132 // For each of the variant selectors that is present in the button's host
158133 // attributes, add the correct corresponding MDC classes.
@@ -195,9 +170,6 @@ export class MatButtonBase
195170 }
196171}
197172
198- /** Shared inputs by buttons using the `<a>` tag */
199- export const MAT_ANCHOR_INPUTS = [ 'disabled' , 'disableRipple' , 'color' , 'tabIndex' ] ;
200-
201173/** Shared host configuration for buttons using the `<a>` tag. */
202174export const MAT_ANCHOR_HOST = {
203175 '[attr.disabled]' : 'disabled || null' ,
@@ -215,14 +187,15 @@ export const MAT_ANCHOR_HOST = {
215187 // Add a class that applies to all buttons. This makes it easier to target if somebody
216188 // wants to target all Material buttons.
217189 '[class.mat-mdc-button-base]' : 'true' ,
190+ '[class]' : 'color ? "mat-" + color : ""' ,
218191} ;
219192
220193/**
221194 * Anchor button base.
222195 */
223196@Directive ( )
224197export class MatAnchorBase extends MatButtonBase implements OnInit , OnDestroy {
225- tabIndex : number ;
198+ @ Input ( ) tabIndex : number ;
226199
227200 constructor ( elementRef : ElementRef , platform : Platform , ngZone : NgZone , animationMode ?: string ) {
228201 super ( elementRef , platform , ngZone , animationMode ) ;
0 commit comments