2021-08-14 19:10:48 +00:00
|
|
|
import { PureComponent } from 'react';
|
2021-02-27 23:51:13 +00:00
|
|
|
|
2021-02-27 13:46:41 +00:00
|
|
|
import Tab from './Tab';
|
2021-03-01 12:06:02 +00:00
|
|
|
import ErrorBoundary from '../../../ErrorBoundary';
|
2021-02-27 13:46:41 +00:00
|
|
|
|
2021-08-14 19:10:48 +00:00
|
|
|
export default class Tabs extends PureComponent {
|
2021-02-27 13:46:41 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2021-07-02 20:29:33 +00:00
|
|
|
currentTab: this.props.children[0].props.label,
|
|
|
|
currentName: this.props.children[0].props.name
|
2021-02-27 13:46:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-02 20:29:33 +00:00
|
|
|
onClick = (tab, name) => {
|
|
|
|
if (name !== this.state.currentName) {
|
2021-08-11 17:15:54 +00:00
|
|
|
window.stats.postEvent('tab', `Opened ${name}`);
|
2021-06-21 22:03:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 17:55:58 +00:00
|
|
|
this.setState({
|
2021-07-02 20:29:33 +00:00
|
|
|
currentTab: tab,
|
|
|
|
currentName: name
|
2021-03-17 17:55:58 +00:00
|
|
|
});
|
2021-02-27 13:46:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let className = 'sidebar';
|
|
|
|
let tabClass = 'tab-content';
|
2021-03-31 11:21:37 +00:00
|
|
|
let optionsText = (<h1>{window.language.modals.main.title}</h1>);
|
2021-02-27 13:46:41 +00:00
|
|
|
|
|
|
|
if (this.props.navbar) {
|
|
|
|
className = 'modalNavbar';
|
|
|
|
tabClass = '';
|
|
|
|
optionsText = '';
|
|
|
|
}
|
2021-06-30 14:25:34 +00:00
|
|
|
|
2021-02-27 13:46:41 +00:00
|
|
|
return (
|
2021-04-02 12:51:22 +00:00
|
|
|
<>
|
2021-02-27 13:46:41 +00:00
|
|
|
<ul className={className}>
|
2021-03-23 09:44:57 +00:00
|
|
|
{optionsText}
|
2021-04-12 13:56:23 +00:00
|
|
|
{this.props.children.map((tab, index) => (
|
|
|
|
<Tab
|
|
|
|
currentTab={this.state.currentTab}
|
2021-07-10 20:59:53 +00:00
|
|
|
key={index}
|
2021-04-12 13:56:23 +00:00
|
|
|
label={tab.props.label}
|
2021-07-02 20:29:33 +00:00
|
|
|
onClick={(nextTab) => this.onClick(nextTab, tab.props.name)}
|
2021-04-12 13:56:23 +00:00
|
|
|
navbar={this.props.navbar || false}
|
|
|
|
/>
|
|
|
|
))}
|
2021-02-27 13:46:41 +00:00
|
|
|
</ul>
|
|
|
|
<div className={tabClass}>
|
2021-03-01 12:06:02 +00:00
|
|
|
<ErrorBoundary>
|
2021-04-12 13:56:23 +00:00
|
|
|
{this.props.children.map((tab) => {
|
|
|
|
if (tab.props.label !== this.state.currentTab) {
|
2021-04-02 12:51:22 +00:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-04-12 13:56:23 +00:00
|
|
|
return tab.props.children;
|
2021-03-23 09:44:57 +00:00
|
|
|
})}
|
2021-03-01 12:06:02 +00:00
|
|
|
</ErrorBoundary>
|
2021-02-27 13:46:41 +00:00
|
|
|
</div>
|
2021-04-02 12:51:22 +00:00
|
|
|
</>
|
2021-02-27 13:46:41 +00:00
|
|
|
);
|
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|