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";
|
2024-03-07 09:09:31 +08:00
|
|
|
import { Image, View } from "react-native";
|
2023-04-15 02:05:35 +01:00
|
|
|
|
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-04-15 02:05:35 +01:00
|
|
|
|
2023-12-21 03:30:21 +08:00
|
|
|
return <ErrorBoundary>
|
2024-03-07 09:09:31 +08:00
|
|
|
<View style={style}>
|
|
|
|
|
<TextInput
|
2024-06-04 20:46:50 +08:00
|
|
|
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}
|
2024-06-04 20:46:50 +08:00
|
|
|
returnKeyType="search"
|
2023-12-21 03:30:21 +08:00
|
|
|
size="md"
|
|
|
|
|
autoCapitalize="none"
|
|
|
|
|
autoCorrect={false}
|
|
|
|
|
value={query}
|
|
|
|
|
/>
|
2024-03-07 09:09:31 +08:00
|
|
|
</View>
|
2024-03-06 01:57:59 +08:00
|
|
|
</ErrorBoundary>;
|
|
|
|
|
};
|