-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More control over merge ordering. #23
Comments
@dchambers If I understand you right you need an ability to mix multiple theme objects on component declaration. You could use import {themr, themeable} from 'react-css-themr';
import css1 from './css1.css';
import css2 from './css2.css';
@themr('Component', themeable(css1, css2))
class Component extends React.Component {
render() {
const {theme} = this.props; //'theme' is mix of context, props, css1 and css2
}
} Please correct me if this's not what you need. |
Hi @raveclassic, thanks for providing some options here. I wasn't aware of the While the presented solution allows more ordering flexibility around the local styles that the component itself provides, it doesn't add any flexibility around the themed styles that are being injected in from the outside -- |
@dchambers You are welcome, |
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,
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. |
That's why I've opened #24
This is exactly what I'm also trying to achieve. I've ended up with not including base styles into components themselves but to include them at base context, here's an example. Then I can modify my library context in consuming project by just extending the default theme context. Additionally I can wrap plain components with additional styles that may be not included in context in consuming project. //CustomComponent
import customCss from './Custom.css';
import Base, {BASE} from 'dx-components/src/components/Base/Base.jsx';
import baseCss from 'dx-components/src/components/Base/Base.css';
import {themr, themeable} from 'react-css-themr';
//one way is to attach styles here, note that base styles are not included at all
export default themr(BASE, customCss)(Base);
//the other way is to mix all styles
export default themr(BASE, themeable(baseCss, customCss)(Base);
//or just
export default themr(BASE, baseCss)(themr(customCss)(Base));
//or mix when defining new context
//context.js
import theme from 'dx-components/src/config/theme.js';
import {BASE} from 'dx-components/src/components/Base/Base.jsx';
//repeat all css-releated stuff here
export default {
...theme,
[BASE]: themeable(baseCss, customCss) //any variations you prefer
}
Yep, this is also undocumented =) Additionally you can use the same keys to avoid nested HOC wrapping. |
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 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! 💯 |
First 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?The text was updated successfully, but these errors were encountered: