-
Notifications
You must be signed in to change notification settings - Fork 559
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 #281 from primer/side_nav_active_style
Adding active style to side nav links
- Loading branch information
Showing
2 changed files
with
59 additions
and
18 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
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 |
---|---|---|
@@ -1,43 +1,72 @@ | ||
import React from 'react' | ||
import {withRouter} from 'next/router' | ||
import {default as NextLink} from 'next/link' | ||
import {Text, Box, Link, FlexContainer, Relative} from '../..' | ||
import * as docs from '../components/docs' | ||
|
||
const SideNav = () => ( | ||
const getLink = router => { | ||
return Object.values(docs).map(({displayName: name}) => { | ||
const isSelected = router.pathname === `/components/docs/${name}` | ||
return ( | ||
<Box mb={3} key={name}> | ||
<NextLink href={`/components/docs/${name}`}> | ||
<Link href={`/components/docs/${name}`} color={isSelected ? 'gray.9' : null} fontSize={1}> | ||
{name} | ||
</Link> | ||
</NextLink> | ||
</Box> | ||
) | ||
}) | ||
} | ||
|
||
const isComponentLink = componentName => { | ||
return Object.values(docs) | ||
.map(n => n.displayName) | ||
.includes(componentName) | ||
} | ||
|
||
const SideNav = ({router}) => ( | ||
<Relative> | ||
<Box width={256} height="100%" bg="gray.0" display="inline-block" borderRight={1} borderColor="gray.2"> | ||
<FlexContainer flexDirection="column" alignItems="start" p={5} borderBottom={1} borderColor="gray.2"> | ||
<NextLink href="/components/docs/system-props"> | ||
<Link color="gray.9" href="/components/docs/system-props" m={0} mb={4}> | ||
<Link | ||
color="gray.9" | ||
href="/components/docs/system-props" | ||
m={0} | ||
mb={4} | ||
fontWeight={router.pathname === '/components/docs/system-props' ? 'bold' : null} | ||
> | ||
System Props | ||
</Link> | ||
</NextLink> | ||
<NextLink href="/components/docs/primer-theme"> | ||
<Link color="gray.9" href="/components/docs/primer-theme" m={0}> | ||
<Link | ||
color="gray.9" | ||
href="/components/docs/primer-theme" | ||
m={0} | ||
fontWeight={router.pathname === '/components/docs/primer-theme' ? 'bold' : null} | ||
> | ||
Primer Theme | ||
</Link> | ||
</NextLink> | ||
</FlexContainer> | ||
<Box pt={5} pl={5}> | ||
<Text is="p" color="black" m={0} mb={3}> | ||
<NextLink href="/components/docs/Avatar"> | ||
<Link color="gray.9" href="/components/docs/Avatar"> | ||
<Link | ||
color="gray.9" | ||
href="/components/docs/Avatar" | ||
fontWeight={isComponentLink(router.pathname.replace('/components/docs/', '')) ? 'bold' : null} | ||
> | ||
Components | ||
</Link> | ||
</NextLink> | ||
</Text> | ||
{Object.values(docs).map(({displayName: name}) => ( | ||
<Box mb={3} key={name}> | ||
<NextLink href={`/components/docs/${name}`}> | ||
<Link href={`/components/docs/${name}`} className="f5"> | ||
{name} | ||
</Link> | ||
</NextLink> | ||
</Box> | ||
))} | ||
{getLink(router)} | ||
</Box> | ||
</Box> | ||
</Relative> | ||
) | ||
|
||
export default SideNav | ||
export default withRouter(SideNav) |