-
Notifications
You must be signed in to change notification settings - Fork 673
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
Expose theme values as CSS Variables #979
Comments
You might be interested in this package: https://github.com/system-ui/theme-ui/tree/master/packages/custom-properties -- it's missing a few nice-to-have features, so PRs are welcome :) |
Yep, seen it. Could be used to create the name/value pairs, but it doesn't fix the need for adjusting code inside ThemeProvider (as in the snippet above). Or maybe, we could export a HOC from there, and use it something like
What do you think? PS: I'd be happy to do the PRs, but first "point me in the right direction" as it's said :D |
I don't think this sort of functionality should be part of the core packages, but I think you could achieve what you're looking for in the |
Great! I'll work on it as soon as possible. Thanks for the input |
Sweet! 👍 |
@lachlanjc is there anything special you have to do to get those variables to show up? I'm using Switching to the "all-in-one" |
Ah, I believe that's the issue. Those custom properties are part of the color-modes package, which isn't included in core. What's your use case? |
Use case is just trying to keep the end result of my app small 😉 |
That makes sense! I was wondering why you wanted these custom properties though—I've personally never used them, since if I'm using Theme UI on a site typically all my styling is going through it |
The main reason I need the custom properties is for things like i.e. if I want to do... backgroundImage: "linear-gradient(to top, var(--theme-ui-colors-buttonPrimary1), var(--theme-ui-colors-buttonPrimary2))", It seems like In another project, we added |
Is there still a usecase/desire for non-color theme values to be accessible via custom properties? |
Right now we can't use theme values when styling native HTML elements. We have to either
<H1>
,<H2>
, etcsx
propI'd like to extend
ThemeProvider
with the ability to expose theme values as CSS Variables so that in a stylesheet we could do something like:I've already done this (just for the colors property as a proof of concept), here's the code:
Thus, any elements inside the
<div className="theme-ui-adapter">
can make use of the CSS Variables. Also, because of the way scope works, we have theme/sub-theme functionality by default.The text was updated successfully, but these errors were encountered: