Files
zitadel/apps/login/src/ui/Theme.tsx

47 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-04-19 10:37:35 +02:00
"use client";
2023-05-24 14:12:38 +02:00
import React, { useEffect, useState } from "react";
2023-04-19 10:37:35 +02:00
import { useTheme } from "next-themes";
2023-05-24 14:49:07 +02:00
import { MoonIcon, SunIcon } from "@heroicons/react/24/outline";
2023-04-19 10:37:35 +02:00
2023-05-24 14:12:38 +02:00
function Theme() {
2023-04-19 10:37:35 +02:00
const { resolvedTheme, setTheme } = useTheme();
const [mounted, setMounted] = useState<boolean>(false);
2023-04-19 10:37:35 +02:00
const isDark = resolvedTheme === "dark";
// useEffect only runs on the client, so now we can safely show the UI
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return null;
}
2023-04-19 10:37:35 +02:00
return (
2023-05-24 14:12:38 +02:00
<div
className={`relative grid grid-cols-2 rounded-full border border-divider-light dark:border-divider-dark p-1`}
2023-04-19 10:37:35 +02:00
>
2023-05-24 14:12:38 +02:00
<button
className={`h-8 w-8 rounded-full flex flex-row items-center justify-center hover:opacity-100 transition-all ${
isDark ? "bg-black/10 dark:bg-white/10" : "opacity-60"
}`}
onClick={() => setTheme("dark")}
2023-04-19 10:37:35 +02:00
>
2023-05-24 14:49:07 +02:00
<MoonIcon className="h-4 w-4 flex-shrink-0 text-xl rounded-full" />
2023-05-24 14:12:38 +02:00
</button>
<button
className={`h-8 w-8 rounded-full flex flex-row items-center justify-center hover:opacity-100 transition-all ${
!isDark ? "bg-black/10 dark:bg-white/10" : "opacity-60"
}`}
onClick={() => setTheme("light")}
>
2023-05-24 14:49:07 +02:00
<SunIcon className="h-6 w-6 flex-shrink-0 text-xl rounded-full" />
2023-05-24 14:12:38 +02:00
</button>
</div>
2023-04-19 10:37:35 +02:00
);
}
2023-05-24 14:12:38 +02:00
export default Theme;