pleroma/app/soapbox/components/ui/emoji/emoji.tsx
marcin mikołajczak 9c49fc3d8a Lexical: Hashtag, emoji autocompletion
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2023-04-02 20:50:15 +02:00

34 lines
771 B
TypeScript

import React from 'react';
import { removeVS16s, toCodePoints } from 'soapbox/utils/emoji';
import { joinPublicPath } from 'soapbox/utils/static';
interface IEmoji extends React.ImgHTMLAttributes<HTMLImageElement> {
/** Unicode emoji character. */
emoji?: string
}
/** A single emoji image. */
const Emoji: React.FC<IEmoji> = (props): JSX.Element | null => {
const { emoji, alt, src, ...rest } = props;
let filename;
if (emoji) {
const codepoints = toCodePoints(removeVS16s(emoji));
filename = codepoints.join('-');
}
if (!filename && !src) return null;
return (
<img
draggable='false'
alt={alt || emoji}
src={src || joinPublicPath(`packs/emoji/${filename}.svg`)}
{...rest}
/>
);
};
export default Emoji;