Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

MaterialSearchField.tsx

59 lines1.8 KB

1import type { RefObject } from "react";
2import { Pressable, TextInput, View } from "react-native";
3​
4import { SymbolView } from "./AppSymbol";
5​
6export function MaterialSearchField({
7 inputRef,
8 accessibilityLabel,
9 clearAccessibilityLabel,
10 placeholder,
11 value,
12 onChangeText,
13}: {
14 readonly inputRef: RefObject<TextInput | null>;
15 readonly accessibilityLabel: string;
16 readonly clearAccessibilityLabel: string;
17 readonly placeholder: string;
18 readonly value: string;
19 readonly onChangeText: (value: string) => void;
20}) {
21 return (
22 <View className="h-12 min-w-0 flex-1 flex-row items-center gap-2 rounded-full border border-input-border bg-input px-3">
23 <SymbolView name="magnifyingglass" size={18} tintColorClassName="accent-foreground-muted" />
24 <TextInput
25 ref={inputRef}
26 accessibilityLabel={accessibilityLabel}
27 autoFocus
28 autoCapitalize="none"
29 autoCorrect={false}
30 returnKeyType="search"
31 placeholder={placeholder}
32 placeholderTextColorClassName="accent-placeholder"
33 selectionColorClassName="accent-focus/32"
34 cursorColorClassName="accent-focus"
35 selectionHandleColorClassName="accent-focus"
36 className="min-w-0 flex-1 py-2 font-sans text-base text-foreground"
37 value={value}
38 onChangeText={onChangeText}
39 />
40 {value.length > 0 ? (
41 <Pressable
42 accessibilityLabel={clearAccessibilityLabel}
43 accessibilityRole="button"
44 hitSlop={10}
45 onPress={() => {
46 onChangeText("");
47 inputRef.current?.focus();
48 }}
49 >
50 <SymbolView
51 name="xmark.circle.fill"
52 size={18}
53 tintColorClassName="accent-foreground-muted"
54 />
55 </Pressable>
56 ) : null}
57 </View>
58 );