Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

feat(checkbox): Add color theme mixins and update default color to secondary #1365

Merged
merged 81 commits into from
Oct 11, 2017

Conversation

acdvorak
Copy link
Contributor

@acdvorak acdvorak commented Sep 29, 2017

  • Removed [aria-disabled="true"] selector, as it doesn't appear to be necessary
  • Fixed preexisting state transition color animation bugs

Resolves #1146

@acdvorak acdvorak added this to the Theme Improvements milestone Sep 29, 2017
This gives the color rules a slightly higher CSS specificy, unfortunately, but as long as clients use our color mixins, it shouldn't be a problem.
@mixin mdc-checkbox-color($color) {
$ripple-config: (base-color: $color);

// TODO(acdvorak): Refactor ripple mixin to do this @if check automatically, or use mdc-theme-prop()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I want to do something about ripple's base-color/theme-style split...

// The frame's ::before element is used as a focus indicator for the checkbox
&::before {
@include mdc-checkbox-cover-element;
@include mdc-theme-prop(background, primary);
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, #1364 is adding $edgeOptOut: true here, so you will want to do likewise wherever the equivalent is (not sure if that will require doing it in all invocations of a mixin now, which will generate more CSS...)

}
}

@mixin mdc-checkbox-ripple-color($color, $opacity: .14) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just take ripple-config as an input. I don't want to invest in ripple customization right now...we'll handle that with states.

You can make a public variable mdc-checkbox-ripple-opacity, and reference it from the demo code (thats what we did for button).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would make the API inconsistent with the other color mixins (which only take a $color param).

If all the mixins take a single $color param (and possibly an optional second param), it makes it easy for users to try all of our mixins without needing to read the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

With button we just take in ripple-config. Ripple config is an existing concept in MDD Web, with its own complications. Our work on states should help improve the state of ripple-config, but lets not tackle that same problem in this PR.

Also when we tried to use a $color param directly with the mdc-button-ripple mixin we hit a lot of weird issues (around theme-ing versus non-theme colors) and I don't want to run into those again.

Also also, it should be just mdc-checkbox-ripple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


$demo-custom-color: $material-color-red-500;

.demo-checkbox--custom {
Copy link
Contributor

Choose a reason for hiding this comment

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

.mdc-checkbox.demo-checkbox--custom

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

In our demos the demo CSS comes after the MDC Web CSS....but on some clients order guarantee is difficult to implement. We want to document how to handle that case, which is to have a more specific CSS selector (two classes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

@mixin mdc-checkbox-stroke-color($color) {
.mdc-checkbox__background {
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 make this two mixins? @mixin mdc-checkbox-filled-stroke-color:

@include mdc-checkbox-background-filled-enabled {
  .mdc-checkbox__background {
    @include mdc-theme-prop(border-color, $color);
  }
}

And @mixin mdc-checkbox-unfilled-stroke-color:

@include mdc-checkbox-background-unfilled-enabled {
  .mdc-checkbox__background {
    @include mdc-theme-prop(border-color, $color);
  }
}

And we dont want to let clients customize the stroke color when the checkbox is disabled (thats what we did for button too).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

@mixin mdc-checkbox-container-color($color) {
.mdc-checkbox__background {
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 make @mixin mdc-checkbox-container-color:

@include mdc-checkbox-background-filled-enabled {
  .mdc-checkbox__background {
    @include mdc-theme-prop(background-color, $color);
  }
}

I can see why we wouldn't want to let clients customize the container color when the checkbox is disabled...But can you customize container color when the checkbox background is "unfilled"? (I'm guessing there is no container when the background is unfilled?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
}

@mixin mdc-checkbox-focus-color($color) {
Copy link
Contributor

Choose a reason for hiding this comment

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

mdc-checkbox-focus-indicator-color

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

mdc-checkbox-transition-enter(transform, 0ms, 80ms);
opacity: .26;
@include mdc-checkbox-background-filled-disabled {
@include mdc-checkbox-stroke-color(transparent);
Copy link
Contributor

Choose a reason for hiding this comment

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

just reference border-color directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

opacity: .26;
@include mdc-checkbox-background-filled-disabled {
@include mdc-checkbox-stroke-color(transparent);
@include mdc-checkbox-container-color($mdc-checkbox-disabled-color);
Copy link
Contributor

Choose a reason for hiding this comment

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

just reference background-color directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

stroke-dashoffset: 0;
}
@include mdc-checkbox-background-unfilled-disabled {
@include mdc-checkbox-stroke-color($mdc-checkbox-disabled-color-dark);
Copy link
Contributor

Choose a reason for hiding this comment

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

just reference border-color directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

transform: scaleX(1) rotate(0deg);
opacity: 1;
@include mdc-checkbox-background-filled-disabled {
@include mdc-checkbox-container-color($mdc-checkbox-disabled-color-dark);
Copy link
Contributor

Choose a reason for hiding this comment

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

just reference background-color directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
}

// Needed to disable hover effects on CSS-only (non-JS) checkboxes
.mdc-checkbox--disabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

how is mdc-checkbox--disabled different from mdc-checkbox-background-filled-disabled and mdc-checkbox-background-unfilled-disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mdc-checkbox--disabled is a modifier class for CSS-only buttons that prevents them from displaying a ripple or pointer cursor on hover.

mdc-checkbox-unfilled-background-selector-disabled_ and friends are convenience mixins that wrap a block of Sass in the big ugly CSS selectors needed to target the 4 different state combinations. This will also hopefully help us keep the relatively complex selectors in sync by putting them all in one place.

@@ -29,5 +29,5 @@ $mdc-checkbox-transition-duration: 90ms;
$mdc-checkbox-item-spacing: 4px;

/* Manual calculation done on SVG */
Copy link
Contributor

Choose a reason for hiding this comment

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

While you're in the neighborhood...switch this to a line comment to avoid emitting it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

background-color: $mdc-checkbox-mark-color;
opacity: 0;
@include mdc-checkbox-background-unfilled-disabled {
@include mdc-checkbox-stroke-color($mdc-checkbox-disabled-color);
Copy link
Contributor

Choose a reason for hiding this comment

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

I was about to say something like this :)

The nice thing about the button mixins is the user doesn't have to think about "enabled" at all, we apply it for them.

Also, we might be able to just use :enabled instead of :not(:disabled) here - the reason for :not(:disabled) on button was to also support its use for a elements across browsers.

@include mdc-checkbox-ripple((base-color: $color, opacity: $mdc-checkbox-ripple-opacity));
@include mdc-checkbox-stroke-and-container-fill-color(
$unmarked-stroke-color: $color,
$unmarked-container-fill-color: rgba($color, .25),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this .25 be a public variable in mdc-checkbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO probably not - this is just a demo page, and we don't have any official material guidelines about what opacity to use for fill color of an unmarked checkbox.

@include mdc-checkbox-ink-color(black);
@include mdc-checkbox-stroke-and-container-fill-color(
$unmarked-stroke-color: $color,
$unmarked-container-fill-color: rgba($color, .35),
Copy link
Contributor

Choose a reason for hiding this comment

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

How about .35?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ditto


Mixin | Description
--- | ---
`mdc-checkbox-stroke-and-container-fill-color($unmarked-stroke-color, $unmarked-container-fill-color, $marked-stroke-color, $marked-container-fill-color, $animate)` | Generates CSS classes to set and animate the stroke color and/or container fill color of a checkbox
Copy link
Contributor

Choose a reason for hiding this comment

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

I hate using "and" in API names...

How about mdc-checkbox-marked-indicator?

Copy link
Contributor

Choose a reason for hiding this comment

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

But it takes both marked and unmarked styles? Coming up with a good descriptive name for this is hard...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'm not wild about the name either...

The mixin covers both marked and unmarked states, so putting marked in the name would probably be misleading. And I'm not sure I would call this an indicator, exactly.

Since stroke and fill are both properties of the container, what about:
mdc-checkbox-container-colors?

Making the mixin name plural will hopefully make it obvious that it takes multiple color arguments, and help differentiate it from the other theme mixins that only take one color argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

mdc-checkbox-container-colors sounds right to me.


All parameters are optional, and if left unspecified will use their default values.

If you plan to use CSS-only checkboxes, set `$animate` to `false` to prevent the mixin from generating `@keyframes` and CSS classes used by the JavaScript component.
Copy link
Contributor

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 $keyframeAnimate...not just $animate. Doesn't the CSS-only checkbox still do some animation? Just not with keyframes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Getting super-pedantic here, but would that be transition rather than animation in that case? In which case animate might be enough distinction, but I could go either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally named it $generate-keyframes, so I changed it back to that. Does that work?

You're correct - the CSS-only checkbox uses transition to tween from marked to unmarked states instead of animation. As you suggested, it's probably more accurate to name the parameter something with "keyframes", because that's what it really controls.

Copy link
Contributor

Choose a reason for hiding this comment

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

generate-keyframes does sound better to me.

Copy link
Contributor

@lynnmercier lynnmercier left a comment

Choose a reason for hiding this comment

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

LGTM!

After discussing with design, it doesn't make sense to allow clients to customize stroke and fill color separately in the marked state. We still allow that in the unmarked state, however.
$color: $material-color-blue-500;

@include mdc-checkbox-container-colors(
$unmarked-stroke-color: $color,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest making this color different to better illustrate how this mixin's parameters work now. I was seriously confused for several minutes thinking we were applying the same stroke color to both states, but IIUC that's not what we're doing; we're making the marked stroke color match the marked fill color, which makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


#### `mdc-checkbox-container-colors($unmarked-stroke-color, $unmarked-fill-color, $marked-fill-color, $generate-keyframes)`

Generates CSS classes to set the stroke color and/or container fill color of a checkbox in its marked and unmarked states. In the unmarked state, stroke and fill color may be customized independently; in the marked state, the stroke disappears, and only the fill may be customized.
Copy link
Contributor

Choose a reason for hiding this comment

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

This sounds a little misleading... the stroke doesn't technically disappear, but it intentionally matches the marked fill color, they can't be customized separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@acdvorak acdvorak merged commit cc7538f into master Oct 11, 2017
@acdvorak acdvorak deleted the feat/theme/checkbox-mixins branch October 11, 2017 21:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants