mirror of
https://github.com/wassname/talk.git
synced 2026-07-06 01:25:34 +08:00
36 lines
812 B
JavaScript
36 lines
812 B
JavaScript
import React from 'react';
|
|
import styles from './TabBar.css';
|
|
|
|
export class TabBar extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.handleClickTab = this.handleClickTab.bind(this);
|
|
}
|
|
|
|
handleClickTab(tabId) {
|
|
if (this.props.onChange) {
|
|
this.props.onChange(tabId);
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const {children, activeTab, cStyle = 'base'} = this.props;
|
|
return (
|
|
<div>
|
|
<ul className={`${styles.base} ${cStyle ? styles[cStyle] : ''}`}>
|
|
{React.Children.map(children, (child, tabId) =>
|
|
React.cloneElement(child, {
|
|
tabId,
|
|
active: tabId === activeTab,
|
|
onTabClick: this.handleClickTab,
|
|
cStyle
|
|
})
|
|
)}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default TabBar;
|