lineContainerComponent.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import * as React from "react";
  2. import { DataStorage } from 'babylonjs/Misc/dataStorage';
  3. const downArrow = require("./downArrow.svg");
  4. interface ILineContainerComponentProps {
  5. title: string;
  6. children: any[] | any;
  7. closed?: boolean;
  8. }
  9. export class LineContainerComponent extends React.Component<ILineContainerComponentProps, { isExpanded: boolean }> {
  10. constructor(props: ILineContainerComponentProps) {
  11. super(props);
  12. let initialState = DataStorage.ReadBoolean(this.props.title, !this.props.closed);
  13. this.state = { isExpanded: initialState };
  14. }
  15. switchExpandedState(): void {
  16. const newState = !this.state.isExpanded;
  17. DataStorage.WriteBoolean(this.props.title, newState);
  18. this.setState({ isExpanded: newState });
  19. }
  20. renderHeader() {
  21. const className = this.state.isExpanded ? "collapse" : "collapse closed";
  22. return (
  23. <div className="header" onClick={() => this.switchExpandedState()}>
  24. <div className="title">
  25. {this.props.title}
  26. </div>
  27. <div className={className}>
  28. <img className="img" title={this.props.title} src={downArrow}/>
  29. </div>
  30. </div>
  31. );
  32. }
  33. render() {
  34. if (!this.state.isExpanded) {
  35. return (
  36. <div className="paneContainer">
  37. <div className="paneContainer-content">
  38. {
  39. this.renderHeader()
  40. }
  41. </div>
  42. </div>
  43. );
  44. }
  45. return (
  46. <div className="paneContainer">
  47. <div className="paneContainer-content">
  48. {
  49. this.renderHeader()
  50. }
  51. <div className="paneList">
  52. {this.props.children}
  53. </div >
  54. </div>
  55. </div>
  56. );
  57. }
  58. }