lineContainerComponent.tsx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import * as React from "react";
  2. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  3. import { faChevronDown } from '@fortawesome/free-solid-svg-icons';
  4. import { GlobalState } from '../../components/globalState';
  5. import { DataStorage } from 'babylonjs/Misc/dataStorage';
  6. interface ILineContainerComponentProps {
  7. globalState?: GlobalState;
  8. title: string;
  9. children: any[] | any;
  10. closed?: boolean;
  11. }
  12. export class LineContainerComponent extends React.Component<ILineContainerComponentProps, { isExpanded: boolean, isHighlighted: boolean }> {
  13. constructor(props: ILineContainerComponentProps) {
  14. super(props);
  15. const initialState = DataStorage.ReadBoolean(this.props.title, !this.props.closed);
  16. this.state = { isExpanded: initialState, isHighlighted: false };
  17. }
  18. switchExpandedState(): void {
  19. const newState = !this.state.isExpanded;
  20. DataStorage.WriteBoolean(this.props.title, newState);
  21. this.setState({ isExpanded: newState });
  22. }
  23. componentDidMount() {
  24. if (!this.props.globalState) {
  25. return;
  26. }
  27. if (this.props.globalState.selectedLineContainerTitles.length === 0 && this.props.globalState.selectedLineContainerTitlesNoFocus.length === 0) {
  28. return;
  29. }
  30. if (this.props.globalState.selectedLineContainerTitles.indexOf(this.props.title) > -1) {
  31. setTimeout(() => {
  32. this.props.globalState!.selectedLineContainerTitles = [];
  33. });
  34. this.setState({ isExpanded: true, isHighlighted: true });
  35. window.setTimeout(() => {
  36. this.setState({ isHighlighted: false });
  37. }, 5000);
  38. } else if (this.props.globalState.selectedLineContainerTitlesNoFocus.indexOf(this.props.title) > -1) {
  39. this.setState({ isExpanded: true, isHighlighted: false });
  40. } else {
  41. this.setState({isExpanded: false});
  42. }
  43. }
  44. renderHeader() {
  45. const className = this.state.isExpanded ? "collapse" : "collapse closed";
  46. return (
  47. <div className="header" onClick={() => this.switchExpandedState()}>
  48. <div className="title">
  49. {this.props.title}
  50. </div>
  51. <div className={className}>
  52. <FontAwesomeIcon icon={faChevronDown} />
  53. </div>
  54. </div>
  55. );
  56. }
  57. render() {
  58. if (!this.state.isExpanded) {
  59. return (
  60. <div className="paneContainer">
  61. <div className="paneContainer-content">
  62. {
  63. this.renderHeader()
  64. }
  65. </div>
  66. </div>
  67. );
  68. }
  69. return (
  70. <div className="paneContainer">
  71. <div className="paneContainer-content">
  72. {
  73. this.renderHeader()
  74. }
  75. <div className="paneList">
  76. {this.props.children}
  77. </div >
  78. </div>
  79. <div className={"paneContainer-highlight-border" + (!this.state.isHighlighted ? " transparent" : "")}>
  80. </div>
  81. </div>
  82. );
  83. }
  84. }