import clsx from 'clsx'; import * as React from 'react'; import { useEffect } from 'react'; import { ClassNames } from '../../DomUtils/classNames'; import { focusFirstVisibleEmoji } from '../../DomUtils/keyboardNavigation'; import { buttonFromTarget, elementHeight, emojiTrueOffsetTop, emojiTruOffsetLeft } from '../../DomUtils/selectors'; import { useEmojiStyleConfig, useGetEmojiUrlConfig } from '../../config/useConfig'; import { emojiHasVariations, emojiUnified, emojiVariations } from '../../dataUtils/emojiSelectors'; import { useAnchoredEmojiRef, useBodyRef, useSetAnchoredEmojiRef, useVariationPickerRef } from '../context/ElementRefContext'; import { useEmojiVariationPickerState } from '../context/PickerContext'; import { ClickableEmoji } from '../emoji/Emoji'; import './EmojiVariationPicker.css'; enum Direction { Up, Down } export function EmojiVariationPicker() { const AnchoredEmojiRef = useAnchoredEmojiRef(); const VariationPickerRef = useVariationPickerRef(); const [emoji] = useEmojiVariationPickerState(); const emojiStyle = useEmojiStyleConfig(); const { getTop, getMenuDirection } = useVariationPickerTop( VariationPickerRef ); const setAnchoredEmojiRef = useSetAnchoredEmojiRef(); const getPointerStyle = usePointerStyle(VariationPickerRef); const getEmojiUrl = useGetEmojiUrlConfig(); const button = buttonFromTarget(AnchoredEmojiRef.current); const visible = emoji && button && emojiHasVariations(emoji) && button.classList.contains(ClassNames.emojiHasVariatios); useEffect(() => { if (!visible) { return; } focusFirstVisibleEmoji(VariationPickerRef.current); }, [VariationPickerRef, visible, AnchoredEmojiRef]); let top, pointerStyle; if (!visible && AnchoredEmojiRef.current) { setAnchoredEmojiRef(null); } else { top = getTop(); pointerStyle = getPointerStyle(); } return (