From 70963ce41f0fea5d4ffc9e625e39fd6d601e0c8d Mon Sep 17 00:00:00 2001 From: Siklos Date: Sun, 31 Jul 2022 18:41:34 +0200 Subject: [PATCH] Delegate MainContainer to App --- src/App.tsx | 47 +++++++++++++++++++++++------- src/Components/Sidebar/Sidebar.tsx | 3 +- src/SVG/Elements/Container.tsx | 2 +- src/SVG/SVG.tsx | 22 ++++++-------- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 00b0f4a..47ffcda 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,6 +4,7 @@ import Sidebar from './Components/Sidebar/Sidebar'; import { SVGSidebar } from './Components/SVGSidebar/SVGSidebar'; import { AvailableContainer } from './Interfaces/AvailableContainer'; import { Configuration } from './Interfaces/Configuration'; +import { MainContainer } from './SVG/Elements/MainContainer'; import { SVG } from './SVG/SVG'; interface IAppProps { @@ -12,7 +13,8 @@ interface IAppProps { interface IAppState { isSidebarOpen: boolean, isSVGSidebarOpen: boolean, - configuration: Configuration + configuration: Configuration, + MainContainer: MainContainer | null } class App extends React.Component { @@ -27,7 +29,8 @@ class App extends React.Component { AvailableContainers: [], AvailableSymbols: [], MainContainer: {} as AvailableContainer - } + }, + MainContainer: null }; } @@ -35,33 +38,55 @@ class App extends React.Component { fetchConfiguration().then((configuration: Configuration) => { this.setState(prevState => ({ ...prevState, - configuration + configuration, + MainContainer: new MainContainer( + { + width: configuration.MainContainer.Width, + height: configuration.MainContainer.Height, + children: [] + } + ) })); }); } public ToggleSidebar() { - this.setState(prevState => ({ - ...prevState, + this.setState({ isSidebarOpen: !this.state.isSidebarOpen - } as IAppState)); + } as IAppState); } public ToggleSVGSidebar() { - this.setState(prevState => ({ - ...prevState, + this.setState({ isSVGSidebarOpen: !this.state.isSVGSidebarOpen - } as IAppState)); + } as IAppState); + } + + public AddContainer(type: string) { + // const container = new Container({ + // x: 0, + // y: 0, + // width: 300, + // height: this.state.configuration.MainContainer.Height, + // children: [] + // }); } render() { return (
- this.ToggleSidebar()} /> + this.ToggleSidebar()} + buttonOnClick={(type: string) => this.AddContainer(type)} + /> this.ToggleSVGSidebar()}/> - + + { this.state.MainContainer } +
); } diff --git a/src/Components/Sidebar/Sidebar.tsx b/src/Components/Sidebar/Sidebar.tsx index 8d806a5..f8da2b6 100644 --- a/src/Components/Sidebar/Sidebar.tsx +++ b/src/Components/Sidebar/Sidebar.tsx @@ -5,12 +5,13 @@ interface ISidebarProps { componentOptions: AvailableContainer[] isOpen: boolean; onClick: () => void; + buttonOnClick: (type: string) => void; } export default class Sidebar extends React.Component { public render() { const listElements = this.props.componentOptions.map(componentOption => - ); diff --git a/src/SVG/Elements/Container.tsx b/src/SVG/Elements/Container.tsx index 71dfa35..ef3008d 100644 --- a/src/SVG/Elements/Container.tsx +++ b/src/SVG/Elements/Container.tsx @@ -7,7 +7,7 @@ interface IContainerProps { y: number, width: number, height: number, - style: React.CSSProperties, + style?: React.CSSProperties, } export class Container extends React.Component { diff --git a/src/SVG/SVG.tsx b/src/SVG/SVG.tsx index 4591bfc..3edb8cd 100644 --- a/src/SVG/SVG.tsx +++ b/src/SVG/SVG.tsx @@ -1,11 +1,9 @@ import * as React from 'react'; -import { AvailableContainer } from '../Interfaces/AvailableContainer'; -import { Container } from './Elements/Container'; import { MainContainer } from './Elements/MainContainer'; import { ReactSVGPanZoom, Tool, Value, TOOL_PAN } from 'react-svg-pan-zoom'; interface ISVGProps { - MainContainer: AvailableContainer + children: MainContainer | MainContainer[] | null, } interface ISVGState { @@ -29,9 +27,7 @@ export class SVG extends React.Component { ], value: { viewerWidth: window.innerWidth, - viewerHeight: window.innerHeight, - SVGHeight: this.props.MainContainer.Height, - SVGWidth: this.props.MainContainer.Width + viewerHeight: window.innerHeight } as Value, tool: TOOL_PAN }; @@ -65,7 +61,12 @@ export class SVG extends React.Component { xmlns }; - const children: Container[] = []; + let children: React.ReactNode | React.ReactNode[] = []; + if (Array.isArray(this.props.children)) { + children = this.props.children.map(child => child.render()); + } else if (this.props.children !== null) { + children = this.props.children.render(); + } return ( { tool={this.state.tool} onChangeTool={tool => this.setState({ tool })} > - - { children } - + { children } );