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.

Support css variables for colors

See original GitHub issue

Feature Proposal

It would be nice to be able to use css variables, so we can keep our styles clean.

For e.g. this css:

:root {
  --main-color: #52006a;
}

Then reference it like this.

export const data = {
  labels,
  datasets: [
    {
      label: 'Dataset 1',
      data: labels.map(() => faker.datatype.number({ min: 0, max: 1000 })),
      backgroundColor: 'var(--main-color)',
    },
    {
      label: 'Dataset 2',
      data: labels.map(() => faker.datatype.number({ min: 0, max: 1000 })),
      backgroundColor: 'var(--main-color)',
    },
  ],
};

https://codesandbox.io/s/headless-snow-htvps?file=/App.tsx

Feature Use Case

I’m trying to keep my charts always styled with the correct color. This depends on dark/light style and is a hassle to have in mulitple places in your app. Ideally, there would be one place where we can change the main-color.

Possible Implementation

I’m not sure if there is anything blocking this, most other components seemed happy with the approach above.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kurklecommented, Dec 14, 2021

Its really simple to implement externally: https://codepen.io/kurkle/pen/KKpaYwx

Similar to #2077

1reaction
kurklecommented, Dec 14, 2021

Makes sense, I guess that’s partly due to in rendering to canvas and not svg?

That might be true, since SVG is in the DOM (and thus has no other platforms). I’d guess you could disable SSR for chart.js (probably depending on the framework you are using), and get it working that way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >
CSS Variables - The var() function - W3Schools
A good way to use CSS variables is when it comes to the colors of your design. Instead of copy and paste the...
Read more >
A Complete Guide To CSS Variables [With Examples]
CSS variables are custom properties in which you can store a value and use it anywhere in the HTML code. They were introduced...
Read more >
CSS Variables (Custom Properties) | Can I use... Support ...
CSS Variables (Custom Properties). - CR. Permits the declaration and usage of cascading variables in stylesheets. Usage % of. all users, all tracked ......
Read more >
How can I define colors as variables in CSS? - Stack Overflow
CSS itself doesn't use variables. However, you can use another language like SASS to define your styling using ...
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