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 {createPortal} from 'react-dom';
    
  13. import SearchInput from 'react-devtools-shared/src/devtools/views/SearchInput';
    
  14. import {TimelineContext} from './TimelineContext';
    
  15. import {TimelineSearchContext} from './TimelineSearchContext';
    
  16. 
    
  17. type Props = {};
    
  18. 
    
  19. export default function TimelineSearchInput(props: Props): React.Node {
    
  20.   const {searchInputContainerRef} = useContext(TimelineContext);
    
  21.   const {dispatch, searchIndex, searchResults, searchText} = useContext(
    
  22.     TimelineSearchContext,
    
  23.   );
    
  24. 
    
  25.   if (searchInputContainerRef.current === null) {
    
  26.     return null;
    
  27.   }
    
  28. 
    
  29.   const search = (text: string) =>
    
  30.     dispatch({type: 'SET_SEARCH_TEXT', payload: text});
    
  31.   const goToNextResult = () => dispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'});
    
  32.   const goToPreviousResult = () =>
    
  33.     dispatch({type: 'GO_TO_PREVIOUS_SEARCH_RESULT'});
    
  34. 
    
  35.   return createPortal(
    
  36.     <SearchInput
    
  37.       goToNextResult={goToNextResult}
    
  38.       goToPreviousResult={goToPreviousResult}
    
  39.       placeholder="Search components by name"
    
  40.       search={search}
    
  41.       searchIndex={searchIndex}
    
  42.       searchResultsCount={searchResults.length}
    
  43.       searchText={searchText}
    
  44.     />,
    
  45.     searchInputContainerRef.current,
    
  46.   );
    
  47. }