Using variables for defining media queries / @custom-media #765
mihkeleidast
started this conversation in
Ideas
Replies: 1 comment
-
I think if variables are not intended to work in this case in CSS, variables should not be used in this case. Why don't you use a simple object? export const media = {
reducedMotion: "(prefers-reduced-motion)",
} as const; I'm new to vanilla-extract but I don't see any drawback to use constants instead of css variables in scenario where there's:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi and thanks for a great tool!
I have a style block with a media query condition that I'd like to share as a variable (simple example):
This currently fails with
Error: Invalid media query: "@media var(--media-reducedMotion__gma9sq98)"
. I get the error - variables cannot be used like this in CSS yet, so this would be invalid right now anyway.In PostCSS, there is a custom-media plugin. That plugin cannot replace the above usage out from the generated CSS because it needs the variable definitions beforehand, but the VE variable names are dynamic and also generated at build time.
I also tried using a predefined
@custom-media
and replacing that out with the PostCSS plugin, which works! But it is less ergonomic to use, as it is not type safe, and requires the additional PostCSS setup.If variables are used for defining media queries, could vanilla-extract not replace it with a variable, rather with the resolved value, making usage like this valid?
Beta Was this translation helpful? Give feedback.
All reactions