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 custom prop #32

Merged
merged 2 commits into from
Oct 14, 2018
Merged

Theme custom prop #32

merged 2 commits into from
Oct 14, 2018

Conversation

ItsJonQ
Copy link
Contributor

@ItsJonQ ItsJonQ commented Oct 14, 2018

Theme custom prop

This update fixes the issue where a theme prop passed into the component
would be overridden by ThemeProvider.

The fix was to change the order of operations for supplying the theme prop to styled:

props.theme || (state !== null && state.theme) || {},

Storybook example below:

screen shot 2018-10-14 at 12 32 10 pm

stories.add('The theme prop', () => {
  // Define our button
  const Button = styled('button')`
    font-size: 1em;
    margin: 1em;
    padding: 0.25em 1em;
    border-radius: 3px;

    /* Color the border and text with theme.main */
    color: ${props => props.theme.main};
    border: 2px solid ${props => props.theme.main};
  `

  // Define what main theme will look like
  const theme = {
    main: 'mediumseagreen',
  }

  return (
    <div>
      <Button theme={{main: 'royalblue'}}>Ad hoc theme</Button>
      <ThemeProvider theme={theme}>
        <div>
          <Button>Themed</Button>
          <Button theme={{main: 'darkorange'}}>Overidden</Button>
        </div>
      </ThemeProvider>
    </div>
  )
})

Jon Q added 2 commits October 14, 2018 12:27
This update fixes the issue where a `theme` prop passed into the component
would be overridden by ThemeProvider.
@ItsJonQ ItsJonQ added the bug Something isn't working label Oct 14, 2018
@ItsJonQ ItsJonQ self-assigned this Oct 14, 2018
@coveralls
Copy link

Pull Request Test Coverage Report for Build 197

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 196: 0.0%
Covered Lines: 73
Relevant Lines: 73

💛 - Coveralls

@ItsJonQ ItsJonQ merged commit 5bfe518 into master Oct 14, 2018
@ItsJonQ ItsJonQ deleted the theme-custom-prop branch November 8, 2018 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants