I am having trouble getting my custom colors to work with hover effects in Tailwind CSS

The code I have written is for a header component in Next.js with Typescript and Tailwind. I named it Header_2 to represent a component display in a library. Initially, the custom colors were not rendering as expected, but I managed to resolve the issue by tweaking the settings in the tailwind.config.ts file. The problem occurred when the custom colors were removed during the css file build process. I found the solution from this source: https://bobbyhadz.com/blog/tailwind-extend-colors-not-working


export default function Header_2() {
  return (
    <div className="w-full h-16 flex justify-between items-center border-b-[1px] border-aui_border px-12 bg-aui_primary">
      <div className="h-full w-[10rem] flex justify-center items-center">
        <Link href="" className="h-full flex justify-center items-center">
          <Image src={Logo} alt="Logo" className="h-[50%] object-contain" />
        </Link>
      </div>
      <div className="h-full flex items-center gap-6">
        <Link href="" className="text-aui_text_secondary hover:text-aui_text">
          Field 1
        </Link>
        <Link href="" className="text-aui_text_secondary hover:text-aui_text">
          Field 2
        </Link>
        <Link href="" className="text-aui_text_secondary hover:text-aui_text">
          Field 3
        </Link>
        <div>
          <a href="#" target="_blank">
            <Image src={Github} alt="Github Image" />
          </a>
        </div>
        <Link
          href="/signin"
          className="w-20 h-8 rounded-md bg-aui_accent hover:bg-aui_accent_hover text-aui_text_accent text-center flex justify-center items-center"
        >
          Login
        </Link>
      </div>
    </div>
  );
}

This is the content of my tailwind.config.ts:


import type { Config } from "tailwindcss";

const config: Config = {
  content: [
    "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
    "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      colors: {
        border: "var(--border)",

        // Website
        background: "var(--background)",
        foreground: "var(--foreground)",
        accent: "var(--accent)",
        accentLight: "var(--accent-light)",
        primary: "var(--primary)",
        primaryHover: "var(--primary-foreground)",
        secondary: "var(--secondary)",

        textPrimary: "var(--text-primary)",
        textSecondary: "var(--text-secondary)",
        textComplementary: "var(--text-complementary)",

        // Atlantic UI styles
        aui_primary: "var(--aui-primary)",
        aui_text: "var(--aui-text)",
        aui_text_secondary: "var(--aui-text-secondary)",
        aui_accent: "var(--aui-accent)",
        aui_accent_hover: "var(--aui-accent-hover)",
        aui_text_accent: "var(--aui-text-accent)",
        aui_accent_secondary: "var(--aui-accent-secondary)",
        aui_border: "var(--aui-border)",
      },
    },
    screens: {
      lg: { max: "1200px" },
      md: { max: "1000px" },
      sm: { max: "600px" },
    },
  },
  plugins: [],
  safelist: [
    {
      pattern:
        /(bg|text|border)-(aui_primary|aui_text|aui_text_secondary|aui_accent|aui_accent_hover|aui_text_accent|aui_accent_secondary|aui_border)/,
    },
    {
      pattern:
        /(hover):(bg|text|border)-(aui_primary|aui_text|aui_text_secondary|aui_accent|aui_accent_hover|aui_text_accent|aui_accent_secondary|aui_border)/,
    },
  ],
};
export default config;

I thought adding a similar hover property to the safelist would solve the issue, but unfortunately, it did not.

Answer №1

If you want to include different versions of regular expression whitelist entries, you can do so by utilizing the variations key within the entry. By doing this, you can merge multiple entries into a single one, like in the example below:

whitelist: [
  {
    pattern:
      /(bg|text|border)-(blue|red|green|yellow)/,
    variations: ['hover'],
  },
],

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React-bootstrap-table Axios delete operation causing [object%20Object] to be displayed in the browser console

I am having trouble executing a delete operation using axios on a react-bootstrap-table, and encountering this error in the console DELETE http://localhost:9000/api/terminals/[object%20Object] Uncaught (in promise) Error: Request failed with status cod ...

How to start Angular2 prototype with an object literal

export abstract class GridColumn { public field?: string; public sortField?: string; public header?: string; public footer?: string; public sortable?: any = true; public editable?: boolean = false; public filter?: boolean = true ...

The absence of the 'profileStore' property is noticed in the '{}' type, which is necessary in the 'Readonly<AppProps>' type according to TypeScript error code ts(2741)

I'm currently using MobX React with TypeScript Why am I getting an error with <MainNote/>? Do I just need to set default props? https://i.stack.imgur.com/5L5bq.png The error message states: Property 'profileStore' is missing in typ ...

Issue with nestjs build due to ts-loader module in dev-dependency

I've encountered a Module Error with ts-loader during a docker build ERROR [6/6] RUN nest build 3.9s ------ > [6/6] RUN ...

What is the best way to generate a component within Next.js?

It seemed like I was on the right path, but now I'm encountering an unexpected error There is an import error occurring: 'Navigation' is not being exported from '../components/navigation'. This is my Navigation component: const Na ...

Uploading Files within Angular FormArray

I am facing an issue with my formArray which contains file upload inputs in each element. Whenever I upload an image in one input, it changes the values of other file inputs in different rows. https://i.stack.imgur.com/3haZW.png Current Behavior: Uploadi ...

What is preventing Angular from letting me pass a parameter to a function in a provider's useFactory method?

app.module.ts bootstrap: [AppComponent], declarations: [AppComponent], imports: [ CoreModule, HelloFrameworkModule, ], providers: [{ provide: Logger, useFactory: loggerProviderFunc(1), }] ...

Error encountered with structured array of objects in React Typescript

What is the reason for typescript warning me about this specific line of code? <TimeSlots hours={[{ dayIndex: 1, day: 'monday', }]}/> Can you please explain how I can define a type in JSX? ...

Jest is having difficulty locating a module while working with Next.js, resulting in

I am encountering some difficulties trying to make jest work in my nextjs application. Whenever I use the script "jest", the execution fails and I get the following result: FAIL __tests__/index.test.tsx ● Test suite failed to run ...

What causes the disparity in the functionality of getServerSideProps between index.js and [id].js in NextJS?

Exploring NextJS and React as part of my e-commerce site development journey has been exciting. However, I encountered a roadblock when trying to connect to an external database that requires real-time updates, making getStaticProps unsuitable for my needs ...

Encountered a 401 error with NextJS and the "openai api" when calling the createChatCompletion() endpoint, but received a 200 ok response when calling create

A Short Summary When using NextJS api router, the call to openai api endpoint createChatCompletion() failed. However, it was successful when done with pure Node.js code. More Details I attempted to use NextJS's api router as demonstrated here for ca ...

Is there a way to restrict the return type of a function property depending on the boolean value of another property?

I'm interested in creating a structure similar to IA<T> as shown below: interface IA<T> { f: () => T | number; x: boolean } However, I want f to return a number when x is true, and a T when x is false. Is this feasible? My attempt ...

While running tslint in an angular unit test, an error was encountered stating 'unused expression, expected an assignment or function call'

Is there a method to resolve this issue without needing to insert an ignore directive in the file? Error encountered during command execution: ./node_modules/tslint/bin/tslint -p src/tsconfig.json --type-check src/app/app.component.spec.ts [21, 5]: unuse ...

Utilizing a third-party API within the next/api endpoint

I've recently started working with NEXTJS and developed a weather application. I'm integrating the openweather API, but I'm unsure how to use it within the next/api. I attempted creating a file named today.js inside the next/api directory an ...

Utilizing JSDoc for establishing an index signature on a class in ES6

When working with JSDoc, achieving the equivalent of Typescript's computed property names can be a challenge. In Typescript, you'd simply define it like this: class Test { [key: string]: whatever } This syntax allows you to access these comput ...

What is the reason behind RematchDispatch returning a `never` type when a reducer and an effect share the same name?

Recently, I made the switch from TypeScript 4.1.2 to 4.3.2 with Rematch integration. Here are the Rematch packages in use: "@rematch/core": "2.0.1" "@rematch/select": "3.0.1" After the upgrade, a TypeScript error p ...

Challenges arise when trying to access environment variables using react-native-dotenv in React

I am currently working on two separate projects, one being an app and the other a webapp. The app project is already set up with react-native-dotenv and is functioning as expected. However, when I attempt to use the same code for the webapp, I encounter an ...

What are the best practices for utilizing generics effectively?

A series of interfaces has been defined: export interface FormData<T extends ControlData = any> { [type: string]: T; } export type FormResult<T extends FormData> = { [type in keyof T]: T[type]; }; export interface ControlData<T = any& ...

Is there a way to customize the styles for the material UI alert component?

My journey with Typescript is relatively new, and I've recently built a snackbar component using React Context. However, when attempting to set the Alert severity, I encountered this error: "Type 'string' is not assignable to type 'Colo ...

Issue: Unable to resolve all parameters for setupRouter function

I encountered an error stating "Can't resolve all parameters for RouteParams" while setting up a basic app for routing. Here is how my app.module.ts file is structured: import { NgModule } from '@angular/core'; import { BrowserModule ...