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

Connect AngularFire to a specific object

I'm facing an issue with my Users.class where I need it to automatically map or bind after fetching data from Firebase. I've been trying to search for the right term but haven't found any information yet. import { Component, OnInit } from & ...

Rendering a component within an asynchronous function using Next.js

I'm currently learning Next.js and attempting to iterate over a collection of items in an array to pass them into a card component. However, I am facing an issue where the Card component is not rendering on the page. When I place the Card element betw ...

Exploring various queries in Firestore

Does anyone know if there is a way to create a sentence similar to this one: return this.db.collection('places', ref => ref.where("CodPais", "<>", pais)).valueChanges(); I have tried using != and <> but neither seem to be valid. Is the ...

Incorporating external scss files into next.js (react) for seamless loading

Encountering an error when trying to load SaSS files from zeit node_modules\@zeit\next-css\node_modules\mini-css-extract-plugin\dist\index.js:21} = _webpack2.default; ^TypeError: Cannot destructure property `createHash` of &a ...

Deactivate the rows within an Office UI Fabric React DetailsList

I've been attempting to selectively disable mouse click events on specific rows within an OUIF DetailsList, but I'm facing some challenges. I initially tried overriding the onRenderRow function and setting CheckboxVisibility to none, but the row ...

"Implementing U2F Authentication in NextJS: A Step-by-Step

Currently, I am looking to integrate U2F into my NextJS project using the beta version of NextJS 13. The server-side code is already functional with the u2f library, but I'm unsure how to implement it on the client side. const U2F = require("u2f ...

Utilize useSWR to trigger a new fetch upon page initialization even when the key is stored in the cache within Next.js

Currently, I am utilizing the useSWR hook to retrieve data from my api endpoints. It is my understanding that it uses the api routes as the key for caching the data. The issue at hand is that I have implemented an api route on 2 separate pages (referred t ...

When I try to load JSON data using the http.get() method in my Angular 2 template, it returns

I've encountered an issue while attempting to read and parse a local json file into a custom class I created. The problem arises when trying to access properties of the class, as it throws errors indicating that the class is either null or undefined. ...

The functionality of ngModel is not functioning properly on a modal page within Ionic version 6

Currently I am working on an Ionic/Angular application and I have encountered a situation where I am attempting to utilize ngModel. Essentially, I am trying to implement the following functionality within my app: <ion-list> <ion-item> <ion ...

A guide on obtaining the date format according to locale using Intl.DateTimeFormat within JavaScript

Can someone assist me in obtaining the standard date format (such as MM/DD/YYYY) based on a specified local id? The code snippet provided below is not returning the desired format. Any guidance on how to achieve this would be greatly appreciated. var da ...

Transitioning a codebase from @angular-builders/custom-webpack to NX for project optimization

I need help migrating my Angular project from using "@angular-builders/custom-webpack" build targets to transitioning to an integrated NX monorepo. When I run the command npx nx@latest init --integrated, I receive the following warning: Unsupported build ...

Can getServerSideProps be adjusted to avoid triggering a complete page reload after the first load?

My server-rendered next.js app consists of a 3-page checkout flow. The first page involves fetching setup data like label translations and basket items within the getServerSideProps function, as shown below: UserDetails.js import React from 'react&apo ...

Formik QR code reader button that triggers its own submission

I recently developed a custom QR code reader feature as a button within the Formik component customTextInput.tsx, but I encountered an issue where clicking on the button would trigger a submission without any value present. The following code snippet show ...

The application's functionality is interrupted when router.navigate() is called within the .subscribe method

I am having an issue with user navigation on my application. After successfully signing in, users get redirected to the home page (/), but they are unable to navigate by clicking any links on that page. Upon further investigation, I discovered that moving ...

Choosing between Angular's Observable and Subject as a DataSourceWhen it comes

I am currently working on an Angular 7 application that utilizes Mat Tables to retrieve data from an API. I have implemented dynamic pagination values, where the pageSizeOptions value changes based on a dropdown selection when loading the grid. By default, ...

TypeScript: The capability to deduce or derive values for a type from a constant object literal that is nested with non-distinct keys

I'm trying to figure out a way to utilize TS/IDE to display specific literal values from a style guide object, instead of just the inferred type. Here's an example: const guide = { colors: { black: { medium: "#000000", } ...

The command stopped abruptly due to a "SIGBUS" signal

As a junior still new to server and website building, I am currently working on creating a next.js project on a server. The build process goes smoothly until it reaches the point where it says Creating an optimized production build..., at which time an err ...

Implementing the 'keepAlive' feature in Axios with NodeJS

I've scoured through numerous sources of documentation, Stack Overflow threads, and various blog posts but I'm still unable to make the 'keepAlive' functionality work. What could I be overlooking? Here's my server setup: import ex ...

What is the best way to close ngx-simple-modal in angular7 when clicking outside of the modal component?

Can anyone help me with closing the modal in my angular7 app when the user clicks outside of the modal component? I have been using the ngx-simple-modal plugin, and I tried implementing the following code: this.SimpleModalService.addModal(LinkPopupCompone ...

What strategies can I implement to eliminate prop drilling when using a headless CMS? I believe that the Context API may have a negative

Looking to integrate a headless CMO into my NextJs app, specifically Sanity.io. SEO is a key consideration for the content. It seems that I can only fetch the data on a page-level using getStaticProps server-side for pre-rendering (crucial for SEO). Howev ...