"use client"; import { FC } from "react"; import { VisuallyHidden } from "@react-aria/visually-hidden"; import { SwitchProps, useSwitch } from "@nextui-org/switch"; import { useTheme } from "next-themes"; import { useIsSSR } from "@react-aria/ssr"; import clsx from "clsx"; 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" || isSSR, "aria-label": `Switch to ${theme === "light" || isSSR ? "dark" : "light"} mode`, onChange, }); return (
{!isSelected || isSSR ? ( ) : ( )}
); };