on master help sign in
feat: allow svg sigils to be scaled to their parent container, preserving aspect ratio
2de2112Matt Condon (shrugs)
src/components/ReactSVGComponents.js+7−2
@@ -3,12 +3,17 @@ import { get, map } from 'lodash';
3
3
4const ReactSVGComponents = {
4const ReactSVGComponents = {
5 svg: (p, key) => {
5 svg: (p, key) => {
6+ const { width, height, ...attrs } = p.attr;
6 return (
7 return (
7 <svg
8 <svg
8− {...p.attr}
9+ {...attrs}
10+ width="100%"
11+ height="100%"
9 version={'1.1'}
12 version={'1.1'}
10 xmlns={'http://www.w3.org/2000/svg'}
13 xmlns={'http://www.w3.org/2000/svg'}
11− key={key}>
14+ key={key}
15+ viewBox={`0 0 ${width} ${height}`}
16+ preserveAspectRatio="xMidYMid meet">
12 {map(get(p, 'children', []), (child, idx) =>
17 {map(get(p, 'children', []), (child, idx) =>
13 ReactSVGComponents[child.tag](child, idx)
18 ReactSVGComponents[child.tag](child, idx)
14 )}
19 )}