Skip to content

Getting started

Dark mode

Connect DavinciUI's semantic tokens to next-themes and keep every component legible in light and dark.

DavinciUI uses the same semantic CSS variables as shadcn. Dark mode is a class on the <html> element; components do not ship separate dark styles.

How the token switch works#

The :root block defines light values and the .dark block overrides them. Every component reads tokens such as --background, --foreground, and --border, so changing the class updates the whole page.

One source of truth

Do not hard-code colors in component overrides. Change the token instead so both modes stay consistent.

Add a theme provider#

app/providers.tsx
"use client"
 
import { ThemeProvider } from "next-themes"
 
export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
      {children}
    </ThemeProvider>
  )
}

Add a toggle#

components/theme-toggle.tsx
"use client"
 
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
 
export function ThemeToggle() {
  const { resolvedTheme, setTheme } = useTheme()
 
  return (
    <button
      type="button"
      aria-label="Toggle theme"
      onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")}
    >
      {resolvedTheme === "dark" ? <Sun /> : <Moon />}
    </button>
  )
}

Tune the palette#

Edit the tokens

Update the :root and .dark blocks in app/globals.css.

Keep contrast

Check body text, muted text, and borders against the new background before shipping.

Verify both modes

Toggle the theme on every component page. Pay attention to code blocks and disabled states.

Avoid a flash of the wrong theme

Pass suppressHydrationWarning to <html> so next-themes can set the class before React hydrates.