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.

CSS custom properties issue

See original GitHub issue
body {
  --theme-ui-colors-text: var(--theme-ui-colors-text, #495057);
  /* --theme-ui-colors-text => undefined */
}

Maybe the right way

body {
  --theme-ui-colors-text: #495057;
  /* --theme-ui-colors-text => #495057 */
}

https://codepen.io/zce/pen/rNaaByE

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
iampavacommented, May 23, 2020

Hey!

If I understand correctly, it’s intended for the CSS variables to not be used directly by us. However, shouldn’t we allow this option (converting all theme props to CSS Variables and inserting in page)?

I arrived here after trying to style common elements like <h1>, <h2>, <strong>, <a> according to the theme and then just use them directly in the page. Later, when a 3rd party app embeds our code, it will change some part of the theme, but since it’s CSS Variables these elements will update as well.

I hacked together this adapter which allow dynamic insertion of CSS Variables. (just colors for now)

export const ThemeAdapter = (props) => {
  const ref = useRef(null);

  useEffect(() => {
    const { theme } = props;

    if (theme && theme.colors) {
      Object.keys(theme.colors).forEach(key => {
        ref.current.style.setProperty(`--colors-${key}`, theme.colors[key]);
      })
    }
  });

  return (
    <div ref={ref} >
      <ThemeProvider {...props} />
    </div>
  )
}

Although this wasn’t hard, I wonder whether this option should be present by default.

1reaction
jxnblkcommented, Jan 2, 2020

Closing this because the internal custom properties implementation will be changing slightly in v0.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom properties (--*): CSS variables - MDN Web Docs
Custom properties are scoped to the element(s) they are declared on, and participate in the cascade: the value of such a custom property...
Read more >
The Issue with Preprocessing CSS Custom Properties
The transformation is not complete and cannot be (dynamic cascading variables based on custom properties relies on the DOM tree). It currently ...
Read more >
using css custom properties variables not working
CSS custom properties are much more powerful than pre-processor ones, as they can be changed at runtime with javascript and be used in...
Read more >
A Strategy Guide To CSS Custom Properties
Custom properties have the same rules about where they can be used as normal CSS properties. It's far better to think of them...
Read more >
Support theming with CSS Custom Properties #4352 - GitHub
feature request Use CSS custom properties for at least color selection. What is the expected behaviour? To be able to alter the color-scheme...
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