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-23 21:55:39 +04:00
|
|
|
import LightModeIcon from '@mui/icons-material/LightMode'
|
|
|
|
|
import DarkModeIcon from '@mui/icons-material/DarkMode'
|
2022-01-19 07:06:26 +04:00
|
|
|
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-22 13:42:09 +04:00
|
|
|
top: '60px',
|
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',
|
2022-05-22 02:57:11 +04:00
|
|
|
right: '0.5em',
|
|
|
|
|
top: '68px',
|
2022-01-19 06:00:14 +04:00
|
|
|
zIndex: 9990,
|
|
|
|
|
cursor: 'pointer'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-21 07:54:50 +04:00
|
|
|
export default function SwitchTheme({switchFixed, mode, setMode}) {
|
|
|
|
|
const handleClick = seletedMode => {
|
|
|
|
|
localStorage.setItem('oki-theme', seletedMode)
|
|
|
|
|
setMode(seletedMode)
|
2021-06-05 21:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-21 07:54:50 +04:00
|
|
|
<StyledBox>
|
|
|
|
|
<div className={switchFixed ? classes.switchFixed : classes.switch} >
|
|
|
|
|
{mode === 'dark' ? (
|
2022-01-23 21:55:39 +04:00
|
|
|
<LightModeIcon onClick={() => handleClick('light')} />
|
2022-01-21 07:54:50 +04:00
|
|
|
) : (
|
2022-01-23 21:55:39 +04:00
|
|
|
<DarkModeIcon onClick={() => handleClick('dark')} />
|
2022-01-21 07:54:50 +04:00
|
|
|
)}
|
|
|
|
|
</div>
|
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,
|
2022-01-21 07:54:50 +04:00
|
|
|
mode: PropTypes.oneOf(['light', 'dark']),
|
|
|
|
|
setMode: PropTypes.func.isRequired
|
2021-06-05 21:25:07 +02:00
|
|
|
}
|