import React, { useState, createRef, useEffect } from 'react'; import { camelCase } from 'lodash'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; // TODO remove this import messages from './messages.json'; import Search from './Search'; import Title from './Title'; import SearchButton from './SearchButton'; import SearchWrapper from './SearchWrapper'; const LeftMenuLinkHeader = ({ section, searchable, setSearch, search }) => { const [showSearch, setShowSearch] = useState(false); const ref = createRef(); const { id, defaultMessage } = messages[camelCase(section)]; useEffect(() => { if (showSearch && ref.current) { ref.current.focus(); } }, [ref, showSearch]); const toggleSearch = () => { setShowSearch(prev => !prev); }; const handleChange = ({ target: { value } }) => { setSearch(value); }; const clearSearch = () => { setSearch(''); setShowSearch(false); }; return (