import type React from 'react'; import { useEffect, useState } from 'react'; import { useUIKit, IconBeautyAR } from '@tencentcloud/uikit-base-component-react'; import cs from 'classnames'; import { Popup } from '../../../baseComp/Popup'; import { View } from 'tuikit-atomicx-react/chat'; import { emojiUrlMap, emojiBaseUrl } from '../../../constant/emoji'; import { useChatUIState } from '../../../context/useChatUIState'; import { MessageContentType } from '../../../types/messageInput'; import { transformTextWithEmojiKeyToName } from '../../../utils/emoji'; import classes from './EmojiPicker.module.scss'; interface EmojiPickerProps { className?: string; style?: React.CSSProperties; disabled?: boolean; } function EmojiPicker({ className = '', style = {}, disabled = false, }: EmojiPickerProps) { const { t, direction } = useUIKit(); const { insertInputContent } = useChatUIState(); const [anchor, setAnchor] = useState(null); // image preload useEffect(() => { Object.values(emojiUrlMap).forEach((url) => { const img = new Image(); img.src = emojiBaseUrl + url; }); }, []); function insertEmojiToInput(emojiKey: string) { if (emojiKey) { insertInputContent([{ type: MessageContentType.EMOJI, content: { url: emojiBaseUrl + emojiUrlMap[emojiKey], key: emojiKey, text: transformTextWithEmojiKeyToName(emojiKey), }, }]); } } function onEmojiPickerClickAway() { setAnchor(null); } return (
) => { if (disabled) return; setAnchor(e.currentTarget); }} >
{ if (!open) { onEmojiPickerClickAway(); } }} anchor={anchor} placement={direction === 'ltr' ? 'top-start' : 'top-end'} offset={10} > { Object.keys(emojiUrlMap).map((emojiKey: string) => ( { insertEmojiToInput(emojiKey); setAnchor(null); }} > {t(`Emoji.${emojiKey}`)} )) }
); } export { EmojiPicker };