cssinjs / styled-jss

Styled Components on top of JSS.
http://cssinjs.org/styled-jss
MIT License
217 stars 25 forks source link

What about dynamic themes? #16

Closed sergeysova closed 6 years ago

kof commented 7 years ago

@iamstarkov is working on a ThemeProvider which will work with styled-jss and react-jss and many others.

igl commented 7 years ago

jss-theme-reactor? the next version of material-ui will be using it.

kof commented 7 years ago

jss-theme-reactor is more an internal tool for mui, for now its not stable enough to rely on it.

igl commented 7 years ago

Unstable internal tool? It's mentioned high up on the JSS README

Making the ThemeProvider portable is already trivial. The rewiring to the component lib is a little annoying but easy peasy.

I just started to look at styled-jss and it's not looking so good there. I probably have to merge the context to the props in a hof/hoc. It should behave like styled-components/styletron imo.

ThemeProvider just needs to provide this:

ThemeProvider.contextTypes = {
    theme: PropTypes.object,
    styleManager: PropTypes.object,
}

styleManager just goes to the jss-lib and theme is read by the component directly:

styledComponent.button`
    color: ${ (props, context) => props.color || context.theme.color.main || 'blue' };
`

styletron('button', (props, context) => {
    color: props.color || context.theme.color.main || 'blue'
})

with hof:

styledComponent.button`
    color: ${ fromTheme('color.main', 'blue') };
`

styletron('button', (props, context) => {
    color: fromTheme('color.main', 'blue')
})
kof commented 7 years ago

Yep, I probably added it too early.

kof commented 7 years ago

The idea we work on is one ThemeProvider which will work with all libs, react-jss, styled-jss, styled-components etc etc

kof commented 7 years ago

We are just not there yet, we still need to finalize it.

kof commented 7 years ago

tbc in https://github.com/cssinjs/styled-jss/issues/20