What is the process of personalizing a DaisyUI theme in Tailwind with TypeScript?

I am trying to tailor an existing DaisyUI theme using my tailwind.config.ts file for my Next.js project.

Although the DaisyUI documentation only provides examples in JavaScript (text), I want to customize it within my TypeScript environment.

Below is a snippet from my tailwind.config.ts where I'm attempting to base my theme on the retro theme:

import type { Config } from 'tailwindcss'

const config: Config = {
  content: [
    './pages/**/*.{js,ts,jsx,tsx,mdx}',
    './components/**/*.{js,ts,jsx,tsx,mdx}',
    './app/**/*.{js,ts,jsx,tsx,mdx}',
  ],
  theme: {
    extend: {
      backgroundImage: {
        'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
        'gradient-conic':
          'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))',
      },
    },
  },
  daisyui: {
    themes: [
      {
        mytheme: {
          ...require("daisyui")['[data-theme=retro]'],
          primary: "magenta",
          ".btn": {
            "border-radius": "0px",
          }
        },
      },
    ],
  },
  // needs to be after custom theme declaration above?
  plugins: [require("daisyui")],
}
export default config

Furthermore, here is a glimpse of my main page layout.tsx in Next.js where I have designated mytheme as the data-theme for DaisyUI:

import './globals.css'
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'

const inter = Inter({ subsets: ['latin'] })

export const metadata: Metadata = {
  title: 'Title',
  description: 'Descr.',
}

export default function RootLayout(
  { children, }: { children: React.ReactNode }) {
  return (
    <html lang="en" data-theme="mytheme">
      <body className={inter.className}>
        <div className='btn btn-primary'>Button</div>
        {children}
      </body>
    </html>
  )
}

Currently, the customized color and border-radius are displaying correctly. However, I expected the background color to align with the retro theme, which is not the case.

This is how the unmodified retro theme should appear: https://i.sstatic.net/tQA7l.jpg

While I can individually change properties like .btn with @apply in CSS, I prefer a centralized approach within the tailwind config for all elements.

Answer №1

Hey there, consider using import instead of require when including daisyui in your project. Take a look at this example!

import type { Config } from "tailwindcss";
import daisyui from "daisyui";
import typography from "@tailwindcss/typography";

const config: Config = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    extend: {
      backgroundImage: {
        "gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
        "gradient-conic": "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
      },
    },
  },
  plugins: [typography, daisyui],
  daisyui: {
    themes: [
      {
        mytheme: {
          // Define your custom theme here
          // To extend an existing DaisyUI theme, use extend instead of the spread operator
          extend: {
            "theme": "retro",
            "primary": "magenta",
          },
          // Customize .btn styles like this
          "btn": {
            "border-radius": "1px",
            "border-width": "10px",
            "color": "yellow",
          },
        },
      },
    ],
  },
};

export default config;

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

Tips for including and excluding personalized Chips from input

Just started learning React/typescript, any assistance would be greatly appreciated Custom Chip (CC.chip) is a specialized Chip UI component that can be utilized as demonstrated below. const [isOpen, setIsOpen] = useState(true); const onClose = Re ...

Sharing the label element as a prop in React component

I encountered the following code snippet: <div className="input-field"> <label htmlFor="timeObjective">Time Objective</label> <FrequencySet label='label'/> //HERE </div> My goal is to tra ...

The data type 'AbstractControl | null' cannot be assigned to type 'FormGroup'

I am facing an issue with passing the [formGroup] to child components in Angular. The error message says Type 'AbstractControl | null' is not assignable to type 'FormGroup'. I have double-checked my conditions and initialization, but I ...

Arrow functions do not function properly with Typescript decorators

I've created a typescript decorator factory that logs the total time taken to execute a function, along with the actual function execution results and parameters passed to the decorator. For example: export function performanceLog(...args: any[]) { ...

Consolidating multiple page files into a single layout

Currently, I find myself on the page https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts My question is about implementing multiple page files within one layout. By default, the children call the page.js file. After displaying ...

Explicit declaration of default parameters

Check out the helpful solution In regard to the following code snippet, type C = { a: string, b: number } function f({ a, b } = {a:"", b:0}): void { // ... } Can you explain the syntax for explicitly typing the default parameter? ...

I encountered a server error stating that the middleware is not functioning properly while implementing Redux in my NEXTJS project

Upon executing my program, an error occurs stating "Server Error Error: middleware is not a function". I am unsure of the cause for this issue. How can I go about resolving this error? Below is the code snippet from store.js import { createStore, combineRe ...

Issues with nested class selectors in sass are causing problems within next.js

I've encountered an issue while using scss modules in next.js. My intention was to use nested class selectors as shown below: .div { .x { color: red; } } However, it appears that this approach is not working with the specific component I&apos ...

The TypeScript compilation is not able to find index.ts at the moment

When I tried to run 'ng serve', I encountered the following error message: The TypeScript compilation is missing node_modules/angular2-indexeddb/index.ts. It is crucial to ensure that this file is included in your tsconfig under the 'file ...

What is the best way to extract text from a dynamically changing element using jQuery?

I've been struggling with a coding issue. Despite trying numerous approaches, I keep encountering the same problem where every new button I add ends up having the same text or, alternatively, nothing seems to work as expected. $j serves as my variabl ...

Using Mongoose with Next.js to implement CRUD operations

I have been successful in implementing POST and GET methods in my Next.js app using mongoose, but I am facing challenges with the delete operation. This is an example of my POST method located in the API folder: export default async function addUser(req, ...

hide elements only when there is no string to display in Angular2/Typescript

As I experiment with my javascript/typescript code, I've encountered an issue where a string is displayed letter by letter perfectly fine. However, once the entire string is shown, the element containing it disappears and allows the bottom element to ...

How can I verify the validity of a regular expression in Typescript without encountering a syntax error?

I am facing an issue with my code where I load a set of regular expressions from an external source. My goal is to determine if a given string is a valid regex without causing the application to crash due to a syntax error. Despite trying to use try/catch ...

Comparing NextJs hydration with using the client-side approach

Currently exploring the ins and outs of NextJs to grasp its fundamental features. It is my understanding that by default, NextJs components operate on the server-side and utilize Hydration to enable interactivity shortly after displaying pre-rendered HTML ...

Is it possible to transform a ReadonlyArray<any> into a standard mutable array []?

At times, when working with Angular functions and callbacks, they may return a ReadonlyArray. However, I prefer using arrays in the traditional way and don't want to use immutable structures like those in Redux. So, what is the best way to convert a ...

Encountering a 'module not found' error while working on a nextJS production build

Just recently set up a new account on Github and cloned the repository. Initially, everything was working fine, but now I'm encountering an error every time I run npm run dev. This issue seems to be related to webpack, and it appears that I don't ...

Error in JSON format detected by Cloudinary in the live environment

For my upcoming project in Next.js, I have integrated a Cloudinary function to handle file uploads. Here is the code snippet: import { v2 as cloudinary, UploadApiResponse } from 'cloudinary' import dotenv from 'dotenv' dotenv.config() ...

Tips for adding a new property to an array object in TypeScript using a condition

Here is an array object that I have: arr = [ { Name: "ABC", Age: 20}, { Name: "XXX", Age: 15} ]; In Typescript, I am looking to dynamically add a new property called "Flag" with a value of 1 only if the Age is greater than 15. Can someone suggest ...

Creating dynamic HTML in Angular 2 can be achieved by utilizing directives, data

I am interested in building an accordion feature in angular2 without needing to duplicate the structure each time it is used. Similar to how we can create plugins in jQuery and include HTML code, I would like to find a way to achieve this in Angular2. Ca ...

Add an asterisk before each line of comment when working in a TypeScript file using the VS Code IDE

Within my VS Code workspace, I am using the Typescript language and would like to format my comments across multiple lines with a specific style (look out for the star character) /** *@desc any text * any text */ However, when I attempt to write a comm ...