cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.07k stars 397 forks source link

[react-jss][jss-compose] Support function values for composed rules #474

Open lttb opened 7 years ago

lttb commented 7 years ago

It would be great to support function values with composed rules.

Online example

import injectSheet from 'react-jss'

const styles = {
  title: {
    fontSize: 20,
    color: ({ color }) => color
  },
  subtitle: {
    composes: '$title',
    fontSize: 16,
  }
}

const App = injectSheet(styles)(({ classes }) => (
  <div>
    <h1 className={classes.title}>jss</h1>
    {/* h2 need to be with green color too */}
    <h2 className={classes.subtitle}>jss</h2>
  </div>
))

render(
  <App color="green" />,
  document.getElementById('root')
)
kof commented 5 years ago

Reproduced the issue on codesandbox https://codesandbox.io/s/v3vo4752ol

The problem is that we are using 2 separate style sheets for dynamic/static styles in react-jss, because we want to reuse the static styles across all components and composes basically refers to the static one.

kof commented 5 years ago

Also to consider #501