-
-
Notifications
You must be signed in to change notification settings - Fork 75
postcss-custom-media - Support variables for setting media rules #680
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
Comments
@Preen Thank you for reaching out. We can not add this to the This plugin has a very clear and well defined scope that must align with what browsers will implement in the future. @custom-media --medium-up-viewport (min-width: design-token("media.breakpoints.medium-up", to px)); We can investigate how design tokens can be used in For now I prefer to keep this unresolved because this is a feature that has been requested in the standardised design token format. Inventing some syntax now would also imply a breaking change later if the two are not compatible. |
Thank you for your quick response and it sounds like a good way forward :) |
Hi @Preen We have released an update to our design tokens plugin : https://www.npmjs.com/package/@csstools/postcss-design-tokens You can now use design tokens in any at rule : @media (min-width: design-token('viewport.medium')) {
.foo {
padding-bottom: design-token('size.spacing.medium' to rem);
}
}
/* becomes */
@media (min-width: 35rem) {
.foo {
padding-bottom: 1.1rem;
}
} |
Hi @Preen, I had the same question. @romainmenke I was wondering if it would be possible to envision using |
@mantismamita Do you have a concrete example? The design tokens plugin supports any and all at rules. This will just work : @something-made-up design-token('foo') {} So will this : @custom-media --foo (min-width: design-token('viewport-tablet' to px)); But it is important to keep in mind that there is no magic here. {
"viewport-tablet": {
"value": "320"
}
} /* 1 */
@custom-media design-token('viewport-tablet');
/* becomes */
@custom-media 320;
/* 2 */
@custom-media --foo design-token('viewport-tablet');
/* becomes */
@custom-media --foo 320; The design token plugin doesn't try to figure out what you are trying to do. |
What I had in mind was
or Ideally
I'm using postcss-global-data in order to have access to Edit: actually the latter syntax works already. I was trying with |
awesome! |
Yes, thank you for responding so quickly! |
@romainmenke wow, nice solution. Great work! |
Argh, I spoke too soon. I'm wondering if it might not be the order of the plugins.
|
The order of the plugins is definitely important. What is you current order? |
I've tried changing the order but this one seems the most logical
|
In that order the design tokens plugin will not see the CSS that is injected by the global data plugin. This is what I would do, but I can't test or verify this obviously :)
|
Ok I tried that as well as
but no luck 😢 |
@mantismamita We found and resolved a minor issue that is likely the cause of what you are seeing. We will release this as soon as possible. |
Release just went out for @mantismamita can you give this a try and let us know if everything is now working? |
Hi, looking good! Its working fine in dev mode but I'll wait till the build to confirm just in case. |
Ok, I think I can safely say that everything is working properly. Thank you so much @romainmenke ! 😄 |
Awesome! |
What would you want to propose?
Be able to set custom-media with variables such as
Suggested solution
I dont have any :)
Additional context
No response
Validations
Would you like to open a PR for this feature?
The text was updated successfully, but these errors were encountered: