2021-05-21 18:36:19 +09:00
|
|
|
import Head from "next/head"
|
|
|
|
import Link from "next/link"
|
|
|
|
import "tailwindcss/tailwind.css";
|
|
|
|
import useTranslation from 'next-translate/useTranslation'
|
|
|
|
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-05-21 18:36:19 +09:00
|
|
|
|
|
|
|
const Layout = (props) => {
|
|
|
|
const { title, children } = props
|
|
|
|
const siteTitle = "yude.jp"
|
|
|
|
const router = useRouter()
|
2021-05-22 10:12:17 +09:00
|
|
|
const { locale, locales, defaultLocale, pathname } = router
|
|
|
|
|
|
|
|
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-05-22 10:23:46 +09:00
|
|
|
<button className="my-4 mx-3 text-2xl" onClick={switchTheme}>
|
|
|
|
{theme === 'light' ? (
|
|
|
|
<span>🌙</span>
|
|
|
|
) : (
|
|
|
|
<span>🌄</span>
|
|
|
|
)}
|
|
|
|
</button>
|
2021-05-21 18:36:19 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
export default Layout
|