mirror of
https://github.com/FranP-code/Pomodoro-Timer-with-Clockify-integration.git
synced 2025-10-12 23:52:30 +00:00
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
import React from 'react'
|
|
|
|
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')
|
|
|
|
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={changeTheme}/>
|
|
<label htmlFor="dark-mode_toogle-switch"></label>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default DarkMode
|