Skip to content

Commit

Permalink
add theme toggle button component
Browse files Browse the repository at this point in the history
  • Loading branch information
firehawk89 committed Sep 30, 2023
1 parent c2a988e commit 5f3803d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/themeToggleBtn.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useTheme } from 'next-themes'
import Image from 'next/image'

export default function ThemeToggleButton() {
const { resolvedTheme, setTheme } = useTheme()

const toggleThemeHandler = () => {
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')
}

return (
<button className="w-fit mx-auto" onClick={toggleThemeHandler}>
{resolvedTheme === 'light' ? (
<Image
src="/icons/moon.svg"
width={28}
height={28}
alt="Dark Theme Icon"
/>
) : (
<Image
src="/icons/sun.svg"
width={28}
height={28}
alt="Light Theme Icon"
/>
)}
</button>
)
}

0 comments on commit 5f3803d

Please sign in to comment.