Extracting type mapping into shared module
This commit is contained in:
parent
f16a51abcb
commit
a118519c3a
@ -1,16 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import SVG from 'rendering/SVG';
|
import nodeTypes from 'rendering/types';
|
||||||
import Text from 'rendering/Text';
|
|
||||||
|
|
||||||
import style from './style.module.css';
|
import style from './style.module.css';
|
||||||
|
|
||||||
const nodeTypes = {
|
|
||||||
SVG,
|
|
||||||
Text
|
|
||||||
};
|
|
||||||
|
|
||||||
const render = (data, extraProps) => {
|
const render = (data, extraProps) => {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
return data;
|
return data;
|
||||||
@ -21,7 +15,7 @@ const render = (data, extraProps) => {
|
|||||||
(data, key) => render(data, { key }));
|
(data, key) => render(data, { key }));
|
||||||
|
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
nodeTypes[type] || type,
|
nodeTypes[type] ? nodeTypes[type].default : type,
|
||||||
{ ...extraProps, ...props },
|
{ ...extraProps, ...props },
|
||||||
children.length === 1 ? children[0] : children);
|
children.length === 1 ? children[0] : children);
|
||||||
};
|
};
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import * as SVG from 'rendering/SVG';
|
import nodeTypes from 'rendering/types';
|
||||||
import * as Text from 'rendering/Text';
|
|
||||||
|
|
||||||
const nodeTypes = {
|
|
||||||
SVG,
|
|
||||||
Text
|
|
||||||
};
|
|
||||||
|
|
||||||
const layout = data => {
|
const layout = data => {
|
||||||
if (typeof data == 'string') {
|
if (typeof data == 'string') {
|
||||||
|
7
src/rendering/types.js
Normal file
7
src/rendering/types.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import * as SVG from 'rendering/SVG';
|
||||||
|
import * as Text from 'rendering/Text';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
SVG,
|
||||||
|
Text
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user