import React, { Component } from ‘react‘
import PropTypes from ‘prop-types‘;
import ‘./style.css‘
export default class TabControll extends Component {
constructor(props){
super(props);
this.state = {
currentIndex:0
}
}
render() {
const {titles} = this.props;
const {currentIndex} = this.state;
return (
<div className="tab-controll">
{
titles.map((item,index) => {
return (
<div
className = {"tab-item " + (currentIndex === index ? ‘ active‘ : ‘‘)}
key={index}
onClick = {e => this.itemClick(index)} >
<span>{item}</span>
</div>
)
} )
}
</div>
)
}
itemClick(index){
this.setState({
currentIndex:index
})
const {itemClick} = this.props;
itemClick(index);
}
}
PropTypes.PropTypes = {
titles:PropTypes.array.isRequired
}