Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding active style to side nav links #281

Merged
merged 10 commits into from
Sep 27, 2018
Merged
20 changes: 16 additions & 4 deletions pages/doc-components/Header.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import {withRouter} from 'next/router'
import Octicon, {MarkGithub} from '@githubprimer/octicons-react'
import NextLink from 'next/link'
import BoxShadow from './BoxShadow'
import {Text, FlexContainer, Link, Sticky} from '../..'

const Header = () => (
const Header = ({router}) => (
<Sticky zIndex={100}>
<BoxShadow py={3} bg="gray.9" color="white">
<FlexContainer className="p-responsive" alignItems="center" justifyContent="space-between">
Expand All @@ -18,12 +19,23 @@ const Header = () => (
</NextLink>
<div>
<NextLink href="/components">
<Link color="white" href="/components" px={4}>
<Link
color="white"
href="/components"
px={4}
fontWeight={router.pathname === '/components' ? 'bold' : null}
>
Docs
</Link>
</NextLink>
<NextLink href="/components/sandbox">
<Link color="white" href="/components/sandbox" mr={0} px={4}>
<Link
color="white"
href="/components/sandbox"
mr={0}
px={4}
fontWeight={router.pathname === '/components/sandbox' ? 'bold' : null}
>
Sandbox
</Link>
</NextLink>
Expand All @@ -33,4 +45,4 @@ const Header = () => (
</Sticky>
)

export default Header
export default withRouter(Header)
57 changes: 43 additions & 14 deletions pages/doc-components/SideNav.js
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)