"use client" import { classNames } from "@repo/config-tailwind/classNames" import { useIsMounted } from "@repo/react-hooks/useIsMounted" import type { Theme } from "@repo/utils/constants" import { THEME_DEFAULT } from "@repo/utils/constants" import { ThemeProvider as NextThemeProvider, useTheme as useNextTheme, } from "next-themes" export interface ThemeProviderProps extends React.PropsWithChildren {} export const ThemeProvider: React.FC = (props) => { const { children } = props return ( {children} ) } export interface UseThemeOutput { theme: Theme toggleTheme: () => void } export const useTheme = (): UseThemeOutput => { const { setTheme, theme: themeData } = useNextTheme() const { isMounted } = useIsMounted() const theme = isMounted ? (themeData as Theme) : THEME_DEFAULT const toggleTheme: UseThemeOutput["toggleTheme"] = () => { const newTheme = theme === "dark" ? "light" : "dark" setTheme(newTheme) } return { theme, toggleTheme, } } export interface SwitchThemeProps {} export const SwitchTheme: React.FC = () => { const { theme, toggleTheme } = useTheme() return (
🌜
🌞
) }