bigbuffet-rw/app/soapbox/components/autosuggest-emoji.tsx

44 lines
958 B
TypeScript
Raw Normal View History

2022-06-04 16:29:58 -07:00
import React from 'react';
2022-07-09 10:02:21 -07:00
import { isCustomEmoji } from 'soapbox/features/emoji';
2022-07-04 13:30:35 -07:00
import unicodeMapping from 'soapbox/features/emoji/mapping';
2022-06-04 16:29:58 -07:00
import { joinPublicPath } from 'soapbox/utils/static';
2022-07-04 20:11:46 -07:00
import type { Emoji } from 'soapbox/features/emoji';
2022-06-04 16:29:58 -07:00
interface IAutosuggestEmoji {
emoji: Emoji
2022-06-04 16:29:58 -07:00
}
const AutosuggestEmoji: React.FC<IAutosuggestEmoji> = ({ emoji }) => {
2022-07-04 20:11:46 -07:00
let url, alt;
2022-06-04 16:29:58 -07:00
2022-07-04 20:11:46 -07:00
if (isCustomEmoji(emoji)) {
2022-06-04 16:29:58 -07:00
url = emoji.imageUrl;
2022-07-04 20:11:46 -07:00
alt = emoji.colons;
2022-07-04 20:59:39 -07:00
} else {
2022-07-04 13:30:35 -07:00
const mapping = unicodeMapping[emoji.native] || unicodeMapping[emoji.native.replace(/\uFE0F$/, '')];
2022-06-04 16:29:58 -07:00
if (!mapping) {
return null;
}
2022-07-04 13:30:35 -07:00
url = joinPublicPath(`packs/emoji/${mapping.unified}.svg`);
2022-07-04 20:11:46 -07:00
alt = emoji.native;
2022-06-04 16:29:58 -07:00
}
return (
<div className='autosuggest-emoji' data-testid='emoji'>
<img
className='emojione'
src={url}
2022-07-04 20:11:46 -07:00
alt={alt}
2022-06-04 16:29:58 -07:00
/>
{emoji.colons}
</div>
);
};
export default AutosuggestEmoji;