withStyle access to component props
See original GitHub issue- 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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
withStyle access to component props · Issue #12768 - GitHub
Is the currently an api to accessing the component props from the style like styled-components? say something like this: const styles = (theme ......
Read more >Passing props to MUI styles - reactjs - Stack Overflow
In MUI v5, this is how you access the props when creating the style object ... When you're using withStyles , you have...
Read more >How to use the @material-ui/core.withStyles function in ... - Snyk
withStyles examples, based on popular ways it is used in public projects. ... withStyles(styles)(RenderComponentsRaw); let components = (props: stateProps) ...
Read more >Advanced (LEGACY) - MUI System
The wrapped component accepts a classes prop, it simply merges the class names provided with the style sheet. const Nested = withStyles({ root:...
Read more >Basics - styled-components
Simple dynamic styling: adapting the styling of a component based on its props or a global theme is simple and intuitive without having...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 not so much of a library is needed to implement the required feature but just a simple like this StyledPropsHOC