question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom colors are not recognized when they are declared as functions

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
francoismassartcommented, Mar 12, 2022

I made a demo base on adam’s demo https://play.tailwindcss.com/EtWivxBTHl

0reactions
gunters63commented, Jun 29, 2022

@francoismassart : Sorry, I just got to try out the new release. Works perfectly now! Thank you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found