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

Leveraging CSS Variables in JavaScript Configurations #56

Open
douglaszaltron opened this issue Mar 20, 2024 · 6 comments
Open

Leveraging CSS Variables in JavaScript Configurations #56

douglaszaltron opened this issue Mar 20, 2024 · 6 comments

Comments

@douglaszaltron
Copy link
Contributor

douglaszaltron commented Mar 20, 2024

An intriguing approach in web development involves harnessing CSS variables within JavaScript files by transforming values to utilize CSS variables in JSON and JavaScript files. This technique is particularly handy when we aim to utilize CSS variables that are globally defined within JavaScript files.

For instance, when creating a preset for Tailwind CSS, I generate the JavaScript configurations for the theme. However, I desire to employ the CSS variables seamlessly within these configurations. This integration not only streamlines development but also enhances the flexibility and maintainability of the codebase, facilitating smoother collaboration and iteration.

export default {
  palette: {
    grey: {
      "100": "var(--palette-grey-100)",
    },
  },
}
@lukasoppermann
Copy link
Owner

@douglaszaltron why did you close this?

@douglaszaltron
Copy link
Contributor Author

@douglaszaltron why did you close this?

I clicked by mistake.🤦‍♂️

@douglaszaltron
Copy link
Contributor Author

douglaszaltron commented Mar 20, 2024

I'm testing some options because upon closer inspection, the JavaScript export might not have the prefix, whereas the CSS value, indeed, might require the prefix.

draft:

image

What do you think, Lukas? Any suggestions?

@lukasoppermann
Copy link
Owner

Wait, why do we need cssPrefix?

Can't we compile css in one step and in js we assume the css exists? Or are you saying you want to be able to have a different prefix for css and js or no prefix for js?

@douglaszaltron
Copy link
Contributor Author

douglaszaltron commented Mar 20, 2024

Wait, why do we need cssPrefix?

Can't we compile css in one step and in js we assume the css exists? Or are you saying you want to be able to have a different prefix for css and js or no prefix for js?

In the case of js not having a prefix and css having one, it is more common for css to have the prefix.

Example

image

@lukasoppermann
Copy link
Owner

Hey @douglaszaltron, sorry, I just noted that I completely misread this PR.

So what this does is it replaces the value of a token with it's own name as a css variable.
To me that makes no sense. I thought you were targeting the references.

E.g. danger.$value: {base.red} would be turned into danger: var(--base-red).

So do you want to target the reference or are you really looking for replacing a variables value with it's own name.

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