diff options
author | Michal Sapka <michal@sapka.me> | 2022-09-06 22:42:59 +0200 |
---|---|---|
committer | Michal Sapka <michal@sapka.me> | 2022-09-06 22:42:59 +0200 |
commit | 596340f811d144fcef3237003ac84798614bc3b4 (patch) | |
tree | 11be61870acf31379857beac37cb0d0a0562a5e0 /components/toggle_theme_button.tsx | |
parent | e3ae3ef10b78347187a01735b049d3275ffe98d4 (diff) |
feat: theme switcher button
Diffstat (limited to 'components/toggle_theme_button.tsx')
-rw-r--r-- | components/toggle_theme_button.tsx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/components/toggle_theme_button.tsx b/components/toggle_theme_button.tsx new file mode 100644 index 0000000..de16397 --- /dev/null +++ b/components/toggle_theme_button.tsx @@ -0,0 +1,28 @@ +import { AnimatePresence, motion } from 'framer-motion' +import { IconButton, useColorMode, useColorModeValue } from '@chakra-ui/react' +import { BsFillSunFill, BsMoonFill } from "react-icons/bs"; +const ThemeToggleButton = () => { + const { toggleColorMode } = useColorMode() + + return ( + <AnimatePresence exitBeforeEnter initial={false}> + <motion.div + style={{ display: 'inline-block' }} + key={useColorModeValue('light', 'dark')} + initial={{ y: -20, opacity: 0 }} + animate={{ y: 0, opacity: 1 }} + exit={{ y: 20, opacity: 0 }} + transition={{ duration: 0.2 }} + > + <IconButton + aria-label="Toggle theme" + colorScheme={useColorModeValue('purple', 'orange')} + icon={useColorModeValue(<BsMoonFill />, <BsFillSunFill />)} + onClick={toggleColorMode} + ></IconButton> + </motion.div> + </AnimatePresence> + ) +} + +export default ThemeToggleButton |