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

Allow referencing other css variables #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

maxsalven
Copy link

@maxsalven maxsalven commented Mar 6, 2024

Fixes #39

@L-Blondy
Copy link
Owner

What's the use case for this?
The whole point of the library is to avoid setting up css variable, why not dynamically modify tw-colors produced variables instead of referencing your own?

@maxsalven
Copy link
Author

maxsalven commented Mar 11, 2024

In our SaaS app, the customer can choose their own brand color for their admin dashboard. We save this as a raw HSL value on our server for compatibility with Tailwind.

We then set the --brand variable to their chosen color when rendering their admin dashboard. We have some logic that will adjust the color if there's not enough contrast, based on dark/light mode.

Many parts of our design are branded, e.g. buttons or focus rings. I'm simplifying things for a basic example:

"focus-ring": "var(--brand)",
"btn-brand-bkg": "var(--brand)",
"bgn-brand-bkg-hover: "var(--brand) / 0.7",

With this PR, these all just work now as long as your CSS (or inline styles) define --brand.

Sure, we could put in dummy values:

"focus-ring": "#f0f",
"btn-brand-bkg": "#f0f",
"bgn-brand-bkg-hover: "#ff00ff70",

And then define these in a stylesheet:

--twc-focus-ring: var(--brand);
--twc-btn-brand-bkg: var(--brand);
--twc-btn-brand-bkg-hover: var(--brand);

But it's less ergonomic and you can't just update a field in the tw-colors config, you have to go update a stylesheet as well and when there's actually multiple branded variables (think primary / secondary / dark / light etc) you need to make sure you're setting the correct values etc etc. Plus if you're using this alongside regular themes (blue/red/etc because branding is a feature for premium subscribers only) then you sometimes don't want to set --twc-focus-ring to var(--brand). You also can't look in the tw-colors config and immediately know if something is a dynamic customer-defined color or not.

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

Successfully merging this pull request may close these issues.

Allow referencing other CSS variables
2 participants