1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import * as React from 'react';
    
  11. import {useContext} from 'react';
    
  12. import {TreeDispatcherContext, TreeStateContext} from './TreeContext';
    
  13. 
    
  14. import SearchInput from '../SearchInput';
    
  15. 
    
  16. type Props = {};
    
  17. 
    
  18. export default function ComponentSearchInput(props: Props): React.Node {
    
  19.   const {searchIndex, searchResults, searchText} = useContext(TreeStateContext);
    
  20.   const dispatch = useContext(TreeDispatcherContext);
    
  21. 
    
  22.   const search = (text: string) =>
    
  23.     dispatch({type: 'SET_SEARCH_TEXT', payload: text});
    
  24.   const goToNextResult = () => dispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'});
    
  25.   const goToPreviousResult = () =>
    
  26.     dispatch({type: 'GO_TO_PREVIOUS_SEARCH_RESULT'});
    
  27. 
    
  28.   return (
    
  29.     <SearchInput
    
  30.       goToNextResult={goToNextResult}
    
  31.       goToPreviousResult={goToPreviousResult}
    
  32.       placeholder="Search (text or /regex/)"
    
  33.       search={search}
    
  34.       searchIndex={searchIndex}
    
  35.       searchResultsCount={searchResults.length}
    
  36.       searchText={searchText}
    
  37.       testName="ComponentSearchInput"
    
  38.     />
    
  39.   );
    
  40. }