MCSM:Tabs: переключение вкладок
This commit is contained in:
@@ -33,15 +33,28 @@ var NvLineChart = React.createClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var Tabs = React.createClass({
|
var Tabs = React.createClass({
|
||||||
|
onTabClick: function(idx){
|
||||||
|
this.setState({ activeTab: idx });
|
||||||
|
},
|
||||||
|
/*--------------------*/
|
||||||
|
getInitialState: function(){return{
|
||||||
|
activeTab: 0
|
||||||
|
}},
|
||||||
render: function(){
|
render: function(){
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
var tabsElm = [];
|
var tabsElm = [];
|
||||||
this.props.tabs.forEach(function(title, i){
|
this.props.tabs.forEach(function(title, i){
|
||||||
tabsElm.push(ce('li', (i === 0 ? {className: 'active'} : null), ce('a', {href: '#'}, title)));
|
tabsElm.push(ce('li', (i === _this.state.activeTab ? {className: 'active'} : null),
|
||||||
|
ce('a', {href: '#tab'+(i+1), onClick: _this.onTabClick.bind(_this, i)}, title)));
|
||||||
});
|
});
|
||||||
|
|
||||||
return(
|
var showElement = this.props.children[this.state.activeTab];
|
||||||
ce('ul', {className: 'nav nav-tabs'}, tabsElm)
|
|
||||||
)
|
return(ce('div', null,
|
||||||
|
ce('ul', {className: 'nav nav-tabs', id: 'tabs'}, tabsElm),
|
||||||
|
showElement
|
||||||
|
))
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -57,13 +70,15 @@ var ServerInfo = React.createClass({
|
|||||||
return(
|
return(
|
||||||
ce('div', null,
|
ce('div', null,
|
||||||
ce('h2', {style: {'margin-top': '0px'}}, this.state.title),
|
ce('h2', {style: {'margin-top': '0px'}}, this.state.title),
|
||||||
ce(Tabs, {tabs: ['Онлайн1', 'Консоль2']}),
|
ce(Tabs, {tabs: ['Онлайн', 'Консоль']},
|
||||||
ce(NvLineChart, {datum: [{
|
ce(NvLineChart, {datum: [{
|
||||||
key: 'Online players',
|
key: 'Online players',
|
||||||
color: '#37d668',
|
color: '#37d668',
|
||||||
area: true,
|
area: true,
|
||||||
values: this.state.data
|
values: this.state.data
|
||||||
}]})
|
}]}),
|
||||||
|
ce('p', null, 'fake console element')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user