"use client" import { classNames } from "@repo/config-tailwind/classNames" import type { Theme } from "@repo/utils/constants" import { THEME_DEFAULT } from "@repo/utils/constants" import { ThemeProvider as NextThemeProvider, useTheme as useNextTheme, } from "next-themes" import { useEffect, useState } from "react" export interface ThemeProviderProps extends React.PropsWithChildren { forcedTheme?: Theme } export const ThemeProvider: React.FC = (props) => { const { children, forcedTheme } = props return ( {children} ) } export interface UseThemeOutput { theme: Theme toggleTheme: () => void } export const useTheme = (): UseThemeOutput => { const { setTheme, theme: themeData } = useNextTheme() const [isMounted, setIsMounted] = useState(false) useEffect(() => { // eslint-disable-next-line react-hooks/set-state-in-effect setIsMounted(true) }, []) 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 (
🌜
🌞
) }