Files
shadcn-ui/apps/v4/components/mobile-nav.tsx
shadcn 1aa35048a5 feat: v4 updates (#7499)
* feat(v4): update home page

* fix

* fix: cards

* feat(v4): charts page

* feat: update pages

* feat: colors

* fix

* feat: add docs

* feat: mdx work

* fix

* fix

* fix: sidebar

* fix: lint

* feat: updates

* feat: update components

* feat: fix docs

* fix: responsive

* feat: implement cmdk

* fix: update navigation menu demo

* fix: code style

* fix: themes

* feat: implement blocks page

* fix: docs config

* refactor

* fix: outputFileTracingIncludes

* fix

* fix: output

* fix

* fix: registry

* refactor: move docs

* debug: docs

* debug

* revert

* fix: mjs

* deps: pin fumadocs

* debug

* fix: downgrade next

* fix: index page

* refactor: move mdx components

* fix: remove copy button

* fix

* was it zod

* yes it was

* remove copy page

* fix: color page

* fix: colors page

* fix: meta colors

* fix: copy button

* feat: sync registry

* fix: registry build script

* feat: update port

* feat: clean up examples

* fix

* fix: mobile nav

* fix: blur for mobile

* fix: sidebar nav

* feat: update examples

* fix: build scripts

* feat: update components

* feat: restyle

* fix: types

* fix: styles

* fix: margins

* fix: screenshots

* fix

* feat: update theme

* fix: charts nav

* fix: image

* feat: optimize images

* fix: menu

* fix: card

* fix: border

* check

* feat: implement charts page

* fix: charts

* fix: og images

* feat: extend touch

* fix: static

* fix: sizing

* fix: mobile screenshots

* fix: page nav

* fix

* feat: update favicon

* fix: theme selector

* fix: feedback

* fix: sink

* docs: update

* fix: styles

* chore: update registry

* fix: command

* fix

* fix: minor updates

* fix: typography on smaller devices

* fix: format

* fix: remove unused icon

* feat: update favicon

* fix: typography

* docs: typography page

* fix: steps
2025-05-30 11:35:16 +04:00

142 lines
4.3 KiB
TypeScript

"use client"
import * as React from "react"
import Link, { LinkProps } from "next/link"
import { useRouter } from "next/navigation"
import { source } from "@/lib/source"
import { cn } from "@/lib/utils"
import { Button } from "@/registry/new-york-v4/ui/button"
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/registry/new-york-v4/ui/popover"
export function MobileNav({
tree,
items,
className,
}: {
tree: typeof source.pageTree
items: { href: string; label: string }[]
className?: string
}) {
const [open, setOpen] = React.useState(false)
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="ghost"
className={cn(
"extend-touch-target h-8 touch-manipulation items-center justify-start gap-2.5 !p-0 hover:bg-transparent focus-visible:bg-transparent focus-visible:ring-0 active:bg-transparent dark:hover:bg-transparent",
className
)}
>
<div className="relative flex h-8 w-4 items-center justify-center">
<div className="relative size-4">
<span
className={cn(
"bg-foreground absolute left-0 block h-0.5 w-4 transition-all duration-100",
open ? "top-[0.4rem] -rotate-45" : "top-1"
)}
/>
<span
className={cn(
"bg-foreground absolute left-0 block h-0.5 w-4 transition-all duration-100",
open ? "top-[0.4rem] rotate-45" : "top-2.5"
)}
/>
</div>
<span className="sr-only">Toggle Menu</span>
</div>
<span className="flex h-8 items-center text-lg leading-none font-medium">
Menu
</span>
</Button>
</PopoverTrigger>
<PopoverContent
className="bg-background/90 no-scrollbar h-(--radix-popper-available-height) w-(--radix-popper-available-width) overflow-y-auto rounded-none border-none p-0 shadow-none backdrop-blur duration-100"
align="start"
side="bottom"
alignOffset={-16}
sideOffset={14}
>
<div className="flex flex-col gap-12 overflow-auto px-6 py-6">
<div className="flex flex-col gap-4">
<div className="text-muted-foreground text-sm font-medium">
Menu
</div>
<div className="flex flex-col gap-3">
<MobileLink href="/" onOpenChange={setOpen}>
Home
</MobileLink>
{items.map((item, index) => (
<MobileLink key={index} href={item.href} onOpenChange={setOpen}>
{item.label}
</MobileLink>
))}
</div>
</div>
<div className="flex flex-col gap-8">
{tree?.children?.map((group, index) => {
if (group.type === "folder") {
return (
<div key={index} className="flex flex-col gap-4">
<div className="text-muted-foreground text-sm font-medium">
{group.name}
</div>
<div className="flex flex-col gap-3">
{group.children.map((item) => {
if (item.type === "page") {
return (
<MobileLink
key={`${item.url}-${index}`}
href={item.url}
onOpenChange={setOpen}
>
{item.name}
</MobileLink>
)
}
})}
</div>
</div>
)
}
})}
</div>
</div>
</PopoverContent>
</Popover>
)
}
function MobileLink({
href,
onOpenChange,
className,
children,
...props
}: LinkProps & {
onOpenChange?: (open: boolean) => void
children: React.ReactNode
className?: string
}) {
const router = useRouter()
return (
<Link
href={href}
onClick={() => {
router.push(href.toString())
onOpenChange?.(false)
}}
className={cn("text-2xl font-medium", className)}
{...props}
>
{children}
</Link>
)
}