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

How to Dynamically Theme Components #6

Closed
liveresume opened this issue Nov 28, 2016 · 1 comment
Closed

How to Dynamically Theme Components #6

liveresume opened this issue Nov 28, 2016 · 1 comment
Labels

Comments

@liveresume
Copy link

liveresume commented Nov 28, 2016

The docs say theming can be done without headaches but I am having trouble doing just that. What is the recommended approach to theming?

I am currently using jss and react and wrote some mods so I can do:

const styles = (theme) => ({
  button: {
    color: theme.palette.primary
  }
})

@injectSheet(styles)
class Button extends React.Component {
  render () {
    const { s, label } = this.props
    return (
      <button className={s.button}>
        <div>{ label }</div>
      </button>
    )
  }
}

This way I can also dynamically modify the theme and have changes instantly appear.
Change Theme -> HOC detects change -> HOC updates its WrappedComponent

Problem with this approach, this lib, and react, is that if the theme is changed then every style needs to be recalculated. In order to update react we could simply update the stylesheet, and the DOM would take care of everything. But this is only possible if the classnames have not changed. If they do change the react comps need updating.

My thoughts on how this could work with your lib and without integrating with React:
Change Theme -> Stylesheet.create (yours wrapped by my code) detects theme change -> triggers a stylesheet update -> DOM automatically updates everything

I believe that for this to work the classnames must remain the same.

If they can not, then I require an HOC to pass new classnames down as props which will trigger the React update. Of course if this is the only way then there is no place for this lib + react + dynamic theming. Correct?

Any ideas?

@kof
Copy link
Member

kof commented Nov 29, 2016

We will be working on a different theming approach for core jss soon.
As of for aphrodisiac you can simply pass the style objects down to children.

@kof kof added the question label Nov 29, 2016
@kof kof closed this as completed Feb 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants