This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(ripple): Expose mdc-states-opacity; fix press fallback #2402
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26a7cbe
feat(ripple): Expose mdc-states-opacity; fix press fallback
fb8608f
WIP Fix README
9bd9adc
WIP Use public function within private mixin
0345266
Merge remote-tracking branch 'origin/master' into feat/ripple-states-…
7286577
Merge branch 'master' into feat/ripple-states-opacity
kfranqueiro 7c1e8ab
Merge branch 'master' into feat/ripple-states-opacity
kfranqueiro 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 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 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,48 @@ | ||
// | ||
// Copyright 2016 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
@import "@material/theme/functions"; | ||
@import "@material/theme/variables"; // for mdc-theme-prop-value | ||
@import "./variables"; | ||
|
||
// | ||
// Public | ||
// | ||
|
||
@function mdc-states-opacity($color, $state) { | ||
$opacity-map: mdc-states-opacities_($color); | ||
|
||
@if not map-has-key($opacity-map, $state) { | ||
@error "Invalid state: '#{$state}'. Choose one of: #{map-keys($opacity-map)}"; | ||
} | ||
|
||
@return map-get($opacity-map, $state); | ||
} | ||
|
||
// | ||
// Private | ||
// | ||
|
||
@function mdc-states-opacities_($color) { | ||
$color-value: mdc-theme-prop-value($color); | ||
$opacity-map: if( | ||
mdc-theme-tone($color-value) == "light", | ||
$mdc-ripple-light-ink-opacities, | ||
$mdc-ripple-dark-ink-opacities | ||
); | ||
|
||
@return $opacity-map; | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
// | ||
|
||
@import "@material/animation/variables"; | ||
@import "@material/theme/functions"; | ||
@import "@material/theme/mixins"; | ||
@import "./functions"; | ||
@import "./variables"; | ||
|
||
@mixin mdc-ripple-surface() { | ||
|
@@ -145,8 +145,7 @@ | |
// Simple mixin for activated states which automatically selects opacity values based on whether the ink color is | ||
// light or dark. | ||
@mixin mdc-states-activated($color, $has-nested-focusable-element: false) { | ||
$opacity-map: mdc-states-opacities_($color); | ||
$activated-opacity: map-get($opacity-map, "activated"); | ||
$activated-opacity: mdc-states-opacity($color, activated); | ||
|
||
&--activated { | ||
// Stylelint seems to think that '&' qualifies as a type selector here? | ||
|
@@ -162,8 +161,7 @@ | |
// Simple mixin for selected states which automatically selects opacity values based on whether the ink color is | ||
// light or dark. | ||
@mixin mdc-states-selected($color, $has-nested-focusable-element: false) { | ||
$opacity-map: mdc-states-opacities_($color); | ||
$selected-opacity: map-get($opacity-map, "selected"); | ||
$selected-opacity: mdc-states-opacity($color, selected); | ||
|
||
&--selected { | ||
// stylelint-disable-next-line selector-max-type | ||
|
@@ -219,26 +217,12 @@ | |
} | ||
} | ||
|
||
// | ||
// Private | ||
// | ||
|
||
@function mdc-states-opacities_($color) { | ||
$color-value: mdc-theme-prop-value($color); | ||
$opacity-map: if( | ||
mdc-theme-tone($color-value) == "light", | ||
$mdc-ripple-light-ink-opacities, | ||
$mdc-ripple-dark-ink-opacities | ||
); | ||
|
||
@return $opacity-map; | ||
} | ||
|
||
@mixin mdc-states-interactions_($color, $has-nested-focusable-element, $opacity-modifier: 0) { | ||
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. Let's use the new public function here too? 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 debated this, but since I'm doing multiple lookups on the same map it seemed like calling the public function repeatedly with the same color is wasted cycles to choose the same map. I'll test whether it actually has any noticeable impact whatsoever on build time though, 'cause I can see the argument that it'd be more readable. |
||
$opacity-map: mdc-states-opacities_($color); | ||
|
||
@include mdc-states-base-color($color); | ||
@include mdc-states-hover-opacity(map-get($opacity-map, "hover") + $opacity-modifier); | ||
@include mdc-states-focus-opacity(map-get($opacity-map, "focus") + $opacity-modifier, $has-nested-focusable-element); | ||
@include mdc-states-press-opacity(map-get($opacity-map, "press") + $opacity-modifier); | ||
@include mdc-states-hover-opacity(mdc-states-opacity($color, hover) + $opacity-modifier); | ||
@include mdc-states-focus-opacity( | ||
mdc-states-opacity($color, focus) + $opacity-modifier, | ||
$has-nested-focusable-element | ||
); | ||
@include mdc-states-press-opacity(mdc-states-opacity($color, press) + $opacity-modifier); | ||
} |
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.
Do
activated
andselected
need to be surrounded in quotes?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 wanted to stay consistent with the usage pattern we use for
mdc-theme-prop
, whereprimary
,secondary
, etc. aren't surrounded in quotes when used as values.Either should technically work, though unquoted values could be seen as a bit sloppy since they may be coerced to color if recognized as one (e.g.
black
), but even this is harmless as long as the usage is consistent both in the map's keys and inmap-get
invocations.If quoting is something we want to eventually encourage instead, we'd want to do so for
mdc-theme-prop
as well though.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.
Ok leaving it without quotes LGTM