-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableta.js
50 lines (48 loc) · 1.39 KB
/
tableta.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var React = require('react');
var Tably = require('./tably.js');
var TabletaNav = React.createClass({
getInitialState: function(){
var _this = this;
var count = 0;
var tabs = _this.props.children.map(function(item) {
return (
<li key={item.props.name} onClick={_this.handleClick.bind(_this, item)} id={item.props.name.replace(' ','')}>{item}</li>
);
});
for (var i = this.props.children.length - 1; i >= 0; i--) {
if(this.props.children[i].props.active == 'active'){
var activeEl = this.props.children[i];
}else{
var activeEl = this.props.children[0];
}
};
return({
content: activeEl.props.children,
activeClass: activeEl.props.name.replace(' ',''),
tabs: tabs
});
},
handleClick: function(item){
var _this = this;
$('#'+_this.state.activeClass).removeClass('active');
$('#'+item.props.name.replace(' ','')).addClass('active');
_this.setState({content: item.props.children, activeClass: item.props.name.replace(' ','')});
},
componentDidMount: function(){
var _this = this;
$('#' + _this.state.activeClass).addClass('active');
},
render: function(){
return(
<div className="tableta">
<ul className="tabletaNav">
{this.state.tabs}
</ul>
<div className={this.props.contName}>
{this.state.content}
</div>
</div>
);
}
});
module.exports = TabletaNav;