mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-27 22:54:18 +00:00
* docs: review all docs * fix Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * docs(spinner): reintroduce data-icon attribute guidance in radix spinner docs (#10059) * Initial plan * docs: add data-icon attribute instructions to radix/spinner.mdx button and badge sections Co-authored-by: shadcn <124599+shadcn@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: shadcn <124599+shadcn@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
67 lines
1.4 KiB
Plaintext
67 lines
1.4 KiB
Plaintext
---
|
|
title: Next.js
|
|
description: Adding dark mode to your Next.js app.
|
|
---
|
|
|
|
<Steps>
|
|
|
|
## Install next-themes
|
|
|
|
Start by installing `next-themes`:
|
|
|
|
```bash
|
|
npm install next-themes
|
|
```
|
|
|
|
## Create a theme provider
|
|
|
|
```tsx title="components/theme-provider.tsx" showLineNumbers
|
|
"use client"
|
|
|
|
import * as React from "react"
|
|
import { ThemeProvider as NextThemesProvider } 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" showLineNumbers
|
|
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>
|