import * as React from 'react'; import classNames from 'classnames'; import { Emoji } from '../emoji/Emoji'; import { useRestoreFocus } from '../hooks'; export type OwnProps = { selected?: string; onClose?: () => unknown; onPick: (emoji: string) => unknown; }; export type Props = OwnProps & Pick, 'style'>; const emojis = ['❤️', '👍', '👎', '😂', '😮', '😢', '😡']; export const ReactionPicker = React.forwardRef( ({ selected, onClose, onPick, ...rest }, ref) => { const focusRef = React.useRef(null); // Handle escape key React.useEffect(() => { const handler = (e: KeyboardEvent) => { if (onClose && e.key === 'Escape') { onClose(); } }; document.addEventListener('keydown', handler); return () => { document.removeEventListener('keydown', handler); }; }, [onClose]); // Focus first button and restore focus on unmount useRestoreFocus(focusRef); return (
{emojis.map((emoji, index) => { const maybeFocusRef = index === 0 ? focusRef : undefined; return ( ); })}
); } );