on master help sign in
feat: allow svg sigils to be scaled to their parent container, preserving aspect ratio
commit2de2112067100d1dc156c98fa89f6c2f5af0b2f9 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateWed 19 Jun 2019, 15:02 (7 years ago) parentaee35bb
1 file changed+7−2
src/components/ReactSVGComponents.js+7−2
src/components/ReactSVGComponents.js+7−2
@@ -3,12 +3,17 @@ import { get, map } from 'lodash';
33
44const ReactSVGComponents = {
55 svg: (p, key) => {
6+ const { width, height, ...attrs } = p.attr;
67 return (
78 <svg
8− {...p.attr}
9+ {...attrs}
10+ width="100%"
11+ height="100%"
912 version={'1.1'}
1013 xmlns={'http://www.w3.org/2000/svg'}
11− key={key}>
14+ key={key}
15+ viewBox={`0 0 ${width} ${height}`}
16+ preserveAspectRatio="xMidYMid meet">
1217 {map(get(p, 'children', []), (child, idx) =>
1318 ReactSVGComponents[child.tag](child, idx)
1419 )}