Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 1 | /** @jsxImportSource theme-ui */ |
| 2 | import { useColorMode } from 'theme-ui'; |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame^] | 3 | import Styles from '../styles/navbar.module.css'; |
| 4 | import Light from '../public/light.svg'; |
| 5 | import Dark from '../public/dark.svg'; |
| 6 | import { useState, useEffect } from 'react'; |
| 7 | |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 8 | |
| 9 | const ThemeChangeButton = () => { |
| 10 | const [colorMode, setColorMode] = useColorMode() |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame^] | 11 | const [render, setRender] = useState(false); |
| 12 | |
| 13 | useEffect(() => { |
| 14 | setRender(true); |
| 15 | }); |
| 16 | |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 17 | return ( |
| 18 | <header> |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame^] | 19 | <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 Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 27 | </header> |
| 28 | ) |
| 29 | } |
| 30 | |
| 31 | export default ThemeChangeButton; |