| 1 | "use client"; |
| 2 | |
| 3 | import { Moon, Sun } from "lucide-react"; |
| 4 | import { |
| 5 | ThemeProvider as NextThemesProvider, |
| 6 | type ThemeProviderProps, |
| 7 | useTheme, |
| 8 | } from "next-themes"; |
| 9 | |
| 10 | import { Button } from "@/components/ui/button"; |
| 11 | import { Switch } from "@/components/ui/switch"; |
| 12 | |
| 13 | export function ThemeProvider({ children, ...props }: ThemeProviderProps) { |
| 14 | return <NextThemesProvider {...props}>{children}</NextThemesProvider>; |
| 15 | } |
| 16 | |
| 17 | export function ThemeToggle() { |
| 18 | const { theme, setTheme } = useTheme(); |
| 19 | |
| 20 | const toggleTheme = () => { |
| 21 | setTheme(theme === "light" ? "dark" : "light"); |
| 22 | }; |
| 23 | |
| 24 | return ( |
| 25 | <Button |
| 26 | variant="outline" |
| 27 | className="flex w-full items-center justify-between gap-2 text-primary" |
| 28 | onClick={toggleTheme} |
| 29 | > |
| 30 | <span>Change Theme</span> |
| 31 | <div className="flex items-center"> |
| 32 | <Sun className="h-4 w-4 rotate-0 transition-all dark:hidden" /> |
| 33 | <Moon className="hidden h-4 w-4 rotate-0 transition-all dark:block" /> |
| 34 | <Switch |
| 35 | checked={theme === "dark"} |
| 36 | onCheckedChange={toggleTheme} |
| 37 | className="ml-2" |
| 38 | /> |
| 39 | </div> |
| 40 | <span className="sr-only">Toggle theme</span> |
| 41 | </Button> |
| 42 | ); |
| 43 | } |
| 44 |