2019-11-11 12:28:13 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import styled from "styled-components";
|
2019-08-07 11:43:24 +00:00
|
|
|
import { Text } from "../text";
|
2019-11-12 06:52:27 +00:00
|
|
|
import Scrollbar from "../scrollbar";
|
2019-08-05 13:09:12 +00:00
|
|
|
|
|
|
|
const NavItem = styled.div`
|
2019-08-06 09:04:01 +00:00
|
|
|
position: relative;
|
|
|
|
white-space: nowrap;
|
2019-11-11 12:28:13 +00:00
|
|
|
display: flex;
|
2019-08-06 09:04:01 +00:00
|
|
|
`;
|
|
|
|
|
2019-11-11 12:28:13 +00:00
|
|
|
const Label = styled.div`
|
2019-08-06 09:04:01 +00:00
|
|
|
height: 32px;
|
|
|
|
border-radius: 16px;
|
2019-11-12 06:52:27 +00:00
|
|
|
min-width: fit-content;
|
2019-11-11 12:28:13 +00:00
|
|
|
margin-right: 8px;
|
|
|
|
width: fit-content;
|
|
|
|
|
|
|
|
.title_style {
|
|
|
|
text-align: center;
|
|
|
|
margin: 7px 15px 7px 15px;
|
2019-11-12 06:52:27 +00:00
|
|
|
overflow: hidden;
|
2019-11-11 12:28:13 +00:00
|
|
|
}
|
2019-08-05 13:09:12 +00:00
|
|
|
|
2019-11-11 12:28:13 +00:00
|
|
|
${props => (props.isDisabled ? `pointer-events: none;` : ``)}
|
2019-08-06 09:04:01 +00:00
|
|
|
|
2019-11-11 12:28:13 +00:00
|
|
|
${props =>
|
|
|
|
props.selected
|
|
|
|
? `cursor: default
|
|
|
|
background-color: #265A8F
|
|
|
|
.title_style {
|
|
|
|
color: #fff
|
|
|
|
}`
|
|
|
|
: `
|
2019-08-05 13:09:12 +00:00
|
|
|
&:hover{
|
|
|
|
cursor: pointer;
|
2019-08-05 16:05:03 +00:00
|
|
|
background-color: #F8F9F9;
|
2019-11-11 12:28:13 +00:00
|
|
|
}`}
|
2019-08-06 09:04:01 +00:00
|
|
|
|
2019-11-11 12:28:13 +00:00
|
|
|
${props =>
|
|
|
|
props.isDisabled && props.selected
|
|
|
|
? `background-color: #A3A9AE
|
|
|
|
.title_style {color: #fff}`
|
|
|
|
: ``}
|
2019-08-05 13:09:12 +00:00
|
|
|
`;
|
|
|
|
|
2019-08-05 16:05:03 +00:00
|
|
|
const BodyContainer = styled.div`
|
|
|
|
margin: 24px 16px 0px 16px;
|
|
|
|
`;
|
2019-08-05 13:09:12 +00:00
|
|
|
|
2019-08-06 09:04:01 +00:00
|
|
|
class TabContainer extends Component {
|
2019-08-05 13:09:12 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-08-07 08:14:12 +00:00
|
|
|
|
2019-08-05 13:09:12 +00:00
|
|
|
this.state = {
|
2019-08-07 11:43:24 +00:00
|
|
|
activeTab: this.props.selectedItem
|
2019-08-05 13:09:12 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-07 11:43:24 +00:00
|
|
|
titleClick = (index, item) => {
|
2019-08-07 08:14:12 +00:00
|
|
|
if (this.state.activeTab !== index) {
|
|
|
|
this.setState({ activeTab: index });
|
2019-08-07 11:43:24 +00:00
|
|
|
let newItem = Object.assign({}, item);
|
|
|
|
delete newItem.content;
|
|
|
|
this.props.onSelect && this.props.onSelect(newItem);
|
2019-08-05 13:09:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-15 07:15:21 +00:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const { activeTab } = this.state;
|
|
|
|
if (activeTab !== nextState.activeTab) {
|
|
|
|
return true;
|
|
|
|
} else return false;
|
|
|
|
}
|
|
|
|
|
2019-08-06 15:46:16 +00:00
|
|
|
render() {
|
2019-11-15 07:15:21 +00:00
|
|
|
//console.log("Tabs container render");
|
2019-11-11 12:28:13 +00:00
|
|
|
|
|
|
|
const { isDisabled, children } = this.props;
|
2019-08-05 13:09:12 +00:00
|
|
|
return (
|
2019-11-11 12:28:13 +00:00
|
|
|
<>
|
2019-11-12 06:52:27 +00:00
|
|
|
<Scrollbar style={{ width: "100%", height: 50 }}>
|
|
|
|
<NavItem className="className_items">
|
|
|
|
{children.map((item, index) => (
|
|
|
|
<Label
|
|
|
|
onClick={this.titleClick.bind(this, index, item)}
|
|
|
|
key={item.key}
|
|
|
|
selected={this.state.activeTab === index}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
>
|
|
|
|
<Text.Body className="title_style" fontSize={13}>
|
|
|
|
{item.title}
|
|
|
|
</Text.Body>
|
|
|
|
</Label>
|
|
|
|
))}
|
|
|
|
</NavItem>
|
|
|
|
</Scrollbar>
|
2019-11-11 12:28:13 +00:00
|
|
|
<BodyContainer>{children[this.state.activeTab].content}</BodyContainer>
|
|
|
|
</>
|
2019-08-05 13:09:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 09:04:01 +00:00
|
|
|
TabContainer.propTypes = {
|
2019-11-11 12:28:13 +00:00
|
|
|
children: PropTypes.PropTypes.arrayOf(PropTypes.object.isRequired).isRequired,
|
2019-08-06 15:46:16 +00:00
|
|
|
isDisabled: PropTypes.bool,
|
2019-08-07 11:43:24 +00:00
|
|
|
onSelect: PropTypes.func,
|
|
|
|
selectedItem: PropTypes.number
|
2019-08-05 13:09:12 +00:00
|
|
|
};
|
2019-08-05 16:05:03 +00:00
|
|
|
|
2019-08-07 11:43:24 +00:00
|
|
|
TabContainer.defaultProps = {
|
|
|
|
selectedItem: 0
|
2019-11-11 12:28:13 +00:00
|
|
|
};
|
2019-08-07 11:43:24 +00:00
|
|
|
|
2019-11-11 12:28:13 +00:00
|
|
|
export default TabContainer;
|