Container: Support for children
This commit is contained in:
parent
5f91128c85
commit
c60a8651db
3 changed files with 26 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
interface IContainerProps {
|
interface IContainerProps {
|
||||||
|
// eslint-disable-next-line no-use-before-define
|
||||||
|
children: Container[],
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
width: number,
|
width: number,
|
||||||
|
@ -9,15 +11,21 @@ interface IContainerProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Container extends React.Component<IContainerProps> {
|
export class Container extends React.Component<IContainerProps> {
|
||||||
public render() {
|
public render(): React.ReactNode {
|
||||||
|
const containersElements = this.props.children.map(child => child.render());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<g>
|
||||||
<rect
|
<rect
|
||||||
x={this.props.x}
|
x={this.props.x}
|
||||||
y={this.props.y}
|
y={this.props.y}
|
||||||
width={this.props.width}
|
width={this.props.width}
|
||||||
height={this.props.height}
|
height={this.props.height}
|
||||||
style={this.props.style}
|
style={this.props.style}
|
||||||
/>
|
>
|
||||||
|
</rect>
|
||||||
|
{ containersElements }
|
||||||
|
</g>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as React from 'react';
|
||||||
import { Container } from './Container';
|
import { Container } from './Container';
|
||||||
|
|
||||||
interface IMainContainerProps {
|
interface IMainContainerProps {
|
||||||
|
children: Container[],
|
||||||
width: number,
|
width: number,
|
||||||
height: number,
|
height: number,
|
||||||
}
|
}
|
||||||
|
@ -20,7 +21,9 @@ export class MainContainer extends React.Component<IMainContainerProps> {
|
||||||
width={this.props.width}
|
width={this.props.width}
|
||||||
height={this.props.height}
|
height={this.props.height}
|
||||||
style={style}
|
style={style}
|
||||||
/>
|
>
|
||||||
|
{ this.props.children }
|
||||||
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { AvailableContainer } from '../Interfaces/AvailableContainer';
|
import { AvailableContainer } from '../Interfaces/AvailableContainer';
|
||||||
|
import { Container } from './Elements/Container';
|
||||||
import { MainContainer } from './Elements/MainContainer';
|
import { MainContainer } from './Elements/MainContainer';
|
||||||
|
|
||||||
interface ISVGProps {
|
interface ISVGProps {
|
||||||
|
@ -21,12 +22,16 @@ export class SVG extends React.Component<ISVGProps> {
|
||||||
xmlns
|
xmlns
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const children: Container[] = [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<svg {...properties}>
|
<svg {...properties}>
|
||||||
<MainContainer
|
<MainContainer
|
||||||
width={this.props.MainContainer.Width}
|
width={this.props.MainContainer.Width}
|
||||||
height={this.props.MainContainer.Height}
|
height={this.props.MainContainer.Height}
|
||||||
/>
|
>
|
||||||
|
{ children }
|
||||||
|
</MainContainer>
|
||||||
</svg>
|
</svg>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue