diff --git a/src/SVG/SVG.tsx b/src/SVG/SVG.tsx index 9b22089..dd3e46a 100644 --- a/src/SVG/SVG.tsx +++ b/src/SVG/SVG.tsx @@ -7,18 +7,49 @@ interface ISVGProps { MainContainer: AvailableContainer } +interface ISVGState { + viewBox: number[] +} + export class SVG extends React.Component { + public state: ISVGState; + + constructor(props: ISVGProps) { + super(props); + this.state = { + viewBox: [ + 0, + 0, + window.innerWidth, + window.innerHeight + ] + }; + } + + updateViewBox() { + this.setState({ + viewBox: [ + 0, + 0, + window.innerWidth, + window.innerHeight + ] + }); + } + + componentDidMount() { + window.addEventListener('resize', this.updateViewBox.bind(this)); + } + + componentWillUnmount() { + window.removeEventListener('resize', this.updateViewBox.bind(this)); + } + render() { - const viewBox: string = [ - 0, - 0, - window.innerWidth, - window.innerHeight - ].join(' '); const xmlns = ''; const properties = { - viewBox, + viewBox: this.state.viewBox.join(' '), xmlns };