Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semi-revert #5651

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions src/components/forms/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react'
import {Pressable, TextInput, View} from 'react-native'
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, native, useTheme, web} from '#/alf'
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'
Expand All @@ -22,6 +23,7 @@ export const SearchInput = React.forwardRef<TextInput, SearchInputProps>(
function SearchInput({value, label, onClearText, ...rest}, ref) {
const t = useTheme()
const {_} = useLingui()
const showClear = value && value.length > 0

return (
<View style={[a.w_full, a.relative]}>
Expand All @@ -40,37 +42,41 @@ export const SearchInput = React.forwardRef<TextInput, SearchInputProps>(
autoCorrect={false}
autoComplete="off"
autoCapitalize="none"
style={[
showClear
? {
paddingRight: 24,
}
: {},
]}
{...rest}
/>
{value && value.length > 0 && (
<Pressable
</TextField.Root>

{showClear && (
<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}
accessibilityLabel={_(msg`Clear search query`)}
accessibilityHint={undefined}
label={_(msg`Clear search query`)}
hitSlop={HITSLOP_10}
style={[
a.z_20,
a.rounded_full,
a.align_center,
a.justify_center,
native(a.ml_xs),
web(a.ml_sm),
{width: 20, height: 20},
t.name === 'light'
? {backgroundColor: 'rgba(0, 0, 0, 0.1)'}
: {
backgroundColor: 'rgba(255, 255, 255, 0.1)',
},
]}>
<X
style={[t.atoms.text_contrast_medium]}
width={14}
height={14}
/>
</Pressable>
)}
</TextField.Root>
size="tiny"
shape="round"
variant="ghost"
color="secondary">
<ButtonIcon icon={X} size="xs" />
</Button>
</View>
)}
</View>
)
},
Expand Down
Loading