Skip to content
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

feat(ripple): Add support for activated and selected states #1696

Merged
merged 4 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mdc-ripple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Mixin | Description

Mixin | Description
--- | ---
`mdc-states($color, $has-nested-focusable-element)` | Adds state and ripple styles for the indicated color, deciding opacities based on whether the passed color is light or dark. `$has-nested-focusable-element` defaults to `false` but should be set to `true` if the component contains a focusable element (e.g. an input) under the root node.
`mdc-states($color, $activated-color, $selected-color, $has-nested-focusable-element)` | Adds state and ripple styles for the indicated color, deciding opacities based on whether the passed color is light or dark.<br>`$activated-color` and `$selected-color` are optional, since not all components support these states; if present, they will emit styles for `--activated` or `--selected` modifiers, respectively.<br>`$has-nested-focusable-element` defaults to `false` but should be set to `true` if the component contains a focusable element (e.g. an input) under the root node.

##### Advanced States Mixins

Expand Down
40 changes: 37 additions & 3 deletions packages/mdc-ripple/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ $mdc-ripple-common-styles-emitted_: false !default;
&::after {
position: absolute;
border-radius: 50%;
opacity: 0;
pointer-events: none;
content: "";
will-change: transform, opacity;
Expand Down Expand Up @@ -104,8 +105,6 @@ $mdc-ripple-common-styles-emitted_: false !default;
&::before,
&::after {
@include mdc-theme-prop(background-color, $color, $edgeOptOut: true);

opacity: 0;
}
}

Expand Down Expand Up @@ -157,7 +156,7 @@ $mdc-ripple-common-styles-emitted_: false !default;
}

// Simple mixin which automatically selects opacity values based on whether the ink color is light or dark.
@mixin mdc-states($color: black, $has-nested-focusable-element: false) {
@mixin mdc-states($color: black, $activated-color: null, $selected-color: null, $has-nested-focusable-element: false) {
$color-value: mdc-theme-prop-value($color);
$opacity-map: if(
mdc-theme-tone($color-value) == "light",
Expand All @@ -169,6 +168,41 @@ $mdc-ripple-common-styles-emitted_: false !default;
@include mdc-states-hover-opacity(map-get($opacity-map, "hover"));
@include mdc-states-focus-opacity(map-get($opacity-map, "focus"), $has-nested-focusable-element);
@include mdc-states-press-opacity(map-get($opacity-map, "press"));

@if $activated-color {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a mdc-activated-state($color, $has-nested-focusable-element) mixin which just handles activated state? It seems like its isolated logic

&--activated {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does --activated work with all existing components? Or will this be a new modifier for some components?

// Stylelint seems to think that '&' qualifies as a type selector here?
// stylelint-disable-next-line selector-max-type
&::before {
opacity: map-get($opacity-map, "activated");
}

@include mdc-states-base-color($activated-color);
@include mdc-states-hover-opacity(map-get($opacity-map, "activated") + map-get($opacity-map, "hover"));
@include mdc-states-focus-opacity(
map-get($opacity-map, "activated") + map-get($opacity-map, "focus"),
$has-nested-focusable-element
);
@include mdc-states-press-opacity(map-get($opacity-map, "activated") + map-get($opacity-map, "press"));
}
}

@if $selected-color {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a mdc-selected-state($color, $has-nested-focusable-element) mixin which just handles selected state? It seems like its isolated logic

&--selected {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does --selected work with all existing components? Or will this be a new modifier for some components?

// stylelint-disable-next-line selector-max-type
&::before {
opacity: map-get($opacity-map, "selected");
}

@include mdc-states-base-color($selected-color);
@include mdc-states-hover-opacity(map-get($opacity-map, "selected") + map-get($opacity-map, "hover"));
@include mdc-states-focus-opacity(
map-get($opacity-map, "selected") + map-get($opacity-map, "focus"),
$has-nested-focusable-element
);
@include mdc-states-press-opacity(map-get($opacity-map, "selected") + map-get($opacity-map, "press"));
}
}
}

@mixin mdc-ripple-radius($radius: 100%) {
Expand Down
8 changes: 6 additions & 2 deletions packages/mdc-ripple/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ $mdc-states-wash-duration: 15ms;
$mdc-ripple-dark-ink-opacities: (
hover: .04,
focus: .12,
press: .16
press: .16,
selected: .04,
activated: .12
) !default;

$mdc-ripple-light-ink-opacities: (
hover: .08,
focus: .24,
press: .32
press: .32,
selected: .08,
activated: .24
) !default;

// Legacy
Expand Down