Skip to content

Commit e7cba43

Browse files
committed
Add dark mode support
1 parent ab4f2b7 commit e7cba43

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/components/ColorModeToggle.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { IconButton, useColorMode } from '@chakra-ui/react'
2+
import { SunIcon, MoonIcon } from '@chakra-ui/icons'
3+
4+
export function ColorModeToggle() {
5+
const { colorMode, toggleColorMode } = useColorMode()
6+
7+
return (
8+
<IconButton
9+
aria-label={`Switch to ${colorMode === 'light' ? 'dark' : 'light'} mode`}
10+
icon={colorMode === 'light' ? <MoonIcon /> : <SunIcon />}
11+
onClick={toggleColorMode}
12+
variant='ghost'
13+
size='md'
14+
position='fixed'
15+
top={4}
16+
right={4}
17+
zIndex={1000}
18+
/>
19+
)
20+
}

src/pages/_app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ChakraProvider } from '@chakra-ui/react'
44
import { useRouter } from 'next/router'
55
import Script from 'next/script'
66
import { useEffect } from 'react'
7+
import { ColorModeToggle } from '@/components/ColorModeToggle'
78

89
function MyApp({ Component, pageProps }) {
910
const router = useRouter()
@@ -41,6 +42,7 @@ function MyApp({ Component, pageProps }) {
4142
}}
4243
/>
4344

45+
<ColorModeToggle />
4446
<Component {...pageProps} />
4547
</ChakraProvider>
4648
)

src/theme.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import '@fontsource-variable/inter'
44

55
// color mode config
66
const config = {
7+
// TODO: Change default color mode to system?
78
initialColorMode: 'light',
89
useSystemColorMode: false,
910
}

0 commit comments

Comments
 (0)