Comments (11)
I would actually be super interested in merging themes in ThemeProvider if there was already ThemeProvider higher in component tree. We have a multi-module application where you would define styles in app root (first ThemeProvider) and then modify them on per module basis.
Would you be ok with such change? I am willing to make a pr, if needed.
from react-css-themr.
In any case it's better if you check the priority of the selector in the browser and boost your own by replicating the same plus a classname for example. I have to revisit react toolbox styles to try to reduce specific selectors as much as possible.
Anyway apply will solve some issues soon :)
from react-css-themr.
I never thought about combining themes from an upper context. Right now the code assumes that you are using just one provider. Since usually providers are defined on the top of your app, maybe you can just merge both themes using Javascript? A deep merge from lodash should be enough.
Apart from that, maybe I'm lost in translation :/ How is this related with postcss-apply?
You can always choose the way you compose your themes and if you want to override the full value of a class you can use softly compose:
Softly merging: theme objects are merged but if a key is present in more than one object, the final value corresponds to the theme with highest priority.
By priority I mean context < default < prop
Sorry if I'm missunderstanding you!
from react-css-themr.
I'll try again via another example(ignore nested ThemeProviders) :
// Bundle Button with react-toolboxes built in theme.scss
import Button from 'react-toolbox/lib/button';
// import global overrides (written by me)
import { global } from '../../styles';
// Say I have a react container/component with a render method that uses ThemeProvider
render() {
return (
<ThemeProvider theme={global}>
<Button />
</ThemeProvider>
);
}
In this example I expect the default Button theme.scss(RTButton is the Key)
to get merged with my overrides specified in global
(also specified with RTButton).
An example attribute I would like to override could be:
Default
.button {
position: relative;
}
Override by global
.button {
position: fixed;
}
In this case they both get applied to the browser, but the Default takes priority. I definitely want to deeply merge, because I don't want to start from scratch with the react toolbox components.
Hope this makes more sense!
from react-css-themr.
Oh I get it now. The thing is that we are getting modules but not the actual CSS. Processing the css is therefore out of the scope of this library. I know see what you mean with apply. It would work as something complementary but it has an important caveat (once this is resolved). Doing:
@import 'react-toolbox/lib/button/theme.css';
:root {
--button-content: {
color: red;
}
}
And then importing that file would work like a charm... We could even expose apply for every node same as we do with classes. But you are importing the whole theme.css so your styles will be duplicated :(
I don't see a way of achieving this right now if it's not with what some people call "functional styles". That means rewriting the styles thought...
from react-css-themr.
@javivelasco No worries, Like I mentioned. One Work around is to include the !important flag. Thats usually a big no no, but In this case since we are keeping things modularized, I think I am okay with it. I'll keep an eye out on the postcss apply
issue/enhancement.
from react-css-themr.
@javivelasco any news here? I believe pascalduez/postcss-apply#10 has been closed. I haven't had time to test.
from react-css-themr.
Not actually @gharwood. Honestly I think we can do nothing with ordering. This issue should be solved by controlling how modules are bundled together from your bundler config and overriding defaults with postcss plugins. Otherwise boosting priority is the only solution I think
from react-css-themr.
@javivelasco can we supply an example of how to override defaults with postcss plugins?
from react-css-themr.
Of course @petemill
from react-css-themr.
@Podlas29 Actually I also need such feature but just do not have time to make a PR :)
from react-css-themr.
Related Issues (20)
- Receiving/passing ref HOT 7
- When using ExtractTextPlugin it break the app HOT 3
- Default theming example HOT 2
- Possible drop of support of using themr as decorator with TypeScript HOT 3
- Allow a theme composition function as option HOT 2
- Typescript compiler fails when using react css themr with error Default export of the module has or is using private name 'TReactCSSThemrTheme' HOT 3
- Backport switch to `prop-types` package to the v1 branch to add compat with react 16 HOT 5
- Publish a new version with React 16 on npm HOT 3
- Do context theme support tree shaking ?
- Context theming works when app is run but not working when app is built
- mismatch dependancy
- Themr with pure functions HOT 1
- Update to be react 16 compitable HOT 2
- how to override styling in default css for a themed component
- Has this project been abandoned? HOT 1
- Css selector with attribute not working
- Multiple class not working HOT 5
- [QUESTION] Move to Friends of React HOT 5
- Warning on console when using react v16.4 HOT 4
- React-css-themr worked perfectly locally but not worked when used it after publishing it and used it as component lib into other project HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-css-themr.