Skip to content

Commit

Permalink
Fix: Handle Theme Selection in Mobile (#165)
Browse files Browse the repository at this point in the history
* fix: add theme toggle in mobile

* fix: use resolvedTheme boolean

* chore: linting
  • Loading branch information
kamescg committed Aug 31, 2023
1 parent 02602d3 commit d4a286f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion components/layout/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function MainNav() {
<Link href="/" className="mr-6 flex items-center space-x-2">
<LightDarkImage
LightImage="/logo-dark.png"
DarkImage="/logo-white.png"
DarkImage="/logo-light.png"
alt="TurboETH"
height={32}
width={32}
Expand Down
34 changes: 19 additions & 15 deletions components/layout/mobile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useState } from "react"
import Link, { LinkProps } from "next/link"
import { useRouter } from "next/navigation"
import { integrations } from "@/data/integrations"
import { ConnectButton } from "@rainbow-me/rainbowkit"
import { LuMenu } from "react-icons/lu"

import { menuDashboard } from "@/config/menu-dashboard"
Expand All @@ -22,6 +21,8 @@ import { Separator } from "@/components/ui/separator"
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"
import { LightDarkImage } from "@/components/shared/light-dark-image"

import { ModeToggle } from "../shared/mode-toggle"

export function MobileNav() {
const [open, setOpen] = useState(false)

Expand All @@ -31,7 +32,7 @@ export function MobileNav() {
<Link href="/" className="mr-6 flex items-center space-x-2">
<LightDarkImage
LightImage="/logo-dark.png"
DarkImage="/logo-white.png"
DarkImage="/logo-light.png"
alt="TurboETH"
height={32}
width={32}
Expand All @@ -51,19 +52,22 @@ export function MobileNav() {
</SheetTrigger>
</div>
<SheetContent side="right" className="pr-0">
<MobileLink
href="/"
className="flex items-center"
onOpenChange={setOpen}
>
<LightDarkImage
LightImage="/logo-dark.png"
DarkImage="/logo-white.png"
alt="TurboETH"
height={32}
width={32}
/>
</MobileLink>
<div className="flex items-center gap-x-4">
<MobileLink
href="/"
className="flex items-center"
onOpenChange={setOpen}
>
<LightDarkImage
LightImage="/logo-dark.png"
DarkImage="/logo-light.png"
alt="TurboETH"
height={32}
width={32}
/>
</MobileLink>
<ModeToggle />
</div>
<ScrollArea className="my-4 mr-4 h-[calc(100vh-8rem)] pb-10">
<div className="flex flex-col space-y-4">
<Accordion type="single" collapsible className="mx-auto w-full">
Expand Down
4 changes: 2 additions & 2 deletions components/shared/is-dark-theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ interface IsDarkThemeProps {
}

export const IsDarkTheme = ({ children }: IsDarkThemeProps) => {
const { theme } = useTheme()
const { resolvedTheme } = useTheme()

if (theme !== "light") return <>{children}</>
if (resolvedTheme === "dark") return <>{children}</>

return null
}
4 changes: 2 additions & 2 deletions components/shared/is-light-theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ interface IsLightThemeProps {
}

export const IsLightTheme = ({ children }: IsLightThemeProps) => {
const { theme } = useTheme()
const { resolvedTheme } = useTheme()

if (theme === "light") return <>{children}</>
if (resolvedTheme === "light") return <>{children}</>

return null
}
4 changes: 2 additions & 2 deletions components/shared/light-dark-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const LightDarkImage = ({
width,
className,
}: LightDarkImageProps) => {
const { theme } = useTheme()
const { resolvedTheme } = useTheme()

let imageUrl = LightImage
if (theme === "dark") {
if (resolvedTheme === "dark") {
imageUrl = DarkImage
}

Expand Down
File renamed without changes

0 comments on commit d4a286f

Please sign in to comment.