Panel
suggest changeimport React from 'react';
class Panel extends React.Component {
constructor(props) {
super(props);
}
render() {
var props = Object.assign({
className: this.props.active ? 'active' : '',
tabIndex: -1
}, this.props);
var elements = React.Children.toArray(this.props.children);
delete props.children;
// css() is static so subclasses can override it
var css = this.constructor.css();
if (css !== '') {
elements.unshift(React.createElement(
'style', null,
css
));
}
return React.createElement(
'div', props,
...elements
);
}
static title() {
return '';
}
static css() {
return '';
}
}
Major differences from simple pane are:
- a panel can take focus when a script activates it or the user clicks it;
- panel has
titlestatic method per component, so it may be extended by other panel component with overriddentitle(reason here is that function can be then called again on rendering for localization purposes, but in bounds of this exampletitledoesn’t make sense); - it can contain individual stylesheet declared in
cssstatic method (you can pre-load file contents fromPANEL.css).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents