Skip to content

Commit 9df7e6d

Browse files
committed
docs: www navbar
1 parent 892eb6f commit 9df7e6d

File tree

1 file changed

+60
-23
lines changed

1 file changed

+60
-23
lines changed
Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
'use client'
2+
3+
import { Portal, useDialog } from '@ark-ui/react'
14
import { SiGithub } from '@icons-pack/react-simple-icons'
5+
import { AlignRightIcon, XIcon } from 'lucide-react'
26
import NextLink from 'next/link'
37
import { css } from 'styled-system/css'
4-
import { Flex, HStack } from 'styled-system/jsx'
8+
import { Flex, HStack, Stack } from 'styled-system/jsx'
59
import { IconButton } from '~/components/ui/icon-button'
610
import { navLinks } from '~/lib/nav-links'
711
import { ColorModeButton } from '../color-mode-button'
812
import { Logo } from '../logo'
13+
import { Dialog } from '../ui/dialog'
14+
15+
const navlinkStyle = css({
16+
display: 'flex',
17+
alignItems: 'center',
18+
gap: '1.5',
19+
textStyle: 'sm',
20+
fontWeight: 'medium',
21+
color: 'fg.emphasized',
22+
whiteSpace: 'nowrap',
23+
_hover: {
24+
color: 'colorPalette.default',
25+
},
26+
'& svg': {
27+
width: '4',
28+
height: '4',
29+
color: 'colorPalette.default',
30+
},
31+
})
932

1033
export const Navbar = () => (
1134
<nav className={css({ position: 'sticky', top: '0', zIndex: 'docked' })}>
@@ -18,42 +41,24 @@ export const Navbar = () => (
1841
justify="space-between"
1942
h="12"
2043
px="3"
44+
w={{ base: 'calc(100% - 24px)', md: 'auto' }}
2145
mt={{ base: '6', md: '10' }}
2246
>
2347
<NextLink href="/" aria-label="Back home">
2448
<Logo />
2549
</NextLink>
2650

27-
<HStack gap="8">
51+
<HStack gap="8" hideBelow="sm">
2852
{navLinks.map((link) => (
29-
<NextLink
30-
key={link.href}
31-
href={link.href}
32-
className={css({
33-
display: 'flex',
34-
alignItems: 'center',
35-
gap: '1.5',
36-
textStyle: 'sm',
37-
fontWeight: 'medium',
38-
color: 'fg.emphasized',
39-
whiteSpace: 'nowrap',
40-
_hover: {
41-
color: 'colorPalette.default',
42-
},
43-
'& svg': {
44-
width: '4',
45-
height: '4',
46-
color: 'colorPalette.default',
47-
},
48-
})}
49-
>
53+
<NextLink key={link.href} href={link.href} className={navlinkStyle}>
5054
{link.label}
5155
{link.icon && <link.icon />}
5256
</NextLink>
5357
))}
5458
</HStack>
5559

5660
<HStack gap="1">
61+
<MobileNavbar />
5762
<IconButton asChild variant="ghost" hideBelow="sm">
5863
<a href="https://github.com/chakra-ui/ark" target="_blank" rel="noreferrer">
5964
<SiGithub />
@@ -65,3 +70,35 @@ export const Navbar = () => (
6570
</Flex>
6671
</nav>
6772
)
73+
74+
const MobileNavbar = () => {
75+
const dialog = useDialog()
76+
return (
77+
<Dialog.RootProvider value={dialog}>
78+
<Dialog.Trigger hideFrom="sm" asChild>
79+
<IconButton aria-label="Open Menu" variant="ghost">
80+
{dialog.open ? <XIcon /> : <AlignRightIcon />}
81+
</IconButton>
82+
</Dialog.Trigger>
83+
84+
<Portal>
85+
<Dialog.Backdrop />
86+
<Dialog.Positioner>
87+
<Dialog.Content minW="xs" p="8">
88+
<Stack gap="4" align="stretch">
89+
{navLinks.map((link) => (
90+
<NextLink key={link.href} href={link.href} className={navlinkStyle}>
91+
{link.label}
92+
{link.icon && <link.icon />}
93+
</NextLink>
94+
))}
95+
</Stack>
96+
<Dialog.CloseTrigger position="absolute" top="2" right="2" cursor="pointer">
97+
<XIcon />
98+
</Dialog.CloseTrigger>
99+
</Dialog.Content>
100+
</Dialog.Positioner>
101+
</Portal>
102+
</Dialog.RootProvider>
103+
)
104+
}

0 commit comments

Comments
 (0)