Skip to content

Commit

Permalink
UI: Improve inline TOC component
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Oct 15, 2023
1 parent 27ce871 commit 1cb6385
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-ducks-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'next-docs-ui': patch
---

Improve Inline TOC component
15 changes: 7 additions & 8 deletions packages/next-docs-ui/src/components/inline-toc.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { cn } from '@/utils/cn'
import * as Collapsible from '@radix-ui/react-collapsible'
import { ChevronDown } from 'lucide-react'
import type { TOCItemType } from 'next-docs-zeta/server'
import type { ReactNode } from 'react'

Expand All @@ -21,8 +21,9 @@ export function InlineTOC({
>
<Collapsible.Trigger asChild>
{children ?? (
<button className="nd-font-medium nd-p-4 nd-w-full nd-text-left">
<button className="nd-inline-flex nd-items-center nd-justify-between nd-font-medium nd-p-4 nd-w-full [&[data-state=open]>svg]:nd-rotate-180">
Table of Contents
<ChevronDown className="nd-h-4 nd-w-4 nd-transition-transform nd-duration-200" />
</button>
)}
</Collapsible.Trigger>
Expand All @@ -32,12 +33,10 @@ export function InlineTOC({
<a
key={item.url}
href={item.url}
className={cn(
'nd-py-1.5 nd-border-l hover:nd-border-primary',
item.depth <= 2 && 'nd-pl-4',
item.depth === 3 && 'nd-pl-7',
item.depth >= 4 && 'nd-pl-10'
)}
className="nd-py-1.5 nd-border-l hover:nd-border-primary"
style={{
paddingLeft: 16 * Math.max(item.depth - 1, 1)
}}
>
{item.title}
</a>
Expand Down

0 comments on commit 1cb6385

Please sign in to comment.