diff --git a/README.md b/README.md index 552f951..40c381e 100644 --- a/README.md +++ b/README.md @@ -60,10 +60,10 @@ export default function App() { // For showing picker just put show state to show prop setShow(false)} // when picker button press you will get the country object with dial code pickerButtonOnPress={(item) => { setCountryCode(item.dial_code); - setShow(false); }} /> @@ -120,10 +120,10 @@ export default function App() { // For showing picker just put show state to show prop setShow(false)} // when picker button press you will get the country object with dial code pickerButtonOnPress={(item) => { setCountryCode(item.dial_code); - setShow(false); }} ListHeaderComponent={ListHeaderComponent} popularCountries={['en', 'ua', 'pl']} @@ -178,6 +178,7 @@ Below are the props you can pass to the React Component. | Prop | Type | Default | Example | Description | | -------------------------- | --------- | ------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | show | boolean | | | This prop using for displaying the modal. Put your show state here. | +| closeModal | function | | closeModal={() => setShow(false)} | Function used to close the modal. | | pickerButtonOnPress | function | | (country) => setCode(country.dial_code) | Put your function/functions here for getting country data from picker. | | inputPlaceholder | string | | inputPlaceholder={'Your placeholder'} | If you need a custom placeholder for your input you may need this prop. | | searchMessage | string | | searchMessage={'Some search message here'} | If you want to customize search message just use this prop. | @@ -193,6 +194,7 @@ Below are the props you can pass to the React Component. | showOnly | array | | showOnly={['UA', 'EN']} | This prop allow you to configure which countries you want to show. | | popularCountries | array | | popularCountries={['UA', 'EN']} | This prop allow you to send popular countries array to your ListHeaderComponent. | | ListHeaderComponent | JSX.Element | | ListHeaderComponent={ListHeaderComponent} | This prop allow you to create header component to show popular countries on top of list! Check example section with ListHeaderComponent | +| showCloseButton | boolean | true | buttonCloseModal={true} | show or not show the close button when the modal is open | :grey_exclamation: Also you can use all other FlatList and TextInput props if you need. :grey_exclamation: @@ -201,6 +203,7 @@ Below are the props you can pass to the React Component. ```JS setShow(false)} lang={'cz'} style={{ // Styles for whole modal [View] @@ -252,7 +255,6 @@ Below are the props you can pass to the React Component. }} pickerButtonOnPress={(item) => { setCountryCode(item.dial_code); - setShow(false); }} /> ``` diff --git a/index.tsx b/index.tsx index da5b226..24c4e0c 100644 --- a/index.tsx +++ b/index.tsx @@ -11,7 +11,8 @@ import { Keyboard, ViewStyle, Modal, - TextStyle + TextStyle, + TouchableOpacity } from 'react-native'; import { CountryItem, ItemTemplateProps, Style, ListHeaderComponentProps } from "./types/Types"; import { useKeyboardStatus } from "./helpers/useKeyboardStatus"; @@ -55,12 +56,14 @@ interface Props { show: boolean, enableModalAvoiding?: boolean, disableBackdrop?: boolean, + closeButton?: boolean, onBackdropPress?: (...args: any) => any, pickerButtonOnPress: (item: CountryItem) => any, itemTemplate?: (props: ItemTemplateProps) => JSX.Element, ListHeaderComponent?: (props: ListHeaderComponentProps) => JSX.Element, onRequestClose?: (...args: any) => any, + closeModal?: (...args: any) => any, lang: string, inputPlaceholder?: string, @@ -89,6 +92,8 @@ export const CountryPicker = ({ showOnly, ListHeaderComponent, itemTemplate: ItemTemplate = CountryButton, + closeModal: closeCountryPicker, + showCloseButton, ...rest }: Props) => { // ToDo refactor exclude and showOnly props to objects @@ -207,6 +212,7 @@ export const CountryPicker = ({ onPress={() => { Keyboard.dismiss(); typeof pickerButtonOnPress === 'function' && pickerButtonOnPress(item); + typeof closeCountryPicker === 'function' && closeCountryPicker() }} /> ); @@ -261,6 +267,14 @@ export const CountryPicker = ({ }, ]} > + {showCloseButton === false ? null : + closeCountryPicker ? closeCountryPicker() : null} + > + × + + } { Keyboard.dismiss(); typeof pickerButtonOnPress === 'function' && pickerButtonOnPress(item); + typeof closeCountryPicker === 'function' && closeCountryPicker() }} /> : null @@ -437,7 +452,7 @@ export const CountryList = ({ }; -type StyleKeys = 'container' | 'modal' | 'modalInner' | 'searchBar' | 'countryMessage' | 'line'; +type StyleKeys = 'container' | 'modal' | 'modalInner' | 'searchBar' | 'countryMessage' | 'line' | 'closeButton' | 'closeButtonText'; const styles: { [key in StyleKeys]: ViewStyle } = { container: { @@ -494,4 +509,29 @@ const styles: { [key in StyleKeys]: ViewStyle } = { alignSelf: 'center', marginVertical: 5, }, + closeButton: { + backgroundColor: '#ee6e73', + shadowColor: '#000', + shadowOffset: { + width: 0, + height: 2, + }, + shadowOpacity: 0.25, + shadowRadius: 3.84, + elevation: 5, + width: 60, + height: 60, + borderRadius: 100, + position: 'absolute', + bottom: 10, + alignSelf: 'center', + justifyContent: 'center', + alignItem: 'center', + zIndex: 999 + }, + closeButtonText:{ + textAlign: 'center', + color: '#0A0A0A', + fontSize: 32 + } }; diff --git a/types/Types.ts b/types/Types.ts index 58548c3..e9ece29 100644 --- a/types/Types.ts +++ b/types/Types.ts @@ -32,5 +32,7 @@ export interface Style { countryButtonStyles?: ViewStyle, flag?: TextStyle, dialCode?: TextStyle, - countryName?: TextStyle + countryName?: TextStyle, + closeButton?: ViewStyle, + closeButtonText?: TextStyle }