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

colorMode key improvements; computed dependencies update #44

Merged

Conversation

thompsongl
Copy link

Summary

Again, more for discussion than to merge this in its current state. Let's see if the changes are closer to your ideal API

@thompsongl
Copy link
Author

thompsongl commented Mar 25, 2021

TS-to-PropTypes parsing has errors. Trying to figure it out.

^ is happening in the target branch, so this does not need to be solved in this branch. It will likely be difficult to resolve before there is a clearer theme shape, and themes (default, ams) match.

Copy link
Owner

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Thanks!! A lot of the consuming syntax is so simple and intuitive. My following comments are mostly for my clarification. Go ahead and merge this when you're happy with it and/or want to address anything as a follow up.

light: {
success: computed(['colors.primary'], () => '#85E89d'),
success: computed(() => '#85E89d', ['colors.primary']),
Copy link
Owner

Choose a reason for hiding this comment

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

Just double-checking that this doesn't actually need to be computed because it seems to just be returning a straight hex value?

Suggested change
success: computed(() => '#85E89d', ['colors.primary']),
success: '#85E89d',

Copy link
Author

Choose a reason for hiding this comment

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

Nope. Just left over from some check I was doing.

Comment on lines +31 to +34
thin: computed(([widthThin, color]) => `${widthThin} solid ${color}`, [
'border.widthThin',
'border.color',
]),
Copy link
Owner

Choose a reason for hiding this comment

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

Is this a possible different way to write this, do does the array values have to be a single key?

Suggested change
thin: computed(([widthThin, color]) => `${widthThin} solid ${color}`, [
'border.widthThin',
'border.color',
]),
thin: computed(([border]) => `${border.widthThin} solid ${border.color}`, ['border']),

Copy link
Owner

Choose a reason for hiding this comment

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

Also could we simplify further to allow the second param to be a single value as well as an array like:

Suggested change
thin: computed(([widthThin, color]) => `${widthThin} solid ${color}`, [
'border.widthThin',
'border.color',
]),
thin: computed((border) => `${border.widthThin} solid ${border.color}`, 'border'),

Copy link
Author

Choose a reason for hiding this comment

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

Is this a possible different way to write this, do does the array values have to be a single key?

This is similar to object spreading, and I haven't been able to make it work yet. It's on my radar, though, and I'll keep exploring options.

Also could we simplify further to allow the second param to be a single value as well as an array like

Sure, we could allow single dependency values in addition to arrays.

Comment on lines +34 to +37
textPrimary: computed((theme) => makeHighContrastColor(theme.colors.primary)),
textAccent: computed(([accent]) => makeHighContrastColor(accent), [
'colors.accent',
]),
Copy link
Owner

Choose a reason for hiding this comment

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

This might have answered my question above. Just want to know what the preferred guidance is for these computed values. Is one method better than the other?

Copy link
Author

Choose a reason for hiding this comment

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

It's entirely up to consumer preference. I'm not sure there's a large enough computational difference to say that one is better than the other.

Comment on lines -36 to +34
xxl: computed([`${COLOR_MODE_KEY}.base`], ([base]) => `${base * 2.5}px`),
xs: computed(sizeToPixel(0.25)),
Copy link
Owner

Choose a reason for hiding this comment

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

This is fantastic! So much simpler! Is this then even something a consumer could do?

Copy link
Author

Choose a reason for hiding this comment

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

Yep, consumers can use utility functions like this if we export them, or they can write their own curried/partial functions to do similar things.

@@ -69,7 +69,7 @@ const font: EuiFont = {

// Font weights
const fontWeight = {
light: '300',
weightLight: '300', // TODO
Copy link
Owner

Choose a reason for hiding this comment

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

Yeah so we talked about maybe for the color mode keys, they're uppercased like LIGHT and DARK leaving any lowercase versions allowed as normal keys here. But I'm fine with this for now.

Copy link
Author

Choose a reason for hiding this comment

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

I'll change this back before merging. I think it's certain we won't use light and dark as color mode keys, so moving to something else right now makes sense.

@thompsongl
Copy link
Author

Gonna make a couple changes before merging this

@thompsongl
Copy link
Author

All done. Apparently only you can merge PRs here

@cchaos cchaos merged commit a2494b2 into cchaos:feature/css-in-js_themes Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants