import React, { useState, useEffect } from 'react'; import { Portal } from 'soapbox/components/ui'; import EmojiSelector from 'soapbox/components/ui/emoji-selector/emoji-selector'; interface IChatMessageReactionWrapper { onOpen(isOpen: boolean): void onSelect(emoji: string): void children: JSX.Element } /** * Emoji Reaction Selector */ function ChatMessageReactionWrapper(props: IChatMessageReactionWrapper) { const { onOpen, onSelect, children } = props; const [isOpen, setIsOpen] = useState(false); const [referenceElement, setReferenceElement] = useState(null); const handleSelect = (emoji: string) => { onSelect(emoji); setIsOpen(false); }; const onToggleVisibility = () => setIsOpen((prevValue) => !prevValue); useEffect(() => { onOpen(isOpen); }, [isOpen]); return ( {React.cloneElement(children, { ref: setReferenceElement, onClick: onToggleVisibility, })} setIsOpen(false)} offset={[-10, 12]} all={false} /> ); } export default ChatMessageReactionWrapper;