Custom colors are not recognized when they are declared as functions
See original GitHub issueDescribe the bug In TailwindCSS colors in the theme can also be defined as functions. In my project it looks like this:
const tailwindColors = {
transparent: 'transparent',
current: 'currentColor',
};
for (const [key, item] of Object.entries(colorsWithDefaults)) {
const { hue, sat, light } = item.hsla;
const value = `${hue} ${sat || '100'}% ${light || '100'}%`;
tailwindColors[key] = ({ opacityVariable, opacityValue }) => {
if (opacityValue !== undefined) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return `hsla(var(--${item.name}, ${value}) / ${opacityValue})`;
} else if (opacityVariable !== undefined) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
return `hsla(var(--${item.name}, ${value}) / var(${opacityVariable}, 1))`;
}
return `hsl(var(--${item.name}, ${value}))`;
};
}
module.exports = tailwindColors;
These gets included in tailwind.config.js like this:
const tailwindColors = require('./src/theming/tailwindColors.cjs');
const constants = require('./src/theming/constants.cjs');
module.exports = {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
colors: tailwindColors,
cursor: {
These colors are all flagged as invalid custom classnames.
I think a fix is easy, I tried it already locally by patching lib\util\groupMethods.js in my node_modules folder:
if (typeof color === 'string' || typeof color === 'function') {
options.push(escapeSpecialChars(k) + opacitySuffixes);
} else {
I just added typeof color === ‘function’, this seemed to work fine for me
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Tailwind CSS, certain custom colors are not working
I 'm trying to use Tailwind custom colors ...
Read more >Custom Color Theme: function does not work.
When I go View, Slide Master, Colors, Customize Colors: It brings up the Create Theme Colors box, and says "Click on the colored...
Read more >Creating custom color not working? - Unity Forum
Color has no definition for brightRed. I've tried adding 32 to the variable type, I've tried declaring the color variable in the OnGui...
Read more >Custom Colors explainer - Grasshopper Support
Walkthrough of the solution: Magenta is not a color that the grasshopper concept drawBox() recognizes. However, you can still create magenta by using...
Read more >Use only Kadence Blocks Colors not working - WordPress.org
Hi! In the Kadence Block Controls I defined a project specific color palette and turned on “Use only Kadence Blocks Colors?”. But when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I made a demo base on adam’s demo https://play.tailwindcss.com/EtWivxBTHl
@francoismassart : Sorry, I just got to try out the new release. Works perfectly now! Thank you.