import React, { useRef, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; // @ts-ignore import Overlay from 'react-overlays/lib/Overlay'; import ForkAwesomeIcon from 'soapbox/components/fork-awesome-icon'; import IconPickerMenu from './icon-picker-menu'; const messages = defineMessages({ emoji: { id: 'icon_button.label', defaultMessage: 'Select icon' }, }); interface IIconPickerDropdown { value: string onPickIcon: (icon: string) => void } const IconPickerDropdown: React.FC = ({ value, onPickIcon }) => { const intl = useIntl(); const [active, setActive] = useState(false); const [placement, setPlacement] = useState<'bottom' | 'top'>(); const target = useRef(null); const onShowDropdown: React.KeyboardEventHandler = ({ target }) => { setActive(true); const { top } = (target as any).getBoundingClientRect(); setPlacement(top * 2 < innerHeight ? 'bottom' : 'top'); }; const onHideDropdown = () => { setActive(false); }; const onToggle: React.KeyboardEventHandler = (e) => { e.stopPropagation(); if (!e.key || e.key === 'Enter') { if (active) { onHideDropdown(); } else { onShowDropdown(e); } } }; const handleKeyDown: React.KeyboardEventHandler = (e) => { if (e.key === 'Escape') { onHideDropdown(); } }; const title = intl.formatMessage(messages.emoji); const forkAwesomeIcons = require('../forkawesome.json'); return (
} onKeyDown={onToggle} tabIndex={0} >
); }; export default IconPickerDropdown;