Created
October 16, 2017 19:53
-
-
Save markphilpot/9755c2c73c0a0f32ece787f929c0968f to your computer and use it in GitHub Desktop.
Example using Compent as Selector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In this example, we have a box with subcomponents BoxInner and Prompt. Both are `styled.div` | |
// In line 5, we are customizing the apperance of BoxInner w/o moving those features in to props | |
// In line 10, we are applying the hover state to nested elements when the parent is hovered. | |
const Box = styled.div` | |
border: 1px dashed #ccc; | |
${BoxInner} { | |
filter: opacity(50%) grayscale(50%); | |
} | |
&:hover { | |
border-color: blue; | |
${BoxInner} { | |
filter: opacity(100%) grayscale(0%); | |
${Prompt} { | |
opacity: 1; | |
height: 1.25rem; | |
transition: all .2s ease-in-out; | |
} | |
} | |
} | |
`; | |
// While all this can be done with prop passing, it's much more economical to do it this way. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you expand on