-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathThemeToggleButton.tsx
37 lines (30 loc) · 1018 Bytes
/
ThemeToggleButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { MoonIcon, SunIcon } from '@chakra-ui/icons';
import { IconButton, IconButtonProps, useColorMode } from '@chakra-ui/react';
import styled from '@emotion/styled';
import transientOptions from '../utils/general';
// PROP TYPES
type ThemeToggleButtonProps = Omit<IconButtonProps, 'aria-label'>;
// CONSTS and LETS
const iconSize = 20;
const RoundButton = styled(IconButton, transientOptions)`
box-shadow: 0 0 100px 20px
${({ $colorMode }) => ($colorMode === 'light' ? 'black' : 'white')};
& svg {
width: ${iconSize}px;
height: ${iconSize}px;
}
`;
function ThemeToggleButton(props: ThemeToggleButtonProps): JSX.Element {
const { colorMode, toggleColorMode } = useColorMode();
return (
<RoundButton
$colorMode={colorMode}
onClick={toggleColorMode}
icon={colorMode === 'light' ? <MoonIcon /> : <SunIcon />}
aria-label={`Activate ${colorMode === 'light' ? 'dark' : 'light'} mode`}
isRound
{...props}
/>
);
}
export default ThemeToggleButton;