packages/ui/THEME.md
This package includes a custom React-based theme provider that works independently of Next.js.
import { ThemeProvider } from '@prisma-docs/ui/components/theme-provider';
function App() {
return (
<ThemeProvider
defaultTheme="system"
storageKey="app-theme"
attribute="data-theme"
>
</ThemeProvider>
);
}
import { ThemeToggle } from '@prisma-docs/ui/components/theme-toggle';
function Header() {
return (
<header>
<ThemeToggle mode="light-dark" />
<ThemeToggle mode="light-dark-system" />
</header>
);
}
import { useTheme } from '@prisma-docs/ui/components/theme-provider';
function MyComponent() {
const { theme, resolvedTheme, setTheme } = useTheme();
return (
<div>
<p>Current theme: {theme}</p>
<p>Resolved theme: {resolvedTheme}</p>
<button onClick={() => setTheme('dark')}>Dark</button>
<button onClick={() => setTheme('light')}>Light</button>
<button onClick={() => setTheme('system')}>System</button>
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNode | required | Your app content |
defaultTheme | 'light' | 'dark' | 'system' | 'system' | Default theme on first load |
storageKey | string | 'theme' | localStorage key for persisting theme |
attribute | string | 'data-theme' | HTML attribute to set on document root |
| Prop | Type | Default | Description |
|---|---|---|---|
mode | 'light-dark' | 'light-dark-system' | 'light-dark' | Toggle mode |
className | string | - | Additional CSS classes |
light-dark: Simple toggle between light and dark (2 icons)light-dark-system: Toggle between light, dark, and system (3 icons)data-theme attribute on <html> elementdark class for Tailwind dark modeMake sure your Tailwind config uses the class or selector strategy:
// tailwind.config.js
module.exports = {
darkMode: 'class', // or 'selector'
// ... rest of config
}
Or use the attribute selector:
// tailwind.config.js
module.exports = {
darkMode: ['selector', '[data-theme="dark"]'],
// ... rest of config
}
You can define theme-specific CSS variables:
:root {
--background: white;
--foreground: black;
}
[data-theme="dark"],
.dark {
--background: black;
--foreground: white;
}