2020-09-21 00:42:01 +02:00
|
|
|
import { useTransition, animated } from 'react-spring';
|
2023-03-22 05:28:36 +01:00
|
|
|
import { Button, Icon } from 'react-basics';
|
2020-09-20 10:33:39 +02:00
|
|
|
import useTheme from 'hooks/useTheme';
|
2023-01-31 06:44:07 +01:00
|
|
|
import Icons from 'components/icons';
|
2020-09-21 00:42:01 +02:00
|
|
|
import styles from './ThemeButton.module.css';
|
2020-09-20 10:33:39 +02:00
|
|
|
|
2023-03-22 05:28:36 +01:00
|
|
|
export default function ThemeButton() {
|
2020-09-20 10:33:39 +02:00
|
|
|
const [theme, setTheme] = useTheme();
|
|
|
|
|
2022-03-03 00:23:47 +01:00
|
|
|
const transitions = useTransition(theme, {
|
|
|
|
initial: { opacity: 1 },
|
2020-09-21 00:42:01 +02:00
|
|
|
from: {
|
|
|
|
opacity: 0,
|
2020-09-21 06:31:53 +02:00
|
|
|
transform: `translateY(${theme === 'light' ? '20px' : '-20px'}) scale(0.5)`,
|
2020-09-21 00:42:01 +02:00
|
|
|
},
|
2023-01-28 06:53:13 +01:00
|
|
|
enter: { opacity: 1, transform: 'translateY(0px) scale(1.0)' },
|
2020-09-21 00:42:01 +02:00
|
|
|
leave: {
|
|
|
|
opacity: 0,
|
2020-09-21 06:31:53 +02:00
|
|
|
transform: `translateY(${theme === 'light' ? '-20px' : '20px'}) scale(0.5)`,
|
2020-09-21 00:42:01 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-09-20 10:33:39 +02:00
|
|
|
function handleClick() {
|
|
|
|
setTheme(theme === 'light' ? 'dark' : 'light');
|
|
|
|
}
|
|
|
|
|
2020-09-20 11:54:38 +02:00
|
|
|
return (
|
2023-03-22 05:28:36 +01:00
|
|
|
<Button variant="quiet" className={styles.button} onClick={handleClick}>
|
|
|
|
{transitions((style, item) => (
|
|
|
|
<animated.div key={item} style={style}>
|
|
|
|
<Icon className={styles.icon}>{item === 'light' ? <Icons.Sun /> : <Icons.Moon />}</Icon>
|
|
|
|
</animated.div>
|
|
|
|
))}
|
|
|
|
</Button>
|
2020-09-20 11:54:38 +02:00
|
|
|
);
|
2020-09-20 10:33:39 +02:00
|
|
|
}
|