SVG: Responsive viewBox
This commit is contained in:
parent
8783de497d
commit
c8c135fa7c
1 changed files with 38 additions and 7 deletions
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue