mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-14 00:08:46 +00:00
32 lines
804 B
TypeScript
32 lines
804 B
TypeScript
import type { ComponentPropsWithoutRef, ElementType } from 'react';
|
|
|
|
import { useEmojify } from './hooks';
|
|
import type { CustomEmojiMapArg } from './types';
|
|
|
|
type EmojiHTMLProps<Element extends ElementType = 'div'> = Omit<
|
|
ComponentPropsWithoutRef<Element>,
|
|
'dangerouslySetInnerHTML'
|
|
> & {
|
|
htmlString: string;
|
|
extraEmojis?: CustomEmojiMapArg;
|
|
as?: Element;
|
|
};
|
|
|
|
export const EmojiHTML = <Element extends ElementType>({
|
|
extraEmojis,
|
|
htmlString,
|
|
as: asElement, // Rename for syntax highlighting
|
|
...props
|
|
}: EmojiHTMLProps<Element>) => {
|
|
const Wrapper = asElement ?? 'div';
|
|
const emojifiedHtml = useEmojify(htmlString, extraEmojis);
|
|
|
|
if (emojifiedHtml === null) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<Wrapper {...props} dangerouslySetInnerHTML={{ __html: emojifiedHtml }} />
|
|
);
|
|
};
|