-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from bensmithett/table-of-contents
Extract table of contents from MDX and add basic TableOfContents component
- Loading branch information
Showing
7 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/components/tropical/TableOfContents/TableOfContents.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function TableOfContents({ tableOfContents }) { | ||
return tableOfContents.length && <List list={tableOfContents} /> | ||
} | ||
|
||
function List({ list }) { | ||
return ( | ||
<ul> | ||
{list.map(({ value, id, children }) => ( | ||
<li> | ||
<a href={`#${id}`}>{value}</a> | ||
{children && <List list={children} />} | ||
</li> | ||
))} | ||
</ul> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
src/components/tropical/TableOfContents/TableOfContents.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { TableOfContents } from './TableOfContents' | ||
import { tableOfContents } from './example.mdx' | ||
|
||
export default { title: 'tropical/TableOfContents' } | ||
|
||
export const Basic = () => <TableOfContents tableOfContents={tableOfContents} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Heading 1 | ||
|
||
# Heading 2 | ||
|
||
## Heading 2.1 | ||
|
||
## Heading 2.2 | ||
|
||
### Heading 2.2.1 | ||
|
||
# Heading 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TableOfContents' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters