react-native-country-select 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -9,6 +9,31 @@ import {
9
9
  ICountrySelectLanguages,
10
10
  } from './interface';
11
11
 
12
+ declare function getAllCountries(): ICountry[];
13
+
14
+ declare function getCountryByCca2(cca2: string): ICountry | undefined;
15
+
16
+ declare function getCountryByCca3(cca3: string): ICountry | undefined;
17
+
18
+ declare function getCountriesByCallingCode(
19
+ callingCode: string,
20
+ ): ICountry[] | undefined;
21
+
22
+ declare function getCountriesByName(
23
+ name: string,
24
+ language: ICountrySelectLanguages,
25
+ ): ICountry[] | undefined;
26
+
27
+ declare function getCountriesByRegion(region: string): ICountry[] | undefined;
28
+
29
+ declare function getCountriesBySubregion(
30
+ subregion: string,
31
+ ): ICountry[] | undefined;
32
+
33
+ declare function getContriesDependents(cca2: string): ICountry[] | undefined;
34
+
35
+ declare function getCountriesIndependents(): ICountry[] | undefined;
36
+
12
37
  declare const CountrySelect: React.FC<ICountrySelectProps>;
13
38
 
14
39
  export default CountrySelect;
@@ -20,4 +45,13 @@ export {
20
45
  ICountrySelectProps,
21
46
  ICountrySelectStyle,
22
47
  ICountrySelectLanguages,
48
+ getAllCountries,
49
+ getCountryByCca2,
50
+ getCountryByCca3,
51
+ getCountriesByCallingCode,
52
+ getCountriesByName,
53
+ getCountriesByRegion,
54
+ getCountriesBySubregion,
55
+ getContriesDependents,
56
+ getCountriesIndependents,
23
57
  };
package/lib/index.tsx CHANGED
@@ -4,15 +4,40 @@ import {
4
4
  ICountryCca2,
5
5
  ICountryItemProps,
6
6
  ICountrySelectProps,
7
+ ICountrySelectStyle,
7
8
  ICountrySelectLanguages,
8
9
  } from './interface';
10
+ import {
11
+ getAllCountries,
12
+ getCountryByCca2,
13
+ getCountryByCca3,
14
+ getCountriesByCallingCode,
15
+ getCountriesByName,
16
+ getCountriesByRegion,
17
+ getCountriesBySubregion,
18
+ getContriesDependents,
19
+ getCountriesIndependents,
20
+ } from './utils/countryHelpers';
9
21
 
10
22
  export default CountrySelect;
11
23
 
24
+ export {
25
+ getAllCountries,
26
+ getCountryByCca2,
27
+ getCountryByCca3,
28
+ getCountriesByCallingCode,
29
+ getCountriesByName,
30
+ getCountriesByRegion,
31
+ getCountriesBySubregion,
32
+ getContriesDependents,
33
+ getCountriesIndependents,
34
+ };
35
+
12
36
  export type {
13
37
  ICountry,
14
38
  ICountryCca2,
15
39
  ICountryItemProps,
16
40
  ICountrySelectProps,
41
+ ICountrySelectStyle,
17
42
  ICountrySelectLanguages,
18
43
  };
@@ -8,5 +8,6 @@ export interface ICountryItemProps {
8
8
  onClose: () => void;
9
9
  language: ICountrySelectLanguages;
10
10
  theme?: 'light' | 'dark';
11
+ modalType?: 'bottomSheet' | 'popup';
11
12
  countrySelectStyle?: ICountrySelectStyle;
12
13
  }
@@ -1,16 +1,16 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import {ModalProps} from 'react-native';
3
-
4
3
  import {ICountry} from './country';
5
4
  import {ICountryCca2} from './countryCca2';
6
- import {ISectionTitle} from './sectionTitle';
7
- import {ICountrySelectStyle} from './countrySelectStyles';
8
5
  import {ICountrySelectLanguages} from './countrySelectLanguages';
6
+ import {ICountrySelectStyle} from './countrySelectStyles';
7
+ import {ISectionTitle} from './sectionTitle';
9
8
 
10
9
  export interface ICountrySelectProps extends ModalProps {
11
10
  visible: boolean;
12
11
  onClose: () => void;
13
12
  onSelect: (country: ICountry) => void;
13
+ modalType?: 'bottomSheet' | 'popup';
14
14
  countrySelectStyle?: ICountrySelectStyle;
15
15
  theme?: 'light' | 'dark';
16
16
  isFullScreen?: boolean;
@@ -20,12 +20,18 @@ export interface ICountrySelectProps extends ModalProps {
20
20
  language?: ICountrySelectLanguages;
21
21
  showSearchInput?: boolean;
22
22
  searchPlaceholder?: string;
23
+ showCloseButton?: boolean;
24
+ minBottomsheetHeight?: number | string;
25
+ maxBottomsheetHeight?: number | string;
26
+ initialBottomsheetHeight?: number | string;
23
27
  disabledBackdropPress?: boolean;
24
28
  removedBackdrop?: boolean;
25
29
  onBackdropPress?: () => void;
26
30
  countryItemComponent?: (item: ICountry) => React.ReactElement;
27
31
  sectionTitleComponent?: (item: ISectionTitle) => React.ReactElement;
32
+ closeButtonComponent?: () => React.ReactElement;
28
33
  popularCountriesTitle?: string;
29
34
  allCountriesTitle?: string;
30
35
  showsVerticalScrollIndicator?: boolean;
36
+ countryNotFoundMessage?: string;
31
37
  }
@@ -16,6 +16,8 @@ interface IBaseModalStyle {
16
16
  countryInfo?: StyleProp<ViewStyle>;
17
17
  callingCode?: StyleProp<TextStyle>;
18
18
  countryName?: StyleProp<TextStyle>;
19
+ countryNotFoundContainer?: StyleProp<ViewStyle>;
20
+ countryNotFoundMessage?: StyleProp<TextStyle>;
19
21
  }
20
22
 
21
23
  interface IPopupStyle extends IBaseModalStyle {
@@ -23,6 +25,12 @@ interface IPopupStyle extends IBaseModalStyle {
23
25
  popupContent?: StyleProp<ViewStyle>;
24
26
  }
25
27
 
28
+ interface IBottomSheetStyle extends IBaseModalStyle {
29
+ sheetContainer?: StyleProp<ViewStyle>;
30
+ sheetContent?: StyleProp<ViewStyle>;
31
+ }
32
+
26
33
  export interface ICountrySelectStyle {
27
34
  popup?: IPopupStyle;
35
+ bottomSheet?: IBottomSheetStyle;
28
36
  }
@@ -0,0 +1,59 @@
1
+ import {ICountry, ICountryCca2} from '../interface';
2
+ import countriesData from '../constants/countries.json';
3
+
4
+ const countries: ICountry[] = countriesData as unknown as ICountry[];
5
+
6
+ export const getAllCountries = (): ICountry[] => {
7
+ return countries;
8
+ };
9
+
10
+ export const getCountriesByCallingCode = (callingCode: string): ICountry[] => {
11
+ return countries.filter(
12
+ (country: ICountry) => country.idd.root === callingCode,
13
+ );
14
+ };
15
+
16
+ export const getCountriesByName = (
17
+ name: string,
18
+ language: keyof ICountry['translations'] = 'eng',
19
+ ): ICountry[] => {
20
+ return countries.filter((country: ICountry) => {
21
+ const translation = country.translations[language];
22
+ if (translation) {
23
+ return (
24
+ translation.common.toLowerCase().includes(name.toLowerCase()) ||
25
+ translation.official.toLowerCase().includes(name.toLowerCase())
26
+ );
27
+ }
28
+ return (
29
+ country.name.common.toLowerCase().includes(name.toLowerCase()) ||
30
+ country.name.official.toLowerCase().includes(name.toLowerCase())
31
+ );
32
+ });
33
+ };
34
+
35
+ export const getCountryByCca2 = (cca2: ICountryCca2): ICountry | undefined => {
36
+ return countries.find((country: ICountry) => country.cca2 === cca2);
37
+ };
38
+
39
+ export const getCountryByCca3 = (cca3: string): ICountry | undefined => {
40
+ return countries.find((country: ICountry) => country.cca3 === cca3);
41
+ };
42
+
43
+ export const getCountriesByRegion = (region: string): ICountry[] => {
44
+ return countries.filter((country: ICountry) => country.region === region);
45
+ };
46
+
47
+ export const getCountriesBySubregion = (subregion: string): ICountry[] => {
48
+ return countries.filter(
49
+ (country: ICountry) => country.subregion === subregion,
50
+ );
51
+ };
52
+
53
+ export const getCountriesIndependents = (): ICountry[] => {
54
+ return countries.filter((country: ICountry) => country.independent);
55
+ };
56
+
57
+ export const getContriesDependents = (): ICountry[] => {
58
+ return countries.filter((country: ICountry) => !country.independent);
59
+ };
@@ -3,7 +3,8 @@ import {ICountrySelectLanguages} from '../interface';
3
3
  type TranslationKey =
4
4
  | 'searchPlaceholder'
5
5
  | 'popularCountriesTitle'
6
- | 'allCountriesTitle';
6
+ | 'allCountriesTitle'
7
+ | 'searchNotFoundMessage';
7
8
  type TranslationMap = Record<
8
9
  TranslationKey,
9
10
  Record<ICountrySelectLanguages, string>
@@ -115,4 +116,39 @@ export const translations: TranslationMap = {
115
116
  'zho-Hans': '所有国家',
116
117
  'zho-Hant': '所有國家',
117
118
  },
119
+ searchNotFoundMessage: {
120
+ ara: 'لا توجد دول مطابقة',
121
+ bel: 'Краіны не знойдзены',
122
+ bre: "N'en eo bet",
123
+ bul: 'Няма намерени държави',
124
+ ces: 'Nebyly nalezeny žádné země',
125
+ deu: 'Keine Länder gefunden',
126
+ ell: 'Δεν βρέθηκαν χώρες',
127
+ eng: 'No countries found',
128
+ est: 'Riikuid ei leitud',
129
+ fin: 'Maita ei löytynyt',
130
+ fra: 'Aucun pays trouvé',
131
+ heb: 'לא נמצאו מדינות',
132
+ hrv: 'Nema pronađenih zemalja',
133
+ hun: 'Nem található ország',
134
+ ita: 'Nessun paese trovato',
135
+ jpn: '国が見つかりません',
136
+ kor: '국가를 찾을 수 없습니다',
137
+ nld: 'Geen landen gevonden',
138
+ per: 'هیچ کشوری یافت نشد',
139
+ pol: 'Nie znaleziono krajów',
140
+ por: 'Nenhum país encontrado',
141
+ ron: 'Nu s-au găsit țări',
142
+ rus: 'Страны не найдены',
143
+ slk: 'Nenašli sa žiadne krajiny',
144
+ spa: 'No se encontró ningún país',
145
+ srp: 'Нису пронађене државе',
146
+ swe: 'Inga länder hittades',
147
+ tur: 'Hiçbir ülke bulunamadı',
148
+ ukr: 'Країни не знайдено',
149
+ urd: 'کوئی ملک نہیں ملا',
150
+ zho: '没有找到国家',
151
+ 'zho-Hans': '没有找到国家',
152
+ 'zho-Hant': '找不到國家',
153
+ },
118
154
  } as const;
@@ -0,0 +1,35 @@
1
+ const parseHeight = (
2
+ value: number | string | undefined,
3
+ windowHeight: number,
4
+ ): number => {
5
+ if (value === undefined) {
6
+ return 0;
7
+ }
8
+
9
+ const MIN_ALLOWED_PERCENTAGE = 0.1; // 10%
10
+ const MAX_ALLOWED_PERCENTAGE = windowHeight; // 100%
11
+
12
+ if (typeof value === 'number') {
13
+ return Math.min(
14
+ Math.max(value, MIN_ALLOWED_PERCENTAGE * MAX_ALLOWED_PERCENTAGE),
15
+ MAX_ALLOWED_PERCENTAGE,
16
+ );
17
+ }
18
+
19
+ if (typeof value === 'string') {
20
+ const percentageMatch = value.match(/^(\d+(?:\.\d+)?)%$/);
21
+
22
+ if (percentageMatch) {
23
+ const percentage = parseFloat(percentageMatch[1]) / 100;
24
+ const height = percentage * MAX_ALLOWED_PERCENTAGE;
25
+ return Math.min(
26
+ Math.max(height, MIN_ALLOWED_PERCENTAGE * MAX_ALLOWED_PERCENTAGE),
27
+ MAX_ALLOWED_PERCENTAGE,
28
+ );
29
+ }
30
+ }
31
+
32
+ return 0;
33
+ };
34
+
35
+ export default parseHeight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-country-select",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "🌍 A lightweight and customizable country picker for React Native with modern UI, flags, search engine, and i18n support. Includes TypeScript types, offline support and no dependencies.",
5
5
  "main": "lib/index.tsx",
6
6
  "types": "lib/index.d.ts",