Replies: 1 comment 1 reply
-
Hi, I stepped into this as I was looking for the same thing! export function hexToRgba(hex: string, alpha: number = 1) {
const color = culori.parseHex(hex);
color.alpha = alpha;
return culori.formatRgb(color);
} And then I can get any tailwind color and apply opacity with the following code: const rgba = hexToRgba(colors.orange[400], 0.4) Cheers! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In Tailwind, it's possible to reference a colour and add opacity to it, e.g.
text-red-400/25
to get red-400 but for 50% opacity (docs: https://tailwindcss.com/docs/text-color#changing-the-opacity)It's also possible to reference a colour from within JavaScript/TypeScript, e.g. with
tailwindConfig.theme.colours.red[400]
(docs: https://tailwindcss.com/docs/configuration#referencing-in-java-script)It would be a nice little feature to allow developers to get the colour with opacity from within JavaScript/TypeScript without having to implement their own logic (or use a library) to calculate the opacity or create separate colour tokens for each colour/opacity combination used in the app.
It might be offered as a utility function that could be imported separately. Or maybe as a more generic function to reference various arbitrary values from JavaScript, e.g.
theme('colors.red.400/25')
🤔Beta Was this translation helpful? Give feedback.
All reactions