GoonCord/src/lib/ui/components/Search.tsx

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-03-06 01:57:59 +08:00
import { Strings } from "@core/i18n";
2024-07-09 15:53:34 +08:00
import { findAssetId } from "@lib/api/assets";
2024-05-23 16:21:22 +08:00
import { TextInput } from "@metro/common/components";
2023-12-21 14:02:32 +08:00
import ErrorBoundary from "@ui/components/ErrorBoundary";
import { Image, View } from "react-native";
2024-02-23 15:11:35 +08:00
export interface SearchProps {
onChangeText?: (v: string) => void;
placeholder?: string;
style?: import("react-native").TextStyle;
}
2023-12-21 03:30:21 +08:00
function SearchIcon() {
2024-07-09 15:53:34 +08:00
return <Image style={{ width: 16, height: 16 }} source={findAssetId("search")} />;
2023-12-21 03:30:21 +08:00
}
2024-02-23 15:11:35 +08:00
2023-12-21 03:30:21 +08:00
export default ({ onChangeText, placeholder, style }: SearchProps) => {
const [query, setQuery] = React.useState("");
2024-03-06 01:57:59 +08:00
2023-12-21 03:30:21 +08:00
const onChange = (value: string) => {
setQuery(value);
onChangeText?.(value);
2024-03-06 01:57:59 +08:00
};
2023-12-21 03:30:21 +08:00
return <ErrorBoundary>
<View style={style}>
<TextInput
grow={true}
isClearable={true}
2023-12-21 03:30:21 +08:00
leadingIcon={SearchIcon}
2024-02-27 17:22:23 +08:00
placeholder={placeholder ?? Strings.SEARCH}
2023-12-21 03:30:21 +08:00
onChange={onChange}
returnKeyType="search"
2023-12-21 03:30:21 +08:00
size="md"
autoCapitalize="none"
autoCorrect={false}
value={query}
/>
</View>
2024-03-06 01:57:59 +08:00
</ErrorBoundary>;
};