soapbox/src/components/ui/emoji.tsx

32 wiersze
677 B
TypeScript
Czysty Zwykły widok Historia

2024-11-10 03:18:55 +00:00
import { removeVS16s, toCodePoints } from 'soapbox/utils/emoji.ts';
2022-04-01 01:32:53 +00:00
interface IEmoji extends React.ImgHTMLAttributes<HTMLImageElement> {
/** Unicode emoji character. */
emoji?: string;
2022-04-01 01:32:53 +00:00
}
/** A single emoji image. */
const Emoji: React.FC<IEmoji> = (props): JSX.Element | null => {
const { emoji, alt, src, ...rest } = props;
2022-04-01 01:32:53 +00:00
let filename;
if (emoji) {
const codepoints = toCodePoints(removeVS16s(emoji));
filename = codepoints.join('-');
}
if (!filename && !src) return null;
2022-04-01 01:32:53 +00:00
return (
<img
draggable='false'
alt={alt || emoji}
src={src || `/packs/emoji/${filename}.svg`}
{...rest}
2022-04-01 01:32:53 +00:00
/>
);
};
export default Emoji;