Created
October 15, 2020 15:56
-
-
Save marxian/479ef80074f6adf04ab3150b3926486f to your computer and use it in GitHub Desktop.
This file contains 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, { useState } from "react"; | |
import PropTypes from "prop-types"; | |
import Tab from "./Tab"; | |
const Tabs = (props) => { | |
const [ activeTab, setActiveTab ] = useState(props.children[0].props.label); | |
return ( | |
<div className="tabs"> | |
<ol className="tab-list"> | |
{props.children.map((child) => ( | |
<Tab | |
activeTab={activeTab} | |
key={child.props.label} | |
label={child.props.label} | |
onClick={() => setActiveTab(child.props.label)} | |
/> | |
)} | |
</ol> | |
<div className="tab-content"> | |
{props.children.map((child) => ( | |
child.props.label !== activeTab ? child.props.children : null | |
))} | |
</div> | |
</div> | |
); | |
}; | |
Tabs.propTypes = { | |
children: PropTypes.instanceOf(Array).isRequired, | |
} | |
export default Tabs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment