-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material-experimental/mdc-button): add extended fab #21585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8f3e3f9
13ccd65
54df3a8
ddb6038
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,20 +27,34 @@ import { | |
MatButtonBase | ||
} from './button-base'; | ||
import {ThemePalette} from '@angular/material-experimental/mdc-core'; | ||
import {BooleanInput} from '@angular/cdk/coercion'; | ||
|
||
/** | ||
* Material Design floating action button (FAB) component. These buttons represent the primary | ||
* or most common action for users to interact with. | ||
* See https://material.io/components/buttons-floating-action-button/ | ||
* | ||
* The `MatFabButton` class has two appearances: normal and mini. | ||
* The `MatFabButton` class has two appearances: normal and extended. | ||
*/ | ||
@Component({ | ||
selector: `button[mat-fab], button[mat-mini-fab]`, | ||
selector: `button[mat-fab]`, | ||
templateUrl: 'button.html', | ||
styleUrls: ['fab.css'], | ||
inputs: MAT_BUTTON_INPUTS, | ||
host: MAT_BUTTON_HOST, | ||
// TODO: change to MAT_BUTTON_INPUTS/MAT_BUTTON_HOST with spread after ViewEngine is deprecated | ||
inputs: ['disabled', 'disableRipple', 'color', 'extended'], | ||
host: { | ||
'[class.mdc-fab--extended]': 'extended', | ||
'[class.mat-mdc-extended-fab]': 'extended', | ||
'[attr.disabled]': 'disabled || null', | ||
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"', | ||
// MDC automatically applies the primary theme color to the button, but we want to support | ||
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to | ||
// select and style this "theme". | ||
'[class.mat-unthemed]': '!color', | ||
// Add a class that applies to all buttons. This makes it easier to target if somebody | ||
// wants to target all Material buttons. | ||
'[class.mat-mdc-button-base]': 'true', | ||
}, | ||
exportAs: 'matButton', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
|
@@ -49,11 +63,41 @@ export class MatFabButton extends MatButtonBase { | |
// The FAB by default has its color set to accent. | ||
color = 'accent' as ThemePalette; | ||
|
||
extended: boolean; | ||
annieyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
constructor( | ||
elementRef: ElementRef, platform: Platform, ngZone: NgZone, | ||
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) { | ||
super(elementRef, platform, ngZone, animationMode); | ||
} | ||
|
||
static ngAcceptInputType_extended: BooleanInput; | ||
} | ||
|
||
/** | ||
* Material Design mini floating action button (FAB) component. These buttons represent the primary | ||
* or most common action for users to interact with. | ||
* See https://material.io/components/buttons-floating-action-button/ | ||
*/ | ||
@Component({ | ||
selector: `button[mat-mini-fab]`, | ||
templateUrl: 'button.html', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, a thought occurred to me that having multiple components with the same template would lead to duplicate generated code. I checked with Andrew K, and he confirmed. So, rather than introducing a separate component with the same template, we should probably try to have one class with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe all buttons extend MatButtonBase with the same template (and anchos MatAnchorBase). Should there be another MatFabBase? |
||
styleUrls: ['fab.css'], | ||
inputs: MAT_BUTTON_INPUTS, | ||
host: MAT_BUTTON_HOST, | ||
exportAs: 'matButton', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MatMiniFabButton extends MatButtonBase { | ||
// The FAB by default has its color set to accent. | ||
color = 'accent' as ThemePalette; | ||
|
||
constructor( | ||
elementRef: ElementRef, platform: Platform, ngZone: NgZone, | ||
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) { | ||
super(elementRef, platform, ngZone, animationMode); | ||
} | ||
} | ||
|
||
|
||
|
@@ -62,14 +106,33 @@ export class MatFabButton extends MatButtonBase { | |
* are used to provide links for the user to navigate across different routes or pages. | ||
* See https://material.io/components/buttons-floating-action-button/ | ||
* | ||
* The `MatFabAnchor` class has two appearances: normal and mini. | ||
* The `MatFabAnchor` class has two appearances: normal and extended. | ||
*/ | ||
@Component({ | ||
selector: `a[mat-fab], a[mat-mini-fab]`, | ||
selector: `a[mat-fab]`, | ||
templateUrl: 'button.html', | ||
styleUrls: ['fab.css'], | ||
inputs: MAT_ANCHOR_INPUTS, | ||
host: MAT_ANCHOR_HOST, | ||
// TODO: change to MAT_ANCHOR_INPUTS/MAT_ANCHOR_HOST with spread after ViewEngine is deprecated | ||
inputs: ['disabled', 'disableRipple', 'color', 'tabIndex', 'extended'], | ||
host: { | ||
'[class.mdc-fab--extended]': 'extended', | ||
'[class.mat-mdc-extended-fab]': 'extended', | ||
'[attr.disabled]': 'disabled || null', | ||
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"', | ||
|
||
// Note that we ignore the user-specified tabindex when it's disabled for | ||
// consistency with the `mat-button` applied on native buttons where even | ||
// though they have an index, they're not tabbable. | ||
'[attr.tabindex]': 'disabled ? -1 : (tabIndex || 0)', | ||
'[attr.aria-disabled]': 'disabled.toString()', | ||
// MDC automatically applies the primary theme color to the button, but we want to support | ||
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to | ||
// select and style this "theme". | ||
'[class.mat-unthemed]': '!color', | ||
// Add a class that applies to all buttons. This makes it easier to target if somebody | ||
// wants to target all Material buttons. | ||
'[class.mat-mdc-button-base]': 'true', | ||
}, | ||
exportAs: 'matButton, matAnchor', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
|
@@ -78,9 +141,39 @@ export class MatFabAnchor extends MatAnchor { | |
// The FAB by default has its color set to accent. | ||
color = 'accent' as ThemePalette; | ||
|
||
extended: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one too |
||
|
||
constructor( | ||
elementRef: ElementRef, platform: Platform, ngZone: NgZone, | ||
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) { | ||
super(elementRef, platform, ngZone, animationMode); | ||
} | ||
|
||
static ngAcceptInputType_extended: BooleanInput; | ||
} | ||
|
||
/** | ||
* Material Design mini floating action button (FAB) component for anchor elements. Anchor elements | ||
* are used to provide links for the user to navigate across different routes or pages. | ||
* See https://material.io/components/buttons-floating-action-button/ | ||
*/ | ||
@Component({ | ||
selector: `a[mat-mini-fab]`, | ||
templateUrl: 'button.html', | ||
styleUrls: ['fab.css'], | ||
inputs: MAT_ANCHOR_INPUTS, | ||
host: MAT_ANCHOR_HOST, | ||
exportAs: 'matButton, matAnchor', | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MatMiniFabAnchor extends MatAnchor { | ||
// The FAB by default has its color set to accent. | ||
color = 'accent' as ThemePalette; | ||
|
||
constructor( | ||
elementRef: ElementRef, platform: Platform, ngZone: NgZone, | ||
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) { | ||
super(elementRef, platform, ngZone, animationMode); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "extended" the only variation or do we expect more? If we expect more, we can turn it into a string instead, e.g.
appearance: 'extended'
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be the only variation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this a setter/getter and use
coerceBooleanInput
that way peopel can do<button mat-fab extended>
instead of<button mat-fab [extended]="true">
(coerceBooleanInput
does some non-standard type coercion, e.g.'' => true
)