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

[theme] Use a single theme variable for the hover effects of Button, IconButton and ListItem #10952

Merged
merged 2 commits into from
Apr 15, 2018
Merged

[theme] Use a single theme variable for the hover effects of Button, IconButton and ListItem #10952

merged 2 commits into from
Apr 15, 2018

Conversation

SebastianSchmidt
Copy link
Contributor

@SebastianSchmidt SebastianSchmidt commented Apr 7, 2018

In #10870 it was decided that all hover effects should be created based on a theme variable to ensure a consistent hover effect in all components. Instead of creating a new theme variable I used the existing theme variable theme.palette.action.hover to keep customizing the theme simple.

For this purpose I have enhanced the existing function fade. This function sets the absolute transparency of a color. So far, the new transparency could be indicated by a number. Now you can also specify a CSS color instead, whose transparency is used. In this way, the transparency from the existing theme variable theme.palette.action.hover can be reused. The advantage of this approach is that all hover effects can be customized using a single theme variable.

@@ -32,7 +32,7 @@ export const light = {
// The color of an active action like an icon button.
active: 'rgba(0, 0, 0, 0.54)',
// The color of an hovered action.
hover: 'rgba(0, 0, 0, 0.08)',
hover: 'rgba(0, 0, 0, 0.12)',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I've misunderstood, as I've only looked at this superficially, but since @oliviertassinari was concerned that 0.12 is too opaque, and you in turn that 0.04 is too transparent, isn't 0.08 the perfect compromise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mbrookes @oliviertassinari Yes, 0.08 looks good! I have added this value to the table with the examples and modified the pull request.

@SebastianSchmidt SebastianSchmidt changed the title [theme] Use a theme variable for the hover effects of Button, IconButton and ListItem [theme] Use a single theme variable for the hover effects of Button, IconButton and ListItem Apr 7, 2018
@SebastianSchmidt
Copy link
Contributor Author

The hover effects of Button and IconButton now use the same transparency as ListItem.

@@ -187,6 +187,17 @@ describe('utils/colorManipulator', () => {
assert.strictEqual(fade('hsla(0, 100%, 50%, 0.2)', 0.5), 'hsla(0, 100%, 50%, 0.5)');
});

it('sets the transparency of a color to the transparency of the color provided', () => {
assert.strictEqual(
fade('rgba(255, 0, 0, 0.2)', 'rgba(1, 2, 3, 0.5)'),
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to support this API? This looks counter-intuitive to me.

Copy link
Member

@mbrookes mbrookes Apr 7, 2018

Choose a reason for hiding this comment

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

My first reaction was "yuck", so I"m glad it wasn't just me! 😄 (Sorry @SebastianSchmidt!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think the approach of reusing the existing theme variable in this way is basically correct? Then I would move the logic for extracting and applying transparency to its own function.

Copy link
Member

@oliviertassinari oliviertassinari Apr 7, 2018

Choose a reason for hiding this comment

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

I was thinking of adding a theme.palette.action.hoverOpacity = 0.08 property or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oliviertassinari In my opinion, adding a new variable causes the following problem:

The transparency of hover effects is configured in two variables and must be kept consistent with each other. If a user changes only one of the two variables, the hover effects of the components are inconsistent. The user does not necessarily notice this error directly; and later the user wonders why the components of his user interface are inconsistent with each other.

To avoid this error, I would suggest to use only one variable and extract the required information (the degree of transparency) via a help function. This simplifies the configuration of the theme for the user.

Copy link
Member

@oliviertassinari oliviertassinari Apr 8, 2018

Choose a reason for hiding this comment

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

The transparency of hover effects is configured in two variables and must be kept consistent with each other.

@SebastianSchmidt It's a tradeoff, I can live with it. But why not addressing the duplication issue 👍 . The helper function can do it. Should we keep the intermediary result (hoverOpacity) in the theme or compute it everytime?

I have realized that the current fade value (0.04) is close to imperceptible with the dark theme.

@oliviertassinari oliviertassinari self-assigned this Apr 15, 2018
@oliviertassinari oliviertassinari added core design: material This is about Material Design, please involve a visual or UX designer in the process and removed core labels Apr 15, 2018
@oliviertassinari oliviertassinari merged commit ebe9b25 into mui:v1-beta Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design: material This is about Material Design, please involve a visual or UX designer in the process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants