Skip to content

Commit

Permalink
feat: collapsible nav (#317)
Browse files Browse the repository at this point in the history
* wip

* radix collapsible

* initial open state

* tweaks
  • Loading branch information
abernier authored Aug 31, 2024
1 parent 87f08b7 commit 9a2d0b3
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 83 deletions.
200 changes: 199 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@codesandbox/sandpack-react": "^2.19.0",
"@radix-ui/react-collapsible": "^1.1.0",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/typography": "^0.5.14",
"clsx": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app/[...slug]/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function Menu({
>
<nav
id="nav"
className="sticky?lg:h-(screen-16) relative z-10 overflow-y-auto px-4 pb-10 text-base font-medium lg:pb-14 lg:text-sm"
className="sticky?lg:h-(screen-16) relative z-10 overflow-y-auto px-4 pb-10 pl-0 lg:pb-14 lg:text-sm"
>
{nav}
</nav>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[...slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'

import Nav from '@/components/Nav'
import { Nav } from '@/components/Nav'
import Search from '@/components/Search'
import { Toc } from '@/components/mdx/Toc'
import cn from '@/lib/cn'
Expand Down
8 changes: 4 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export default function RootLayout({
</head>
<body className={cn(inter.className, 'bg-surface break-words')}>
<ThemeProvider
// attribute="class"
// defaultTheme="system"
// enableSystem
// disableTransitionOnChange
// attribute="class"
// defaultTheme="system"
// enableSystem
disableTransitionOnChange
>
{children}
</ThemeProvider>
Expand Down
67 changes: 0 additions & 67 deletions src/components/Nav.tsx

This file was deleted.

33 changes: 33 additions & 0 deletions src/components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Doc } from '@/app/[...slug]/DocsContext'
import * as React from 'react'
import { NavCategory } from './NavCategory'

type NavList = Record<string, Record<string, Doc>>

export function Nav({ docs, asPath }: { docs: Doc[]; asPath: string }) {
const nav = React.useMemo(
() =>
docs.reduce((acc, doc) => {
const page = doc.slug.at(-1)
const category = doc.slug.at(-2) || 'root'

acc[category] ??= {}
if (page) acc[category][page] = doc

return acc
}, {} as NavList),
[docs],
)

return (
<ul className="mt-8">
{Object.entries(nav).map(([category, docs]) => {
return (
<li key={category}>
<NavCategory {...{ category, docs, asPath }} />
</li>
)
})}
</ul>
)
}
Loading

0 comments on commit 9a2d0b3

Please sign in to comment.