mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-10-30 18:22:59 +00:00
Squash merge of shadcn-ui/ui main branch into hanzo/ui, bringing in: - [email protected] through [email protected] releases - New apps/v4 directory structure - Registry system improvements and MCP server - Framework support (Vue, Svelte, React Native) - New templates (vite-app, monorepo-next, laravel) - Zod 4 compatibility (scoped override for zod@>4) - Test fixture corrections for alias resolution All 867 merge conflicts resolved preserving Hanzo customizations. 1020/1020 shadcn tests pass.
70 lines
1.4 KiB
Plaintext
70 lines
1.4 KiB
Plaintext
---
|
|
title: Next.js
|
|
description: Adding dark mode to your next app.
|
|
---
|
|
|
|
## Dark mode
|
|
|
|
<Steps>
|
|
|
|
### Install next-themes
|
|
|
|
Start by installing `next-themes`:
|
|
|
|
```bash
|
|
npm install next-themes
|
|
```
|
|
|
|
### Create a theme provider
|
|
|
|
```tsx title="components/theme-provider.tsx"
|
|
"use client"
|
|
|
|
import * as React from "react"
|
|
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
|
import type { ThemeProviderProps } from "next-themes"
|
|
|
|
export function ThemeProvider({
|
|
children,
|
|
...props
|
|
}: React.ComponentProps<typeof NextThemesProvider>) {
|
|
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
|
|
}
|
|
```
|
|
|
|
### Wrap your root layout
|
|
|
|
Add the `ThemeProvider` to your root layout and add the `suppressHydrationWarning` prop to the `html` tag.
|
|
|
|
```tsx {1,6,9-14,16} title="app/layout.tsx"
|
|
import { ThemeProvider } from "@/components/theme-provider"
|
|
|
|
export default function RootLayout({ children }: RootLayoutProps) {
|
|
return (
|
|
<>
|
|
<html lang="en" suppressHydrationWarning>
|
|
<head />
|
|
<body>
|
|
<ThemeProvider
|
|
attribute="class"
|
|
defaultTheme="system"
|
|
enableSystem
|
|
disableTransitionOnChange
|
|
>
|
|
{children}
|
|
</ThemeProvider>
|
|
</body>
|
|
</html>
|
|
</>
|
|
)
|
|
}
|
|
```
|
|
|
|
### Add a mode toggle
|
|
|
|
Place a mode toggle on your site to toggle between light and dark mode.
|
|
|
|
<ComponentPreview name="mode-toggle" className="[&_.preview]:items-start" />
|
|
|
|
</Steps>
|