lineContainerComponent.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 && this.props.globalState.selectedLineContainerTitles.length === 0) {
  25. return;
  26. }
  27. if (this.props.globalState && this.props.globalState.selectedLineContainerTitles.indexOf(this.props.title) > -1) {
  28. setTimeout(() => {
  29. this.props.globalState!.selectedLineContainerTitles = [];
  30. });
  31. this.setState({ isExpanded: true, isHighlighted: true });
  32. window.setTimeout(() => {
  33. this.setState({ isHighlighted: false });
  34. }, 5000);
  35. } else {
  36. this.setState({isExpanded: false});
  37. }
  38. }
  39. renderHeader() {
  40. const className = this.state.isExpanded ? "collapse" : "collapse closed";
  41. return (
  42. <div className="header" onClick={() => this.switchExpandedState()}>
  43. <div className="title">
  44. {this.props.title}
  45. </div>
  46. <div className={className}>
  47. <FontAwesomeIcon icon={faChevronDown} />
  48. </div>
  49. </div>
  50. );
  51. }
  52. render() {
  53. if (!this.state.isExpanded) {
  54. return (
  55. <div className="paneContainer">
  56. <div className="paneContainer-content">
  57. {
  58. this.renderHeader()
  59. }
  60. </div>
  61. </div>
  62. );
  63. }
  64. return (
  65. <div className="paneContainer">
  66. <div className="paneContainer-content">
  67. {
  68. this.renderHeader()
  69. }
  70. <div className="paneList">
  71. {this.props.children}
  72. </div >
  73. </div>
  74. <div className={"paneContainer-highlight-border" + (!this.state.isHighlighted ? " transparent" : "")}>
  75. </div>
  76. </div>
  77. );
  78. }
  79. }