blob: b4c80c802fcfa04ea2a63e34330ca389fb2a68c3 [file] [log] [blame]
Skyler Turner16c08d32021-11-04 20:06:50 +00001/** @jsxImportSource theme-ui */
2import { useColorMode } from 'theme-ui';
pineafan78727452021-11-04 21:25:07 +00003import Styles from '../styles/navbar.module.css';
4import Light from '../public/light.svg';
5import Dark from '../public/dark.svg';
6import { useState, useEffect } from 'react';
7
Skyler Turner16c08d32021-11-04 20:06:50 +00008
9const ThemeChangeButton = () => {
10 const [colorMode, setColorMode] = useColorMode()
pineafan78727452021-11-04 21:25:07 +000011 const [render, setRender] = useState(false);
12
13 useEffect(() => {
14 setRender(true);
15 });
16
Skyler Turner16c08d32021-11-04 20:06:50 +000017 return (
18 <header>
pineafan78727452021-11-04 21:25:07 +000019 <a className={Styles.icon + " " + Styles.ThemeChangeButton} onClick={(e) => {
20 e.preventDefault();
21 setColorMode(colorMode === 'light' ? 'dark' : 'light');
22 }}>
23 {
24 !render ? null : (colorMode == 'light' ? <Light /> : <Dark />)
25 }
26 </a>
Skyler Turner16c08d32021-11-04 20:06:50 +000027 </header>
28 )
29}
30
31export default ThemeChangeButton;