2018-11-09 06:17:41 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar';
|
|
|
|
import { FadeIn } from 'app/core/components/Animations/FadeIn';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
children: JSX.Element;
|
2018-11-09 08:49:55 -06:00
|
|
|
main: EditorToolBarView;
|
2018-11-09 06:17:41 -06:00
|
|
|
toolbarItems: EditorToolBarView[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EditorToolBarView {
|
|
|
|
title: string;
|
2018-11-09 08:49:55 -06:00
|
|
|
imgSrc?: string;
|
|
|
|
icon?: string;
|
2018-11-09 06:17:41 -06:00
|
|
|
render: () => JSX.Element;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
openView?: EditorToolBarView;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class EditorTabBody extends PureComponent<Props, State> {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
openView: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onToggleToolBarView = (item: EditorToolBarView) => {
|
|
|
|
this.setState({
|
|
|
|
openView: item === this.state.openView ? null : item,
|
|
|
|
});
|
2018-11-09 08:49:55 -06:00
|
|
|
};
|
2018-11-09 06:17:41 -06:00
|
|
|
|
|
|
|
onCloseOpenView = () => {
|
|
|
|
this.setState({ openView: null });
|
2018-11-09 08:49:55 -06:00
|
|
|
};
|
2018-11-09 06:17:41 -06:00
|
|
|
|
2018-11-09 08:49:55 -06:00
|
|
|
renderMainSelection(view: EditorToolBarView) {
|
2018-11-09 06:17:41 -06:00
|
|
|
return (
|
2018-11-10 10:27:25 -06:00
|
|
|
<div className="toolbar__main" onClick={() => this.onToggleToolBarView(view)} key={view.title}>
|
|
|
|
<img className="toolbar__main-image" src={view.imgSrc} />
|
|
|
|
<div className="toolbar__main-name">{view.title}</div>
|
2018-11-09 06:17:41 -06:00
|
|
|
<i className="fa fa-caret-down" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-09 08:49:55 -06:00
|
|
|
renderButton(view: EditorToolBarView) {
|
|
|
|
return (
|
|
|
|
<div className="nav-buttons" key={view.title}>
|
2018-11-09 13:33:33 -06:00
|
|
|
<button className="btn navbar-button" onClick={() => this.onToggleToolBarView(view)}>
|
|
|
|
{view.icon && <i className={view.icon} />} {view.title}
|
2018-11-09 08:49:55 -06:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-09 06:17:41 -06:00
|
|
|
renderOpenView(view: EditorToolBarView) {
|
|
|
|
return (
|
2018-11-10 10:27:25 -06:00
|
|
|
<div className="toolbar-subview">
|
|
|
|
<button className="toolbar-subview__close" onClick={this.onCloseOpenView}>
|
2018-11-09 13:33:33 -06:00
|
|
|
<i className="fa fa-chevron-up" />
|
2018-11-09 06:17:41 -06:00
|
|
|
</button>
|
|
|
|
{view.render()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-11-09 08:49:55 -06:00
|
|
|
const { children, toolbarItems, main } = this.props;
|
2018-11-09 06:17:41 -06:00
|
|
|
const { openView } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2018-11-10 10:27:25 -06:00
|
|
|
<div className="toolbar">
|
|
|
|
{this.renderMainSelection(main)}
|
|
|
|
<div className="gf-form--grow" />
|
|
|
|
{toolbarItems.map(item => this.renderButton(item))}
|
2018-11-09 08:49:55 -06:00
|
|
|
</div>
|
|
|
|
<div className="panel-editor__scroll">
|
2018-11-12 10:54:44 -06:00
|
|
|
<CustomScrollbar autoHide={false}>
|
2018-11-09 08:49:55 -06:00
|
|
|
<div className="panel-editor__content">
|
|
|
|
<FadeIn in={openView !== null} duration={200}>
|
|
|
|
{openView && this.renderOpenView(openView)}
|
|
|
|
</FadeIn>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</CustomScrollbar>
|
|
|
|
</div>
|
2018-11-09 06:17:41 -06:00
|
|
|
</>
|
2018-11-09 08:49:55 -06:00
|
|
|
);
|
2018-11-09 06:17:41 -06:00
|
|
|
}
|
|
|
|
}
|