SVG: Responsive viewBox

This commit is contained in:
Siklos 2022-07-31 12:01:20 +02:00
parent 8783de497d
commit c8c135fa7c

View file

@ -7,18 +7,49 @@ interface ISVGProps {
MainContainer: AvailableContainer MainContainer: AvailableContainer
} }
interface ISVGState {
viewBox: number[]
}
export class SVG extends React.Component<ISVGProps> { export class SVG extends React.Component<ISVGProps> {
render() { public state: ISVGState;
const viewBox: string = [
constructor(props: ISVGProps) {
super(props);
this.state = {
viewBox: [
0, 0,
0, 0,
window.innerWidth, window.innerWidth,
window.innerHeight window.innerHeight
].join(' '); ]
};
}
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 xmlns = '<http://www.w3.org/2000/svg>'; const xmlns = '<http://www.w3.org/2000/svg>';
const properties = { const properties = {
viewBox, viewBox: this.state.viewBox.join(' '),
xmlns xmlns
}; };