Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

feat: Checkbox color updates & Extending theme based styling to variants #46

Merged
merged 8 commits into from
Jul 18, 2019

Conversation

jadenlemmon
Copy link
Contributor

Summary

  • Add the ability to pass colorOn & colorOff when using a CheckboxGroup
  • Add the ability to extend theme based styling into variants as well
  • Changes are based on issues encountered with PRD updates

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. The style key accepts a template string or a style object.

{  
  Button: {
      variants: {
        secondary: {
          style: `
            &:hover {
              background-color: tomato;
            }
          `,
        },
      },
    },
}

@jadenlemmon jadenlemmon requested a review from a team July 12, 2019 20:55
@ghost ghost requested review from cehsu and kylealwyn July 12, 2019 20:56
@codecov
Copy link

codecov bot commented Jul 12, 2019

Codecov Report

Merging #46 into master will increase coverage by 0.21%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/utils.js 95.12% <100%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fada878...fa2cd3b. Read the comment docs.

2 similar comments
@codecov
Copy link

codecov bot commented Jul 12, 2019

Codecov Report

Merging #46 into master will increase coverage by 0.21%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/utils.js 95.12% <100%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fada878...fa2cd3b. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 12, 2019

Codecov Report

Merging #46 into master will increase coverage by 0.21%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/utils.js 95.12% <100%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fada878...fa2cd3b. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 12, 2019

Codecov Report

Merging #46 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/utils.js 95% <100%> (+0.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fada878...e8bde4e. Read the comment docs.

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`);
Copy link
Contributor

@erikshestopal erikshestopal Jul 12, 2019

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.

Copy link
Contributor Author

@jadenlemmon jadenlemmon Jul 15, 2019

Choose a reason for hiding this comment

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

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])({
Copy link
Contributor

@cehsu cehsu Jul 12, 2019

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.

Copy link
Contributor Author

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`);
Copy link
Contributor

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)?

Copy link
Contributor Author

@jadenlemmon jadenlemmon Jul 15, 2019

Choose a reason for hiding this comment

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

Copy link
Contributor

@cehsu cehsu 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 me. I'll do some QA, and plan to approve.

Copy link
Contributor

@kylealwyn kylealwyn left a 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

package.json Outdated Show resolved Hide resolved
This reverts commit fba7a2b.
@jadenlemmon
Copy link
Contributor Author

@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.

{
  Button: {
      variants: {
        secondary: {
          style: `
            &:hover {
              background-color: tomato;
            }
          `,
        },
      },
  }
}

or what you mention above

{
  primary: {
    backgroundColor: colors.primary,
    fontColor: 'white',
    style: css`
	  &:hover {
         background: coral;
      },
  },
}

@kylealwyn
Copy link
Contributor

@jlemm45 @cehsu I don't see why we would need or want to support both methods of styling variants

@jadenlemmon
Copy link
Contributor Author

@kylealwyn @cehsu Happy to remove the first pattern if no one sees a need.

@kylealwyn
Copy link
Contributor

@jlemm45 Lets remove

@kylealwyn
Copy link
Contributor

kylealwyn commented Jul 16, 2019

@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;
        `
     }
}

@kylealwyn kylealwyn changed the title Checkbox color updates & Extending theme based styling to variants feat: Checkbox color updates & Extending theme based styling to variants Jul 16, 2019
Copy link
Contributor

@cehsu cehsu 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 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}
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@jadenlemmon
Copy link
Contributor Author

jadenlemmon commented Jul 17, 2019

@cehsu Are referring to testing the new util functions in utils.js? Just want to confirm.

@jadenlemmon
Copy link
Contributor Author

@cehsu I added some tests. LMK if you were thinking of something different. @kylealwyn Any further thoughts?

Copy link
Contributor

@kylealwyn kylealwyn left a comment

Choose a reason for hiding this comment

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

Awesome

@jadenlemmon jadenlemmon merged commit 6f3569f into master Jul 18, 2019
@jadenlemmon jadenlemmon deleted the feat/patient-rd-color-scheme branch July 18, 2019 00:49
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