Last active
December 26, 2020 08:22
-
-
Save kwoncharles/cf2ced1ece0e8745c37187238e2ddf39 to your computer and use it in GitHub Desktop.
composition tab3
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
// Tabs.js | |
import React from 'react' | |
function Tabs({ children }) { | |
const [selectedTab, setTab] = React.useState(initialTab) | |
return ( | |
<ul className="tab-container"> | |
{React.Children.map(children, child => ( | |
React.cloneElement(child, { | |
isSelected: child.props.value === selectedTab, | |
onSelect: () => setTab(child.props.value), | |
}) | |
))} | |
</ul> | |
) | |
} | |
Tabs.Item = ({ isSelected, onSelect, children }) => ( | |
<li | |
onClick={onSelect} | |
className={`tab-item ${isSelected ? 'selected' : ''}`} | |
> | |
{children} | |
</li> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment