Last active
July 26, 2017 18:32
-
-
Save dadamssg/921ef01a12b964945f0e9c3c1afbdadd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react' | |
import { Route, Link } from 'react-router-dom' | |
const TabLink = ({ to, exact, title }) => ( | |
<Route path={to} exact={exact} children={({ match }) => ( | |
<li className={`nav-item ${match ? 'active' : ''}`}> | |
<Link to={to} className='nav-link' role='tab'>{title}</Link> | |
</li> | |
)} /> | |
) | |
const TabPanel = ({ to, exact, content }) => ( | |
<Route path={to} exact={exact} children={({ match }) => ( | |
<div className={`tab-pane ${match ? 'active' : ''}`} role='tabpanel'> | |
{match ? content : null} | |
</div> | |
)} /> | |
) | |
export function Tabs ({ children }) { | |
return ( | |
<span> | |
<ul className='nav nav-tabs' role='tablist'> | |
{React.Children.map(children, tab => ( | |
<TabLink | |
key={`nav-item-${tab.props.to}`} | |
to={tab.props.to} | |
exact={tab.props.exact} | |
title={tab.props.title} | |
/> | |
))} | |
</ul> | |
<div className='tab-content'> | |
{React.Children.map(children, tab => ( | |
<TabPanel | |
key={`tab-panel-${tab.props.to}`} | |
to={tab.props.to} | |
exact={tab.props.exact} | |
content={tab.props.children} | |
/> | |
))} | |
</div> | |
</span> | |
) | |
} | |
export const Tab = () => {} |
This file contains hidden or 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
import {Tabs, Tab} from './Tabs' | |
function PageWithTabs ({ match }) { | |
return ( | |
<Tabs> | |
<Tab title='Foo' exact to={`${match.url}`}> | |
FOO | |
</Tab> | |
<Tab title='Bar' to={`${match.url}/bar`}> | |
<Foobar /> | |
</Tab> | |
<Tab title='Baz' to={`${match.url}/baz`}> | |
BAZ | |
</Tab> | |
</Tabs> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment