2021-05-21 18:36:19 +09:00
|
|
|
import "tailwindcss/tailwind.css";
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import React, { useEffect, useState } from 'react'
|
2021-05-22 10:12:17 +09:00
|
|
|
import { useTheme } from "next-themes";
|
2021-06-22 12:08:26 +09:00
|
|
|
import { faMoon, faSun } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
2021-05-21 18:36:19 +09:00
|
|
|
|
2021-06-22 12:08:26 +09:00
|
|
|
const ThemeSelector = (props) => {
|
2021-05-21 18:36:19 +09:00
|
|
|
const { title, children } = props
|
2021-05-22 10:12:17 +09:00
|
|
|
const [isMounted, setIsMounted] = useState(false);
|
2021-05-22 10:23:46 +09:00
|
|
|
const { theme, setTheme, getTheme } = useTheme();
|
|
|
|
useEffect(() => {
|
2021-05-22 10:12:17 +09:00
|
|
|
setIsMounted(true);
|
|
|
|
}, []);
|
2021-05-22 10:23:46 +09:00
|
|
|
const switchTheme = () => {
|
2021-05-22 10:12:17 +09:00
|
|
|
if (isMounted) {
|
|
|
|
setTheme(theme === "light" ? "dark" : "light");
|
|
|
|
}
|
|
|
|
};
|
2021-05-21 18:36:19 +09:00
|
|
|
return (
|
2021-06-22 12:39:51 +09:00
|
|
|
<button className="inline-flex rounded-md border border-gray-300 dark:border-gray-800 shadow-sm px-2 bg-white font-medium text-gray-700 hover:bg-gray-50 dark:bg-gray-700 dark:text-white my-3 py-1 text-2xl focus:outline-none" onClick={switchTheme}>
|
2021-07-15 14:42:52 +09:00
|
|
|
{theme !== undefined && (theme === "light" ? (
|
2021-06-22 12:39:51 +09:00
|
|
|
<FontAwesomeIcon icon={faMoon} className="w-10 h-7" />
|
2021-05-22 10:23:46 +09:00
|
|
|
) : (
|
2021-06-22 12:39:51 +09:00
|
|
|
<FontAwesomeIcon icon={faSun} className="w-10 h-7" />
|
2021-07-15 14:42:52 +09:00
|
|
|
))}
|
2021-05-22 10:23:46 +09:00
|
|
|
</button>
|
2021-05-21 18:36:19 +09:00
|
|
|
)
|
|
|
|
}
|
2021-06-22 12:08:26 +09:00
|
|
|
export default ThemeSelector
|