on 2de2112 help sign in
bridge/src/components/ReactSVGComponents.js
88 lines 2.1 kB history raw
1import React from 'react';
2import { get, map } from 'lodash';
4const ReactSVGComponents = {
5 svg: (p, key) => {
6 const { width, height, ...attrs } = p.attr;
7 return (
8 <svg
9 {...attrs}
10 width="100%"
11 height="100%"
12 version={'1.1'}
13 xmlns={'http://www.w3.org/2000/svg'}
14 key={key}
15 viewBox={`0 0 ${width} ${height}`}
16 preserveAspectRatio="xMidYMid meet">
17 {map(get(p, 'children', []), (child, idx) =>
18 ReactSVGComponents[child.tag](child, idx)
19 )}
20 </svg>
21 );
22 },
23 circle: (p, key) => {
24 return (
25 <circle {...p.attr} key={key}>
26 {map(get(p, 'children', []), (child, idx) =>
27 ReactSVGComponents[child.tag](child, idx)
28 )}
29 </circle>
30 );
31 },
32 rect: (p, key) => {
33 return (
34 <rect {...p.attr} key={key}>
35 {map(get(p, 'children', []), (child, idx) =>
36 ReactSVGComponents[child.tag](child, idx)
37 )}
38 </rect>
39 );
40 },
41 path: (p, key) => {
42 return (
43 <path {...p.attr} key={key}>
44 {map(get(p, 'children', []), (child, idx) =>
45 ReactSVGComponents[child.tag](child, idx)
46 )}
47 </path>
48 );
49 },
50 g: (p, key) => {
51 return (
52 <g {...p.attr} key={key}>
53 {map(get(p, 'children', []), (child, idx) =>
54 ReactSVGComponents[child.tag](child, idx)
55 )}
56 </g>
57 );
58 },
59 polygon: (p, key) => {
60 return (
61 <polygon {...p.attr} key={key}>
62 {map(get(p, 'children', []), (child, idx) =>
63 ReactSVGComponents[child.tag](child, idx)
64 )}
65 </polygon>
66 );
67 },
68 line: (p, key) => {
69 return (
70 <line {...p.attr} key={key}>
71 {map(get(p, 'children', []), (child, idx) =>
72 ReactSVGComponents[child.tag](child, idx)
73 )}
74 </line>
75 );
76 },
77 polyline: (p, key) => {
78 return (
79 <polyline {...p.attr} key={key}>
80 {map(get(p, 'children', []), (child, idx) =>
81 ReactSVGComponents[child.tag](child, idx)
82 )}
83 </polyline>
84 );
85 },
86};
88export default ReactSVGComponents;