2018-05-14 20:52:10 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
2018-05-18 19:00:46 +00:00
|
|
|
import { getSizeClass } from '../../util/emoji';
|
|
|
|
import { Emojify } from './Emojify';
|
2018-05-18 21:48:20 +00:00
|
|
|
import { AddNewLines } from './AddNewLines';
|
|
|
|
import { Linkify } from './Linkify';
|
2018-05-14 20:52:10 +00:00
|
|
|
|
2018-05-18 21:48:20 +00:00
|
|
|
import { RenderTextCallback } from '../../types/Util';
|
2018-05-14 20:52:10 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
text: string;
|
2018-05-18 21:48:20 +00:00
|
|
|
/** If set, all emoji will be the same size. Otherwise, just one emoji will be large. */
|
2018-05-14 20:52:10 +00:00
|
|
|
disableJumbomoji?: boolean;
|
2018-05-18 21:48:20 +00:00
|
|
|
/** If set, links will be left alone instead of turned into clickable `<a>` tags. */
|
2018-05-14 20:52:10 +00:00
|
|
|
disableLinks?: boolean;
|
|
|
|
}
|
|
|
|
|
2018-05-18 21:48:20 +00:00
|
|
|
const renderNewLines: RenderTextCallback = ({
|
|
|
|
text: textWithNewLines,
|
|
|
|
key,
|
|
|
|
}) => <AddNewLines key={key} text={textWithNewLines} />;
|
|
|
|
|
|
|
|
const renderLinks: RenderTextCallback = ({ text: textWithLinks, key }) => (
|
|
|
|
<Linkify key={key} text={textWithLinks} renderNonLink={renderNewLines} />
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This component makes it very easy to use all three of our message formatting
|
|
|
|
* components: `Emojify`, `Linkify`, and `AddNewLines`. Because each of them is fully
|
|
|
|
* configurable with their `renderXXX` props, this component will assemble all three of
|
|
|
|
* them for you.
|
|
|
|
*/
|
2018-05-14 20:52:10 +00:00
|
|
|
export class MessageBody extends React.Component<Props, {}> {
|
|
|
|
public render() {
|
|
|
|
const { text, disableJumbomoji, disableLinks } = this.props;
|
|
|
|
const sizeClass = disableJumbomoji ? '' : getSizeClass(text);
|
|
|
|
|
2018-05-18 21:48:20 +00:00
|
|
|
return (
|
|
|
|
<Emojify
|
|
|
|
text={text}
|
|
|
|
sizeClass={sizeClass}
|
|
|
|
renderNonEmoji={disableLinks ? renderNewLines : renderLinks}
|
|
|
|
/>
|
2018-05-14 20:52:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|