import React from 'react'; import classnames from 'classnames'; import is from '@sindresorhus/is'; import { findImage, getRegex, getReplacementData, getTitle, } from '../../util/emoji'; import { AddNewLines } from './AddNewLines'; // Some of this logic taken from emoji-js/replacement function getImageTag({ match, sizeClass, key, }: { match: any; sizeClass: string | undefined; key: string | number; }) { const result = getReplacementData(match[0], match[1], match[2]); if (is.string(result)) { return {match[0]}; } const img = findImage(result.value, result.variation); const title = getTitle(result.value); return ( ); } interface Props { text: string; sizeClass?: string; } export class Emojify extends React.Component { public render() { const { text, sizeClass } = this.props; const results: Array = []; const regex = getRegex(); let match = regex.exec(text); let last = 0; let count = 1; if (!match) { return ; } while (match) { if (last < match.index) { const textWithNoEmoji = text.slice(last, match.index); results.push(); } results.push(getImageTag({ match, sizeClass, key: count++ })); last = regex.lastIndex; match = regex.exec(text); } if (last < text.length) { results.push(); } return {results}; } }