I have an idea of how to do responsive props using Styled Components, but I can't figure out how to implement it. My idea goes something like this:
<MyComponent
sm={{color: 'red', bg: 'green', }}
md={{color: 'yellow', bg: 'orange' }}
/>
In this case color
and bg
are just props that I set in my styled component:
The idea is that I have a top-level prop that is for a particular media query and that within that I have an object full of props that whose values that are props that I want to set at that media query.
Now, I know how to do a check for the props of color and bg -- i.e., like this:
const MyComponent = styled.div`
${props => props.color && `color: ${props.color};`}
${props => props.bg && `background-color: ${props.bg};`}
`
But is it possible for me to do something like this:
const MyComponent = styled.div`
${props => props.sm && MEDIA_QUERY_WITH_OBJECT_WITH_COLOR_AND_BG_PROPS}
${props => props.md && MEDIA_QUERY_WITH_OBJECT_WITH_COLOR_AND_BG_PROPS};`}
`
Or is there some way to accomplish to do this?
MEDIA_QUERY_WITH_OBJECT_WITH_COLOR_AND_BG_PROPS
looks like? try showing expected behaviour – Dennis Vash