Skip to content

Commit

Permalink
fix(docz): link component
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 1, 2018
1 parent 05c4639 commit 7626982
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const Menu: SFC<MenuProps> = ({ menu, docs }) => (
<dl>
{docs.map(doc => (
<dt key={doc.id}>
<Link to={doc.slug}>{doc.name}</Link>
<Link to={doc.route}>{doc.name}</Link>
</dt>
))}
</dl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const Sidebar = () => (
</ThemeConfig>
<Menus>
{docsWithoutMenu.map(doc => (
<Link key={doc.id} to={doc.slug}>
<Link key={doc.id} to={doc.route}>
{doc.name}
</Link>
))}
Expand Down
18 changes: 2 additions & 16 deletions packages/docz/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,9 @@ import * as React from 'react'
import { SFC } from 'react'
import { NavLink, NavLinkProps } from 'react-router-dom'

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 isActive={isActive} {...props} to={entry.route} />
)
}}
</dataContext.Consumer>
export const Link: SFC<NavLinkProps> = props => (
<NavLink isActive={isActive} {...props} />
)

0 comments on commit 7626982

Please sign in to comment.