Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(docz): add isActive to Link components
  • Loading branch information
pedronauck committed May 29, 2018
1 parent bdeffc1 commit 9cecc08
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Expand Up @@ -27,9 +27,6 @@ const Icon = styled<IconProps, 'div'>('div')`
}
`

export const isActive = (match: any, location: any) =>
match && match.url === location.pathname

export interface MenuProps {
menu: string
docs: Entry[]
Expand All @@ -55,9 +52,7 @@ export const Menu: SFC<MenuProps> = ({ menu, docs }) => (
<dl>
{docs.map(doc => (
<dt key={doc.id}>
<Link isActive={isActive} to={doc.slug}>
{doc.name}
</Link>
<Link to={doc.slug}>{doc.name}</Link>
</dt>
))}
</dl>
Expand Down
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Docs, Link, Entry, ThemeConfig } from 'docz'
import styled from 'react-emotion'

import { Menu, isActive } from './Menu'
import { Menu } from './Menu'
import logo from '../../../images/docz.svg'

const Wrapper = styled('div')`
Expand Down Expand Up @@ -101,7 +101,7 @@ export const Sidebar = () => (
</ThemeConfig>
<Menus>
{docsWithoutMenu.map(doc => (
<Link key={doc.id} to={doc.slug} isActive={isActive}>
<Link key={doc.id} to={doc.slug}>
{doc.name}
</Link>
))}
Expand Down
8 changes: 7 additions & 1 deletion packages/docz/src/components/Link.tsx
Expand Up @@ -6,13 +6,19 @@ import { dataContext, Entry } from '../theme'

const findEntryBySlug = (to: any) => (entry: Entry) => entry.slug === to

export const isActive = (match: any, location: any) =>
match && match.url === location.pathname

export const Link: SFC<NavLinkProps> = ({ to, ...props }) => (
<dataContext.Consumer>
{({ entries }) => {
const entriesArr = Object.values(entries || {})
const entry = entriesArr.find(findEntryBySlug(to))

return entry && entries && <NavLink {...props} to={entry.route} />
return (
entry &&
entries && <NavLink isActive={isActive} {...props} to={entry.route} />
)
}}
</dataContext.Consumer>
)

0 comments on commit 9cecc08

Please sign in to comment.