jsketcher/modules/brep/debug/debugger/section.jsx
Val Erastov (xibyte) f053cab1ba move brep to a module
2020-07-19 22:59:42 -07:00

46 lines
1.2 KiB
JavaScript

import React from 'react';
import cx from 'classnames';
export default class Section extends React.PureComponent {
constructor() {
super();
this.state = {
closed: null
}
}
render() {
let {name, tabs, closable, defaultClosed, accent, children, captionStyles, controls} = this.props;
let closed = this.isClosed();
return <div className={cx('section', {closable, closed})} style={{paddingLeft: tabs + 'em'}}>
<div className={cx('caption', {accent}, captionStyles)} >
<span className='title' onClick={closable ? this.tweakClose : undefined}>
{closable && <i className={cx('fa fa-fw fa-caret-' + (closed ? 'right': 'down'), {'invisible': !children} )} />} {name}
</span>
<span className='control'>{controls}</span>
</div>
{!closed && children}
</div>;
}
isClosed() {
let {closable, defaultClosed} = this.props;
if (!closable) return false;
return closable && (this.state.closed === null ? defaultClosed : this.state.closed)
}
tweakClose = () => {
this.setState({closed: !this.isClosed()});
}
}
function mapIterator(it, fn) {
for (let i of it) {
fn(i);
}
}