import React from 'react'; import styled from 'styled-components'; import type { ChangeEvent, JSX, SyntheticEvent } from 'react'; import { SearchIcon } from '@redocly/theme/icons/SearchIcon/SearchIcon'; import { Spinner } from '@redocly/theme/icons/Spinner/Spinner'; import { Button } from '@redocly/theme/components/Button/Button'; import { useInputKeyCommands, useRecentSearches, useThemeHooks } from '@redocly/theme/core/hooks'; import { CloseFilledIcon } from '@redocly/theme/icons/CloseFilledIcon/CloseFilledIcon'; import { ChevronLeftIcon } from '@redocly/theme/icons/ChevronLeftIcon/ChevronLeftIcon'; export type SearchInputProps = { placeholder?: string; value: string; onChange: (value: string) => void; inputRef?: React.RefObject; isLoading: boolean; showReturnButton?: boolean; onReturn?: () => void; onSubmit?: (evt: React.KeyboardEvent) => void; className?: string; }; export function SearchInput({ placeholder, value, onChange, isLoading, showReturnButton, inputRef, onReturn, onSubmit, className, }: SearchInputProps): JSX.Element { const { useTelemetry } = useThemeHooks(); const { addSearchHistoryItem } = useRecentSearches(); const telemetry = useTelemetry(); const { onKeyDown } = useInputKeyCommands({ onEnter: (event) => onSubmit?.(event), onClear: () => addSearchHistoryItem(value), }); const stopPropagation = (event: SyntheticEvent) => event.stopPropagation(); const handleOnChange = (event: ChangeEvent) => { onChange(event.target.value); }; const handleOnReset = () => { onChange(''); addSearchHistoryItem(value); telemetry.sendSearchInputResetButtonClickedMessage(); }; return ( {showReturnButton ? (