-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Checkbox color updates & Extending theme based styling to variants #46
Conversation
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
==========================================
+ Coverage 68.36% 68.57% +0.21%
==========================================
Files 22 22
Lines 433 436 +3
Branches 92 92
==========================================
+ Hits 296 299 +3
Misses 107 107
Partials 30 30
Continue to review full report at Codecov.
|
2 similar comments
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
==========================================
+ Coverage 68.36% 68.57% +0.21%
==========================================
Files 22 22
Lines 433 436 +3
Branches 92 92
==========================================
+ Hits 296 299 +3
Misses 107 107
Partials 30 30
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
==========================================
+ Coverage 68.36% 68.57% +0.21%
==========================================
Files 22 22
Lines 433 436 +3
Branches 92 92
==========================================
+ Hits 296 299 +3
Misses 107 107
Partials 30 30
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #46 +/- ##
=========================================
+ Coverage 68.36% 68.5% +0.14%
=========================================
Files 22 22
Lines 433 435 +2
Branches 92 92
=========================================
+ Hits 296 298 +2
Misses 107 107
Partials 30 30
Continue to review full report at Codecov.
|
src/utils.js
Outdated
if (!config) throw new Error(`Molekule: "${variant}" variant not found in theme...`); | ||
return config; | ||
}; | ||
|
||
export const getComponentStyle = componentName => themeGet(`components.${componentName}.style`); | ||
|
||
export const getComponentVariantStyles = (componentName, variant) => | ||
themeGet(`components.${componentName}.variants.${variant}.style`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlemm45 This will return a function instead of a value because themeGet
returns a function that accepts theme
as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be the way it has been used here https://github.com/sappira-inc/molekule/blob/0656ca13a18efe5b70ebbced48f3848572fe321f/src/utils.js#L15 ? LMK @erikshestopal
src/utils.js
Outdated
@@ -4,15 +4,19 @@ import styled from 'styled-components'; | |||
export const themeGet = (lookup, fallback) => ({ theme } = {}) => get(theme, lookup, fallback); | |||
|
|||
export const getComponentVariant = (theme, componentName, variant) => { | |||
const config = themeGet(`components.${componentName}.variants.${variant}`, theme.variants[componentName][variant])({ | |||
const config = themeGet(`variants.${componentName}.${variant}`, theme.variants[componentName][variant])({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are now using the same thing for the lookup and the fallback? Should we keep the other property (components.${componentName}.variants.${variant}
) as the fallback now? If not, we might want to bump the version number, since it's potentially a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cehsu I bumped the major version
src/utils.js
Outdated
if (!config) throw new Error(`Molekule: "${variant}" variant not found in theme...`); | ||
return config; | ||
}; | ||
|
||
export const getComponentStyle = componentName => themeGet(`components.${componentName}.style`); | ||
|
||
export const getComponentVariantStyles = (componentName, variant) => | ||
themeGet(`components.${componentName}.variants.${variant}.style`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we want to support two conventions: components.${componentName}.variants.${variant}
and also variants.${componentName}.${variant}
(similar to getComponentVariant
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I addressed this here https://github.com/sappira-inc/molekule/blob/0656ca13a18efe5b70ebbced48f3848572fe321f/src/utils.js#L20 LMK @cehsu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'll do some QA, and plan to approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Component variants are already defined in isolation, .e.g https://github.com/heydoctor/molekule/blob/master/src/theme.js#L148-L152. It may make more sense to add the style property to the variant declaration:
const buttonVariants = {
primary: {
backgroundColor: colors.primary,
fontColor: 'white',
style: css`
&:hover {
background: coral;
}
`
},
}
//
const { backgroundColor, fontColor, style } = getComponentVariant(theme, 'Button', variant);
return css`
${style}
`
In getComponentVariant
, we can merge our custom variant with the default variant. We can discuss further at all hands
This reverts commit fba7a2b.
@kylealwyn Per @cehsu's comments I've already included that pattern you mention in tandem with the pattern above so you can do the following.
or what you mention above
|
@jlemm45 @cehsu I don't see why we would need or want to support both methods of styling variants |
@kylealwyn @cehsu Happy to remove the first pattern if no one sees a need. |
@jlemm45 Lets remove |
@heydoctor/engineering Given this is already going going to be a breaking change, albeit a minor, one file break, I propose we convert component style overrides to the same pattern as variants: const theme = {
...,
variants: {
Button: {
primary: {
style: css`
background: coral;
`
}
},
},
styles: {
Button: `
border-radius: 42px;
`
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, should we add some tests for these utils?
@@ -77,7 +78,8 @@ class CheckboxGroup extends Component { | |||
id={key} | |||
name={key} | |||
label={choice.label} | |||
color={color} | |||
colorOn={colorOn} | |||
colorOff={colorOff} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@cehsu Are referring to testing the new util functions in |
@cehsu I added some tests. LMK if you were thinking of something different. @kylealwyn Any further thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
Summary
colorOn
&colorOff
when using aCheckboxGroup
Theme styling updates
Problem
When extending the styles for a particular component at the theme level, I can't dig deeper into a per variant basis. This causes problems when trying to change the
hover
state for a secondary button only for example.Solution
Allow for the ability to pass styles into the variant level as well.
For example if I want to target a secondary button only I can pass this following in
theme.js
. Thestyle
key accepts a template string or a style object.