Skip to content
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

Support css variables in Color #7628

Open
tume opened this issue Jan 17, 2025 · 1 comment
Open

Support css variables in Color #7628

tume opened this issue Jan 17, 2025 · 1 comment

Comments

@tume
Copy link

tume commented Jan 17, 2025

Provide a general summary of the feature here

Would be nice to have support for css variables in different Color* components.

🤔 Expected Behavior?

These should use css defined --primary-color as specified.

 <ColorSlider
      colorSpace="rgb"
      channel="alpha"
      defaultValue="var(--primary-color)"
    />

<ColorSwatch color="var(--primary-color)" />

😯 Current Behavior

Currently passing the "var(--primary-color)" will result Error: Invalid color value: var(--primary-color)

💁 Possible Solution

No response

🔦 Context

I have whole theme(colors) defined in css variables and current use case is that would be nice to have defaultValue set straight from css variables as don't have the color defined anywhere else.

💻 Examples

No response

🧢 Your Company/Team

ReceiptHero

🕷 Tracking Issue

No response

@reidbarber
Copy link
Member

reidbarber commented Jan 17, 2025

I think you could create a utility function:

let getCSSVariableValue = (variableName) => window.getComputedStyle(document.body).getPropertyValue(`--${variableName}`)

// ...

<ColorSlider
    colorSpace="rgb"
    channel="alpha"
    defaultValue={getCSSVariableValue("primary-color")}
  />

and use that. I'm not sure about including this as part of the API. We'd need to update parseColor from '@react-stately/color' to parse this. It doesn't really match the existing function of passing in a color value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants