Compare commits
No commits in common. "ea156060c4f2009e9f85a7cade7cc00207d357da" and "2a445cfdc20f8cacc678c5e81df916d83a26459b" have entirely different histories.
ea156060c4
...
2a445cfdc2
5 changed files with 41 additions and 58 deletions
22
src/App.tsx
22
src/App.tsx
|
@ -5,6 +5,7 @@ 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 './Components/SVG/Elements/Container';
|
import { Container } from './Components/SVG/Elements/Container';
|
||||||
|
import { MainContainer } from './Components/SVG/Elements/MainContainer';
|
||||||
import { SVG } from './Components/SVG/SVG';
|
import { SVG } from './Components/SVG/SVG';
|
||||||
|
|
||||||
interface IAppProps {
|
interface IAppProps {
|
||||||
|
@ -14,7 +15,7 @@ interface IAppState {
|
||||||
isSidebarOpen: boolean,
|
isSidebarOpen: boolean,
|
||||||
isSVGSidebarOpen: boolean,
|
isSVGSidebarOpen: boolean,
|
||||||
configuration: Configuration,
|
configuration: Configuration,
|
||||||
MainContainer: Container | null
|
MainContainer: MainContainer | null
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends React.Component<IAppProps> {
|
class App extends React.Component<IAppProps> {
|
||||||
|
@ -39,18 +40,11 @@ class App extends React.Component<IAppProps> {
|
||||||
this.setState(prevState => ({
|
this.setState(prevState => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
configuration,
|
configuration,
|
||||||
MainContainer: new Container(
|
MainContainer: new MainContainer(
|
||||||
{
|
{
|
||||||
id: 'main',
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: configuration.MainContainer.Width,
|
width: configuration.MainContainer.Width,
|
||||||
height: configuration.MainContainer.Height,
|
height: configuration.MainContainer.Height,
|
||||||
children: [],
|
children: []
|
||||||
style: {
|
|
||||||
fillOpacity: 0,
|
|
||||||
stroke: 'black'
|
|
||||||
} as React.CSSProperties
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}));
|
}));
|
||||||
|
@ -94,13 +88,9 @@ class App extends React.Component<IAppProps> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const newMainContainer = new Container({
|
const newMainContainer = new MainContainer({
|
||||||
id: this.state.MainContainer.props.id,
|
|
||||||
x: this.state.MainContainer.props.x,
|
|
||||||
y: this.state.MainContainer.props.y,
|
|
||||||
width: this.state.MainContainer.props.width,
|
width: this.state.MainContainer.props.width,
|
||||||
height: this.state.MainContainer.props.height,
|
height: this.state.MainContainer.props.height,
|
||||||
style: this.state.MainContainer.props.style,
|
|
||||||
children: this.state.MainContainer.props.children.concat([container])
|
children: this.state.MainContainer.props.children.concat([container])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -119,7 +109,7 @@ class App extends React.Component<IAppProps> {
|
||||||
buttonOnClick={(type: string) => this.AddContainer(type)}
|
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 MainContainer={this.state.MainContainer} 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>
|
||||||
{ this.state.MainContainer }
|
{ this.state.MainContainer }
|
||||||
|
|
|
@ -9,7 +9,7 @@ interface IContainerProps {
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
style?: React.CSSProperties,
|
style?: React.CSSProperties,
|
||||||
userData?: Record<string, string | number>
|
userData?: Record<string, string | number | symbol>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Container extends React.Component<IContainerProps> {
|
export class Container extends React.Component<IContainerProps> {
|
||||||
|
|
30
src/Components/SVG/Elements/MainContainer.tsx
Normal file
30
src/Components/SVG/Elements/MainContainer.tsx
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Container } from './Container';
|
||||||
|
|
||||||
|
interface IMainContainerProps {
|
||||||
|
children: Container[],
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MainContainer extends React.Component<IMainContainerProps> {
|
||||||
|
public render() {
|
||||||
|
const style: React.CSSProperties = {
|
||||||
|
fillOpacity: 0,
|
||||||
|
stroke: 'black'
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container
|
||||||
|
id={'main'}
|
||||||
|
x={0}
|
||||||
|
y={0}
|
||||||
|
width={this.props.width}
|
||||||
|
height={this.props.height}
|
||||||
|
style={style}
|
||||||
|
>
|
||||||
|
{ this.props.children }
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
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';
|
||||||
import { Container } from './Elements/Container';
|
|
||||||
|
|
||||||
interface ISVGProps {
|
interface ISVGProps {
|
||||||
children: Container | Container[] | null,
|
children: MainContainer | MainContainer[] | null,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ISVGState {
|
interface ISVGState {
|
||||||
|
|
|
@ -1,49 +1,13 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Container } from '../SVG/Elements/Container';
|
|
||||||
|
|
||||||
interface ISVGSidebarProps {
|
interface ISVGSidebarProps {
|
||||||
MainContainer: Container | null,
|
isOpen: boolean;
|
||||||
isOpen: boolean,
|
onClick: () => void;
|
||||||
onClick: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SVGSidebar extends React.Component<ISVGSidebarProps> {
|
export class SVGSidebar extends React.Component<ISVGSidebarProps> {
|
||||||
public iterateChilds(handleContainer: (container: Container) => void): React.ReactNode {
|
|
||||||
const root = this.props.MainContainer;
|
|
||||||
if (!root) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queue = [root];
|
|
||||||
const visited = new Set([root]);
|
|
||||||
while (queue.length > 0) {
|
|
||||||
const container = queue.pop() as Container;
|
|
||||||
|
|
||||||
handleContainer(container);
|
|
||||||
|
|
||||||
container.props.children.forEach((child) => {
|
|
||||||
if (visited.has(child)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
visited.add(child);
|
|
||||||
queue.push(child);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64';
|
const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64';
|
||||||
|
|
||||||
const containerRows: React.ReactNode[] = [];
|
|
||||||
this.iterateChilds((container: Container) => {
|
|
||||||
const key = container.props.id.toString();
|
|
||||||
containerRows.push(
|
|
||||||
<button className='hover:bg-slate-600 transition-all sidebar-row' key={key} >
|
|
||||||
{ key }
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`fixed bg-slate-400 text-white transition-all h-screen w-64 overflow-y-auto z-20 ${isOpenClasses}`}>
|
<div className={`fixed bg-slate-400 text-white transition-all h-screen w-64 overflow-y-auto z-20 ${isOpenClasses}`}>
|
||||||
<div className='w-full h-auto p-4 flex justify-start' onClick={this.props.onClick}>
|
<div className='w-full h-auto p-4 flex justify-start' onClick={this.props.onClick}>
|
||||||
|
@ -52,7 +16,6 @@ export class SVGSidebar extends React.Component<ISVGSidebarProps> {
|
||||||
<div className='bg-slate-500 sidebar-row'>
|
<div className='bg-slate-500 sidebar-row'>
|
||||||
Liste des éléments
|
Liste des éléments
|
||||||
</div>
|
</div>
|
||||||
{ containerRows }
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue