Files
t3code/apps/mobile/src/components/MaterialSearchField.tsx
T

74 lines
2.2 KiB
TypeScript

import type { RefObject } from "react";
import { Pressable, TextInput, type TextInputInstance, View } from "react-native";
import { SymbolView } from "./AppSymbol";
import { useAndroidControlSizing } from "./useAndroidControlSizing";
export function MaterialSearchField({
inputRef,
accessibilityLabel,
clearAccessibilityLabel,
placeholder,
value,
onChangeText,
}: {
readonly inputRef: RefObject<TextInputInstance | null>;
readonly accessibilityLabel: string;
readonly clearAccessibilityLabel: string;
readonly placeholder: string;
readonly value: string;
readonly onChangeText: (value: string) => void;
}) {
const { scale, mediumIconSize } = useAndroidControlSizing();
return (
<View
className="min-w-0 flex-1 flex-row items-center rounded-full border border-input-border bg-input"
style={{
minHeight: Math.max(48, 42 * scale),
gap: 7 * scale,
paddingHorizontal: 10.5 * scale,
}}
>
<SymbolView
name="magnifyingglass"
size={mediumIconSize}
tintColorClassName="accent-foreground-muted"
/>
<TextInput
ref={inputRef}
accessibilityLabel={accessibilityLabel}
autoFocus
autoCapitalize="none"
autoCorrect={false}
returnKeyType="search"
placeholder={placeholder}
placeholderTextColorClassName="accent-placeholder"
selectionColorClassName="accent-focus/32"
cursorColorClassName="accent-focus"
selectionHandleColorClassName="accent-focus"
className="min-w-0 flex-1 font-sans text-base text-foreground"
style={{ paddingVertical: 7 * scale }}
value={value}
onChangeText={onChangeText}
/>
{value.length > 0 ? (
<Pressable
accessibilityLabel={clearAccessibilityLabel}
accessibilityRole="button"
hitSlop={10}
onPress={() => {
onChangeText("");
inputRef.current?.focus();
}}
>
<SymbolView
name="xmark.circle.fill"
size={mediumIconSize}
tintColorClassName="accent-foreground-muted"
/>
</Pressable>
) : null}
</View>
);
}