Skip to content

Instantly share code, notes, and snippets.

@markphilpot
Created October 16, 2017 19:53
Show Gist options
  • Save markphilpot/9755c2c73c0a0f32ece787f929c0968f to your computer and use it in GitHub Desktop.
Save markphilpot/9755c2c73c0a0f32ece787f929c0968f to your computer and use it in GitHub Desktop.
Example using Compent as Selector
// 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.
@ChristopherBiscardi
Copy link

Can you expand on

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