import { type NativeSyntheticEvent, type TextInput, type TextInputKeyPressEventData, View, } from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {HITSLOP_10} from '#/lib/constants' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonIcon} from '#/components/Button' import * as TextField from '#/components/forms/TextField' import {MagnifyingGlass_Stroke2_Corner0_Rounded as MagnifyingGlassIcon} from '#/components/icons/MagnifyingGlass' import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' import {IS_NATIVE} from '#/env' type SearchInputProps = Omit & { ref?: React.Ref label?: TextField.InputProps['label'] /** * Called when the user presses the (X) button */ onClearText?: () => void /** * Called when the user presses the Escape key */ onEscape?: () => void } export function SearchInput({ ref, value, label, onClearText, onEscape, ...rest }: SearchInputProps) { const t = useTheme() const {_} = useLingui() const showClear = value && value.length > 0 const onKeyPress = ( evt: NativeSyntheticEvent, ) => { if (evt.nativeEvent.key === 'Escape') { onEscape?.() } } return ( {showClear && ( )} ) }