Added components for web setup

This commit is contained in:
Ildar Kamalov
2019-01-18 20:17:48 +03:00
committed by Eugene Bujak
parent 71259c5f19
commit 5349ec76fd
31 changed files with 1144 additions and 15 deletions

View File

@@ -0,0 +1,59 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Tab from './Tab';
import './Tabs.css';
class Tabs extends Component {
state = {
activeTab: this.props.children[0].props.label,
};
onClickTabControl = (tab) => {
this.setState({ activeTab: tab });
}
render() {
const {
props: {
children,
},
state: {
activeTab,
},
} = this;
return (
<div className="tabs">
<div className="tabs__controls">
{children.map((child) => {
const { label } = child.props;
return (
<Tab
activeTab={activeTab}
key={label}
label={label}
onClick={this.onClickTabControl}
/>
);
})}
</div>
<div className="tabs__content">
{children.map((child) => {
if (child.props.label !== activeTab) {
return false;
}
return child.props.children;
})}
</div>
</div>
);
}
}
Tabs.propTypes = {
children: PropTypes.array.isRequired,
};
export default Tabs;