import React from 'react';
export default class TabPanel extends React.PureComponent
{
state = { selected: 0, tabs: this.props.tabs }
render()
{
let bar = [];
let body = [];
for (let i = 0; i < this.state.tabs.length; i++)
{
let t = this.state.tabs[i];
bar.push(
{t.noclose ? null :
}
{t.title}
);
body.push(
{t.children}
);
}
return
}
componentWillReceiveProps(nextProps, nextContent)
{
// FIXME: Do not own tabs?
this.setState({ selected: this.state.selected % nextProps.tabs.length, tabs: nextProps.tabs });
}
switchTab = (ev) =>
{
this.setState({ selected: ev.target.id.substr(5) });
}
closeTab = (ev) =>
{
let tab = ev.target.parentNode;
//this.setState({ closing: tab.id.substr(5) });
tab.style.width = '1px';
tab.style.padding = '0';
tab.style.opacity = '0';
setTimeout(() =>
{
let t = this.state.tabs;
t.splice(tab.id.substr(5), 1);
let s = this.state.selected;
if ('t-tab'+s == tab.id)
s = this.state.selected-1;
this.setState({ tabs: t, selected: s });
}, 200);
ev.stopPropagation();
}
}