({ hideInMobile, align }: Props)
| 15 | }; |
| 16 | |
| 17 | export default function ToggleDarkMode({ hideInMobile, align }: Props) { |
| 18 | const { t } = useTranslation(); |
| 19 | const { data } = useUser(); |
| 20 | const updateUserPreference = useUpdateUserPreference(); |
| 21 | |
| 22 | const handleToggle = (e: ChangeEvent<HTMLInputElement>) => { |
| 23 | updateUserPreference.mutateAsync({ |
| 24 | theme: e.target.checked ? "dark" : "light", |
| 25 | }); |
| 26 | }; |
| 27 | |
| 28 | if (!data?.theme) return <></>; |
| 29 | |
| 30 | return ( |
| 31 | <TooltipProvider> |
| 32 | <Tooltip> |
| 33 | <TooltipTrigger className={hideInMobile ? "hidden sm:inline-grid" : ""}> |
| 34 | <Button |
| 35 | asChild |
| 36 | variant="ghost" |
| 37 | size="icon" |
| 38 | className={"inline-grid swap swap-rotate text-neutral"} |
| 39 | > |
| 40 | <label> |
| 41 | <input |
| 42 | type="checkbox" |
| 43 | onChange={handleToggle} |
| 44 | className="theme-controller" |
| 45 | checked={data?.theme === "dark"} |
| 46 | /> |
| 47 | <i className="bi-sun-fill text-xl swap-on"></i> |
| 48 | <i className="bi-moon-fill text-xl swap-off"></i> |
| 49 | </label> |
| 50 | </Button> |
| 51 | </TooltipTrigger> |
| 52 | <TooltipContent side={align || "bottom"}> |
| 53 | <p> |
| 54 | {t("switch_to", { |
| 55 | theme: data?.theme === "light" ? "Dark" : "Light", |
| 56 | })} |
| 57 | </p> |
| 58 | </TooltipContent> |
| 59 | </Tooltip> |
| 60 | </TooltipProvider> |
| 61 | ); |
| 62 | } |
nothing calls this directly
no test coverage detected