hamburgerMenu.tsx 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import * as React from "react";
  2. import { GlobalState } from '../globalState';
  3. import { CommandButtonComponent } from './commandButtonComponent';
  4. import HambugerButton from "../imgs/hamburger.svg";
  5. require("../scss/hamburgerMenu.scss");
  6. interface IHamburgerMenuComponentProps {
  7. globalState: GlobalState;
  8. }
  9. export class HamburgerMenuComponent extends React.Component<IHamburgerMenuComponentProps, {isExpanded: boolean}> {
  10. public constructor(props: IHamburgerMenuComponentProps) {
  11. super(props);
  12. this.state = {isExpanded: false};
  13. }
  14. onPlay() {
  15. this.props.globalState.onRunRequiredObservable.notifyObservers();
  16. this.setState({isExpanded: false});
  17. }
  18. onNew() {
  19. this.props.globalState.onNewRequiredObservable.notifyObservers();
  20. this.setState({isExpanded: false});
  21. }
  22. onClear() {
  23. this.props.globalState.onClearRequiredObservable.notifyObservers();
  24. this.setState({isExpanded: false});
  25. }
  26. onSave() {
  27. this.props.globalState.onSaveRequiredObservable.notifyObservers();
  28. this.setState({isExpanded: false});
  29. }
  30. onDownload() {
  31. this.props.globalState.onDownloadRequiredObservable.notifyObservers();
  32. this.setState({isExpanded: false});
  33. }
  34. onInspector() {
  35. this.props.globalState.onInspectorRequiredObservable.notifyObservers(!this.props.globalState.inspectorIsOpened);
  36. this.setState({isExpanded: false});
  37. }
  38. onFormatCode() {
  39. this.props.globalState.onFormatCodeRequiredObservable.notifyObservers();
  40. this.setState({isExpanded: false});
  41. }
  42. onMetadata() {
  43. this.props.globalState.onDisplayMetadataObservable.notifyObservers(true);
  44. this.setState({isExpanded: false});
  45. }
  46. onExamples() {
  47. this.props.globalState.onExamplesDisplayChangedObservable.notifyObservers();
  48. this.setState({isExpanded: false});
  49. }
  50. switch() {
  51. this.setState({isExpanded: !this.state.isExpanded});
  52. }
  53. public render() {
  54. return (
  55. <>
  56. {
  57. this.state.isExpanded &&
  58. <div className="click-blocker" onClick={() => this.setState({isExpanded: false})}>
  59. </div>
  60. }
  61. <div className={"hamburger-button " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")} onClick={() => this.switch()}>
  62. <HambugerButton />
  63. </div>
  64. <div className={"hambuger-menu " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts") + (this.state.isExpanded ? " expanded" : "")}>
  65. <CommandButtonComponent globalState={this.props.globalState} tooltip="Run" icon="play" isActive={true} onClick={()=> this.onPlay()}/>
  66. <CommandButtonComponent globalState={this.props.globalState} tooltip="Save" icon="save" isActive={false} onClick={()=> this.onSave()}/>
  67. <CommandButtonComponent globalState={this.props.globalState} tooltip="Inspector" icon="inspector" isActive={false} onClick={()=> this.onInspector()}/>
  68. <CommandButtonComponent globalState={this.props.globalState} tooltip="Download" icon="download" isActive={false} onClick={()=> this.onDownload()}/>
  69. <CommandButtonComponent globalState={this.props.globalState} tooltip="Create new" icon="new" isActive={false} onClick={()=> this.onNew()}/>
  70. <CommandButtonComponent globalState={this.props.globalState} tooltip="Clear code" icon="clear" isActive={false} onClick={()=> this.onClear()}/>
  71. <CommandButtonComponent globalState={this.props.globalState} tooltip="Format code" icon="options" isActive={false} onClick={()=> this.onFormatCode()}/>
  72. <CommandButtonComponent globalState={this.props.globalState} tooltip="Metadata" icon="options" isActive={false} onClick={()=> this.onMetadata()}/>
  73. <CommandButtonComponent globalState={this.props.globalState} tooltip="Examples" icon="examples" onClick={()=> this.onExamples()} isActive={false}/>
  74. </div>
  75. </>
  76. );
  77. }
  78. }