Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a TabBar component to render a list of tabs
- Loading branch information
1 parent
a155664
commit 325a103
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import {Menu} from "semantic-ui-react"; | ||
|
||
const Tab = ({name, label, onClick, active}) => ( | ||
<Menu.Item | ||
name={name} | ||
content={label} | ||
active={active} | ||
onClick={() => onClick(name)} | ||
/> | ||
); | ||
|
||
export default Tab; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react"; | ||
import {Menu} from "semantic-ui-react"; | ||
|
||
import Tab from "./Tab"; | ||
|
||
const TabBar = (props) => { | ||
const {tabs, currentTab, onTabClick, ...otherProps} = props; | ||
|
||
const tabItems = tabs.map(tabInfo => { | ||
const {name, label} = tabInfo; | ||
|
||
return ( | ||
<Tab | ||
key={name} | ||
name={name} | ||
label={label} | ||
active={currentTab === name} | ||
onClick={onTabClick} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<div> | ||
<Menu tabular attached="top" {...otherProps}> | ||
{tabItems} | ||
</Menu> | ||
</div> | ||
) | ||
} | ||
|
||
export default TabBar; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React, {Component} from "react"; | ||
|
||
import TabBar from "./TabBar"; | ||
|
||
export default class TabBarContainer extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const {tabs = [{name : null}]} = props; | ||
|
||
const firstTab = tabs[0]; | ||
|
||
this.state = { | ||
currentTab : firstTab.name | ||
} ; | ||
} | ||
|
||
onTabClick = (name) => { | ||
this.setState({currentTab : name}); | ||
} | ||
|
||
render() { | ||
const {tabs, ...otherProps} = this.props; | ||
const {currentTab} = this.state; | ||
|
||
return ( | ||
<TabBar | ||
{...otherProps} | ||
currentTab={currentTab} | ||
onTabClick={this.onTabClick} | ||
tabs={tabs} | ||
/> | ||
) | ||
} | ||
} |