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

withStyle access to component props #12768

Closed
2 tasks done
2p4b opened this issue Sep 3, 2018 · 5 comments
Closed
2 tasks done

withStyle access to component props #12768

2p4b opened this issue Sep 3, 2018 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@2p4b
Copy link

2p4b commented Sep 3, 2018

  • This is a v1.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Is the currently an api to accessing the component props from the style like styled-components?
say something like this:

const styles = (theme, props) => ({
    root: {
        display: 'flex',
        flexDirection: 'row',
        backgroundImage: `url("${props.url}")`,
        backgroundColor: props.color? props.color : theme.pallete.primary.main
    }
})

const Hero = ({classes, title}) => <div className={classes.root}>{title}</div>

export default withStyle(styles)(Hero)

Current Behavior

I'm currently using inline styling

Example

const styles = (theme, props) => ({
    root: {
        display: 'flex',
        flexDirection: 'row'
    }
})
const genStyle = (url, color='blue') => ({
    backgroundColor: color,
    backgroundImage: `url("${url}")`
})

const Hero = ({classes, title, url, color}) => (
    <div className={classes.root} style={genStyle(url, color)}>
        {title}
    </div>
)

export default withStyle(styles)(Hero)

Context

Generate styles based on the props of the component like determining theme, passing in background colors etc.

@oliviertassinari oliviertassinari added the duplicate This issue or pull request already exists label Sep 3, 2018
@oliviertassinari
Copy link
Member

@mfoncho It's a duplicate of #7633

@2p4b
Copy link
Author

2p4b commented Sep 3, 2018

@oliviertassinari thanks for the reference thread, but after much talk about getting it into the 1.x is the api there? or should i have to write a HOC to wrap the withStyle HOC to get both props and theme? because #7633 was closed without a consensus on if the feature will be added or not. just trying not to reinvent the wheel here since withStyle already does some caching

@oliviertassinari
Copy link
Member

@mfoncho The issue is still open. It's one of my top priorities. I also want to look into emotion at the same time, see if we can leverage it.

@JacquesBonet
Copy link

JacquesBonet commented Sep 10, 2018

You can use my library @mfoncho, it match what you like : https://github.com/JacquesBonet/jss-material-ui

@2p4b
Copy link
Author

2p4b commented Sep 10, 2018

@JacquesBonet not so much of a library is needed to implement the required feature but just a simple like this StyledPropsHOC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants