Converting rendering components to functional components
This commit is contained in:
parent
d4aa207f75
commit
754868b9d5
@ -21,16 +21,7 @@ const metadata = `<rdf:rdf>
|
|||||||
</rdf:rdf>`;
|
</rdf:rdf>`;
|
||||||
/* eslint-enable max-len */
|
/* eslint-enable max-len */
|
||||||
|
|
||||||
class SVG extends React.PureComponent {
|
const SVG = ({ innerWidth, innerHeight, children }) => {
|
||||||
static propTypes = {
|
|
||||||
children: PropTypes.node,
|
|
||||||
innerWidth: PropTypes.number,
|
|
||||||
innerHeight: PropTypes.number
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { innerWidth, innerHeight, children } = this.props;
|
|
||||||
|
|
||||||
const width = Math.round(innerWidth + 2 * padding);
|
const width = Math.round(innerWidth + 2 * padding);
|
||||||
const height = Math.round(innerHeight + 2 * padding);
|
const height = Math.round(innerHeight + 2 * padding);
|
||||||
|
|
||||||
@ -48,7 +39,12 @@ class SVG extends React.PureComponent {
|
|||||||
{ children }
|
{ children }
|
||||||
</g>
|
</g>
|
||||||
</svg>;
|
</svg>;
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
SVG.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
innerWidth: PropTypes.number,
|
||||||
|
innerHeight: PropTypes.number
|
||||||
|
};
|
||||||
|
|
||||||
export default SVG;
|
export default SVG;
|
||||||
|
@ -3,42 +3,28 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
import * as style from './style';
|
import * as style from './style';
|
||||||
|
|
||||||
class Text extends React.PureComponent {
|
const Text = ({ transform, quoted, children }) => {
|
||||||
static propTypes = {
|
|
||||||
quoted: PropTypes.bool,
|
|
||||||
transform: PropTypes.string,
|
|
||||||
children: PropTypes.oneOfType([
|
|
||||||
PropTypes.arrayOf(PropTypes.node),
|
|
||||||
PropTypes.node
|
|
||||||
]).isRequired
|
|
||||||
}
|
|
||||||
|
|
||||||
renderContent() {
|
|
||||||
const { children, quoted } = this.props;
|
|
||||||
|
|
||||||
if (!quoted) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <>
|
|
||||||
<tspan style={ style.quote }>“</tspan>
|
|
||||||
<tspan>{ children }</tspan>
|
|
||||||
<tspan style={ style.quote }>”</tspan>
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { transform } = this.props;
|
|
||||||
|
|
||||||
const textProps = {
|
const textProps = {
|
||||||
style: style.text,
|
style: style.text,
|
||||||
transform
|
transform
|
||||||
};
|
};
|
||||||
|
|
||||||
return <text { ...textProps }>
|
return <text { ...textProps }>
|
||||||
{ this.renderContent() }
|
{ quoted ? <>
|
||||||
|
<tspan style={ style.quote }>“</tspan>
|
||||||
|
<tspan>{ children }</tspan>
|
||||||
|
<tspan style={ style.quote }>”</tspan>
|
||||||
|
</> : children }
|
||||||
</text>;
|
</text>;
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
Text.propTypes = {
|
||||||
|
quoted: PropTypes.bool,
|
||||||
|
transform: PropTypes.string,
|
||||||
|
children: PropTypes.oneOfType([
|
||||||
|
PropTypes.arrayOf(PropTypes.node),
|
||||||
|
PropTypes.node
|
||||||
|
]).isRequired
|
||||||
|
};
|
||||||
|
|
||||||
export default Text;
|
export default Text;
|
||||||
|
Loading…
Reference in New Issue
Block a user