You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
import { Ionicons } from '@expo/vector-icons';
|
|
import { Pressable, StyleSheet, TextInput, View } from 'react-native';
|
|
import { colors } from '../../../src/theme';
|
|
|
|
interface Props {
|
|
value: string;
|
|
onChangeText: (t: string) => void;
|
|
placeholder?: string;
|
|
onClear?: () => void;
|
|
}
|
|
|
|
/** 带搜索图标与清除按钮的输入框 */
|
|
export function SearchInput({ value, onChangeText, placeholder = '搜索', onClear }: Props) {
|
|
return (
|
|
<View style={styles.box}>
|
|
<Ionicons name="search" size={18} color={colors.textHint} />
|
|
<TextInput
|
|
style={styles.input}
|
|
value={value}
|
|
onChangeText={onChangeText}
|
|
placeholder={placeholder}
|
|
placeholderTextColor={colors.textHint}
|
|
/>
|
|
{value.length > 0 ? (
|
|
<Pressable onPress={onClear} hitSlop={8}>
|
|
<Ionicons name="close-circle" size={18} color={colors.textHint} />
|
|
</Pressable>
|
|
) : null}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
box: {
|
|
flexDirection: 'row',
|
|
alignItems: 'center',
|
|
gap: 8,
|
|
height: 44,
|
|
paddingHorizontal: 14,
|
|
borderRadius: 12,
|
|
borderWidth: 1,
|
|
borderColor: colors.border,
|
|
backgroundColor: colors.white,
|
|
},
|
|
input: { flex: 1, fontSize: 15, color: colors.textPrimary },
|
|
});
|
|
|