import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faWindowRestore, faTimes, faArrowLeft } from "@fortawesome/free-solid-svg-icons"; import { Observable, Observer, Nullable } from "babylonjs"; import * as React from "react"; export interface IHeaderComponentProps { title: string, handleBack?: boolean, noExpand?: boolean, noClose?: boolean, noCommands?: boolean, onPopup: () => void, onClose: () => void, onSelectionChangedObservable?: Observable } export class HeaderComponent extends React.Component { private _backStack = new Array(); private _onSelectionChangeObserver: Nullable>; constructor(props: IHeaderComponentProps) { super(props); this.state = { isBackVisible: false }; } componentWillMount() { if (!this.props.onSelectionChangedObservable) { return; } this._onSelectionChangeObserver = this.props.onSelectionChangedObservable.add((entity) => { if (this._backStack.length === 0 || entity !== this._backStack[this._backStack.length - 1]) { this._backStack.push(entity); this.setState({ isBackVisible: this._backStack.length > 1 }); } }); } componentWillUnmount() { if (this._onSelectionChangeObserver) { this.props.onSelectionChangedObservable!.remove(this._onSelectionChangeObserver); } } goBack() { this._backStack.pop(); // remove current var entity = this._backStack[this._backStack.length - 1]; if (this.props.onSelectionChangedObservable) { this.props.onSelectionChangedObservable.notifyObservers(entity); } this.setState({ isBackVisible: this._backStack.length > 1 }); } renderLogo() { if (this.props.noCommands) { return null; } if (this.props.handleBack) { if (!this.state.isBackVisible) { return null; } return (
this.goBack()} >
) } return ( ) } render() { return ( ) } }