Skip to content

Commit

Permalink
feat(ui): create mobile menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Jun 20, 2023
1 parent 8700b0a commit 96a8af4
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/app/(blog)/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useGlitch } from 'react-powerglitch'
import { ToggleTheme } from './toggle-theme'
import { Search } from './search'
import { CategorySelector } from './category-selector'
import { MobileMenu } from './mobile-menu/index'

export function Header() {
const [percentScrollPosition, setPercentScrollPosition] = useState(0)
Expand Down Expand Up @@ -60,15 +61,16 @@ export function Header() {

return (
<header
className={`fixed top-3 left-3 right-3 rounded-xl bg-neutral-100/80 backdrop-blur-lg dark:bg-neutral-1000/80 md:top-0 md:right-0 md:left-0 md:w-full md:rounded-none ${
className={`fixed top-3 left-3 right-3 z-10 rounded-xl bg-neutral-100/80 backdrop-blur-lg dark:bg-neutral-1000/80 md:top-0 md:right-0 md:left-0 md:w-full md:rounded-none ${
isNotOnTop ? 'py-3' : 'py-3 md:py-6'
} border border-neutral-50 dark:border-neutral-800 md:border-b md:border-none ${
isNotOnTop
? 'md:border-b-neutral-50 md:dark:border-b-neutral-800'
: 'md:border-b-transparent'
}`}
>
<div className="blog-content-w m-auto flex flex-col flex-wrap items-center justify-between md:flex-row">
<div className="blog-content-w m-auto flex flex-wrap items-center justify-between">
<div className="md:hidden" />
<Link href="/">
<h1
ref={glitch.ref}
Expand All @@ -79,7 +81,7 @@ export function Header() {
Mateus Felipe
</h1>
</Link>
<div className="flex flex-wrap items-center justify-center gap-3 md:gap-8">
<div className="hidden flex-wrap items-center justify-center gap-8 md:flex">
<nav className="flex flex-wrap items-center justify-center gap-5">
<MenuItem name="Home" path="/" />
<MenuItem name="Portifolio" path="/portifolio" />
Expand All @@ -91,6 +93,7 @@ export function Header() {
<ToggleTheme />
</div>
</div>
<MobileMenu />
</div>
</header>
)
Expand Down
124 changes: 124 additions & 0 deletions src/app/(blog)/components/header/mobile-menu/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import * as Dialog from '@radix-ui/react-dialog'
import NextLink, { LinkProps as NextLinkProps } from 'next/link'
import {
Icon as IconType,
List,
X,
House,
ArrowUpRight,
ReadCvLogo,
Tag,
FolderOpen,
File,
GithubLogo,
RssSimple,
TreeStructure
} from '@/shared/lib/phosphor-icons'
import { AnchorHTMLAttributes, useState } from 'react'

import './styles.css'
import { ToggleTheme } from './toggle-theme'

interface LinkProps extends NextLinkProps {
title: string
icon: IconType
}

interface OutLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
title: string
icon: IconType
}

export function MobileMenu() {
const [isDialogOpen, setIsDialogOpen] = useState(false)

const Link = ({ title, icon, ...props }: LinkProps) => {
const Icon = icon

return (
<NextLink
{...props}
onClick={() => setIsDialogOpen(false)}
className="menu-item"
>
<Icon weight="duotone" />
<span>{title}</span>
</NextLink>
)
}

const OutLink = ({ title, icon, ...props }: OutLinkProps) => {
const Icon = icon

return (
<a {...props} className="menu-item" target="_blank">
<Icon weight="duotone" />
<span className="flex items-end gap-px">
<span>{title}</span>
<ArrowUpRight className="text-xs" />
</span>
</a>
)
}

return (
<Dialog.Root open={isDialogOpen} onOpenChange={setIsDialogOpen}>
<Dialog.Trigger asChild className="md:hidden">
<button>
<List />
</button>
</Dialog.Trigger>
<Dialog.Portal className="z-50">
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/40 backdrop-blur-md data-[state=open]:animate-overlayShow" />
<Dialog.Content className="fixed top-0 bottom-0 right-0 z-50 w-3/4 data-[state=open]:animate-slide-left data-[state=closed]:animate-slide-right">
<div className="relative flex h-screen w-full">
<Dialog.Close
asChild
className="absolute top-2 left-2 rounded-full p-2 backdrop-blur-lg active:bg-red-300/20 active:text-red-500 active:dark:bg-red-300/10 active:dark:text-red-400"
>
<button aria-label="Close">
<X weight="bold" />
</button>
</Dialog.Close>
<div className="flex flex-1 flex-col overflow-y-scroll rounded-tl-[2rem] rounded-bl-[2rem] bg-neutral-100 py-10 text-xl dark:bg-neutral-900">
<Link title="Home" icon={House} href="/" />
<Link title="Tags" icon={Tag} href="/tag" />
<Link title="Categories" icon={FolderOpen} href="/categories" />
<OutLink
title="Portifolio"
icon={ReadCvLogo}
rel="author"
href="/portifolio"
/>
<OutLink
title="License"
icon={File}
rel="license"
href="https://github.com/mateusfg7/mfg-b/blob/main/LICENSE"
/>
<OutLink
title="Github"
icon={GithubLogo}
rel="external"
href="https://github.com/mateusfg7/mfg-b"
/>
<OutLink
title="RSS"
icon={RssSimple}
rel="noreferrer"
href="/feed"
/>
<OutLink
title="Sitemap"
icon={TreeStructure}
rel="noreferrer"
href="/sitemap.xml"
/>
<ToggleTheme />
</div>
</div>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
)
}
3 changes: 3 additions & 0 deletions src/app/(blog)/components/header/mobile-menu/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.menu-item {
@apply flex items-center gap-7 px-7 py-5 leading-none active:bg-neutral-200 active:dark:bg-neutral-1000;
}
33 changes: 33 additions & 0 deletions src/app/(blog)/components/header/mobile-menu/toggle-theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useTheme } from 'next-themes'
import { Desktop, Moon, Sun } from '@/shared/lib/phosphor-icons'

export function ToggleTheme() {
const { setTheme, theme: currTheme } = useTheme()

return (
<div className="flex flex-1 items-end justify-center pt-5">
<div className="flex overflow-hidden rounded-xl bg-neutral-200/50 text-2xl dark:bg-neutral-1000/50">
<button
onClick={() => setTheme('light')}
className={`p-4 ${currTheme === 'light' && 'bg-neutral-300'}`}
>
<Sun weight={currTheme === 'light' ? 'duotone' : 'regular'} />
</button>
<button
onClick={() => setTheme('system')}
className={`p-4 ${
currTheme === 'system' && 'bg-neutral-300 dark:bg-neutral-800'
}`}
>
<Desktop weight={currTheme === 'system' ? 'duotone' : 'regular'} />
</button>
<button
onClick={() => setTheme('dark')}
className={`p-4 ${currTheme === 'dark' && 'bg-neutral-800'}`}
>
<Moon weight={currTheme === 'dark' ? 'duotone' : 'regular'} />
</button>
</div>
</div>
)
}

0 comments on commit 96a8af4

Please sign in to comment.