PrismLink UI

Dark Mode

A wrapper component for managing themes using next-themes and shadcn/ui.

Theme Provider

A client-side wrapper component that provides theme switching functionality powered by next-themes.

import { ThemeProvider } from "@prismlinkapp/ui/themes/theme-provider";
 
export default function Layout({ children }) {
  return (
    <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
      {children}
    </ThemeProvider>
  );
}

Note

We use shadcn/ui for the theme switching functionality. You can use the useTheme hook to access the current theme.

Options

PropTypeDefaultDescription
childrenReactNodeRequiredChild elements to be rendered
attributestring"class"Attribute to add to the html element
defaultThemestring"system"Default theme when first loading
enableSystembooleantrueEnable system theme detection
valueRecord<string, any>-Controlled theme value
forcedThemestring-Forced theme to use (disables switching)
disableTransitionOnChangebooleanfalseDisable transitions when switching themes

Mode Toggle

Place a mode toggle on your site at @/components/themes/mode-toggle.tsx to toggle between light and dark mode.

With Dropdown Menu

Preview

"use client"
 
import * as React from "react"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
 
import { Button } from "@/components/ui/button"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
 
export function ModeToggle() {
  const { setTheme } = useTheme()
 
  return (
    <DropdownMenu>
      <DropdownMenuTrigger asChild>
        <Button variant="outline" size="icon">
          <Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
          <Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
          <span className="sr-only">Toggle theme</span>
        </Button>
      </DropdownMenuTrigger>
      <DropdownMenuContent align="end">
        <DropdownMenuItem onClick={() => setTheme("light")}>
          Light
        </DropdownMenuItem>
        <DropdownMenuItem onClick={() => setTheme("dark")}>
          Dark
        </DropdownMenuItem>
        <DropdownMenuItem onClick={() => setTheme("system")}>
          System
        </DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  )
}

Without Dropdown Menu

Preview

"use client"
 
import * as React from "react"
import { Moon, Sun } from "lucide-react"
import { useTheme } from "next-themes"
 
import { Button } from "@/components/ui/button"
 
export function ModeToggle() {
  const { theme, setTheme } = useTheme();
 
  return (
    <Button
      variant="outline"
      size="icon"
      onClick={() => setTheme(theme === "light" ? "dark" : "light")}
      aria-label="Toggle theme"
    >
      <Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
      <Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
    </Button>
  );
}

Example Usage

import { ModeToggle } from "@/components/themes/mode-toggle"
 
function App() {
  return <ModeToggle />
}

On this page