More control over merge ordering.
See original GitHub issueFirst off, thanks for an awesome project thatās helping to solve the CSS Modules theming conundrum š .
Although @themr('injectedStyles', localStyles)
allows the injected stylesheet to override the component-local styles (where the override granularity can be increased if thatās helpful), there are other more complex ordering strategies that can be useful depending on the project, so Iād really prefer to have specific control over both the number of stylesheets being merged, and the order in which they are merged.
For example, in my case Iād really like to invoke as @themr('siteTheme', localStyles, 'componentOverrides')
. My motivation for wanting to do this is that Iād like the ability to very quickly theme an app we have using a site-theme that involves the cross-cutting concerns that affect all components, or go further and start theming specific components when we can justify spending more time, while still retaining the ability to just use the app as it is, with its default theme specified directly within the React components.
Iām not suggesting here that āreact-css-themrā also supports the particular function signature Iāve used above, but that any number of theme objects (string | object
) can be provided as suits the end-developer. Itās possible that this might also address @gharwood1ās issue?
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
We donāt currently use the props approach because they donāt help with the nested components that re-usable components will be using internally, but which also need to be themed. That leaves only the basic styling that the component provides and the context theming that the app provides, which isnāt enough.
The motivation for doing what Iām doing is that Iād like to create a set of re-usable components where each component provides some neutral styling so that it works out of the box, but where the components can be re-styled by each app that wants to make use of them.
The important difference is that I want there to be two approaches to app theming:
As you point out,
!important
can be used, but this is quite awkward. Additionally, I discovered that I can also do what I want by applying multiple@themr
decorators, as follows:but this only worked if I also controlled the load order of the associated stylesheets, which is even more awkward.
Maybe Iām still misunderstanding this though. Although Iāve read the docs maybe ten times, I still struggle a bit to understand everything.
Awesome š
This is perfect! I need to study your ādx-componentsā library and try that approach out myself and see how I get on.
Thanks for this excellent code snippet showing all the different ways you can go about doing this. That really helps. Itās also interesting to see that youāre using the
themr
function instead of the@themr
decorator (also undocumented š) as weāre also using that approach as we use pure stateless components everywhere.Iām going to close this issue until Iāve had a chance to try the approach youāre taking. Thanks for all the help! šÆ