Compare commits
No commits in common. "6c029ac13cd77fcc990fb987134cbf803718f867" and "6db63d5a47511cdc5d77756f636630e7de19eae1" have entirely different histories.
6c029ac13c
...
6db63d5a47
4 changed files with 27 additions and 71 deletions
63
src/App.tsx
63
src/App.tsx
|
@ -4,8 +4,6 @@ import Sidebar from './Components/Sidebar/Sidebar';
|
||||||
import { SVGSidebar } from './Components/SVGSidebar/SVGSidebar';
|
import { SVGSidebar } from './Components/SVGSidebar/SVGSidebar';
|
||||||
import { AvailableContainer } from './Interfaces/AvailableContainer';
|
import { AvailableContainer } from './Interfaces/AvailableContainer';
|
||||||
import { Configuration } from './Interfaces/Configuration';
|
import { Configuration } from './Interfaces/Configuration';
|
||||||
import { Container } from './SVG/Elements/Container';
|
|
||||||
import { MainContainer } from './SVG/Elements/MainContainer';
|
|
||||||
import { SVG } from './SVG/SVG';
|
import { SVG } from './SVG/SVG';
|
||||||
|
|
||||||
interface IAppProps {
|
interface IAppProps {
|
||||||
|
@ -14,8 +12,7 @@ interface IAppProps {
|
||||||
interface IAppState {
|
interface IAppState {
|
||||||
isSidebarOpen: boolean,
|
isSidebarOpen: boolean,
|
||||||
isSVGSidebarOpen: boolean,
|
isSVGSidebarOpen: boolean,
|
||||||
configuration: Configuration,
|
configuration: Configuration
|
||||||
MainContainer: MainContainer | null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends React.Component<IAppProps> {
|
class App extends React.Component<IAppProps> {
|
||||||
|
@ -30,8 +27,7 @@ class App extends React.Component<IAppProps> {
|
||||||
AvailableContainers: [],
|
AvailableContainers: [],
|
||||||
AvailableSymbols: [],
|
AvailableSymbols: [],
|
||||||
MainContainer: {} as AvailableContainer
|
MainContainer: {} as AvailableContainer
|
||||||
},
|
}
|
||||||
MainContainer: null
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,70 +35,33 @@ class App extends React.Component<IAppProps> {
|
||||||
fetchConfiguration().then((configuration: Configuration) => {
|
fetchConfiguration().then((configuration: Configuration) => {
|
||||||
this.setState(prevState => ({
|
this.setState(prevState => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
configuration,
|
configuration
|
||||||
MainContainer: new MainContainer(
|
|
||||||
{
|
|
||||||
width: configuration.MainContainer.Width,
|
|
||||||
height: configuration.MainContainer.Height,
|
|
||||||
children: []
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToggleSidebar() {
|
public ToggleSidebar() {
|
||||||
this.setState({
|
this.setState(prevState => ({
|
||||||
|
...prevState,
|
||||||
isSidebarOpen: !this.state.isSidebarOpen
|
isSidebarOpen: !this.state.isSidebarOpen
|
||||||
} as IAppState);
|
} as IAppState));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToggleSVGSidebar() {
|
public ToggleSVGSidebar() {
|
||||||
this.setState({
|
this.setState(prevState => ({
|
||||||
|
...prevState,
|
||||||
isSVGSidebarOpen: !this.state.isSVGSidebarOpen
|
isSVGSidebarOpen: !this.state.isSVGSidebarOpen
|
||||||
} as IAppState);
|
} as IAppState));
|
||||||
}
|
|
||||||
|
|
||||||
public AddContainer(type: string): void {
|
|
||||||
if (this.state.MainContainer === null ||
|
|
||||||
this.state.MainContainer === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const container = new Container({
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 300,
|
|
||||||
height: this.state.configuration.MainContainer.Height,
|
|
||||||
children: []
|
|
||||||
});
|
|
||||||
|
|
||||||
const newMainContainer = new MainContainer({
|
|
||||||
width: this.state.MainContainer.props.width,
|
|
||||||
height: this.state.MainContainer.props.height,
|
|
||||||
children: this.state.MainContainer.props.children.concat([container])
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
MainContainer: newMainContainer
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="App font-sans h-full">
|
<div className="App font-sans h-full">
|
||||||
<Sidebar
|
<Sidebar componentOptions={this.state.configuration.AvailableContainers} isOpen={this.state.isSidebarOpen} onClick={() => this.ToggleSidebar()} />
|
||||||
componentOptions={this.state.configuration.AvailableContainers}
|
|
||||||
isOpen={this.state.isSidebarOpen}
|
|
||||||
onClick={() => this.ToggleSidebar()}
|
|
||||||
buttonOnClick={(type: string) => this.AddContainer(type)}
|
|
||||||
/>
|
|
||||||
<button className='fixed z-10 top-4 left-4 text-lg bg-blue-200 hover:bg-blue-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg' onClick={() => this.ToggleSidebar()}>☰ Menu</button>
|
<button className='fixed z-10 top-4 left-4 text-lg bg-blue-200 hover:bg-blue-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg' onClick={() => this.ToggleSidebar()}>☰ Menu</button>
|
||||||
<SVGSidebar isOpen={this.state.isSVGSidebarOpen} onClick={() => this.ToggleSVGSidebar()}/>
|
<SVGSidebar isOpen={this.state.isSVGSidebarOpen} onClick={() => this.ToggleSVGSidebar()}/>
|
||||||
<button className='fixed z-10 top-4 right-12 text-lg bg-slate-200 hover:bg-slate-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg' onClick={() => this.ToggleSVGSidebar()}>☰ Menu</button>
|
<button className='fixed z-10 top-4 right-12 text-lg bg-slate-200 hover:bg-slate-300 transition-all drop-shadow-md hover:drop-shadow-lg py-2 px-3 rounded-lg' onClick={() => this.ToggleSVGSidebar()}>☰ Menu</button>
|
||||||
<SVG>
|
<SVG MainContainer={this.state.configuration.MainContainer} />
|
||||||
{ this.state.MainContainer }
|
|
||||||
</SVG>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,12 @@ interface ISidebarProps {
|
||||||
componentOptions: AvailableContainer[]
|
componentOptions: AvailableContainer[]
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
buttonOnClick: (type: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Sidebar extends React.Component<ISidebarProps> {
|
export default class Sidebar extends React.Component<ISidebarProps> {
|
||||||
public render() {
|
public render() {
|
||||||
const listElements = this.props.componentOptions.map(componentOption =>
|
const listElements = this.props.componentOptions.map(componentOption =>
|
||||||
<button className='hover:bg-blue-600 transition-all sidebar-row' key={componentOption.Type} onClick={() => this.props.buttonOnClick(componentOption.Type)}>
|
<button className='hover:bg-blue-600 transition-all sidebar-row' key={componentOption.Type}>
|
||||||
{componentOption.Type}
|
{componentOption.Type}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,22 +7,16 @@ interface IContainerProps {
|
||||||
y: number,
|
y: number,
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
style?: React.CSSProperties,
|
style: React.CSSProperties,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Container extends React.Component<IContainerProps> {
|
export class Container extends React.Component<IContainerProps> {
|
||||||
public static ContainerCount = 0;
|
|
||||||
|
|
||||||
componentWillUnMount() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
Container.ContainerCount++;
|
|
||||||
const containersElements = this.props.children.map(child => child.render());
|
const containersElements = this.props.children.map(child => child.render());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g
|
<g
|
||||||
transform={`translate(${this.props.x}, ${this.props.y})`}
|
transform={`translate(${this.props.x}, ${this.props.y})`}
|
||||||
key={`container-${Container.ContainerCount}`}
|
|
||||||
>
|
>
|
||||||
<rect
|
<rect
|
||||||
width={this.props.width}
|
width={this.props.width}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { AvailableContainer } from '../Interfaces/AvailableContainer';
|
||||||
|
import { Container } from './Elements/Container';
|
||||||
import { MainContainer } from './Elements/MainContainer';
|
import { MainContainer } from './Elements/MainContainer';
|
||||||
import { ReactSVGPanZoom, Tool, Value, TOOL_PAN } from 'react-svg-pan-zoom';
|
import { ReactSVGPanZoom, Tool, Value, TOOL_PAN } from 'react-svg-pan-zoom';
|
||||||
|
|
||||||
interface ISVGProps {
|
interface ISVGProps {
|
||||||
children: MainContainer | MainContainer[] | null,
|
MainContainer: AvailableContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISVGState {
|
interface ISVGState {
|
||||||
|
@ -27,7 +29,9 @@ export class SVG extends React.Component<ISVGProps> {
|
||||||
],
|
],
|
||||||
value: {
|
value: {
|
||||||
viewerWidth: window.innerWidth,
|
viewerWidth: window.innerWidth,
|
||||||
viewerHeight: window.innerHeight
|
viewerHeight: window.innerHeight,
|
||||||
|
SVGHeight: this.props.MainContainer.Height,
|
||||||
|
SVGWidth: this.props.MainContainer.Width
|
||||||
} as Value,
|
} as Value,
|
||||||
tool: TOOL_PAN
|
tool: TOOL_PAN
|
||||||
};
|
};
|
||||||
|
@ -61,12 +65,7 @@ export class SVG extends React.Component<ISVGProps> {
|
||||||
xmlns
|
xmlns
|
||||||
};
|
};
|
||||||
|
|
||||||
let children: React.ReactNode | React.ReactNode[] = [];
|
const children: Container[] = [];
|
||||||
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 (
|
return (
|
||||||
<ReactSVGPanZoom
|
<ReactSVGPanZoom
|
||||||
|
@ -78,7 +77,12 @@ export class SVG extends React.Component<ISVGProps> {
|
||||||
tool={this.state.tool} onChangeTool={tool => this.setState({ tool })}
|
tool={this.state.tool} onChangeTool={tool => this.setState({ tool })}
|
||||||
>
|
>
|
||||||
<svg ref={this.svg} {...properties}>
|
<svg ref={this.svg} {...properties}>
|
||||||
{ children }
|
<MainContainer
|
||||||
|
width={this.props.MainContainer.Width}
|
||||||
|
height={this.props.MainContainer.Height}
|
||||||
|
>
|
||||||
|
{ children }
|
||||||
|
</MainContainer>
|
||||||
</svg>
|
</svg>
|
||||||
</ReactSVGPanZoom>
|
</ReactSVGPanZoom>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue