0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-09-27 23:20:24 +09:00

Add themeChanger

This commit is contained in:
yude 2021-02-07 17:01:04 +09:00
parent 4d14548d09
commit 6e45ef3eae
2 changed files with 32 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import "tailwindcss/tailwind.css";
import Popper from "popper.js";
import Link from 'next/link';
import LangSelector from "./LangSelector"
import ThemeChanger from './ThemeChanger';
const Navbar = () => {
return (
@ -16,8 +17,10 @@ const Navbar = () => {
</Link>
<div className="origin-top-right absolute right-0">
<LangSelector />
</div>
</nav>
<ThemeChanger />
</>
);
};

View File

@ -0,0 +1,29 @@
import "tailwindcss/tailwind.css";
import { useEffect, useState } from 'react';
import { useTheme } from 'next-themes';
const ThemeChanger = () => {
const [mounted, setMounted] = useState(false)
const { theme, setTheme } = useTheme()
// When mounted on client, now we can show the UI
useEffect(() => setMounted(true), [])
if (!mounted) return null
return (
<div className="p-8 bg-gray-200 flex justify-between items-center font-bold text-xl">
The current theme is: {theme}
<div>
<button className="hover:text-orange-600" onClick={() => setTheme('light')}>
<svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" /></svg>
</button>
<button className="ml-4 hover:text-orange-600" onClick={() => setTheme('dark')}>
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" id="moon" class="w-8 h-8 text-cool-gray-800 dark:text-cool-gray-200 group-hover:text-purple-600 group-focus:text-purple-600 dark:group-hover:text-purple-50 dark:group-focus:text-purple-50"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path></svg>
</button>
</div>
</div>
)
}
export default ThemeChanger;