react-country-kit-core 1.3.0 → 2.0.0
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/README.md +256 -1
- package/dist/data/countries.d.ts +4 -4
- package/dist/data/currencies.d.ts +2 -2
- package/dist/data/divisions.d.ts +2 -2
- package/dist/data/languages.d.ts +2 -2
- package/dist/data/phoneFormats.d.ts +2 -2
- package/dist/data/timezones.d.ts +2 -2
- package/dist/hooks/useBasePicker.d.ts +4 -2
- package/dist/hooks/useCountry.d.ts +15 -0
- package/dist/hooks/useCountryPicker.d.ts +2 -2
- package/dist/hooks/useCurrencyPicker.d.ts +2 -2
- package/dist/hooks/useDivisionPicker.d.ts +2 -2
- package/dist/hooks/useLanguagePicker.d.ts +2 -2
- package/dist/hooks/useMultiSelect.d.ts +4 -2
- package/dist/hooks/usePhoneInput.d.ts +23 -9
- package/dist/hooks/useTimezonePicker.d.ts +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +693 -496
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +70 -34
- package/dist/utils/countries.d.ts +10 -13
- package/dist/utils/currencies.d.ts +4 -4
- package/dist/utils/languages.d.ts +4 -4
- package/dist/utils/phone.d.ts +21 -0
- package/dist/utils/timezones.d.ts +4 -4
- package/package.json +1 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface IPhoneFormat {
|
|
2
2
|
iso2: string;
|
|
3
3
|
dialCode: string;
|
|
4
4
|
patterns: string;
|
|
@@ -6,14 +6,14 @@ export interface PhoneFormat {
|
|
|
6
6
|
example: string | number;
|
|
7
7
|
countryCode: string;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface ICurrency {
|
|
10
10
|
code: string;
|
|
11
11
|
name: string;
|
|
12
12
|
symbol: string;
|
|
13
13
|
countryCode: string;
|
|
14
14
|
precision: number;
|
|
15
15
|
}
|
|
16
|
-
export interface
|
|
16
|
+
export interface ITimezone {
|
|
17
17
|
name: string;
|
|
18
18
|
offset: number;
|
|
19
19
|
offset_name: string;
|
|
@@ -21,13 +21,13 @@ export interface Timezone {
|
|
|
21
21
|
tzName: string;
|
|
22
22
|
countryCode: string;
|
|
23
23
|
}
|
|
24
|
-
export interface
|
|
24
|
+
export interface IDivision {
|
|
25
25
|
name: string;
|
|
26
26
|
iso2: string;
|
|
27
27
|
timezone: string;
|
|
28
28
|
countryCode: string;
|
|
29
29
|
}
|
|
30
|
-
export interface
|
|
30
|
+
export interface ICountry {
|
|
31
31
|
name: string;
|
|
32
32
|
iso2: string;
|
|
33
33
|
iso3: string;
|
|
@@ -48,16 +48,16 @@ export interface Country {
|
|
|
48
48
|
/** Label for postal/zip code (e.g. "ZIP Code", "Postcode", "PIN Code") */
|
|
49
49
|
postal_code_label: string;
|
|
50
50
|
}
|
|
51
|
-
export interface
|
|
51
|
+
export interface ILanguage {
|
|
52
52
|
code: string;
|
|
53
53
|
english_name: string;
|
|
54
54
|
native_name: string;
|
|
55
55
|
}
|
|
56
|
-
export interface
|
|
56
|
+
export interface ICountryPickerProps {
|
|
57
57
|
/** Currently selected country */
|
|
58
|
-
value?:
|
|
58
|
+
value?: ICountry | null;
|
|
59
59
|
/** Callback when user selects a country */
|
|
60
|
-
onChange: (country:
|
|
60
|
+
onChange: (country: ICountry) => void;
|
|
61
61
|
placeholder?: string;
|
|
62
62
|
/** Enable search input */
|
|
63
63
|
searchable?: boolean;
|
|
@@ -72,9 +72,9 @@ export interface CountryPickerProps {
|
|
|
72
72
|
/** aria-label */
|
|
73
73
|
label?: string;
|
|
74
74
|
}
|
|
75
|
-
export interface
|
|
76
|
-
value?:
|
|
77
|
-
onChange: (currency:
|
|
75
|
+
export interface ICurrencyPickerProps {
|
|
76
|
+
value?: ICurrency | null;
|
|
77
|
+
onChange: (currency: ICurrency) => void;
|
|
78
78
|
placeholder?: string;
|
|
79
79
|
searchable?: boolean;
|
|
80
80
|
/** Filter currencies to a specific country (iso2) and enable auto-selection */
|
|
@@ -87,9 +87,9 @@ export interface CurrencyPickerProps {
|
|
|
87
87
|
className?: string;
|
|
88
88
|
label?: string;
|
|
89
89
|
}
|
|
90
|
-
export interface
|
|
91
|
-
value?:
|
|
92
|
-
onChange: (timezone:
|
|
90
|
+
export interface ITimezonePickerProps {
|
|
91
|
+
value?: ITimezone | null;
|
|
92
|
+
onChange: (timezone: ITimezone) => void;
|
|
93
93
|
placeholder?: string;
|
|
94
94
|
searchable?: boolean;
|
|
95
95
|
/** Filter timezones to a specific country (iso2) and enable auto-selection */
|
|
@@ -100,9 +100,9 @@ export interface TimezonePickerProps {
|
|
|
100
100
|
className?: string;
|
|
101
101
|
label?: string;
|
|
102
102
|
}
|
|
103
|
-
export interface
|
|
104
|
-
value?:
|
|
105
|
-
onChange: (language:
|
|
103
|
+
export interface ILanguagePickerProps {
|
|
104
|
+
value?: ILanguage | null;
|
|
105
|
+
onChange: (language: ILanguage) => void;
|
|
106
106
|
placeholder?: string;
|
|
107
107
|
searchable?: boolean;
|
|
108
108
|
/** Show native language name alongside english name */
|
|
@@ -111,18 +111,18 @@ export interface LanguagePickerProps {
|
|
|
111
111
|
className?: string;
|
|
112
112
|
label?: string;
|
|
113
113
|
}
|
|
114
|
-
export interface
|
|
114
|
+
export interface IDivisionPickerProps {
|
|
115
115
|
/** ISO2 code of the parent country (required) */
|
|
116
116
|
countryIso2: string;
|
|
117
|
-
value?:
|
|
118
|
-
onChange: (division:
|
|
117
|
+
value?: IDivision | null;
|
|
118
|
+
onChange: (division: IDivision) => void;
|
|
119
119
|
placeholder?: string;
|
|
120
120
|
searchable?: boolean;
|
|
121
121
|
disabled?: boolean;
|
|
122
122
|
className?: string;
|
|
123
123
|
label?: string;
|
|
124
124
|
}
|
|
125
|
-
export interface
|
|
125
|
+
export interface IUsePickerReturn<T> {
|
|
126
126
|
isOpen: boolean;
|
|
127
127
|
searchQuery: string;
|
|
128
128
|
filteredItems: T[];
|
|
@@ -134,22 +134,39 @@ export interface UsePickerReturn<T> {
|
|
|
134
134
|
selectItem: (item: T) => void;
|
|
135
135
|
clearSelection: () => void;
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Phone number validation rules and metadata for a country
|
|
139
|
+
*/
|
|
140
|
+
export interface IPhoneValidation {
|
|
141
|
+
/** Min phone number length (without dial code) */
|
|
142
|
+
minLength?: number;
|
|
143
|
+
/** Max phone number length (without dial code) */
|
|
144
|
+
maxLength?: number;
|
|
145
|
+
/** Regex pattern for validation */
|
|
146
|
+
pattern?: string;
|
|
147
|
+
/** Example phone number without dial code */
|
|
148
|
+
example?: string;
|
|
149
|
+
/** Placeholder text for the phone input */
|
|
150
|
+
placeholder?: string;
|
|
151
|
+
}
|
|
137
152
|
/**
|
|
138
153
|
* Value object returned by PhoneInput.
|
|
139
154
|
*/
|
|
140
|
-
export interface
|
|
155
|
+
export interface IPhoneValue {
|
|
141
156
|
/** Full Country object of the selected country */
|
|
142
|
-
country:
|
|
157
|
+
country: ICountry;
|
|
143
158
|
/** Dial code with + prefix, e.g. "+1" */
|
|
144
159
|
dialCode: string;
|
|
145
160
|
/** Raw phone number without dial code, e.g. "4155551234" */
|
|
146
161
|
number: string;
|
|
147
162
|
/** Full number with dial code, e.g. "+14155551234" */
|
|
148
163
|
full: string;
|
|
164
|
+
/** Validation rules and metadata for the phone number */
|
|
165
|
+
validation?: IPhoneValidation;
|
|
149
166
|
}
|
|
150
|
-
export interface
|
|
151
|
-
value?:
|
|
152
|
-
onChange: (value:
|
|
167
|
+
export interface IPhoneInputProps {
|
|
168
|
+
value?: IPhoneValue | null;
|
|
169
|
+
onChange: (value: IPhoneValue) => void;
|
|
153
170
|
/** Pre-select a country by ISO2 on first render */
|
|
154
171
|
defaultCountryIso2?: string;
|
|
155
172
|
placeholder?: string;
|
|
@@ -158,9 +175,9 @@ export interface PhoneInputProps {
|
|
|
158
175
|
className?: string;
|
|
159
176
|
label?: string;
|
|
160
177
|
}
|
|
161
|
-
export interface
|
|
162
|
-
value:
|
|
163
|
-
onChange: (countries:
|
|
178
|
+
export interface ICountryMultiSelectProps {
|
|
179
|
+
value: ICountry[];
|
|
180
|
+
onChange: (countries: ICountry[]) => void;
|
|
164
181
|
placeholder?: string;
|
|
165
182
|
/** Maximum number of selections (undefined = unlimited) */
|
|
166
183
|
maxItems?: number;
|
|
@@ -170,9 +187,9 @@ export interface CountryMultiSelectProps {
|
|
|
170
187
|
className?: string;
|
|
171
188
|
label?: string;
|
|
172
189
|
}
|
|
173
|
-
export interface
|
|
174
|
-
value:
|
|
175
|
-
onChange: (currencies:
|
|
190
|
+
export interface ICurrencyMultiSelectProps {
|
|
191
|
+
value: ICurrency[];
|
|
192
|
+
onChange: (currencies: ICurrency[]) => void;
|
|
176
193
|
placeholder?: string;
|
|
177
194
|
maxItems?: number;
|
|
178
195
|
showSymbol?: boolean;
|
|
@@ -181,7 +198,7 @@ export interface CurrencyMultiSelectProps {
|
|
|
181
198
|
className?: string;
|
|
182
199
|
label?: string;
|
|
183
200
|
}
|
|
184
|
-
export interface
|
|
201
|
+
export interface IUseMultiSelectReturn<T> {
|
|
185
202
|
isOpen: boolean;
|
|
186
203
|
searchQuery: string;
|
|
187
204
|
filteredItems: T[];
|
|
@@ -195,3 +212,22 @@ export interface UseMultiSelectReturn<T> {
|
|
|
195
212
|
removeItem: (item: T) => void;
|
|
196
213
|
clearAll: () => void;
|
|
197
214
|
}
|
|
215
|
+
export interface IUseCountryReturn {
|
|
216
|
+
country: ICountry | null;
|
|
217
|
+
divisions: IDivision[];
|
|
218
|
+
timezones: ITimezone[];
|
|
219
|
+
currency: ICurrency | null;
|
|
220
|
+
phoneFormat: IPhoneFormat | null;
|
|
221
|
+
phoneLengths: {
|
|
222
|
+
min?: number;
|
|
223
|
+
max?: number;
|
|
224
|
+
};
|
|
225
|
+
exampleNumber?: string;
|
|
226
|
+
tax: {
|
|
227
|
+
label: string;
|
|
228
|
+
placeholder: string;
|
|
229
|
+
};
|
|
230
|
+
postalCode: {
|
|
231
|
+
label: string;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { iso2ToFlag as _iso2ToFlag } from '../data/countries';
|
|
2
|
-
import {
|
|
2
|
+
import { ICountry, ICurrency, IDivision, IPhoneFormat, ITimezone } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Convert ISO2 code to emoji flag
|
|
5
5
|
* Re-exported from the generated data module.
|
|
@@ -8,42 +8,39 @@ export { _iso2ToFlag as iso2ToFlag };
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns all countries
|
|
10
10
|
*/
|
|
11
|
-
export declare function getAllCountries():
|
|
11
|
+
export declare function getAllCountries(): ICountry[];
|
|
12
12
|
/**
|
|
13
13
|
* Find a country by its ISO2 code (case-insensitive)
|
|
14
14
|
*/
|
|
15
|
-
export declare function getCountryByIso2(iso2: string):
|
|
15
|
+
export declare function getCountryByIso2(iso2: string): ICountry | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* Find a country by its ISO3 code (case-insensitive)
|
|
18
18
|
*/
|
|
19
|
-
export declare function getCountryByIso3(iso3: string):
|
|
19
|
+
export declare function getCountryByIso3(iso3: string): ICountry | undefined;
|
|
20
20
|
/**
|
|
21
21
|
* Find a country by its name (partial, case-insensitive)
|
|
22
22
|
*/
|
|
23
|
-
export declare function getCountryByName(name: string):
|
|
23
|
+
export declare function getCountryByName(name: string): ICountry | undefined;
|
|
24
24
|
/**
|
|
25
25
|
* Search countries by name, iso2, iso3 or phone code
|
|
26
26
|
*/
|
|
27
|
-
export declare function searchCountries(query: string):
|
|
27
|
+
export declare function searchCountries(query: string): ICountry[];
|
|
28
28
|
/**
|
|
29
29
|
* Get all divisions for a country
|
|
30
30
|
*/
|
|
31
|
-
export declare function getDivisionsByCountry(iso2: string):
|
|
31
|
+
export declare function getDivisionsByCountry(iso2: string): IDivision[];
|
|
32
32
|
/**
|
|
33
33
|
* Get all timezones for a country
|
|
34
34
|
*/
|
|
35
|
-
export declare function getTimezonesByCountry(iso2: string):
|
|
36
|
-
/**
|
|
37
|
-
* Get the currency of a country
|
|
38
|
-
*/
|
|
35
|
+
export declare function getTimezonesByCountry(iso2: string): ITimezone[];
|
|
39
36
|
/**
|
|
40
37
|
* Get the currency for a country
|
|
41
38
|
*/
|
|
42
|
-
export declare function getCurrencyByCountry(iso2: string):
|
|
39
|
+
export declare function getCurrencyByCountry(iso2: string): ICurrency | undefined;
|
|
43
40
|
/**
|
|
44
41
|
* Get the phone format for a country
|
|
45
42
|
*/
|
|
46
|
-
export declare function getPhoneFormatByCountry(iso2: string):
|
|
43
|
+
export declare function getPhoneFormatByCountry(iso2: string): IPhoneFormat | undefined;
|
|
47
44
|
/**
|
|
48
45
|
* Get the min and max phone number lengths for a country
|
|
49
46
|
*/
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ICurrency } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Returns all unique currencies across all countries
|
|
4
4
|
*/
|
|
5
|
-
export declare function getAllCurrencies():
|
|
5
|
+
export declare function getAllCurrencies(): ICurrency[];
|
|
6
6
|
/**
|
|
7
7
|
* Find a currency by its code (e.g. "USD")
|
|
8
8
|
*/
|
|
9
|
-
export declare function getCurrencyByCode(code: string):
|
|
9
|
+
export declare function getCurrencyByCode(code: string): ICurrency | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Search currencies by code, name, or symbol
|
|
12
12
|
*/
|
|
13
|
-
export declare function searchCurrencies(query: string, countryIso2?: string):
|
|
13
|
+
export declare function searchCurrencies(query: string, countryIso2?: string): ICurrency[];
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ILanguage } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Returns all languages
|
|
4
4
|
*/
|
|
5
|
-
export declare function getAllLanguages():
|
|
5
|
+
export declare function getAllLanguages(): ILanguage[];
|
|
6
6
|
/**
|
|
7
7
|
* Find a language by its BCP-47 code
|
|
8
8
|
*/
|
|
9
|
-
export declare function getLanguageByCode(code: string):
|
|
9
|
+
export declare function getLanguageByCode(code: string): ILanguage | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Search languages by english name, native name, or code
|
|
12
12
|
*/
|
|
13
|
-
export declare function searchLanguages(query: string):
|
|
13
|
+
export declare function searchLanguages(query: string): ILanguage[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IPhoneValidation } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Get phone number validation rules for a country
|
|
4
|
+
* Combines libphonenumber-js data with custom formatting rules
|
|
5
|
+
*/
|
|
6
|
+
export declare function getPhoneValidation(countryIso2: string): IPhoneValidation;
|
|
7
|
+
/**
|
|
8
|
+
* Format phone example as a user-friendly placeholder
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatPhoneExample(example: string, countryIso2: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Validate phone number against country-specific rules
|
|
13
|
+
*/
|
|
14
|
+
export declare function validatePhoneNumber(dialCode: string, number: string, countryIso2: string): {
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
errors: string[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Format phone number for display based on country conventions
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatPhoneNumber(number: string, countryIso2: string): string;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ITimezone } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Returns all unique timezones across all countries
|
|
4
4
|
*/
|
|
5
|
-
export declare function getAllTimezones():
|
|
5
|
+
export declare function getAllTimezones(): ITimezone[];
|
|
6
6
|
/**
|
|
7
7
|
* Find a timezone by its IANA name (e.g. "America/New_York")
|
|
8
8
|
* Supports modern names and common deprecated aliases.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getTimezoneByName(name: string):
|
|
10
|
+
export declare function getTimezoneByName(name: string): ITimezone | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* Search timezones by name, abbreviation, or offset string
|
|
13
13
|
*/
|
|
14
|
-
export declare function searchTimezones(query: string, countryIso2?: string):
|
|
14
|
+
export declare function searchTimezones(query: string, countryIso2?: string): ITimezone[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-country-kit-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core datasets, utilities, and hooks for react-country-kit. Comprehensive data for countries, currencies, timezones, languages, and divisions.",
|
|
6
6
|
"author": "Kishor Mainali",
|