Dark mode done

This commit is contained in:
2021-10-02 15:49:23 -03:00
parent fdbd8a1be6
commit e4f3bccd8c
33 changed files with 604 additions and 80 deletions

View File

@@ -1,11 +1,40 @@
import React from 'react'
const DarkMode = () => {
const DarkMode = (props) => {
React.useEffect( () => {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
props.setDarkmode(true)
const darkModeSwitch = document.getElementById('dark-mode_toogle-switch')
darkModeSwitch.checked = true
}
const darkModeCache = localStorage.getItem('dark-mode')
console.log(darkModeCache)
if (darkModeCache === 'true') {
props.setDarkmode(true)
const darkModeSwitch = document.getElementById('dark-mode_toogle-switch')
darkModeSwitch.checked = true
}
}, [])
const changeTheme = () => {
props.setDarkmode(!props.darkMode)
localStorage.setItem('dark-mode', !props.darkMode)
}
return (
<div className="dark-mode">
<input type="checkbox" id="dark-mode_toogle-switch" onChange={() => {
}}/>
<input type="checkbox" id="dark-mode_toogle-switch" onChange={changeTheme}/>
<label htmlFor="dark-mode_toogle-switch"></label>
</div>
)