-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seperated search bar into its own component
- Loading branch information
1 parent
7df5939
commit 2d13856
Showing
6 changed files
with
154 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import { Text, TextInput, TouchableOpacity, View } from "react-native"; | ||
import Icon from "react-native-vector-icons/Feather"; | ||
|
||
import styles from "./SearchBarStyles"; | ||
|
||
type SearchBarProps = { | ||
query: string; | ||
setQuery: (query: string) => void; | ||
onFocus?: () => void; | ||
onBlur?: () => void; | ||
onClear: () => void; | ||
onCancel: () => void; | ||
isFocused: boolean; | ||
inputRef: React.RefObject<TextInput>; | ||
}; | ||
|
||
const SearchBar: React.FC<SearchBarProps> = ({ | ||
query, | ||
setQuery, | ||
onFocus, | ||
onBlur, | ||
onClear, | ||
onCancel, | ||
isFocused, | ||
inputRef, | ||
}) => { | ||
return ( | ||
<View style={styles.searchContainer}> | ||
<View style={styles.searchSection}> | ||
<Icon name="search" size={20} color="gray" style={styles.searchIcon} /> | ||
<TextInput | ||
ref={inputRef} | ||
style={styles.input} | ||
placeholder="Search" | ||
value={query} | ||
onChangeText={setQuery} | ||
onFocus={onFocus} | ||
onBlur={onBlur} | ||
selectionColor="#909090" | ||
/> | ||
{query.length > 0 && ( | ||
<TouchableOpacity onPress={onClear} style={{ padding: 10 }}> | ||
<Icon name="x" size={20} color="gray" /> | ||
</TouchableOpacity> | ||
)} | ||
</View> | ||
{isFocused && ( | ||
<TouchableOpacity onPress={onCancel} style={styles.cancelButton}> | ||
<Text>Cancel</Text> | ||
</TouchableOpacity> | ||
)} | ||
</View> | ||
); | ||
}; | ||
|
||
export default SearchBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { StyleSheet } from "react-native"; | ||
|
||
const styles = StyleSheet.create({ | ||
searchContainer: { | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
}, | ||
searchSection: { | ||
flexDirection: "row", | ||
flex: 1, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
borderWidth: 1, | ||
borderColor: "rgba(0, 0, 0, 0.4)", | ||
borderRadius: 10, | ||
margin: 0, | ||
marginBottom: 10, | ||
}, | ||
input: { | ||
flex: 1, | ||
paddingVertical: 10, | ||
color: "#424242", | ||
}, | ||
searchIcon: { | ||
padding: 10, | ||
}, | ||
cancelButton: { | ||
paddingLeft: 10, | ||
marginBottom: 8, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
overflow: "visible", | ||
}, | ||
}); | ||
|
||
export default styles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters