In styled-components
we can have contextual styles using component selector patterns. But how do we parents variant to contextual the child component? For example, we have three components here, Child
, NoteWrapper
, and Note
.
const Child = styled.div<{ editing?: boolean }>`
${props => props.editing && css`some styles`}
`
const NoteWrapper = styled.div<{ compact?: boolean }>`
${props => props.compact && css`some styles`}
`
const Note = styled.input`
/* How do I style this when Child is editing and NoteWrapper is compact */
`
const App = () => {
return (
<Child editing>
<NoteWrapper compact>
<Note/>
</NoteWrapper>
</Child>
)
}
`
With plain CSS we could do something like this
.child.editing .note-wrapper.compact .note {
/* Contextual styles here */
}
My question is how do I style Note
when Child
is editing
and NoteWrapper
is compact
in styled components selector pattern ?