Proposal: CSS Variables in Media Queries #263
Replies: 2 comments 2 replies
-
|
Hi, first of all thanks for detailed discussion
What kind of additional media query features? I think that uniwind supports only the one that you mentioned and I don't think that native side is compatible with something else 🤔
Syntax is fine, generally our idea is to have web compatible css so no parsing needs to be applied for the web. Of course sometimes it's not possible but in this case it just works 👍
I've seen the initial implementation and this could be improved. I think that resolution of variables should happen only once in like it happens for platform/theme variables. Every group of variables under media query should have a listener that would update "global" variables from store and will notify listeners withStyleDependency.Variables. We can also refactor theme variables so they will follow the same logic
Yes it should work seamlessly We also need to think about order/priority of resolving those in css this happens automatically but not there I will take a look at this feature, but it doesn't really have high priority because only one person asked for it, and the topic isn't really continued. If you wish you can try to implement it we're always happy for contributions outside our core team. It's pretty big feature and we need to discuss some things before the final implementation, but in the meantime you can start with implementing just width/height media queries variables with the logic I've suggested - no tests, no refactors needed, just a starting point for future implementation. Looking forward to your thoughts 😄 |
Beta Was this translation helpful? Give feedback.
-
|
Updated as PR #335 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'd like to propose adding support for CSS custom properties (variables) within media queries in Uniwind. This would enable responsive and adaptive styling where variable values can change based on screen dimensions, device orientation, and color scheme preferences.
Issue: #242
Problem
Currently, CSS variables in Uniwind are static - once defined, they cannot adapt to different device conditions. This creates limitations when building responsive applications where you might want:
Current Limitation Example
If you want larger text on tablets, you'd need to use JavaScript or create separate classes, which isn't as elegant as native CSS media queries.
Proposed Solution
Allow CSS variables to be defined conditionally within media queries, similar to how standard CSS properties work:
Supported Media Query Types
The implementation would support:
Width-based queries
min-width- For responsive breakpointsmax-width- For maximum width constraintsOrientation queries
orientation: portraitorientation: landscapeColor scheme queries
prefers-color-scheme: lightprefers-color-scheme: darkCombined conditions
andoperator@media (min-width: 768px) and (orientation: landscape)Use Cases
1. Responsive Typography
2. Orientation-Aware Spacing
3. Theme-Aware Variables
4. Complex Responsive Design
Implementation Approach
Runtime Resolution
Variables would be resolved at runtime based on current device state:
UniwindRuntime)Dependency Tracking
The system would automatically track dependencies and trigger updates when:
Performance Considerations
Questions for Discussion
Scope: Should we start with basic width/orientation/color-scheme support, or include additional media query features from the start?
Syntax: Does the proposed CSS syntax align with Uniwind's design philosophy? Any concerns about compatibility?
Performance: Are there any performance concerns with runtime variable resolution? Should we consider compile-time optimizations?
API: Should this work seamlessly with existing
useCSSVariablehook, or do we need additional APIs?Potential Challenges
Next Steps
If this proposal is accepted, I'm happy to:
Feedback Requested
I'd love to hear thoughts from:
Note: I've already implemented a working prototype of this feature PR 261, but I wanted to discuss it with the community first before proposing it as an official feature. The implementation includes comprehensive test coverage and performance optimizations.
Let me know what you think! 🚀
Beta Was this translation helpful? Give feedback.
All reactions