Moving layout function into component module

This commit is contained in:
Jeff Avallone 2019-01-27 08:46:48 -05:00
parent 1ee3055f37
commit f16a51abcb
5 changed files with 25 additions and 28 deletions

View File

@ -1,8 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import SVG from 'rendering/SVG/layout';
import Text from 'rendering/Text/layout';
import * as SVG from 'rendering/SVG';
import * as Text from 'rendering/Text';
const nodeTypes = {
SVG,
@ -20,7 +20,7 @@ const layout = data => {
data.children = data.children.map(layout);
}
return nodeTypes[type]({
return nodeTypes[type].layout({
props: {},
...data
});

View File

@ -47,4 +47,14 @@ SVG.propTypes = {
innerHeight: PropTypes.number
};
const layout = data => {
const child = data.children[0];
data.props.innerWidth = child.box.width;
data.props.innerHeight = child.box.height;
return data;
};
export default SVG;
export { layout };

View File

@ -1,10 +0,0 @@
const layoutSVG = data => {
const child = data.children[0];
data.props.innerWidth = child.box.width;
data.props.innerHeight = child.box.height;
return data;
};
export default layoutSVG;

View File

@ -1,6 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import { getBBox } from 'layout';
import * as style from './style';
const Text = ({ transform, quoted, children }) => {
@ -27,4 +29,14 @@ Text.propTypes = {
]).isRequired
};
const layout = data => {
const {x, y, width, height } = getBBox(
<Text { ...data.props }>{ data.children }</Text>);
data.box = { width, height };
data.props.transform = `translate(${ -x } ${ -y })`;
return data;
};
export default Text;
export { layout };

View File

@ -1,15 +0,0 @@
import React from 'react';
import { getBBox } from 'layout';
import Text from 'rendering/Text';
const layoutText = data => {
const {x, y, width, height } = getBBox(
<Text { ...data.props }>{ data.children }</Text>);
data.box = { width, height };
data.props.transform = `translate(${ -x } ${ -y })`;
return data;
};
export default layoutText;