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: make text-input theme-able #563

Merged
merged 3 commits into from
Apr 2, 2019
Merged

feat: make text-input theme-able #563

merged 3 commits into from
Apr 2, 2019

Conversation

montezume
Copy link
Contributor

@montezume montezume commented Feb 21, 2019

Making UI-Kit Themeable

This PR contains two major changes.

New choices

The first change introduces new choices. These choices have more semantically meaningful names that the old choices. For example, color-green, becomes color-primary. For now, this is a non breaking change. The choices are duplicated, and the old choices remain. At some point in the future, we will remove these now deprecated choices. See the table below for the new (and old) names.

(deprecated) choice new choice decision (value)
color-green color-primary #00b39e
color-green-25 color-primary-25 hsl(172.9608938547486, 100%, 25%)
color-green-40 color-primary-40 hsl(172.9608938547486, 100%, 40%)
color-green-85 color-primary-85 hsl(172.9608938547486, 100%, 85%)
color-green-95 color-primary-95 hsl(172.9608938547486, 100%, 95%)
color-navy color-accent #213c45
color-navy-30 color-accent-30 hsl(195, 35.2941176471%, 30)
color-navy-40 color-accent-40 hsl(195, 35.2941176471%, 40)
color-navy-95 color-accent-95 hsl(195, 35.2941176471%, 95)
color-navy-98 color-accent-98 hsl(195, 35.2941176471%, 98)
color-gray color-neutral #cccccc
color-gray-60 color-neutral-60 hsl(0, 0%, 60%)
color-gray-90 color-neutral-90 hsl(0, 0%, 90%)
color-gray-95 color-neutral-95 hsl(0, 0%, 95%)
color-blue color-info #078cdf
color-blue-85 color-info-85 hsl(203.05555555555554, 93.9130434783%, 85%)
color-blue-95 color-info-95 hsl(203.05555555555554, 93.9130434783%, 95%)
color-orange color-warning #f16d0e
color-orange-95 color-warning-95 hsl(25.110132158590307, 89.0196078431%, 95%)
color-red color-error #e60050
color-red-95 color-error-95 hsl(339.1304347826087, 100%, 95%)
color-black color-solid #1a1a1a
color-white color-surface #ffffff

Internally we now use these new choices for our design tokens.

Introducing the concept of a theme

By default, we can think about UI-Kit's theme as being the relationship between a choice and a decision. For example, in our (default) theme, we set the color-surface choice to the decision #FFF.

Overriding the default theme for a specific component.

In this PR, the ability to override the default theme for the component text-input has been added. A user can set a custom theme to the component as follows.

import { ThemeProvider } from 'emotion-theming';
import { TextInput } from '@commercetools-frontend/ui-kit';

const darkTheme = {
  colorSurface: 'black',
  colorSolid: 'white',
  colorDarkAccent98: 'white',
  colorError: 'darkred',
};

const DarkTextInput = ({value, onChange}) => (
    <ThemeProvider theme={darkTheme}>
        <TextInput name="dark-input" value={value} onChange={onChange} />
    </ThemeProvider>
);

Overriding the default theme for an entire application.

ThemeProvider supports nested themes, so once we have added theming to more components, users will be able to override the theme once in their app, and have it propagated everywhere UI-Kit is used.

What's next?

Once this PR has been merged, we can go about supporting themeing in the other components.

@montezume montezume requested a review from emmenko February 21, 2019 16:41
@montezume montezume changed the title feat: show example of how themeing and design tokens could work together [WIP] show example of how themeing and design tokens could work together Feb 21, 2019
@@ -0,0 +1,18 @@
export default {
backgroundColorForInput: 'colorWhite',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file would need to be autogenerated

const getInputStyles = (props, theme) => {
const overwrittenVars = {
...vars,
...theme,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

basically how it works, is in your theme, you overwrite one of our choices. So for "colorGreen", you can specify "pink".

background-color: ${vars.backgroundColorForInput};
border: 1px solid ${vars.borderColorForInput};
border-radius: ${vars.borderRadiusForInput};
background-color: ${overwrittenVars[designTokens.backgroundColorForInput]};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we use design tokens, but the design tokens variables contain "choices"

@tdeekens
Copy link
Contributor

Nice. Can you maybe, for us on the outside, give a set of use cases we need theming fir?

@emmenko
Copy link
Member

emmenko commented Feb 22, 2019

Can you maybe, for us on the outside, give a set of use cases we need theming fir?

We wanted to look into it to see if/how we can use the ui-kit components/design tokens for other use cases other than the MC (e.g. documentation websites).

However, I feel like having a "theme-like" structure, will help/force us to keep the design system/tokens more consistent. For example, the color names as we have them now don't make much sense. Instead of --color-green we should probably use --color-primary.

@tdeekens
Copy link
Contributor

tdeekens commented Feb 22, 2019

the color names as we have them now don't make much sense

Yes, that's my main concern. We would need more generic/semantic colour names. Like primary, accent, warning etc pp.

other use cases other than the MC (e.g. documentation websites).

Do we have designs or colour palettes for those? Feels a bit hard to anticipate what we need without. Even though this exploration is obviously great.

Sorry for clicking the wrong button

@tdeekens tdeekens closed this Feb 22, 2019
@tdeekens tdeekens reopened this Feb 22, 2019
@montezume
Copy link
Contributor Author

We can support theming without actually coming up with other colour palettes. As you can see from this PR, the code changes are very minimal 😇.

The blocker right now is renaming the choices.

@tdeekens
Copy link
Contributor

I like the names!

@montezume montezume changed the title [WIP] show example of how themeing and design tokens could work together feat: make text-input theme-able Feb 28, 2019
@montezume montezume force-pushed the ml-theme branch 2 times, most recently from f5db7e3 to 4327dd3 Compare March 29, 2019 08:46
@montezume montezume requested a review from tdeekens March 29, 2019 09:57
@montezume montezume self-assigned this Mar 29, 2019
@montezume montezume requested a review from Shecki March 29, 2019 09:58
@Shecki
Copy link

Shecki commented Mar 29, 2019

in the design-team, we had a closer look at the naming and changed three proposals to make it more generic. (bold=new)

green = Primary
navy = accent
Blue = Information
Orange = Warning
Red = Error
Black = solid
Gray = Neutral
White = surface

sorry for mention it so late.. could these one be updated?
This would be awesome! Thanks!

@tdeekens
Copy link
Contributor

Thanks. I am a bit worried about these

Black = solid
Gray = Neutral
White = surface

White is not the surface whenever a theme is inverted. Just saying.

@emmenko
Copy link
Member

emmenko commented Mar 29, 2019

I agree with @tdeekens . Think about if you would have a dark theme, what would the color names map to.

Why not keeping black/white as dark/light?

@Shecki
Copy link

Shecki commented Mar 29, 2019

maybe this graphic will help a bit.
if we would use (light) + (dark) all colors have to be at least light or dark.. we already setting limitations
image

this is why we went for (surface) (solid)

Hope it helps?

@emmenko
Copy link
Member

emmenko commented Mar 29, 2019

Yeah dark/light names for the inverted colors is a bit weird.

I think we all want the same thing eventually, solid/surface for me also feels a bit weird but maybe we just need to get used to it. At least I can't think of any better name...

Thanks

@tdeekens
Copy link
Contributor

tdeekens commented Mar 29, 2019

Thanks. Agreed. Maybe it's just we're not used to it but eventually the smallest evil name :)

@montezume
Copy link
Contributor Author

Okay I updated the color names 👍

@montezume
Copy link
Contributor Author

Sven gave the okay from the design side. Is there anything from the code review side or can I merge? @tdeekens @emmenko ?

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

Looks good to give it a shot I think. Curious to see where this leads and how it may be used. I presume we consider theming a beta feature for now?

--color-primary-25: hsl(172.9608938547486, 100%, 25%);
--color-primary-40: hsl(172.9608938547486, 100%, 40%);
--color-primary-85: hsl(172.9608938547486, 100%, 85%);
--color-primary-95: hsl(172.9608938547486, 100%, 95%);
Copy link
Contributor

Choose a reason for hiding this comment

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

172.9608938547486 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK these values haven't changed 😆. They are just copy pasted of color-green-25, etc. But yeah, the weird 172.9608938547486 value comes because before we were using some postcss plugin to generate the value. Might make sense to round these 🤔

Copy link
Contributor

@tdeekens tdeekens Apr 2, 2019

Choose a reason for hiding this comment

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

I guess rounding them would be a separate task but it would make sense.

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe use rgba instead of hsl?

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Cool, looking forward to see the first results! 🚀

const darkTheme = {
colorLight: 'black',
colorDark: 'white',
colorDarkAccent98: 'white',
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't those be solid/surface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah true, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂️

@montezume montezume merged commit 6b49e33 into master Apr 2, 2019
@montezume montezume deleted the ml-theme branch April 2, 2019 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants