import React from 'react'; import stringToRGB from 'utils/color'; function nickStyle(nick, color) { const style = { fontWeight: 400 }; if (color) { style.color = stringToRGB(nick); } return style; } function renderBlock(block, coloredNick, key) { switch (block.type) { case 'text': return block.text; case 'link': return ( {block.text} ); case 'format': return ( {block.text} ); case 'nick': return ( {block.text} ); case 'events': return ( {block.text} ); default: return null; } } const Text = ({ children, coloredNick }) => { if (!children) { return null; } if (children.length > 1) { let key = 0; return children.map(block => renderBlock(block, coloredNick, key++)); } if (children.length === 1) { return renderBlock(children[0], coloredNick); } return children; }; export default Text;