Files
shadcn-ui/apps/www/content/docs/dark-mode/next.mdx
Nikhar Pandya c21ecfb665 docs(www): update contrubuting.md and next.mdx (#1343)
* docs: Update CONTRIBUTING.md

added commit convention section to the contribution docs.

* docs: Update next.mdx for dark mode

---------

Co-authored-by: shadcn <m@shadcn.com>
2023-08-31 17:01:36 +04:00

62 lines
1.3 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/dist/types"
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
}
```
### Wrap your root layout
Add the `ThemeProvider` to your root layout.
```tsx {1,9-11} 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>
{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>