Files
pawol.nu/components/switch-theme.js
T

46 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-06-05 21:25:07 +02:00
import PropTypes from 'prop-types'
import WbSunnyIcon from '@material-ui/icons/WbSunny'
import Brightness3Icon from '@material-ui/icons/Brightness3'
2022-01-19 06:00:14 +04:00
import {Box, makeStyles} from '@material-ui/core'
2021-06-05 21:25:07 +02:00
2022-01-19 06:00:14 +04:00
const useStyles = makeStyles({
switch: {
position: 'absolute',
right: '1em',
top: '95px',
zIndex: 1,
cursor: 'pointer'
},
switchFixed: {
position: 'fixed',
right: '1em',
top: '95px',
zIndex: 9990,
cursor: 'pointer'
}
})
export default function SwitchTheme({switchFixed, darkMode, setDarkMode}) {
const classes = useStyles()
2021-06-05 21:25:07 +02:00
const handleClick = () => {
localStorage.setItem('oki-dark', !darkMode)
2021-06-05 21:25:07 +02:00
setDarkMode(!darkMode)
}
return (
2022-01-19 06:00:14 +04:00
<Box className={switchFixed ? classes.switchFixed : classes.switch}>
2021-06-05 21:25:07 +02:00
{darkMode ? (
<WbSunnyIcon onClick={handleClick} />
) : (
<Brightness3Icon onClick={handleClick} />
)}
2022-01-19 06:00:14 +04:00
</Box>
2021-06-05 21:25:07 +02:00
)
}
SwitchTheme.propTypes = {
2022-01-19 06:00:14 +04:00
switchFixed: PropTypes.bool.isRequired,
2021-06-05 21:25:07 +02:00
darkMode: PropTypes.bool.isRequired,
setDarkMode: PropTypes.func.isRequired
}