Files
Homarr/components/ColorSchemeToggle/ColorSchemeToggle.tsx

29 lines
794 B
TypeScript
Raw Normal View History

2022-04-25 23:33:19 +02:00
import { ActionIcon, Box, useMantineColorScheme } from '@mantine/core';
2022-04-25 00:11:32 +02:00
import { Sun, MoonStars } from 'tabler-icons-react';
import { motion } from 'framer-motion';
2022-04-24 22:36:47 +02:00
export function ColorSchemeToggle() {
const { colorScheme, toggleColorScheme } = useMantineColorScheme();
return (
2022-04-25 00:11:32 +02:00
<motion.div
whileHover={{ scale: 1.2, rotate: 90 }}
whileTap={{
scale: 0.8,
rotate: -90,
borderRadius: '100%',
}}
>
2022-04-25 23:33:19 +02:00
<Box
2022-04-24 22:36:47 +02:00
onClick={() => toggleColorScheme()}
sx={(theme) => ({
2022-04-25 23:33:19 +02:00
cursor: "pointer",
2022-04-24 22:36:47 +02:00
color: theme.colorScheme === 'dark' ? theme.colors.yellow[4] : theme.colors.blue[6],
})}
>
2022-04-25 00:11:32 +02:00
{colorScheme === 'dark' ? <Sun size={24} /> : <MoonStars size={24} />}
2022-04-25 23:33:19 +02:00
</Box>
2022-04-25 00:11:32 +02:00
</motion.div>
2022-04-24 22:36:47 +02:00
);
}