mue/src/components/modals/main/tabs/backend/Tabs.jsx

67 lines
1.6 KiB
React
Raw Normal View History

2021-08-14 19:10:48 +00:00
import { PureComponent } from 'react';
2021-02-27 23:51:13 +00:00
import Tab from './Tab';
2021-03-01 12:06:02 +00:00
import ErrorBoundary from '../../../ErrorBoundary';
2021-08-14 19:10:48 +00:00
export default class Tabs extends PureComponent {
constructor(props) {
super(props);
this.state = {
currentTab: this.props.children[0].props.label,
currentName: this.props.children[0].props.name
};
}
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
}
this.setState({
currentTab: tab,
currentName: name
});
};
render() {
let className = 'sidebar';
let tabClass = 'tab-content';
let optionsText = (<h1>{window.language.modals.main.title}</h1>);
if (this.props.navbar) {
className = 'modalNavbar';
tabClass = '';
optionsText = '';
}
return (
2021-04-02 12:51:22 +00:00
<>
<ul className={className}>
2021-03-23 09:44:57 +00:00
{optionsText}
{this.props.children.map((tab, index) => (
<Tab
currentTab={this.state.currentTab}
key={index}
label={tab.props.label}
onClick={(nextTab) => this.onClick(nextTab, tab.props.name)}
navbar={this.props.navbar || false}
/>
))}
</ul>
<div className={tabClass}>
2021-03-01 12:06:02 +00:00
<ErrorBoundary>
{this.props.children.map((tab) => {
if (tab.props.label !== this.state.currentTab) {
2021-04-02 12:51:22 +00:00
return undefined;
}
return tab.props.children;
2021-03-23 09:44:57 +00:00
})}
2021-03-01 12:06:02 +00:00
</ErrorBoundary>
</div>
2021-04-02 12:51:22 +00:00
</>
);
}
}