import React, { createRef, useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import Search from './Search'; function LeftMenuHeader({ count, search, searchable, setSearch, title }) { const [showSearch, setShowSearch] = useState(false); const ref = createRef(); useEffect(() => { if (showSearch && ref.current) { ref.current.focus(); } }, [ref, showSearch]); const toggleSearch = () => setShowSearch(!showSearch); const getTitle = () => { if (searchable) { return ( 1 ? 'plural' : 'singular'}`} /> ); } return ; }; const handleClose = () => { clearSearch(); toggleSearch(); }; const clearSearch = () => { setSearch(''); }; const handleChange = ({ target: { value } }) => { setSearch(value); }; return !showSearch ? (

{getTitle()}    {searchable && ( {count} )}

{searchable && ( )}
) : (
); } LeftMenuHeader.defaultProps = { count: 0, search: null, searchable: false, setSearch: () => {}, }; LeftMenuHeader.propTypes = { count: PropTypes.number, title: PropTypes.shape({ id: PropTypes.string.isRequired, }).isRequired, search: PropTypes.string, searchable: PropTypes.bool, setSearch: PropTypes.func, }; export default LeftMenuHeader;