You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you show me your real case. You need !default only because you are thinking in Sass-way. In PostCSS you have much more power, so you could find much better code design.
@ai
If I could make variables defined in local scope global, I could override them and switch themes only by changing class names. Here is the real case belowl.
Are there any better code design for theming?
The best way is to use CSS Custom Variables, they support it native in browser. But not all browsers support CSS Custom Variables. In PostCSS we have polyfill, but it works only for :root definitions, so it is useless here.
My use-case would be consuming node_modules which use postcss, and being able to override variables defined there before compilation time, thus being able to theme them. For example:
$ns_bg_color:'red';
body {
background-color: $ns_bg_color;}
Hm not sure how that would be implemented in a real world scenario - for example
node_modules/slider/slider.js <-- imports ./slider.css which has $slider-color: 'black'
app:
index.js <--- imports './bla.css'
import 'slider'; <-- some module in app imports this which imports slider.css
How would you go about changing the colour of the slider in that scenario using mixins? (Without literally overriding the output css of the slider module)?
Activity
ai commentedon Jul 10, 2016
Nope #52
ai commentedon Jul 10, 2016
Can you show me your real case. You need
!defaultonly because you are thinking in Sass-way. In PostCSS you have much more power, so you could find much better code design.ryoikarashi commentedon Jul 10, 2016
@ai
If I could make variables defined in local scope global, I could override them and switch themes only by changing class names. Here is the real case belowl.
Are there any better code design for theming?
index.html
main.css
themes.css
variables.css
base.css
ai commentedon Jul 10, 2016
This code will not work in Sass.
The best way is to use CSS Custom Variables, they support it native in browser. But not all browsers support CSS Custom Variables. In PostCSS we have polyfill, but it works only for
:rootdefinitions, so it is useless here.ai commentedon Jul 10, 2016
But I have awesome idea. Let’s write a polyfill for dynamic CSS Custom Properties!
You pass this
<body>switching classes to plugin:Then plugin will find all overrides definitions like and remember a variable names:
Then it will find all rules, where this variables used, like:
On final step it merge themes classes and overrides and generate this:
Sorry, maybe my description is little confused. Please ask me any question about it.
What do you think about this idea? Do you have time for it? (I will help you step-by-step)
ryoikarashi commentedon Jul 10, 2016
@ai Your idea looks great but the npm module you provided,
postcss-dynamic-custom-propsis not found in npm registries.Is it already deprecated?
ai commentedon Jul 10, 2016
😆 it is only idea. We need to write it 😉.
Do you want to do it?
ryoikarashi commentedon Jul 10, 2016
Oh I got it. 😆
I'm trying to do it 👍
ai commentedon Jul 10, 2016
@ryoikarashi here is a issue for this idea: postcss/postcss-plugin-suggestion-box#6
Here is our chat for quick help: https://gitter.im/postcss/postcss
Here is links how start develop a plugin: https://github.com/postcss/postcss/blob/master/docs/writing-a-plugin.md
ryoikarashi commentedon Jul 10, 2016
@ai Thanks! ;)
dominictobias commentedon Aug 22, 2016
My use-case would be consuming node_modules which use postcss, and being able to override variables defined there before compilation time, thus being able to theme them. For example:
Background should be blue.
ai commentedon Aug 22, 2016
@dominictobias use mixin for it ;)
This variables logic is non-intuitive, there is no languages with such logic
dominictobias commentedon Aug 22, 2016
@ai thanks, do you mind giving a basic example of what you mean pls?
ai commentedon Aug 22, 2016
@dominictobias
dominictobias commentedon Aug 22, 2016
Hm not sure how that would be implemented in a real world scenario - for example
node_modules/slider/slider.js <-- imports ./slider.css which has $slider-color: 'black'
app:
index.js <--- imports './bla.css'
import 'slider'; <-- some module in app imports this which imports slider.css
How would you go about changing the colour of the slider in that scenario using mixins? (Without literally overriding the output css of the slider module)?
ai commentedon Aug 22, 2016
@dominictobias are you a developer pf that
node_modules/slider?dominictobias commentedon Aug 22, 2016
Yep I am so can modify it however - this is for an sdk of components and
consuming apps (we control both)
On Monday, 22 August 2016, Andrey Sitnik [email protected] wrote:
ai commentedon Aug 22, 2016
@dominictobias so, just define a mixin in that
node_modules/slider/slider.css;)