Implement MainContainer

This commit is contained in:
Hydroxycarbamide 2022-07-30 23:43:28 +02:00
parent adf86ebea1
commit 40fae7dde3
4 changed files with 88 additions and 6 deletions

View file

@ -3,13 +3,14 @@ import './App.scss';
import Sidebar from './Components/Sidebar/Sidebar'; import Sidebar from './Components/Sidebar/Sidebar';
import { IAvailableContainerModel } from './Interfaces/IAvailableContainerModel'; import { IAvailableContainerModel } from './Interfaces/IAvailableContainerModel';
import { IConfigurationResponseModel } from './Interfaces/IConfigurationResponseModel'; import { IConfigurationResponseModel } from './Interfaces/IConfigurationResponseModel';
import { SVG } from './SVG/SVG';
interface IAppProps { interface IAppProps {
} }
interface IAppState { interface IAppState {
componentOptions: IAvailableContainerModel[] isSidebarOpen: boolean,
isSidebarOpen: boolean configuration: IConfigurationResponseModel
} }
class App extends React.Component<IAppProps> { class App extends React.Component<IAppProps> {
@ -19,7 +20,11 @@ class App extends React.Component<IAppProps> {
super(props); super(props);
this.state = { this.state = {
isSidebarOpen: true, isSidebarOpen: true,
componentOptions: [] configuration: {
AvailableContainers: [],
AvailableSymbols: [],
MainContainer: {} as IAvailableContainerModel
}
}; };
} }
@ -27,7 +32,7 @@ class App extends React.Component<IAppProps> {
fetchConfiguration().then((configuration: IConfigurationResponseModel) => { fetchConfiguration().then((configuration: IConfigurationResponseModel) => {
this.setState({ this.setState({
isSidebarOpen: this.state.isSidebarOpen, isSidebarOpen: this.state.isSidebarOpen,
componentOptions: configuration.AvailableContainers configuration
}); });
}); });
} }
@ -35,15 +40,16 @@ class App extends React.Component<IAppProps> {
public ToggleMenu() { public ToggleMenu() {
this.setState({ this.setState({
isSidebarOpen: !this.state.isSidebarOpen, isSidebarOpen: !this.state.isSidebarOpen,
componentOptions: this.state.componentOptions configuration: this.state.configuration
}); });
} }
render() { render() {
return ( return (
<div className="App font-sans h-full"> <div className="App font-sans h-full">
<Sidebar componentOptions={this.state.componentOptions} isOpen={this.state.isSidebarOpen} onClick={() => this.ToggleMenu()} /> <Sidebar componentOptions={this.state.configuration.AvailableContainers} isOpen={this.state.isSidebarOpen} onClick={() => this.ToggleMenu()} />
<button className='fixed z-0 top-4 left-4 text-lg' onClick={() => this.ToggleMenu()}>&#9776; Menu</button> <button className='fixed z-0 top-4 left-4 text-lg' onClick={() => this.ToggleMenu()}>&#9776; Menu</button>
<SVG MainContainer={this.state.configuration.MainContainer} />
</div> </div>
); );
} }

View file

@ -0,0 +1,23 @@
import * as React from 'react';
interface IContainerProps {
x: number,
y: number,
width: number,
height: number,
}
export class Container extends React.Component<IContainerProps> {
public render() {
const properties = {
x: this.props.x,
y: this.props.y,
width: this.props.width,
height: this.props.height
};
return (
<rect {...properties} />
);
}
}

View file

@ -0,0 +1,20 @@
import * as React from 'react';
import { Container } from './Container';
interface IMainContainerProps {
width: number,
height: number,
}
export class MainContainer extends React.Component<IMainContainerProps> {
public render() {
return (
<Container
x={0}
y={0}
width={this.props.width}
height={this.props.height}
/>
);
}
}

33
src/SVG/SVG.tsx Normal file
View file

@ -0,0 +1,33 @@
import * as React from 'react';
import { IAvailableContainerModel } from '../Interfaces/IAvailableContainerModel';
import { MainContainer } from './Elements/MainContainer';
interface ISVGProps {
MainContainer: IAvailableContainerModel
}
export class SVG extends React.Component<ISVGProps> {
render() {
const viewBox: string = [
0,
0,
window.innerWidth,
window.innerHeight
].join(' ');
const xmlns = '<http://www.w3.org/2000/svg>';
const properties = {
viewBox,
xmlns
};
return (
<svg {...properties}>
<MainContainer
width={this.props.MainContainer.Width}
height={this.props.MainContainer.Height}
/>
</svg>
);
};
}