react-country-kit-core 1.1.3 → 1.3.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 CHANGED
@@ -20,26 +20,32 @@ npm install react-country-kit-core
20
20
  ## 🛠 Utility Functions
21
21
 
22
22
  ### Localized Metadata
23
+
23
24
  Get labels and placeholders for billing/registration forms:
24
25
 
25
26
  ```tsx
26
- import {
27
- getTaxLabelByCountry,
28
- getTaxPlaceholderByCountry,
29
- getPostalLabelByCountry
30
- } from 'react-country-kit-core';
31
-
32
- const label = getTaxLabelByCountry('US'); // "EIN / SSN"
33
- const placeholder = getTaxPlaceholderByCountry('US'); // "00-0000000"
34
- const postalLabel = getPostalLabelByCountry('JP'); // "Postal Code (〒)"
27
+ import {
28
+ getTaxLabelByCountry,
29
+ getTaxPlaceholderByCountry,
30
+ getPostalLabelByCountry,
31
+ } from "react-country-kit-core";
32
+
33
+ const label = getTaxLabelByCountry("US"); // "EIN / SSN"
34
+ const placeholder = getTaxPlaceholderByCountry("US"); // "00-0000000"
35
+ const postalLabel = getPostalLabelByCountry("JP"); // "Postal Code (〒)"
35
36
  ```
36
37
 
37
38
  ### Data Retrieval
38
- ```tsx
39
- import { getAllCountries, getCountryByIso2, searchCountries } from 'react-country-kit-core';
40
39
 
41
- const usa = getCountryByIso2('US');
42
- const results = searchCountries('united');
40
+ ```tsx
41
+ import {
42
+ getAllCountries,
43
+ getCountryByIso2,
44
+ searchCountries,
45
+ } from "react-country-kit-core";
46
+
47
+ const usa = getCountryByIso2("US");
48
+ const results = searchCountries("united");
43
49
  ```
44
50
 
45
51
  ## 🧠 Headless Hooks
@@ -47,17 +53,23 @@ const results = searchCountries('united');
47
53
  Our hooks handle state, filtering, and interaction logic so you can focus on the UI:
48
54
 
49
55
  ```tsx
50
- import { useCountryPicker } from 'react-country-kit-core';
56
+ import { useCountryPicker } from "react-country-kit-core";
51
57
 
52
58
  function CustomPicker() {
53
- const { filteredItems, searchQuery, setSearchQuery, selectItem } = useCountryPicker();
54
-
59
+ const { filteredItems, searchQuery, setSearchQuery, selectItem } =
60
+ useCountryPicker();
61
+
55
62
  return (
56
63
  <div>
57
- <input value={searchQuery} onChange={(e) => setSearchQuery(e.target.value)} />
64
+ <input
65
+ value={searchQuery}
66
+ onChange={(e) => setSearchQuery(e.target.value)}
67
+ />
58
68
  <ul>
59
- {filteredItems.map(c => (
60
- <li key={c.iso2} onClick={() => selectItem(c)}>{c.name}</li>
69
+ {filteredItems.map((c) => (
70
+ <li key={c.iso2} onClick={() => selectItem(c)}>
71
+ {c.name}
72
+ </li>
61
73
  ))}
62
74
  </ul>
63
75
  </div>
@@ -73,6 +85,7 @@ export interface Country {
73
85
  iso2: string;
74
86
  iso3: string;
75
87
  phone_code: string;
88
+ division_type: string;
76
89
  flag: string;
77
90
  flag_url: string;
78
91
  currency_code: string;
@@ -0,0 +1,10 @@
1
+ import { Country } from '../types';
2
+ /**
3
+ * Auto-generated country dataset — DO NOT EDIT MANUALLY.
4
+ * Source: https://raw.githubusercontent.com/kishormainali/country_division_database/refs/heads/main/countries.json
5
+ * Generated: 2026-05-18T08:54:17.574Z
6
+ * Countries: 250
7
+ */
8
+ export declare function iso2ToFlag(iso2: string): string;
9
+ export declare const COUNTRIES: Country[];
10
+ export default COUNTRIES;
@@ -0,0 +1,3 @@
1
+ import { Currency } from '../types';
2
+ export declare const CURRENCIES: Currency[];
3
+ export default CURRENCIES;
@@ -0,0 +1,3 @@
1
+ import { Division } from '../types';
2
+ export declare const DIVISIONS: Division[];
3
+ export default DIVISIONS;
@@ -0,0 +1,3 @@
1
+ import { Language } from '../types';
2
+ declare const languages: Language[];
3
+ export default languages;
@@ -0,0 +1,3 @@
1
+ import { PhoneFormat } from '../types';
2
+ export declare const PHONE_FORMATS: PhoneFormat[];
3
+ export default PHONE_FORMATS;
@@ -0,0 +1,3 @@
1
+ import { Timezone } from '../types';
2
+ export declare const TIMEZONES: Timezone[];
3
+ export default TIMEZONES;
@@ -0,0 +1,6 @@
1
+ import { UsePickerReturn } from '../types';
2
+ /**
3
+ * Generic base hook for all pickers.
4
+ * Handles open/close state, search query, and item selection.
5
+ */
6
+ export declare function useBasePicker<T>(allItems: T[], filterFn: (items: T[], query: string) => T[], initialValue?: T | null, onChange?: (item: T) => void): UsePickerReturn<T>;
@@ -0,0 +1,2 @@
1
+ import { Country, UsePickerReturn } from '../types';
2
+ export declare function useCountryPicker(initialValue?: Country | null, onChange?: (country: Country) => void): UsePickerReturn<Country>;
@@ -0,0 +1,2 @@
1
+ import { Currency, UsePickerReturn } from '../types';
2
+ export declare function useCurrencyPicker(initialValue?: Currency | null, onChange?: (currency: Currency) => void): UsePickerReturn<Currency>;
@@ -0,0 +1,2 @@
1
+ import { Division, UsePickerReturn } from '../types';
2
+ export declare function useDivisionPicker(countryIso2: string, initialValue?: Division | null, onChange?: (division: Division) => void): UsePickerReturn<Division>;
@@ -0,0 +1,2 @@
1
+ import { Language, UsePickerReturn } from '../types';
2
+ export declare function useLanguagePicker(initialValue?: Language | null, onChange?: (language: Language) => void): UsePickerReturn<Language>;
@@ -0,0 +1,6 @@
1
+ import { UseMultiSelectReturn } from '../types';
2
+ /**
3
+ * Generic multi-selection hook.
4
+ * Handles open/close, search, and toggle-selection of multiple items.
5
+ */
6
+ export declare function useMultiSelect<T>(allItems: T[], filterFn: (items: T[], query: string) => T[], keyFn: (item: T) => string, initialValue?: T[], onChange?: (items: T[]) => void, maxItems?: number): UseMultiSelectReturn<T>;
@@ -0,0 +1,17 @@
1
+ import { Country, PhoneValue } from '../types';
2
+ export interface UsePhoneInputReturn {
3
+ country: Country | null;
4
+ number: string;
5
+ value: PhoneValue | null;
6
+ isOpen: boolean;
7
+ searchQuery: string;
8
+ filteredCountries: Country[];
9
+ minLength?: number;
10
+ maxLength?: number;
11
+ setSearchQuery: (q: string) => void;
12
+ selectCountry: (country: Country) => void;
13
+ setNumber: (num: string) => void;
14
+ toggle: () => void;
15
+ close: () => void;
16
+ }
17
+ export declare function usePhoneInput(initialValue?: PhoneValue | null, onChange?: (value: PhoneValue) => void, defaultCountryIso2?: string): UsePhoneInputReturn;
@@ -0,0 +1,2 @@
1
+ import { Timezone, UsePickerReturn } from '../types';
2
+ export declare function useTimezonePicker(initialValue?: Timezone | null, onChange?: (timezone: Timezone) => void, countryIso2?: string): UsePickerReturn<Timezone>;
package/dist/index.d.ts CHANGED
@@ -1,393 +1,19 @@
1
- export declare const COUNTRIES: Country[];
2
-
3
- export declare interface Country {
4
- name: string;
5
- iso2: string;
6
- iso3: string;
7
- phone_code: string;
8
- phone_format?: PhoneFormat;
9
- currency?: Currency;
10
- division_type: string;
11
- divisions?: Division[];
12
- timezones?: Timezone[];
13
- /** Emoji flag computed from iso2 */
14
- flag: string;
15
- /** SVG/Image URL for the country flag */
16
- flag_url: string;
17
- /** Default language code for the country */
18
- language_code: string;
19
- /** Default currency code for the country */
20
- currency_code: string;
21
- /** Label for tax identification number (e.g. "VAT", "SSN", "ABN") */
22
- tax_id_label?: string;
23
- /** Placeholder for tax identification number */
24
- tax_id_placeholder?: string;
25
- /** Label for postal/zip code (e.g. "ZIP Code", "Postcode", "PIN Code") */
26
- postal_code_label?: string;
27
- }
28
-
29
- export declare interface CountryMultiSelectProps {
30
- value: Country[];
31
- onChange: (countries: Country[]) => void;
32
- placeholder?: string;
33
- /** Maximum number of selections (undefined = unlimited) */
34
- maxItems?: number;
35
- showFlags?: boolean;
36
- searchable?: boolean;
37
- disabled?: boolean;
38
- className?: string;
39
- label?: string;
40
- }
41
-
42
- export declare interface CountryPickerProps {
43
- /** Currently selected country */
44
- value?: Country | null;
45
- /** Callback when user selects a country */
46
- onChange: (country: Country) => void;
47
- placeholder?: string;
48
- /** Enable search input */
49
- searchable?: boolean;
50
- /** Show emoji flag next to country name */
51
- showFlag?: boolean;
52
- /** Show phone dial code */
53
- showPhoneCode?: boolean;
54
- /** Disable the picker */
55
- disabled?: boolean;
56
- /** Additional wrapper class */
57
- className?: string;
58
- /** aria-label */
59
- label?: string;
60
- }
61
-
62
- export declare const CURRENCIES: Currency[];
63
-
64
- export declare interface Currency {
65
- code: string;
66
- name: string;
67
- symbol: string;
68
- countryCode: string;
69
- }
70
-
71
- export declare interface CurrencyMultiSelectProps {
72
- value: Currency[];
73
- onChange: (currencies: Currency[]) => void;
74
- placeholder?: string;
75
- maxItems?: number;
76
- showSymbol?: boolean;
77
- searchable?: boolean;
78
- disabled?: boolean;
79
- className?: string;
80
- label?: string;
81
- }
82
-
83
- export declare interface CurrencyPickerProps {
84
- value?: Currency | null;
85
- onChange: (currency: Currency) => void;
86
- placeholder?: string;
87
- searchable?: boolean;
88
- /** Filter currencies to a specific country (iso2) and enable auto-selection */
89
- countryIso2?: string;
90
- /** Auto-select the first currency if countryIso2 is provided. Defaults to true if countryIso2 is present and value is empty. */
91
- autoSelect?: boolean;
92
- /** Show currency symbol alongside code */
93
- showSymbol?: boolean;
94
- disabled?: boolean;
95
- className?: string;
96
- label?: string;
97
- }
98
-
99
- export declare interface Division {
100
- name: string;
101
- iso2: string;
102
- timezone: string;
103
- countryCode: string;
104
- }
105
-
106
- export declare interface DivisionPickerProps {
107
- /** ISO2 code of the parent country (required) */
108
- countryIso2: string;
109
- value?: Division | null;
110
- onChange: (division: Division) => void;
111
- placeholder?: string;
112
- searchable?: boolean;
113
- disabled?: boolean;
114
- className?: string;
115
- label?: string;
116
- }
117
-
118
- export declare const DIVISIONS: Division[];
119
-
120
- /**
121
- * Returns all countries
122
- */
123
- export declare function getAllCountries(): Country[];
124
-
125
- /**
126
- * Returns all unique currencies across all countries
127
- */
128
- export declare function getAllCurrencies(): Currency[];
129
-
130
- /**
131
- * Returns all languages
132
- */
133
- export declare function getAllLanguages(): Language[];
134
-
135
- /**
136
- * Returns all unique timezones across all countries
137
- */
138
- export declare function getAllTimezones(): Timezone[];
139
-
140
- /**
141
- * Find a country by its ISO2 code (case-insensitive)
142
- */
143
- export declare function getCountryByIso2(iso2: string): Country | undefined;
144
-
145
- /**
146
- * Find a country by its ISO3 code (case-insensitive)
147
- */
148
- export declare function getCountryByIso3(iso3: string): Country | undefined;
149
-
150
- /**
151
- * Find a country by its name (partial, case-insensitive)
152
- */
153
- export declare function getCountryByName(name: string): Country | undefined;
154
-
155
- /**
156
- * Find a currency by its code (e.g. "USD")
157
- */
158
- export declare function getCurrencyByCode(code: string): Currency | undefined;
159
-
160
- /**
161
- * Get the currency of a country
162
- */
163
- /**
164
- * Get the currency for a country
165
- */
166
- export declare function getCurrencyByCountry(iso2: string): Currency | undefined;
167
-
168
- /**
169
- * Get all divisions for a country
170
- */
171
- export declare function getDivisionsByCountry(iso2: string): Division[];
172
-
173
- /**
174
- * Find a language by its BCP-47 code
175
- */
176
- export declare function getLanguageByCode(code: string): Language | undefined;
177
-
178
- /**
179
- * Get the phone format for a country
180
- */
181
- export declare function getPhoneFormatByCountry(iso2: string): PhoneFormat | undefined;
182
-
183
- /**
184
- * Get the min and max phone number lengths for a country
185
- */
186
- export declare function getPhoneLengths(iso2: string): {
187
- min?: number;
188
- max?: number;
189
- };
190
-
191
- /**
192
- * Get the localized Postal Code label for a country
193
- */
194
- export declare function getPostalLabelByCountry(iso2: string): string;
195
-
196
- /**
197
- * Get the localized Tax ID label for a country
198
- */
199
- export declare function getTaxLabelByCountry(iso2: string): string;
200
-
201
- /**
202
- * Get the localized Tax ID placeholder for a country
203
- */
204
- export declare function getTaxPlaceholderByCountry(iso2: string): string;
205
-
206
- /**
207
- * Find a timezone by its IANA name (e.g. "America/New_York")
208
- * Supports modern names and common deprecated aliases.
209
- */
210
- export declare function getTimezoneByName(name: string): Timezone | undefined;
211
-
212
- /**
213
- * Get all timezones for a country
214
- */
215
- export declare function getTimezonesByCountry(iso2: string): Timezone[];
216
-
217
- /**
218
- * Auto-generated country dataset — DO NOT EDIT MANUALLY.
219
- * Source: https://raw.githubusercontent.com/kishormainali/country_division_database/refs/heads/main/countries.json
220
- * Generated: 2026-05-15T08:46:14.513Z
221
- * Countries: 250
222
- */
223
- export declare function iso2ToFlag(iso2: string): string;
224
-
225
- export declare interface Language {
226
- code: string;
227
- english_name: string;
228
- native_name: string;
229
- }
230
-
231
- export declare interface LanguagePickerProps {
232
- value?: Language | null;
233
- onChange: (language: Language) => void;
234
- placeholder?: string;
235
- searchable?: boolean;
236
- /** Show native language name alongside english name */
237
- showNativeName?: boolean;
238
- disabled?: boolean;
239
- className?: string;
240
- label?: string;
241
- }
242
-
243
- export declare const PHONE_FORMATS: PhoneFormat[];
244
-
245
- export declare interface PhoneFormat {
246
- countryCode?: string;
247
- iso2: string;
248
- dialCode: string;
249
- patterns: string;
250
- possibleLengths: string;
251
- example: string | number;
252
- }
253
-
254
- export declare interface PhoneInputProps {
255
- value?: PhoneValue | null;
256
- onChange: (value: PhoneValue) => void;
257
- /** Pre-select a country by ISO2 on first render */
258
- defaultCountryIso2?: string;
259
- placeholder?: string;
260
- showFlag?: boolean;
261
- disabled?: boolean;
262
- className?: string;
263
- label?: string;
264
- }
265
-
266
- /**
267
- * Value object returned by PhoneInput.
268
- */
269
- export declare interface PhoneValue {
270
- /** Full Country object of the selected country */
271
- country: Country;
272
- /** Dial code with + prefix, e.g. "+1" */
273
- dialCode: string;
274
- /** Raw phone number without dial code, e.g. "4155551234" */
275
- number: string;
276
- /** Full number with dial code, e.g. "+14155551234" */
277
- full: string;
278
- }
279
-
280
- /**
281
- * Search countries by name, iso2, iso3 or phone code
282
- */
283
- export declare function searchCountries(query: string): Country[];
284
-
285
- /**
286
- * Search currencies by code, name, or symbol
287
- */
288
- export declare function searchCurrencies(query: string, countryIso2?: string): Currency[];
289
-
290
- /**
291
- * Search languages by english name, native name, or code
292
- */
293
- export declare function searchLanguages(query: string): Language[];
294
-
295
- /**
296
- * Search timezones by name, abbreviation, or offset string
297
- */
298
- export declare function searchTimezones(query: string, countryIso2?: string): Timezone[];
299
-
300
- export declare interface Timezone {
301
- name: string;
302
- offset: number;
303
- offset_name: string;
304
- abbreviation: string;
305
- tzName: string;
306
- countryCode: string;
307
- }
308
-
309
- export declare interface TimezonePickerProps {
310
- value?: Timezone | null;
311
- onChange: (timezone: Timezone) => void;
312
- placeholder?: string;
313
- searchable?: boolean;
314
- /** Filter timezones to a specific country (iso2) and enable auto-selection */
315
- countryIso2?: string;
316
- /** Auto-select the first timezone if countryIso2 is provided. Defaults to true if countryIso2 is present and value is empty. */
317
- autoSelect?: boolean;
318
- disabled?: boolean;
319
- className?: string;
320
- label?: string;
321
- }
322
-
323
- export declare const TIMEZONES: Timezone[];
324
-
325
- /**
326
- * Generic base hook for all pickers.
327
- * Handles open/close state, search query, and item selection.
328
- */
329
- export declare function useBasePicker<T>(allItems: T[], filterFn: (items: T[], query: string) => T[], initialValue?: T | null, onChange?: (item: T) => void): UsePickerReturn<T>;
330
-
331
- export declare function useCountryPicker(initialValue?: Country | null, onChange?: (country: Country) => void): UsePickerReturn<Country>;
332
-
333
- export declare function useCurrencyPicker(initialValue?: Currency | null, onChange?: (currency: Currency) => void): UsePickerReturn<Currency>;
334
-
335
- export declare function useDivisionPicker(countryIso2: string, initialValue?: Division | null, onChange?: (division: Division) => void): UsePickerReturn<Division>;
336
-
337
- export declare function useLanguagePicker(initialValue?: Language | null, onChange?: (language: Language) => void): UsePickerReturn<Language>;
338
-
339
- /**
340
- * Generic multi-selection hook.
341
- * Handles open/close, search, and toggle-selection of multiple items.
342
- */
343
- export declare function useMultiSelect<T>(allItems: T[], filterFn: (items: T[], query: string) => T[], keyFn: (item: T) => string, initialValue?: T[], onChange?: (items: T[]) => void, maxItems?: number): UseMultiSelectReturn<T>;
344
-
345
- export declare interface UseMultiSelectReturn<T> {
346
- isOpen: boolean;
347
- searchQuery: string;
348
- filteredItems: T[];
349
- selectedItems: T[];
350
- open: () => void;
351
- close: () => void;
352
- toggle: () => void;
353
- setSearchQuery: (query: string) => void;
354
- toggleItem: (item: T) => void;
355
- isSelected: (item: T) => boolean;
356
- removeItem: (item: T) => void;
357
- clearAll: () => void;
358
- }
359
-
360
- export declare function usePhoneInput(initialValue?: PhoneValue | null, onChange?: (value: PhoneValue) => void, defaultCountryIso2?: string): UsePhoneInputReturn;
361
-
362
- export declare interface UsePhoneInputReturn {
363
- country: Country | null;
364
- number: string;
365
- value: PhoneValue | null;
366
- isOpen: boolean;
367
- searchQuery: string;
368
- filteredCountries: Country[];
369
- minLength?: number;
370
- maxLength?: number;
371
- setSearchQuery: (q: string) => void;
372
- selectCountry: (country: Country) => void;
373
- setNumber: (num: string) => void;
374
- toggle: () => void;
375
- close: () => void;
376
- }
377
-
378
- export declare interface UsePickerReturn<T> {
379
- isOpen: boolean;
380
- searchQuery: string;
381
- filteredItems: T[];
382
- selectedItem: T | null;
383
- open: () => void;
384
- close: () => void;
385
- toggle: () => void;
386
- setSearchQuery: (query: string) => void;
387
- selectItem: (item: T) => void;
388
- clearSelection: () => void;
389
- }
390
-
391
- export declare function useTimezonePicker(initialValue?: Timezone | null, onChange?: (timezone: Timezone) => void, countryIso2?: string): UsePickerReturn<Timezone>;
392
-
393
- export { }
1
+ export * from './data/countries';
2
+ export * from './data/divisions';
3
+ export * from './data/languages';
4
+ export * from './data/timezones';
5
+ export * from './data/phoneFormats';
6
+ export * from './data/currencies';
7
+ export * from './hooks/useCountryPicker';
8
+ export * from './hooks/useCurrencyPicker';
9
+ export * from './hooks/useDivisionPicker';
10
+ export * from './hooks/useLanguagePicker';
11
+ export * from './hooks/useTimezonePicker';
12
+ export * from './hooks/usePhoneInput';
13
+ export * from './hooks/useMultiSelect';
14
+ export * from './hooks/useBasePicker';
15
+ export * from './utils/countries';
16
+ export * from './utils/currencies';
17
+ export * from './utils/languages';
18
+ export * from './utils/timezones';
19
+ export * from './types';