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.

Feature: support var(--variables) with fallback for runtime change

See original GitHub issue

We have in :root a map of variables with can be use by default in all elements/components with proper fallback. Can we add another $support-css4 to generate additional fallback styles? This feature can be added later in roadmap if docs aren’t stable right now.

Example:

.swatch-blue {
    color: #fff;
    background-color: #007bff;
}

to:

.swatch-blue {
    color: #fff;
    background-color: #007bff;
    background-color: var(--blue);
}

Benefits:

  • works same as before
  • new way to change color in runtime!
  • can be change by js in one place to enable fast change of parameters
  • can be enabled by setting

$support-runtime-variable or $support-css4

(or something like that)

  • this feature expand to not only colors but breakpoints and other properties

Need to:

  • check if some browser incorrect implement that feature
  • invert colors can be tricky

How to do that in clever way and I added benefit of this approach: https://codepen.io/anon/pen/XVLvLQ

Better idea:

  • create some tool like autoprefixer to enable it by default without bloat code. But add documentation about that solution on site so no new issue will be generated.

Documentation and credits for amazing work: https://getbootstrap.com/docs/4.0/getting-started/theming/#color https://css-tricks.com/difference-between-types-of-css-variables/

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
hwhelchelcommented, Feb 6, 2018

Being able to easily change the theme colors at runtime would be a very neat feature.

Let me know if I can help write a PR to add support.

1reaction
mdocommented, May 2, 2018

Closing out as not a bug and not a feature request we can take on right now. I think we’re better served in v4’s lifespan by focusing first on Sass variables and then CSS as a first class come v5 or so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS — ::selection with var() fallback - Stack Overflow
I'm curious of your use case where an unset variable could find it's way into your code that's not because of a typo....
Read more >
Using CSS custom properties (variables) - MDN Web Docs
Custom property fallback values. Using the var() function, you can define multiple fallback values when the given variable is not yet defined; ...
Read more >
How to use CSS custom properties (a.k.a. variables)
It is important to note the var() function provides a fallback mechanism itself, in case your custom property is not set. The function...
Read more >
A user's guide to CSS variables – Increment: Frontend
Their values are referenced via the function var(--name) , which can be used in any CSS property. The var() function also supports a...
Read more >
A Complete Guide To CSS Variables [With Examples]
The fallback value works as a safety net in the variable ... This makes the variable static and irresistible to change at runtime....
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