-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ALF text input for generic search input (#5511)
* alf text input for generic search input * clearer ref naming * Adjust props and definition * Migrate props * Migrate props * Migrate props * Replace on search screen * rm old props --------- Co-authored-by: Eric Bailey <[email protected]>
- Loading branch information
1 parent
b4941d8
commit 2129f69
Showing
8 changed files
with
129 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React from 'react' | ||
import {TextInput, View} from 'react-native' | ||
import {msg} from '@lingui/macro' | ||
import {useLingui} from '@lingui/react' | ||
|
||
import {HITSLOP_10} from '#/lib/constants' | ||
import {isNative} from '#/platform/detection' | ||
import {atoms as a, useTheme} from '#/alf' | ||
import {Button, ButtonIcon} from '#/components/Button' | ||
import * as TextField from '#/components/forms/TextField' | ||
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as MagnifyingGlassIcon} from '#/components/icons/MagnifyingGlass2' | ||
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' | ||
|
||
type SearchInputProps = Omit<TextField.InputProps, 'label'> & { | ||
label?: TextField.InputProps['label'] | ||
/** | ||
* Called when the user presses the (X) button | ||
*/ | ||
onClearText?: () => void | ||
} | ||
|
||
export const SearchInput = React.forwardRef<TextInput, SearchInputProps>( | ||
function SearchInput({value, label, onClearText, ...rest}, ref) { | ||
const t = useTheme() | ||
const {_} = useLingui() | ||
|
||
return ( | ||
<View style={[a.w_full, a.relative]}> | ||
<TextField.Root> | ||
<TextField.Icon icon={MagnifyingGlassIcon} /> | ||
<TextField.Input | ||
inputRef={ref} | ||
label={label || _(msg`Search`)} | ||
value={value} | ||
placeholder={_(msg`Search`)} | ||
returnKeyType="search" | ||
keyboardAppearance={t.scheme} | ||
selectTextOnFocus={isNative} | ||
autoFocus={false} | ||
accessibilityRole="search" | ||
autoCorrect={false} | ||
autoComplete="off" | ||
autoCapitalize="none" | ||
{...rest} | ||
/> | ||
</TextField.Root> | ||
|
||
{value && value.length > 0 && ( | ||
<View | ||
style={[ | ||
a.absolute, | ||
a.z_10, | ||
a.my_auto, | ||
a.inset_0, | ||
a.justify_center, | ||
a.pr_sm, | ||
{left: 'auto'}, | ||
]}> | ||
<Button | ||
testID="searchTextInputClearBtn" | ||
onPress={onClearText} | ||
label={_(msg`Clear search query`)} | ||
hitSlop={HITSLOP_10} | ||
size="tiny" | ||
shape="round" | ||
variant="ghost" | ||
color="secondary"> | ||
<ButtonIcon icon={X} size="xs" /> | ||
</Button> | ||
</View> | ||
)} | ||
</View> | ||
) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.