2014-11-01 14:52:37 +01:00
|
|
|
var React = require('react');
|
|
|
|
|
|
|
|
var TabView = React.createClass({
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {tabPanes: []};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
2014-11-01 15:35:26 +01:00
|
|
|
var activeTab = this.props.tabPanes[0];
|
2014-11-01 14:52:37 +01:00
|
|
|
|
2014-11-01 15:19:10 +01:00
|
|
|
var userHash = window.location.hash;
|
|
|
|
if(userHash) {
|
|
|
|
userHash = userHash.split("#")[1];
|
|
|
|
this.props.tabPanes.forEach(function(pane) {
|
2014-11-01 15:35:26 +01:00
|
|
|
if(pane.name === userHash) {
|
|
|
|
activeTab = pane;
|
|
|
|
}
|
2014-11-01 15:19:10 +01:00
|
|
|
}.bind(this));
|
|
|
|
}
|
2014-11-01 15:35:26 +01:00
|
|
|
|
|
|
|
return {activeTab: activeTab};
|
2014-11-01 15:19:10 +01:00
|
|
|
},
|
|
|
|
|
2014-11-03 21:37:40 +01:00
|
|
|
onChangeTab: function(tabPane) {
|
2014-11-01 14:52:37 +01:00
|
|
|
this.setState({activeTab: tabPane});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var tabNodes = this.props.tabPanes.map(function (tabPane) {
|
|
|
|
return (
|
|
|
|
<li key={tabPane.name} className={tabPane.name===this.state.activeTab.name ? "active": ""}>
|
|
|
|
<a href={"#" + tabPane.name}
|
2014-11-03 21:37:40 +01:00
|
|
|
onClick={this.onChangeTab.bind(this, tabPane)}>{tabPane.name}
|
2014-11-01 14:52:37 +01:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<ul className="tabs mbn">
|
|
|
|
{tabNodes}
|
|
|
|
</ul>
|
|
|
|
<div className="tab-content">
|
|
|
|
<div className="active">
|
|
|
|
<div className="mod shadow mrn prn">
|
|
|
|
<div className="inner">
|
|
|
|
<div className="bd">
|
|
|
|
{this.state.activeTab.content}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = TabView;
|