-
First, I find StyleX very attractive due to its simplicity and clear principles. I have a question related to Modularity and composability and Applying Themes. I am trying to integrate StyleX into a React components library. The library will have StyleX variables for theme properties like colors, fonts, spacing, sizes...etc. Components will also be able to receive additional StyleX styles as props. When a component is imported in another project (or used within the library) the concept of overriding/merging styles via props is clear. However, in the documentation it is mentioned that "themes can be passed around across files or components". How can I pass a theme as a prop to a component, what is the theme type or do I have to pass the theme name instead? Should I be able to create a theme in the consumer project based on the theme variables defined in the library and pass it somehow to the component? In the documentation it is also mentioned that when applying a theme, variables will be overridden for the element and all its descendants. Will this "overriding" work for descendant which are react components without a "theme provider"? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
A theme can be passed around exactly like styles.
The type for a theme is Assuming you have a
You pass the reference to theme. There are no "names" or magic strings in StyleX. Everything works by reference.
Yes, a consumer can import
I'm not completely sure what this means but when a theme is applied on an HTML element, that element and all descendent elements will have that theme applied. I.e the values of the varGroup overridden by that theme will take the overridden values within that sub-tree. This is just how CSS variables work. A Theme is simply a single class that sets variables to values. Hope that answers all your questions? |
Beta Was this translation helpful? Give feedback.
A theme can be passed around exactly like styles.
The type for a theme is
Theme
.Assuming you have a
VarGroup
calledcolors
, a theme for thatvarGroup
has the typeTheme<typeof colors>
.You pass the reference to theme. There are no "names" or magic strings in StyleX. Everything works by reference.
Yes, a consumer can import
varGroup
objects, create their own themes and pass them in where aTheme<typeof varGroup>
is expected.