-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): Add dynamic navigation (based on mdx content) (#1149)
- Loading branch information
Showing
23 changed files
with
327 additions
and
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"docs": patch | ||
--- | ||
|
||
feat(docs): Add dynamic navigation (based on mdx content) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { Link as GatsbyLink, GatsbyLinkProps } from 'gatsby'; | ||
import { Link as MarigoldLink } from '@marigold/components'; | ||
|
||
export const Link: React.FC<GatsbyLinkProps<unknown>> = ({ | ||
children, | ||
...props | ||
}) => ( | ||
<MarigoldLink {...props} as={GatsbyLink}> | ||
{children} | ||
</MarigoldLink> | ||
); |
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 React from 'react'; | ||
import { StaticImage } from 'gatsby-plugin-image'; | ||
|
||
export const Logo: React.FC = () => ( | ||
<StaticImage src="./logo.png" alt="Marigold Logo" /> | ||
); |
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 './Logo'; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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,63 @@ | ||
import React from 'react'; | ||
import { Box } from '@marigold/components'; | ||
|
||
import { Link } from '../Link'; | ||
import { NavigationItem, NavigationTree, useNavigation } from './useNavigation'; | ||
|
||
type NavigationSectionProps = { | ||
name: string; | ||
children: NavigationTree; | ||
}; | ||
|
||
// Helper | ||
// --------------- | ||
const dirToText = (dir: string) => | ||
dir | ||
.split('/')[0] | ||
.split('-') | ||
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
|
||
// Components | ||
// --------------- | ||
const NavigationItemComponent = ({ title, slug }: NavigationItem) => ( | ||
<Box variant="navigation.item"> | ||
<Link to={slug.startsWith('/') ? slug : `/${slug}`}>{title}</Link> | ||
</Box> | ||
); | ||
|
||
const NavigationSection = ({ name, children }: NavigationSectionProps) => { | ||
return ( | ||
<div> | ||
{Boolean(name.length) && ( | ||
<Box as="h2" variant="navigation.header"> | ||
{dirToText(name)} | ||
</Box> | ||
)} | ||
<Box as="ul" variant="navigation.list"> | ||
{children.map(child => | ||
'title' in child ? ( | ||
<NavigationItemComponent key={child.slug} {...child} /> | ||
) : ( | ||
<NavigationSection key={child.name} {...child} /> | ||
) | ||
)} | ||
</Box> | ||
</div> | ||
); | ||
}; | ||
|
||
export const Navigation: React.FC = () => { | ||
const tree = useNavigation(); | ||
console.log(tree); | ||
|
||
return ( | ||
<Box | ||
as="nav" | ||
variant="navigation.wrapper" | ||
aria-labelledby="primary-navigation" | ||
> | ||
<NavigationSection name="" children={tree} /> | ||
</Box> | ||
); | ||
}; |
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 './Navigation'; |
Oops, something went wrong.
8894212
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: