-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(material/button): switch to tokens theming API #27784
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8f88283
refactor(material/button): switch to tokens theming API
wagnermaciel 2b0c208
fixup! refactor(material/button): switch to tokens theming API
wagnermaciel deddbef
fixup! refactor(material/button): switch to tokens theming API
wagnermaciel 9621ae0
fixup! refactor(material/button): switch to tokens theming API
wagnermaciel 1638385
fixup! refactor(material/button): switch to tokens theming API
wagnermaciel 0e81dd1
fixup! refactor(material/button): switch to tokens theming API
wagnermaciel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
@use '../../token-utils'; | ||
@use '../../../mdc-helpers/mdc-helpers'; | ||
@use '../../../style/sass-utils'; | ||
@use '../../../theming/inspection'; | ||
|
||
// The prefix used to generate the fully qualified name for tokens in this file. | ||
$prefix: (mdc, button-filled); | ||
|
||
// Tokens that can't be configured through Angular Material's current theming API, | ||
// but may be in a future version of the theming API. | ||
// | ||
// Tokens that are available in MDC, but not used in Angular Material should be mapped to `null`. | ||
// `null` indicates that we are intentionally choosing not to emit a slot or value for the token in | ||
// our CSS. | ||
@function get-unthemable-tokens() { | ||
@return ( | ||
container-elevation: 0, | ||
container-height: 36px, | ||
container-shape: 4px, | ||
disabled-container-elevation: 0, | ||
focus-container-elevation: 0, | ||
hover-container-elevation: 0, | ||
keep-touch-target: false, | ||
pressed-container-elevation: 0, | ||
|
||
focus-state-layer-opacity: null, | ||
hover-state-layer-opacity: null, | ||
pressed-state-layer-opacity: null, | ||
container-shadow-color: null, | ||
focus-label-text-color: null, | ||
hover-label-text-color: null, | ||
label-text-font: null, | ||
label-text-size: null, | ||
label-text-tracking: null, | ||
label-text-transform: null, | ||
label-text-weight: null, | ||
pressed-label-text-color: null, | ||
with-icon-disabled-icon-color: null, | ||
with-icon-focus-icon-color: null, | ||
with-icon-hover-icon-color: null, | ||
with-icon-icon-color: null, | ||
with-icon-icon-size: null, | ||
with-icon-pressed-icon-color: null | ||
); | ||
} | ||
|
||
@function on-color($theme, $palette) { | ||
@if ($palette) { | ||
$is-dark: inspection.get-theme-type($theme) == dark; | ||
@return if(mdc-helpers.variable-safe-contrast-tone($palette, $is-dark) == 'dark', #000, #fff); | ||
} | ||
} | ||
|
||
// Tokens that can be configured through Angular Material's color theming API. | ||
@function get-color-tokens($theme, $color: null, $on-color: null) { | ||
$is-dark: inspection.get-theme-type($theme) == dark; | ||
$primary: inspection.get-theme-color($theme, primary); | ||
$surface: inspection.get-theme-color($theme, background, card); | ||
$on-primary: on-color($theme, $primary); | ||
$on-surface: on-color($theme, $surface); | ||
|
||
@return ( | ||
container-color: if($color, $color, transparent), | ||
disabled-container-color: rgba($on-surface, 0.12), | ||
disabled-label-text-color: rgba($on-surface, if($is-dark, 0.5, 0.38)), | ||
focus-state-layer-color: $on-primary, | ||
hover-state-layer-color: $on-primary, | ||
label-text-color: if($on-color, $on-color, inherit), | ||
pressed-state-layer-color: $on-primary | ||
); | ||
} | ||
|
||
// Tokens that can be configured through Angular Material's typography theming API. | ||
@function get-typography-tokens($theme) { | ||
@return (); | ||
} | ||
|
||
// Tokens that can be configured through Angular Material's density theming API. | ||
@function get-density-tokens($theme) { | ||
@return (); | ||
} | ||
|
||
// Combines the tokens generated by the above functions into a single map with placeholder values. | ||
// This is used to create token slots. | ||
@function get-token-slots() { | ||
@return sass-utils.deep-merge-all( | ||
get-unthemable-tokens(), | ||
get-color-tokens(token-utils.$placeholder-color-config), | ||
get-typography-tokens(token-utils.$placeholder-typography-config), | ||
get-density-tokens(token-utils.$placeholder-density-config) | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The typography and density styles are still using MDC's old API. Shouldn't we switch them over as well?
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.
Yeah this is what I was trying to bring up in standup but didn't have time to dive into. Currently all button variants are relying on the same styles for density & typography. I asked if I should split those out and Andrew said he was ok with landing this without doing so
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.
That said, I don't really know if I was able to explain the situation in the short time we had during standup. I'll ping Andrew and see if he can weigh in here
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.
That's at least what we've been doing when converting the other components to tokens. For the filled button specifically it looks like we have these 5 tokens for the typography:
label-text-font
,label-text-size
,label-text-tracking
,label-text-transform
,label-text-weight
and thecontainer-height
token for the density.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.
Had a chat with Wagner - it'll be a bit easier to land the typography changes across all the variants at once after these PRs land. It'll just be a different iterative approach that reaches the same goal in the end (remove the old MDC mixins)
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.
Alright, I wanted to make sure that we do it before we consider the button as migrated.