Last active
July 20, 2022 12:35
-
-
Save webrgp/40ef461c21961cae325be325f40df9e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { ThemeToggler } from "gatsby-plugin-dark-mode" | |
function ThemeToggle() { | |
return ( | |
<ThemeToggler> | |
{({ theme, toggleTheme }) => ( | |
<div className="flex justify-between items-center"> | |
<label className={`w-14 h-8 flex items-center rounded-full p-1 ${ theme === 'dark' ? "bg-indigo-500" : "bg-yellow-200"}`}> | |
<input type="checkbox" className="hidden" | |
onChange={e => toggleTheme(e.target.checked ? 'dark' : 'light')} | |
checked={theme === 'dark'} | |
/> | |
<div className={`bg-white w-6 h-6 rounded-full shadow-md duration-300 ease-in-out ${theme === 'dark' ? "transform translate-x-6" : ""}`} /> | |
</label> | |
</div> | |
)} | |
</ThemeToggler> | |
) | |
} | |
export default ThemeToggle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment