-
As StyleX does not support any advanced selector syntax, I wonder what the recommended or alternative approach is to writing contextual styles. For example, I have a sidebar which can be collapsed or expanded, and this affects the styling of multiple elements in the sidebar. If I want the icons to be bigger in the collapsed state, I could do something like this in SCSS. .icon {
width: 2rem;
height: 2rem;
.sidebar-collapsed & {
width: 3rem;
height: 3rem;
}
} or in Styled Components: const SidebarIcon = styled(Icon)`
width: 2rem;
height: 2rem;
${SidebarCollapsed} & {
width: 3rem;
height: 3rem;
}
`; The only alternative I can think of right now in StyleX is to pass a conditional className to every child of the sidebar which would need this conditional styling. In my example, I would write I understand StyleX does not support selectors such as What solution does StyleX offer for scenarios like this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I suggest that you try looking at the issue as a matter of passing For example, if the sidebar is a collection of icons, you can extract a This is exactly the same as your |
Beta Was this translation helpful? Give feedback.
I suggest that you try looking at the issue as a matter of passing
collapsed
state to components that need to know about this state.For example, if the sidebar is a collection of icons, you can extract a
<SidebarIcon>
component and pass thecollapsed
state to it and conditionally apply style once within the component.This is exactly the same as your
styled-components
example but in a more predictable way.