Skip to content

Commit

Permalink
add theme toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
saml33 committed Sep 19, 2023
1 parent d7c2bfa commit 4e979da
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
30 changes: 30 additions & 0 deletions components/ThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useTheme } from 'next-themes'
import { IconButton } from './shared/Button'
import { useState } from 'react'
import { MoonIcon, SunIcon } from '@heroicons/react/20/solid'

const ThemeToggle = () => {
const { setTheme } = useTheme()
const [isDarkTheme, setIsDarkTheme] = useState(false)

const handleToggleTheme = (isDark: boolean) => {
setIsDarkTheme(!isDark)
if (isDark) {
setTheme('Light')
} else {
setTheme('Dark')
}
}

return (
<IconButton onClick={() => handleToggleTheme(isDarkTheme)} size="medium">
{isDarkTheme ? (
<SunIcon className="h-5 w-5" />
) : (
<MoonIcon className="h-5 w-5" />
)}
</IconButton>
)
}

export default ThemeToggle
6 changes: 4 additions & 2 deletions components/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRouter } from 'next/router'
// import SolanaTps from './SolanaTps'
import useOnlineStatus from 'hooks/useOnlineStatus'
import mangoStore from '@store/mangoStore'
import ThemeToggle from './ThemeToggle'

const TopBar = () => {
const { connected } = useWallet()
Expand All @@ -27,7 +28,7 @@ const TopBar = () => {

return (
<div className="mb-8 flex h-16 items-center justify-between px-6 shadow">
<div className="flex w-full items-center justify-between md:space-x-4">
<div className="flex w-full items-center justify-between">
<span className="mb-0 flex items-center">
{query.token || query.market ? (
<button
Expand All @@ -53,7 +54,8 @@ const TopBar = () => {
</p>
</div>
) : null}
<div className="flex items-center">
<div className="flex items-center space-x-4">
<ThemeToggle />
{connected ? <ConnectedMenu /> : <ConnectWalletButton />}
</div>
</div>
Expand Down

0 comments on commit 4e979da

Please sign in to comment.