2021-06-05 21:25:07 +02:00
|
|
|
import PropTypes from 'prop-types'
|
2022-01-19 06:35:04 +04:00
|
|
|
import {styled} from '@mui/material/styles'
|
2022-01-19 07:06:26 +04:00
|
|
|
import WbSunnyIcon from '@mui/icons-material/WbSunny'
|
|
|
|
|
import Brightness3Icon from '@mui/icons-material/Brightness3'
|
|
|
|
|
import {Box} from '@mui/material'
|
2021-06-05 21:25:07 +02:00
|
|
|
|
2022-01-19 06:35:04 +04:00
|
|
|
const PREFIX = 'switch-theme'
|
|
|
|
|
|
|
|
|
|
const classes = {
|
|
|
|
|
switch: `${PREFIX}-switch`,
|
|
|
|
|
switchFixed: `${PREFIX}-switchFixed`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StyledBox = styled(Box)({
|
|
|
|
|
[`& .${classes.switch}`]: {
|
2022-01-19 06:00:14 +04:00
|
|
|
position: 'absolute',
|
|
|
|
|
right: '1em',
|
2022-01-19 06:35:04 +04:00
|
|
|
top: '200px',
|
2022-01-19 06:00:14 +04:00
|
|
|
zIndex: 1,
|
|
|
|
|
cursor: 'pointer'
|
|
|
|
|
},
|
2022-01-19 06:35:04 +04:00
|
|
|
[`& .${classes.switchFixed}`]: {
|
2022-01-19 06:00:14 +04:00
|
|
|
position: 'fixed',
|
|
|
|
|
right: '1em',
|
|
|
|
|
top: '95px',
|
|
|
|
|
zIndex: 9990,
|
|
|
|
|
cursor: 'pointer'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default function SwitchTheme({switchFixed, darkMode, setDarkMode}) {
|
2021-06-05 21:25:07 +02:00
|
|
|
const handleClick = () => {
|
2021-06-05 23:44:39 +02:00
|
|
|
localStorage.setItem('oki-dark', !darkMode)
|
2021-06-05 21:25:07 +02:00
|
|
|
setDarkMode(!darkMode)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-19 06:35:04 +04:00
|
|
|
<StyledBox 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:35:04 +04:00
|
|
|
</StyledBox>
|
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
|
|
|
|
|
}
|