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