import { FC } from "react"; import { VisuallyHidden } from "@react-aria/visually-hidden"; import { SwitchProps, useSwitch } from "@heroui/switch"; import { useIsSSR } from "@react-aria/ssr"; import clsx from "clsx"; import { SunFilledIcon, MoonFilledIcon } from "../../icons/Icons"; import { useTheme } from "@heroui/use-theme"; 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 ? ( ) : ( )}
) } export default ThemeSwitch