Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(doc): added movil menu #279

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions apps/web/components/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use client'
import { Button } from '@openui-org/react'
import Link from 'next/link'
import { DocsSearch } from './docs-search'
import { Icons } from './icons'
import MovilSidebar from './movil-sidebar-nav'

const links = [
{ name: 'Documentation', path: '/docs/getting-started/introduction' },
Expand Down Expand Up @@ -42,24 +44,7 @@ export default function Menu() {
</Link>
</Button>
</div>
<Button variant="ghost" size="icon" className="relative lg:hidden ml-auto">
<span className=" absolute transform -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2">
<svg
xmlns="http://www.w3.org/2000/svg"
className="size-6"
fill="none"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M4 6h16M4 12h16M4 18h16"
/>
</svg>
</span>
</Button>

<MovilSidebar />
</div>
</div>
</div>
Expand Down
36 changes: 36 additions & 0 deletions apps/web/components/movil-sidebar-nav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useState } from 'react'
import { Button, ScrollArea, Sheet, SheetContent, SheetTrigger } from '@openui-org/react'
import { DocsSidebarNav } from './sidebar-nav'
import { docsConfig } from '@/constants/docs'

export default function MovilSidebar() {
const [open, setOpen] = useState(false)
return (
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
<Button variant="ghost" size="icon" className="relative lg:hidden ml-auto">
<span className=" absolute transform -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2">
<svg
xmlns="http://www.w3.org/2000/svg"
className="size-6"
fill="none"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M4 6h16M4 12h16M4 18h16"
/>
</svg>
</span>
</Button>
</SheetTrigger>
<SheetContent side="left">
<ScrollArea className="h-screen">
<DocsSidebarNav items={docsConfig.sidebarNav} setOpen={setOpen} />
</ScrollArea>
</SheetContent>
</Sheet>
)
}
15 changes: 12 additions & 3 deletions apps/web/components/sidebar-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { Button } from '@openui-org/react'
import type { Dispatch, SetStateAction } from 'react'
import { cn } from '@openui-org/theme'
import type { NavItem } from './main-nav'

Expand All @@ -23,9 +24,10 @@ export type SidebarNavItem = {

export interface DocsSidebarNavProps {
items: SidebarNavItem[]
setOpen?: Dispatch<SetStateAction<boolean>>
}

export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
export function DocsSidebarNav({ items, setOpen }: DocsSidebarNavProps) {
return items.length
? (
<div className="w-full pr-2">
Expand All @@ -35,7 +37,12 @@ export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
{item.title}
</h4>
{item.items
? (<DocsSidebarNavItems items={item.items} />)
? (
<DocsSidebarNavItems
items={item.items}
setOpen={setOpen}
/>
)
: null}
</div>
))}
Expand All @@ -46,9 +53,10 @@ export function DocsSidebarNav({ items }: DocsSidebarNavProps) {

interface DocsSidebarNavItemsProps {
items: SidebarNavItem[]
setOpen?: Dispatch<SetStateAction<boolean>>
}

export function DocsSidebarNavItems({ items }: DocsSidebarNavItemsProps) {
export function DocsSidebarNavItems({ items, setOpen }: DocsSidebarNavItemsProps) {
const path = usePathname()
return items?.length
? (
Expand All @@ -59,6 +67,7 @@ export function DocsSidebarNavItems({ items }: DocsSidebarNavItemsProps) {
href={item.href!}
className="!font-light"
target={item.external ? '_blank' : ''}
onClick={() => setOpen?.(false)}
>
{item.title}
</Link>
Expand Down
Loading