import clsx from 'clsx';
import * as React from 'react';
import { ClassNames } from '../../DomUtils/classNames';
import { DataEmoji } from '../../dataUtils/DataTypes';
import {
emojiByUnified,
emojiHasVariations,
emojiName,
emojiNames,
emojiUrlByUnified,
} from '../../dataUtils/emojiSelectors';
import { parseNativeEmoji } from '../../dataUtils/parseNativeEmoji';
import { EmojiStyle } from '../../types/exposedTypes';
import { Button } from '../atoms/Button';
import { useEmojisThatFailedToLoadState } from '../context/PickerContext';
import './Emoji.css';
type ClickableEmojiProps = Readonly<
BaseProps & {
hidden?: boolean;
showVariations?: boolean;
hiddenOnSearch?: boolean;
emoji: DataEmoji;
}
>;
type BaseProps = {
emoji?: DataEmoji;
emojiStyle: EmojiStyle;
unified: string;
size?: number;
lazyLoad?: boolean;
getEmojiUrl?: GetEmojiUrl;
};
export function ClickableEmoji({
emoji,
unified,
hidden,
hiddenOnSearch,
emojiStyle,
showVariations = true,
size,
lazyLoad,
getEmojiUrl,
}: ClickableEmojiProps) {
const hasVariations = emojiHasVariations(emoji);
return (
);
}
export function ViewOnlyEmoji({
emoji,
unified,
emojiStyle,
size,
lazyLoad,
getEmojiUrl = emojiUrlByUnified,
}: BaseProps) {
const style = {} as React.CSSProperties;
if (size) {
style.width = style.height = style.fontSize = `${size}px`;
}
const emojiToRender = emoji ? emoji : emojiByUnified(unified);
if(!emojiToRender) {
return null
}
return (
<>
{emojiStyle === EmojiStyle.NATIVE ? (
) : (
)}
>
);
}
function NativeEmoji({
unified,
style,
}: {
unified: string;
style: React.CSSProperties;
}) {
return (
{parseNativeEmoji(unified)}
);
}
function EmojiImg({
emoji,
unified,
emojiStyle,
style,
lazyLoad = false,
getEmojiUrl,
}: {
emoji: DataEmoji;
unified: string;
emojiStyle: EmojiStyle;
style: React.CSSProperties;
lazyLoad?: boolean;
getEmojiUrl: GetEmojiUrl;
}) {
const [, setEmojisThatFailedToLoad] = useEmojisThatFailedToLoadState();
return (
);
function onError() {
setEmojisThatFailedToLoad((prev) => new Set(prev).add(unified));
}
}
export type GetEmojiUrl = (unified: string, style: EmojiStyle) => string;