Download wp-calypso/client/blocks/inline-help/inline-help-search-card.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/blocks/inline-help/inline-help-search-card.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/blocks/inline-help/inline-help-search-card.tsx
-
curl -L -o inline-help-search-card.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/blocks/inline-help/inline-help-search-card.tsx
2.06 kB
| /* eslint-disable no-restricted-imports */ | |
| import { recordTracksEvent } from '@automattic/calypso-analytics'; | |
| import debugFactory from 'debug'; | |
| import { useTranslate } from 'i18n-calypso'; | |
| import { useRef, useEffect } from 'react'; | |
| import SearchCard from 'calypso/components/search-card'; | |
| /** | |
| * Module variables | |
| */ | |
| const debug = debugFactory( 'calypso:inline-help' ); | |
| type Props = { | |
| searchQuery: string; | |
| location?: string; | |
| isVisible?: boolean; | |
| placeholder?: string; | |
| onSearch?: ( query: string ) => void; | |
| sectionName: string; | |
| }; | |
| const AUTO_FOCUS_LOCATION = [ 'help-center', 'inline-help-popover' ]; | |
| const InlineHelpSearchCard = ( { | |
| searchQuery = '', | |
| location = 'inline-help-popover', | |
| isVisible = true, | |
| placeholder, | |
| onSearch, | |
| sectionName, | |
| }: Props ) => { | |
| const cardRef = useRef< { searchInput: HTMLInputElement } >(); | |
| const translate = useTranslate(); | |
| // Focus in the input element. | |
| useEffect( () => { | |
| const inputElement = cardRef.current?.searchInput; | |
| if ( ! AUTO_FOCUS_LOCATION.includes( location ) || ! inputElement || ! isVisible ) { | |
| return; | |
| } | |
| const timerId = setTimeout( () => inputElement.focus(), 0 ); | |
| return () => window.clearTimeout( timerId ); | |
| }, [ cardRef, location, isVisible ] ); | |
| const searchHelperHandler = ( query: string ) => { | |
| const inputQuery = query.trim(); | |
| if ( location === 'help-center' ) { | |
| if ( inputQuery?.length > 2 ) { | |
| recordTracksEvent( 'calypso_inlinehelp_search', { | |
| search_query: query, | |
| location: location, | |
| section: sectionName, | |
| } ); | |
| } | |
| } else if ( inputQuery?.length ) { | |
| debug( 'search query received: ', query ); | |
| recordTracksEvent( 'calypso_inlinehelp_search', { | |
| search_query: query, | |
| location: location, | |
| section: sectionName, | |
| } ); | |
| } | |
| // Set the query search | |
| onSearch?.( query ); | |
| }; | |
| return ( | |
| <SearchCard | |
| ref={ cardRef } | |
| initialValue={ searchQuery } | |
| onSearch={ searchHelperHandler } | |
| placeholder={ placeholder || translate( 'Search for help…' ) } | |
| delaySearch | |
| /> | |
| ); | |
| }; | |
| export default InlineHelpSearchCard; | |