/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Icon, search } from '@wordpress/icons'; import { useEffect, useState } from '@wordpress/element'; import { navigateTo, getNewPath, useQuery } from '@woocommerce/navigation'; /** * Internal dependencies */ import './search.scss'; const searchPlaceholder = __( 'Search for extensions', 'woocommerce' ); /** * Search component. * * @return {JSX.Element} Search component. */ function Search(): JSX.Element { const [ searchTerm, setSearchTerm ] = useState( '' ); const query = useQuery(); useEffect( () => { if ( query.term ) { setSearchTerm( query.term ); } }, [ query.term ] ); const runSearch = () => { const term = searchTerm.trim(); // When the search term changes, we reset the category on purpose. navigateTo( { url: getNewPath( { term, category: null, tab: 'extensions' } ), } ); return []; }; const handleInputChange = ( event: React.ChangeEvent< HTMLInputElement > ) => { setSearchTerm( event.target.value ); }; const handleKeyUp = ( event: { key: string } ) => { if ( event.key === 'Enter' ) { runSearch(); } if ( event.key === 'Escape' ) { setSearchTerm( '' ); } }; return (