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";
import { requireAssetIndex } from "@lib/api/assets";
2024-03-07 12:35:07 +08:00
import { TextInput } from "@ui/components/discord/Redesign";
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() {
return <Image style={{ transform: [{ scale: 0.8 }] }} source={requireAssetIndex("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
isClearable
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"}
size="md"
autoCapitalize="none"
autoCorrect={false}
value={query}
/>
</View>
2024-03-06 01:57:59 +08:00
</ErrorBoundary>;
};