Skip to content

Commit ae5c524

Browse files
committed
Add Typing for list items and update index.d.ts
1 parent b1e2bdd commit ae5c524

File tree

2 files changed

+93
-68
lines changed

2 files changed

+93
-68
lines changed

index.d.ts

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,72 @@
1-
import {ViewStyle} from 'react-native';
2-
1+
import React from "react";
2+
import { ViewStyle, TextStyle } from "react-native";
33

44
export interface CountryCodeProps {
5-
/**
6-
* Selected Country Dial Code
7-
*/
8-
selected: string,
9-
/**
10-
* Function to set the country
11-
*/
12-
setSelected: React.Dispatch<React.SetStateAction<undefined>>,
13-
/**
14-
* Function to set the country
15-
*/
16-
setCountryDetails: React.Dispatch<React.SetStateAction<undefined>>,
17-
/**
18-
* State variable for storing the phone number
19-
*/
20-
phone?: string,
21-
/**
22-
* Function to set the phone number state variable
23-
*/
24-
setPhone?: React.Dispatch<React.SetStateAction<undefined>>,
25-
/**
26-
* Style the Country Code Container
27-
*/
28-
countryCodeContainerStyles?: ViewStyle,
29-
/**
30-
* Style the text inside Country Code
31-
*/
32-
countryCodeTextStyles?: ViewStyle,
33-
/**
34-
* Phone Text Input Styles
35-
*/
36-
phoneStyles?: ViewStyle,
37-
/**
38-
* URL for the search Icon
39-
*/
40-
searchIcon?: string,
41-
/**
42-
* URL for the close Icon
43-
*/
44-
closeIcon?: string,
45-
/**
46-
* Search Input Container Styles
47-
*/
48-
searchStyles?: ViewStyle,
49-
/**
50-
* Search Input Text Styles
51-
*/
52-
searchTextStyles?: ViewStyle,
53-
/**
54-
* Search Dropdown Container Styles
55-
*/
56-
dropdownStyles?: ViewStyle,
57-
/**
58-
* Search Dropdown Text Styles
59-
*/
60-
dropdownTextStyles?: ViewStyle
5+
/**
6+
* Selected Country Dial Code
7+
*/
8+
selected: string;
9+
/**
10+
* Function to set the country
11+
*/
12+
setSelected: React.Dispatch<React.SetStateAction<undefined>>;
13+
/**
14+
* Function to set the country
15+
*/
16+
setCountryDetails: React.Dispatch<React.SetStateAction<undefined>>;
17+
/**
18+
* State variable for storing the phone number
19+
*/
20+
phone?: string;
21+
/**
22+
* Function to set the phone number state variable
23+
*/
24+
setPhone?: React.Dispatch<React.SetStateAction<undefined>>;
25+
/**
26+
* Style the Country Code Container
27+
*/
28+
countryCodeContainerStyles?: ViewStyle;
29+
/**
30+
* Style the text inside Country Code
31+
*/
32+
countryCodeTextStyles?: TextStyle;
33+
/**
34+
* Phone Text Input Styles
35+
*/
36+
phoneStyles?: ViewStyle;
37+
/**
38+
* URL for the search Icon
39+
*/
40+
searchIcon?: string;
41+
/**
42+
* URL for the close Icon
43+
*/
44+
closeIcon?: string;
45+
/**
46+
* Search Input Container Styles
47+
*/
48+
searchStyles?: ViewStyle;
49+
/**
50+
* Search Input Text Styles
51+
*/
52+
searchTextStyles?: TextStyle;
53+
/**
54+
* Search Dropdown Container Styles
55+
*/
56+
dropdownStyles?: ViewStyle;
57+
/**
58+
* Search Dropdown Text Styles
59+
*/
60+
dropdownTextStyles?: TextStyle;
61+
/**
62+
* Search Dropdown List Item Styles
63+
*/
64+
dropdownTextContainerStyles?: ViewStyle;
65+
}
6166

62-
}
67+
export interface CountryCodeDropdownItemProps {
68+
name: string;
69+
dial_code: string;
70+
code: string;
71+
flag: string;
72+
}

index.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
} from "react-native";
1414
import { countries, _getFlag } from "./_inc/_lib/enhanced";
1515

16+
const Countries: CountryCodeDropdownItemProps[] = countries;
17+
1618
interface CountryCodeProps {
1719
/**
1820
* Selected Country Dial Code
@@ -21,19 +23,21 @@ interface CountryCodeProps {
2123
/**
2224
* Function to set the country
2325
*/
24-
setSelected: React.Dispatch<React.SetStateAction<undefined>>;
26+
setSelected: React.Dispatch<React.SetStateAction<string>>;
2527
/**
2628
* Function to set the country
2729
*/
28-
setCountryDetails: React.Dispatch<React.SetStateAction<undefined>>;
30+
setCountryDetails: React.Dispatch<
31+
React.SetStateAction<CountryCodeDropdownItemProps>
32+
>;
2933
/**
3034
* State variable for storing the phone number
3135
*/
3236
phone?: string;
3337
/**
3438
* Function to set the phone number state variable
3539
*/
36-
setPhone?: React.Dispatch<React.SetStateAction<undefined>>;
40+
setPhone?: React.Dispatch<React.SetStateAction<string | undefined>>;
3741
/**
3842
* Style the Country Code Container
3943
*/
@@ -72,11 +76,18 @@ interface CountryCodeProps {
7276
*/
7377
dropdownTextStyles?: TextStyle;
7478
/**
75-
* Search Dropdown Text Container Styles
79+
* Search Dropdown List Item Styles
7680
*/
7781
dropdownTextContainerStyles?: ViewStyle;
7882
}
7983

84+
interface CountryCodeDropdownItemProps {
85+
name: string;
86+
dial_code: string;
87+
code: string;
88+
flag: string;
89+
}
90+
8091
const CountryCodeDropdownPicker: React.FC<CountryCodeProps> = ({
8192
selected,
8293
setSelected,
@@ -96,7 +107,7 @@ const CountryCodeDropdownPicker: React.FC<CountryCodeProps> = ({
96107
}) => {
97108
const [_selected, _setSelected] = React.useState(false);
98109
const [_search, _setSearch] = React.useState("");
99-
const [_countries, _setCountries] = React.useState(countries);
110+
const [_countries, _setCountries] = React.useState(Countries);
100111

101112
const slideAnim = React.useRef(new Animated.Value(0)).current;
102113

@@ -122,9 +133,9 @@ const CountryCodeDropdownPicker: React.FC<CountryCodeProps> = ({
122133
}).start(() => _setSelected(false));
123134
};
124135

125-
function _searchCountry(country) {
136+
function _searchCountry(country: string) {
126137
_setSearch(country);
127-
let c = countries.filter((item) => {
138+
let c = Countries.filter((item) => {
128139
return item.name.includes(country);
129140
});
130141
_setCountries(c);
@@ -137,7 +148,7 @@ const CountryCodeDropdownPicker: React.FC<CountryCodeProps> = ({
137148
<TouchableOpacity
138149
style={{ flexDirection: "row" }}
139150
onPress={() => {
140-
_setCountries(countries);
151+
_setCountries(Countries);
141152
slideDown();
142153
}}
143154
>
@@ -209,7 +220,11 @@ const CountryCodeDropdownPicker: React.FC<CountryCodeProps> = ({
209220
}
210221
};
211222

212-
const renderCountryItem = ({ item }) => {
223+
const renderCountryItem = ({
224+
item,
225+
}: {
226+
item: CountryCodeDropdownItemProps;
227+
}) => {
213228
return (
214229
<TouchableOpacity
215230
style={[styles.countryContainer, dropdownTextContainerStyles]}

0 commit comments

Comments
 (0)