Skip to content

Commit

Permalink
Merge pull request #39 from azeezat/feat/search
Browse files Browse the repository at this point in the history
refactor: searchControls
  • Loading branch information
azeezat authored Sep 8, 2023
2 parents 1998326 + dd1891a commit 83b2fa1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ For more examples visit our [wiki page](https://github.com/azeezat/react-native-
| listFooterComponent | `React Component` | `<Text> You can add any component here <Text>` |
| hideModal | `Boolean` | Use this to hide the modal as needed |
| listComponentStyles | `Object` | `{listEmptyComponentStyle: ViewStyle, itemSeparatorStyle: ViewStyle, sectionHeaderStyle: TextStyle}` |
| checkboxComponentStyles | `Object` | `{checkboxSize?: number, checkboxStyle?: ViewStyle, checkboxLabelStyle: TextStyle}` |
| checkboxComponentStyles | `Object` | `{checkboxSize: number, checkboxStyle: ViewStyle, checkboxLabelStyle: TextStyle}` |
| checkboxComponent | `React Component` | `<View style={styles.radioButton} />` |
| listControls | `Object` | `{ selectAllText: 'Choose all', unselectAllText: 'Remove all', selectAllCallback?: () => {}, unselectAllCallback?: () => {}}` |
| searchControls | `Object` | `{ searchInputStyle?: ViewStyle | TextStyle, textInputProps: TextInputProps}` |
| listControls | `Object` | `{ selectAllText: 'Choose all', unselectAllText: 'Remove all', selectAllCallback: () => {}, unselectAllCallback: () => {}}` |
| searchControls | `Object` | `{ textInputStyle: ViewStyle \| TextStyle, textInputContainerStyle: ViewStyle, textInputProps: TextInputProps}` |

## Deprecation Notice

Expand All @@ -295,20 +295,29 @@ checkboxComponentStyles = {
};
```

- `searchInputStyle` would now be inside `searchControls`
- `searchInputStyle` would now be inside replaced with `textInputStyle` in the `searchControls` object

```js
searchControls={{
searchInputStyle: {
backgroundColor: 'yellow',
searchControls={
textInputStyle: {
color: 'blue',
fontWeight: '900',
fontWeight: '500',
minHeight: 10,
paddingVertical: 10,
paddingHorizontal: 5,
width: '50%',
textAlign: 'center',
},
textInputContainerStyle: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
textInputProps: {
placeholder: 'Search anything here',
placeholderTextColor: 'gray',
},
}}
}
```

## Contributing
Expand Down
15 changes: 12 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,19 @@ export default function App() {
}
dropdownIconStyle={users && { top: 20, right: 15 }}
searchControls={{
searchInputStyle: {
backgroundColor: 'yellow',
textInputStyle: {
color: 'blue',
fontWeight: '900',
fontWeight: '500',
minHeight: 10,
paddingVertical: 10,
paddingHorizontal: 5,
width: '50%',
textAlign: 'center',
},
textInputContainerStyle: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
textInputProps: {
placeholder: 'Search anything here',
Expand Down
3 changes: 1 addition & 2 deletions src/components/CustomModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { colors } from '../../styles/colors';

const CustomModal = ({
open,
handleToggleModal,
onRequestClose,
modalBackgroundStyle,
modalOptionsContainerStyle,
Expand All @@ -25,7 +24,7 @@ const CustomModal = ({
{...modalProps}
>
<TouchableOpacity
onPress={() => handleToggleModal()}
onPress={() => onRequestClose()}
style={[
styles.modalContainer,
styles.modalBackgroundStyle,
Expand Down
9 changes: 7 additions & 2 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export const Input = ({
onChangeText,
style,
primaryColor,
textInputContainerStyle,
openModal,
...rest
}: any) => {
const [isFocused, setFocus] = useState(false);

return (
<View style={styles.container}>
<View style={[styles.container, textInputContainerStyle]}>
<TextInput
placeholder={placeholder}
style={[
Expand All @@ -26,7 +28,10 @@ export const Input = ({
isFocused && { borderColor: primaryColor },
style,
]}
onFocus={() => setFocus(true)}
onFocus={() => {
setFocus(true);
openModal();
}}
onBlur={() => setFocus(false)}
value={value}
onChangeText={onChangeText}
Expand Down
19 changes: 12 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
itemIndex: number;
}>({ itemIndex: 0 }); // for scrollToIndex in Sectionlist and Flatlist

if (!options || options.length === 0) {
throw new Error('Options array cannot be empty or undefined');
}

useEffect(() => {
if (options) {
setNewOptions(options);
}
setNewOptions(options);
return () => {};
}, [options]);

Expand Down Expand Up @@ -342,22 +344,25 @@ export const DropdownSelect: React.FC<DropdownProps> = ({
/>
<CustomModal
open={open}
handleToggleModal={handleToggleModal}
modalBackgroundStyle={modalBackgroundStyle}
modalOptionsContainerStyle={modalOptionsContainerStyle}
onRequestClose={() => {}}
onRequestClose={() => handleToggleModal()}
modalProps={modalProps}
>
<ListTypeComponent
keyboardShouldPersistTaps="always"
removeClippedSubviews={false}
ListHeaderComponent={
<>
{isSearchable && (
<Input
value={searchValue}
onChangeText={(text: string) => onSearch(text)}
style={searchControls?.searchInputStyle || searchInputStyle}
style={searchControls?.textInputStyle || searchInputStyle}
primaryColor={primary}
textInputContainerStyle={
searchControls?.textInputContainerStyle
}
openModal={() => setOpen(true)} // There seems to a known issue on expo web that closes the modal when the input is focused
{...searchControls?.textInputProps}
/>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export type DropdownProps = {
unselectAllCallback?: () => void;
};
searchControls?: {
searchInputStyle?: ViewStyle | TextStyle;
textInputStyle?: ViewStyle | TextStyle;
textInputContainerStyle?: ViewStyle;
textInputProps?: TextInputProps;
};
};
Expand Down

0 comments on commit 83b2fa1

Please sign in to comment.