Created
March 27, 2017 21:19
-
-
Save qstrahl/ff5f1ea47370ccfd95211728769cbbfd 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, { Children, PropTypes } from 'react'; | |
import cssModules from 'react-css-modules'; | |
import styles from './style.css'; | |
import { omit } from 'lodash'; | |
import { find } from 'wu'; | |
const isLabel = node => node.tagName === 'label'; | |
const isContent = node => node.tagName === 'content'; | |
const getLabel = node => find(node.childNodes.values(), isLabel); | |
const getContent = node => find(node.childNodes.values(), isContent); | |
class Tabs extends React.Component { | |
static propTypes = { | |
onSelect: PropTypes.func, | |
children: PropTypes.oneOf( | |
PropTypes.node, | |
PropTypes.arrayOf(PropTypes.node), | |
), | |
}; | |
state = { selected: 0 }; | |
render() { | |
const { onSelect } = this.props; | |
const { getTabLabel, getTabPage } = this; | |
const { selected } = this.state; | |
const props = omit(this.props, ['styles']); | |
const children = Children.toArray(this.props.children); | |
return ( | |
<article styleName="wrapper" {...props}> | |
<header styleName="tab-labels"> | |
{children.map(getLabel)} | |
</header> | |
<section styleName="tab-page"> | |
{getContent(Children.toArray(children)[selected])} | |
</section> | |
</article> | |
); | |
} | |
} | |
export default cssModules(Tabs, styles); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment