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'; |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame] | 4 | import { useState, useEffect } from 'react'; |
| 5 | |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 6 | |
| 7 | const ThemeChangeButton = () => { |
| 8 | const [colorMode, setColorMode] = useColorMode() |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame] | 9 | const [render, setRender] = useState(false); |
| 10 | |
| 11 | useEffect(() => { |
| 12 | setRender(true); |
| 13 | }); |
| 14 | |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 15 | return ( |
| 16 | <header> |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame] | 17 | <a className={Styles.icon + " " + Styles.ThemeChangeButton} onClick={(e) => { |
| 18 | e.preventDefault(); |
| 19 | setColorMode(colorMode === 'light' ? 'dark' : 'light'); |
| 20 | }}> |
| 21 | { |
pineafan | 0a17873 | 2022-02-09 21:00:05 +0000 | [diff] [blame] | 22 | !render ? null : (colorMode == 'light' ? <img alt="Light" src="https://assets.clicksminuteper.net/web/icons/light.svg" /> : <img alt="Dark" src="https://assets.clicksminuteper.net/web/icons/dark.svg" />) |
pineafan | 7872745 | 2021-11-04 21:25:07 +0000 | [diff] [blame] | 23 | } |
| 24 | </a> |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 25 | </header> |
| 26 | ) |
| 27 | } |
| 28 | |
| 29 | export default ThemeChangeButton; |