question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Referencing Theme Colors with CSS Custom Properties

See original GitHub issue

Is your feature request related to a problem? Please describe.

I’ve been running into many challenges regarding the usage of theme colors. It works great when using the properties that are already linked to the colors theme key, but this isn’t always flexible enough.

For example, the variant of a complex component can get messy really quickly if the background-color need’s to be in a pseudo-element or something like that.

Shot_0 15

Also, the theme custom properties can’t actually be used like var(--theme-ui-colors-primary), which doesn’t help.

Describe the solution you’d like

I’m thinking about linking theme keys to custom properties by checking if that property contains a color related key. Example: –color-random-name || –bg-of-something || –fill-of-something || …

'--color-base': "primary",
'--color-hover': "text",

This pattern could be implemented with many other properties too

This would allow for cleaner and more flexible variants.

Shot_0 16

Describe alternatives you’ve considered I initially wanted to just use the custom properties from the theme, but because of their shape, they can’t be used outside of Theme UI.

Changing the shape of those variables would allow using the theme defined colors, by simply referencing the var().

Should change from: --theme-ui-colors-primary: var(--theme-ui-colors-primary,#0759F9); to: --theme-ui-colors-primary: #0759F9;

Additional context Another use case that would benefit from this would be theming SVG’s. By running SVG’s through SVGO I can replace set color codes with custom properties. Then I would create color sets for those, but can’t access them on the SVG.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
atanasstercommented, Nov 19, 2020

guys, I think we can close this issue and consolidate all conversation to #1234 or directly to the babel plugin repo

1reaction
atanasstercommented, Nov 2, 2020

@fcisio - thanks a lot, I created a new thread #1234 where we can discuss the specs and work together on those transformations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using CSS custom properties (variables) - MDN Web Docs
Custom properties allow a value to be stored in one place, then referenced in multiple other places. An additional benefit is semantic ...
Read more >
How To Configure Application Color Schemes With CSS ...
In this article, Artur Basak introduces a modern approach on how to set up CSS Custom Properties that respond to the application colors....
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
Everything important and useful to know about CSS Custom Properties. Like that they are often referred to as "CSS Variables" but that's not ......
Read more >
Theming with CSS Custom Properties (variables) and calc()
So instead of referencing a custom property for a specific color, the components reference a named custom property from the color scheme, ...
Read more >
A guide to theming in CSS - LogRocket Blog
A CSS variable (also called a custom property) is a variable you ... So, when we are viewing the black theme, the text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found