"use client"; import {FC} from "react"; import {VisuallyHidden} from "@react-aria/visually-hidden"; import {SwitchProps, useSwitch} from "@nextui-org/react"; import {useTheme} from "next-themes"; import {clsx} from "@nextui-org/shared-utils"; import {useIsSSR} from "@react-aria/ssr"; import {SunFilledIcon, MoonFilledIcon} from "@/components/icons"; export interface ThemeSwitchProps { className?: string; classNames?: SwitchProps["classNames"]; } export const ThemeSwitch: FC = ({className, classNames}) => { const {theme, setTheme} = useTheme(); const isSSR = useIsSSR(); const onChange = () => { theme === "light" ? setTheme("dark") : setTheme("light"); }; const {Component, slots, isSelected, getBaseProps, getInputProps, getWrapperProps} = useSwitch({ isSelected: theme === "light", "aria-label": `Switch to ${theme === "light" ? "dark" : "light"} mode`, onChange, }); return (
{!isSelected || isSSR ? : }
); };