Skip to content

Commit

Permalink
add collapse option
Browse files Browse the repository at this point in the history
  • Loading branch information
timlrx committed Nov 20, 2023
1 parent 2ad37da commit 06973b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/healthy-clocks-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pliny': patch
---

Add option to collapse TOCInline
8 changes: 7 additions & 1 deletion packages/pliny/src/ui/TOCInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ export interface TOCInlineProps {
toHeading?: number
asDisclosure?: boolean
exclude?: string | string[]
collapse?: boolean
}

/**
* Generates an inline table of contents
* Exclude titles matching this string (new RegExp('^(' + string + ')$', 'i')).
* If an array is passed the array gets joined with a pipe (new RegExp('^(' + array.join('|') + ')$', 'i')).
*
* `asDisclosure` will wrap the TOC in a `details` element with a `summary` element.
* `collapse` will collapse the TOC when `AsDisclosure` is true.
*
* @param {TOCInlineProps} {
* toc,
* indentDepth = 3,
* fromHeading = 1,
* toHeading = 6,
* asDisclosure = false,
* exclude = '',
* collapse = false,
* }
*
*/
Expand All @@ -31,6 +36,7 @@ const TOCInline = ({
toHeading = 6,
asDisclosure = false,
exclude = '',
collapse = false,
}: TOCInlineProps) => {
const re = Array.isArray(exclude)
? new RegExp('^(' + exclude.join('|') + ')$', 'i')
Expand All @@ -54,7 +60,7 @@ const TOCInline = ({
return (
<>
{asDisclosure ? (
<details open>
<details open={!collapse}>
<summary className="ml-6 pt-2 pb-2 text-xl font-bold">Table of Contents</summary>
<div className="ml-6">{tocList}</div>
</details>
Expand Down

0 comments on commit 06973b1

Please sign in to comment.