grafana/public/app/features/dashboard/dashgrid/EditorTabBody.tsx

98 lines
2.6 KiB
TypeScript
Raw Normal View History

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-15 00:33:59 -06:00
main?: EditorToolBarView;
toolbarItems: EditorToolBarView[];
}
export interface EditorToolBarView {
title: string;
2018-11-09 08:49:55 -06:00
imgSrc?: string;
icon?: string;
render: (closeFunction: any) => 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
};
onCloseOpenView = () => {
this.setState({ openView: null });
2018-11-09 08:49:55 -06:00
};
2018-11-09 08:49:55 -06:00
renderMainSelection(view: EditorToolBarView) {
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>
<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}>
<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>
);
}
renderOpenView(view: EditorToolBarView) {
return (
2018-11-10 10:27:25 -06:00
<div className="toolbar-subview">
<button className="toolbar-subview__close" onClick={this.onCloseOpenView}>
<i className="fa fa-chevron-up" />
</button>
{view.render(this.onCloseOpenView)}
</div>
);
}
render() {
2018-11-09 08:49:55 -06:00
const { children, toolbarItems, main } = this.props;
const { openView } = this.state;
return (
<>
2018-11-15 00:33:59 -06:00
{main && (
<div className="toolbar">
{this.renderMainSelection(main)}
<div className="gf-form--grow" />
{toolbarItems.map(item => this.renderButton(item))}
</div>
)}
2018-11-09 08:49:55 -06:00
<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 08:49:55 -06:00
);
}
}