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
}
interface ISVGState {
viewBox: number[]
}
export class SVG extends React.Component<ISVGProps> {
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 = '<http://www.w3.org/2000/svg>';
const properties = {
viewBox,
viewBox: this.state.viewBox.join(' '),
xmlns
};