svelte-tel-input 0.11.0 → 0.12.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +46 -34
  2. package/README.md +66 -14
  3. package/components/Input/AdvancedTelInput.svelte +187 -0
  4. package/components/Input/AdvancedTelInput.svelte.d.ts +24 -0
  5. package/components/Input/TelInput.svelte +15 -15
  6. package/components/Input/TelInput.svelte.d.ts +4 -4
  7. package/index.d.ts +4 -0
  8. package/index.js +4 -0
  9. package/package.json +24 -48
  10. package/stores/index.d.ts +0 -14
  11. package/stores/index.js +1 -34
  12. package/types/enums/index.d.ts +10 -2
  13. package/types/enums/index.js +12 -2
  14. package/types/index.d.ts +1 -2
  15. package/types/interfaces/Country.interface.d.ts +1 -1
  16. package/types/interfaces/Phone.interface.d.ts +2 -1
  17. package/types/interfaces/index.d.ts +2 -3
  18. package/types/interfaces/index.js +2 -1
  19. package/utils/helpers.d.ts +3 -3
  20. package/utils/helpers.js +1 -1
  21. package/components/Select/Select.svelte +0 -103
  22. package/components/Select/Select.svelte.d.ts +0 -27
  23. package/components/Select/SelectListItem.svelte +0 -11
  24. package/components/Select/SelectListItem.svelte.d.ts +0 -18
  25. package/components/Select/TelCountrySelect/TelCountrySelect.svelte +0 -56
  26. package/components/Select/TelCountrySelect/TelCountrySelect.svelte.d.ts +0 -19
  27. package/components/utils/PayloadBlock.svelte +0 -33
  28. package/components/utils/PayloadBlock.svelte.d.ts +0 -17
  29. package/stores/DevExampleStores.d.ts +0 -6
  30. package/stores/DevExampleStores.js +0 -30
  31. package/types/DynamicSvelteComponent.type.d.ts +0 -8
  32. package/types/DynamicSvelteComponent.type.js +0 -1
  33. package/types/enums/PhoneNumberParseError.enum.d.ts +0 -6
  34. package/types/enums/PhoneNumberParseError.enum.js +0 -7
  35. package/types/enums/PhoneType.enum.d.ts +0 -4
  36. package/types/enums/PhoneType.enum.js +0 -5
  37. package/types/interfaces/Select.interface.d.ts +0 -5
  38. package/types/interfaces/Select.interface.js +0 -1
  39. package/utils/simulator.d.ts +0 -1
  40. package/utils/simulator.js +0 -5
  41. package/utils/typeCheck.d.ts +0 -4
  42. package/utils/typeCheck.js +0 -11
package/CHANGELOG.md CHANGED
@@ -1,157 +1,169 @@
1
1
  # svelte-tel-input
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: Update exports to make the package as simple to use as possible. ([#85](https://github.com/gyurielf/svelte-tel-input/pull/85))
8
+
9
+ ## 0.11.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Update readme and prepare to 1.0 ([#79](https://github.com/gyurielf/svelte-tel-input/pull/79))
14
+
3
15
  ## 0.11.0
4
16
 
5
17
  ### Minor Changes
6
18
 
7
- - feat: dark mode, example page enhancemet ([#76](https://github.com/gyurielf/svelte-tel-input/pull/76))
19
+ - feat: dark mode, example page enhancemet ([#76](https://github.com/gyurielf/svelte-tel-input/pull/76))
8
20
 
9
21
  ## 0.10.0
10
22
 
11
23
  ### Minor Changes
12
24
 
13
- - refactor: components and views ([#74](https://github.com/gyurielf/svelte-tel-input/pull/74))
25
+ - refactor: components and views ([#74](https://github.com/gyurielf/svelte-tel-input/pull/74))
14
26
 
15
27
  ## 0.9.0
16
28
 
17
29
  ### Minor Changes
18
30
 
19
- - feat: masking/formatting and parsing extends ([#72](https://github.com/gyurielf/svelte-tel-input/pull/72))
31
+ - feat: masking/formatting and parsing extends ([#72](https://github.com/gyurielf/svelte-tel-input/pull/72))
20
32
 
21
33
  ## 0.8.0
22
34
 
23
35
  ### Minor Changes
24
36
 
25
- - feat: example improvements, extend functionality ([#70](https://github.com/gyurielf/svelte-tel-input/pull/70))
37
+ - feat: example improvements, extend functionality ([#70](https://github.com/gyurielf/svelte-tel-input/pull/70))
26
38
 
27
39
  ## 0.7.0
28
40
 
29
41
  ### Minor Changes
30
42
 
31
- - feat: example page payload feature, parsing improvements" ([#68](https://github.com/gyurielf/svelte-tel-input/pull/68))
43
+ - feat: example page payload feature, parsing improvements" ([#68](https://github.com/gyurielf/svelte-tel-input/pull/68))
32
44
 
33
45
  ## 0.6.5
34
46
 
35
47
  ### Patch Changes
36
48
 
37
- - fix: add changeset ([#61](https://github.com/gyurielf/svelte-tel-input/pull/61))
49
+ - fix: add changeset ([#61](https://github.com/gyurielf/svelte-tel-input/pull/61))
38
50
 
39
51
  ## 0.6.4
40
52
 
41
53
  ### Patch Changes
42
54
 
43
- - chore: update to vite 3 ([#58](https://github.com/gyurielf/svelte-tel-input/pull/58))
55
+ - chore: update to vite 3 ([#58](https://github.com/gyurielf/svelte-tel-input/pull/58))
44
56
 
45
57
  ## 0.6.3
46
58
 
47
59
  ### Patch Changes
48
60
 
49
- - update dependencies ([#56](https://github.com/gyurielf/svelte-tel-input/pull/56))
61
+ - update dependencies ([#56](https://github.com/gyurielf/svelte-tel-input/pull/56))
50
62
 
51
63
  ## 0.6.2
52
64
 
53
65
  ### Patch Changes
54
66
 
55
- - Update readme & update packages ([#54](https://github.com/gyurielf/svelte-tel-input/pull/54))
67
+ - Update readme & update packages ([#54](https://github.com/gyurielf/svelte-tel-input/pull/54))
56
68
 
57
69
  ## 0.6.1
58
70
 
59
71
  ### Patch Changes
60
72
 
61
- - Readme update ([#52](https://github.com/gyurielf/svelte-tel-input/pull/52))
73
+ - Readme update ([#52](https://github.com/gyurielf/svelte-tel-input/pull/52))
62
74
 
63
75
  ## 0.6.0
64
76
 
65
77
  ### Minor Changes
66
78
 
67
- - feat: example page preparations & extend functionality (part 1) ([#50](https://github.com/gyurielf/svelte-tel-input/pull/50))
79
+ - feat: example page preparations & extend functionality (part 1) ([#50](https://github.com/gyurielf/svelte-tel-input/pull/50))
68
80
 
69
81
  ## 0.5.1
70
82
 
71
83
  ### Patch Changes
72
84
 
73
- - chore: update packages and resolve breaking changes ([#46](https://github.com/gyurielf/svelte-tel-input/pull/46))
85
+ - chore: update packages and resolve breaking changes ([#46](https://github.com/gyurielf/svelte-tel-input/pull/46))
74
86
 
75
87
  ## 0.5.0
76
88
 
77
89
  ### Minor Changes
78
90
 
79
- - feat: prepare github pages deployment ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
91
+ - feat: prepare github pages deployment ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
80
92
 
81
- * feat: implement selects and input ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
93
+ * feat: implement selects and input ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
82
94
 
83
- - feat: basic stores created ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
95
+ - feat: basic stores created ([#43](https://github.com/gyurielf/svelte-tel-input/pull/43))
84
96
 
85
97
  ## 0.4.2
86
98
 
87
99
  ### Patch Changes
88
100
 
89
- - fix: fix readme ([#41](https://github.com/gyurielf/svelte-tel-input/pull/41))
101
+ - fix: fix readme ([#41](https://github.com/gyurielf/svelte-tel-input/pull/41))
90
102
 
91
103
  ## 0.4.1
92
104
 
93
105
  ### Patch Changes
94
106
 
95
- - fix: readme fix ([#39](https://github.com/gyurielf/svelte-tel-input/pull/39))
107
+ - fix: readme fix ([#39](https://github.com/gyurielf/svelte-tel-input/pull/39))
96
108
 
97
109
  ## 0.4.0
98
110
 
99
111
  ### Minor Changes
100
112
 
101
- - fix: rework ci
113
+ - fix: rework ci
102
114
 
103
115
  ### Patch Changes
104
116
 
105
- - fix: minor ci fix ([#34](https://github.com/gyurielf/svelte-tel-input/pull/34))
117
+ - fix: minor ci fix ([#34](https://github.com/gyurielf/svelte-tel-input/pull/34))
106
118
 
107
- * fix: fix ci again ([#35](https://github.com/gyurielf/svelte-tel-input/pull/35))
119
+ * fix: fix ci again ([#35](https://github.com/gyurielf/svelte-tel-input/pull/35))
108
120
 
109
- - fix: last ci fix for today ([#36](https://github.com/gyurielf/svelte-tel-input/pull/36))
121
+ - fix: last ci fix for today ([#36](https://github.com/gyurielf/svelte-tel-input/pull/36))
110
122
 
111
- * fix: ci fixxx ([#33](https://github.com/gyurielf/svelte-tel-input/pull/33))
123
+ * fix: ci fixxx ([#33](https://github.com/gyurielf/svelte-tel-input/pull/33))
112
124
 
113
- - something 1 ([#37](https://github.com/gyurielf/svelte-tel-input/pull/37))
125
+ - something 1 ([#37](https://github.com/gyurielf/svelte-tel-input/pull/37))
114
126
 
115
- * fix: ci extend 321 ([#32](https://github.com/gyurielf/svelte-tel-input/pull/32))
127
+ * fix: ci extend 321 ([#32](https://github.com/gyurielf/svelte-tel-input/pull/32))
116
128
 
117
129
  ## 0.3.2
118
130
 
119
131
  ### Patch Changes
120
132
 
121
- - feat: add MIT license ([#29](https://github.com/gyurielf/svelte-tel-input/pull/29))
133
+ - feat: add MIT license ([#29](https://github.com/gyurielf/svelte-tel-input/pull/29))
122
134
 
123
- * fix: fix readme deps ([#29](https://github.com/gyurielf/svelte-tel-input/pull/29))
135
+ * fix: fix readme deps ([#29](https://github.com/gyurielf/svelte-tel-input/pull/29))
124
136
 
125
137
  ## 0.3.1
126
138
 
127
139
  ### Patch Changes
128
140
 
129
- - fix: lets check with different folder structure ([#25](https://github.com/gyurielf/svelte-tel-input/pull/25))
141
+ - fix: lets check with different folder structure ([#25](https://github.com/gyurielf/svelte-tel-input/pull/25))
130
142
 
131
143
  ## 0.3.0
132
144
 
133
145
  ### Minor Changes
134
146
 
135
- - fix: ci modifications ([#22](https://github.com/gyurielf/svelte-tel-input/pull/22))
147
+ - fix: ci modifications ([#22](https://github.com/gyurielf/svelte-tel-input/pull/22))
136
148
 
137
149
  ## 0.2.0
138
150
 
139
151
  ### Minor Changes
140
152
 
141
- - remove unused packages, cleanup, fix ci ([#19](https://github.com/gyurielf/svelte-tel-input/pull/19))
153
+ - remove unused packages, cleanup, fix ci ([#19](https://github.com/gyurielf/svelte-tel-input/pull/19))
142
154
 
143
- * fix: another CI fix ([#20](https://github.com/gyurielf/svelte-tel-input/pull/20))
155
+ * fix: another CI fix ([#20](https://github.com/gyurielf/svelte-tel-input/pull/20))
144
156
 
145
157
  ## 0.1.0
146
158
 
147
159
  ### Minor Changes
148
160
 
149
- - test_1
161
+ - test_1
150
162
 
151
163
  ### Patch Changes
152
164
 
153
- - szo
165
+ - szo
154
166
 
155
- * test 2
167
+ * test 2
156
168
 
157
- - test3
169
+ - test3
package/README.md CHANGED
@@ -1,37 +1,89 @@
1
- # Svelte Tel Input
1
+ <a name="readme-top"></a>
2
2
 
3
- ## Under development!
3
+ [![npm version](https://badge.fury.io/js/svelte-tel-input.svg)](https://badge.fury.io/js/svelte-tel-input)
4
4
 
5
- <ins>Do not use it before 1.0, it won't works properly!</ins>
5
+ # Svelte Tel Input
6
6
 
7
- Lightweight phone input standardization.
7
+ > Lightweight svelte tel/phone input standardizer.
8
8
 
9
- ---
9
+ The package is in `BETA` stage, expect bugs.
10
10
 
11
11
  ## Installation
12
12
 
13
13
  Svelte Tel Input is distributed via [npm](https://www.npmjs.com/package/svelte-tel-input).
14
14
 
15
- ```sh
16
- yarn add svelte-tel-input
17
- ```
18
-
19
- ```
15
+ ```bash
20
16
  npm install --save svelte-tel-input
21
17
  ```
22
18
 
23
- ## Dependencies
19
+ ## Usage
24
20
 
25
- [libphonenumber-js](https://gitlab.com/catamphetamine/libphonenumber-js)
21
+ ### Basic
22
+
23
+ ```html
24
+ <script lang="ts">
25
+ import { TelInput } from 'svelte-tel-input';
26
+ import type { NormalizedTelNumber, CountryCode } from 'svelte-tel-input/types';
27
+
28
+ // Any Country Code Alpha-2 (ISO 3166)
29
+ let country: CountryCode = 'US';
30
+
31
+ let parsedTelInput: NormalizedTelNumber | null = null;
32
+ </script>
33
+
34
+ <TelInput {country} bind:parsedTelInput class="any class passed down" />
35
+ ```
36
+
37
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
26
38
 
27
39
  ## Features
28
40
 
29
- - Automatically set the user's current country using an IP lookup. #TODO should be optional (IP (by default)|browserLang|off)
41
+ - Parse and validate phone number.
42
+ - Standardize parsed phone numbers. You can store one exact format, no matter how users type their phone numbers.
43
+ - Mask typed inputs (country specificly), to make it more readable.
44
+ - Automatically set the user's current country using an IP lookup.
45
+
46
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
30
47
 
31
- ---
48
+ ## Dependencies
49
+
50
+ [libphonenumber-js](https://gitlab.com/catamphetamine/libphonenumber-js)
51
+
52
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
32
53
 
33
54
  ## Changelog
34
55
 
35
56
  | Package | Changelog |
36
57
  | ------------------------------ | ------------------------- |
37
58
  | [@gyurielf/svelte-tel-input]() | [Changelog](CHANGELOG.md) |
59
+
60
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
61
+
62
+ ## Roadmap
63
+
64
+ - [x] Add Changelog
65
+ - [x] Add CI/CD
66
+ - [x] Integrate libphonenumber
67
+ - [x] Implement parser
68
+ - [x] Add basics docs and examples
69
+ - [ ] Add advanced examples
70
+ - [ ] Improve A11Y
71
+ - [ ] Default country sould be optional. ( ip | browserLang |off )
72
+ - [ ] Simlify code and types
73
+ - [ ] Multi-language Support
74
+
75
+ See the [open issues](https://github.com/gyurielf/svelte-tel-input/issues) for a list of proposed features (and known issues).
76
+
77
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
78
+
79
+ ## Support
80
+
81
+ <a href="https://www.buymeacoffee.com/gyurielf" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
82
+
83
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
84
+
85
+ ## License
86
+
87
+ Distributed under the MIT License. See `LICENSE.md` for more information.
88
+
89
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -0,0 +1,187 @@
1
+ <script>import { createEventDispatcher } from 'svelte';
2
+ import { normalizedCountries } from '../../assets';
3
+ import { clickOutsideAction } from '../../utils/directives/clickOutsideAction';
4
+ import TelInput from './TelInput.svelte';
5
+ import { isSelected } from '../../utils/helpers';
6
+ export let searchText = '';
7
+ export let selected = {
8
+ id: 'HU',
9
+ label: 'Hungary (Magyarország) +36',
10
+ name: 'Hungary (Magyarország)',
11
+ iso2: 'HU',
12
+ dialCode: '36',
13
+ priority: 0,
14
+ areaCodes: null
15
+ };
16
+ export let clickOutside = true;
17
+ export let closeOnClick = true;
18
+ export let disabled = false;
19
+ export let parsedTelInput = {
20
+ countryCode: 'HU',
21
+ isValid: true,
22
+ phoneNumber: '+36301234567',
23
+ countryCallingCode: '36',
24
+ formattedNumber: '+36 30 123 4567',
25
+ nationalNumber: '301234567',
26
+ formatInternational: '+36 30 123 4567',
27
+ formatOriginal: '30 123 4567',
28
+ formatNational: '06 30 123 4567',
29
+ uri: 'tel:+36301234567',
30
+ e164: '+36301234567'
31
+ };
32
+ let isOpen = false;
33
+ $: isValid = parsedTelInput?.isValid ?? false;
34
+ const toggleDropDown = (e) => {
35
+ e.preventDefault();
36
+ isOpen = !isOpen;
37
+ };
38
+ const closeDropdown = (e) => {
39
+ e?.preventDefault();
40
+ isOpen = false;
41
+ searchText = '';
42
+ };
43
+ const selectClick = () => {
44
+ if (closeOnClick)
45
+ closeDropdown();
46
+ };
47
+ const closeOnClickOutside = () => {
48
+ if (clickOutside) {
49
+ closeDropdown();
50
+ }
51
+ };
52
+ $: filteredItems =
53
+ searchText && searchText.length > 0
54
+ ? normalizedCountries
55
+ .filter((el) => el.label.toLowerCase().indexOf(searchText.toLowerCase()) >= 0)
56
+ .sort((a, b) => (a.label < b.label ? -1 : 1))
57
+ : normalizedCountries;
58
+ const handleSelect = (val, e) => {
59
+ if (disabled)
60
+ return;
61
+ e?.preventDefault();
62
+ if (typeof selected === 'object' && typeof val === 'object' && selected?.id && val?.id) {
63
+ if (typeof selected === 'object' && typeof val === 'object' && selected.id !== val.id) {
64
+ selected = val;
65
+ onChange(val);
66
+ selectClick();
67
+ }
68
+ else {
69
+ dispatch('same', { option: val });
70
+ selectClick();
71
+ }
72
+ }
73
+ else if (((selected === undefined || selected === null) && typeof val === 'object') ||
74
+ (typeof selected === typeof val && selected !== val)) {
75
+ selected = val;
76
+ onChange(val);
77
+ selectClick();
78
+ }
79
+ else {
80
+ dispatch('same', { option: val });
81
+ selectClick();
82
+ }
83
+ };
84
+ const dispatch = createEventDispatcher();
85
+ const onChange = (selectedCountry) => {
86
+ dispatch('change', { option: selectedCountry });
87
+ };
88
+ </script>
89
+
90
+ <div
91
+ class="flex rounded-lg {isValid
92
+ ? ``
93
+ : ` ring-pink-500 dark:ring-pink-500 ring-1 focus-within:ring-offset-1 focus-within:ring-offset-pink-500/50 focus-within:ring-2`}"
94
+ use:clickOutsideAction={closeOnClickOutside}
95
+ >
96
+ <button
97
+ id="states-button"
98
+ data-dropdown-toggle="dropdown-states"
99
+ class="flex-shrink-0 overflow-hidden z-10 inline-flex items-center py-2.5 px-4 text-sm font-medium text-center text-gray-500 bg-gray-100 border border-gray-300 rounded-l-lg hover:bg-gray-200 focus:outline-none dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-white dark:border-gray-600"
100
+ type="button"
101
+ on:click={toggleDropDown}
102
+ >
103
+ {#if selected && selected !== null}
104
+ <div class="inline-flex items-center text-left">
105
+ <span class="flag flag-{selected.iso2.toLowerCase()} flex-shrink-0 mr-3" />
106
+ <span class=" text-gray-500">+{selected.dialCode}</span>
107
+ </div>
108
+ {:else}
109
+ Please select
110
+ {/if}
111
+ <svg
112
+ aria-hidden="true"
113
+ class="ml-1 w-4 h-4"
114
+ fill="currentColor"
115
+ viewBox="0 0 20 20"
116
+ xmlns="http://www.w3.org/2000/svg"
117
+ >
118
+ <path
119
+ fill-rule="evenodd"
120
+ d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
121
+ clip-rule="evenodd"
122
+ />
123
+ </svg>
124
+ </button>
125
+ {#if isOpen}
126
+ <div
127
+ id="dropdown-countries"
128
+ class="z-10 max-w-fit bg-white rounded divide-y divide-gray-100 shadow dark:bg-gray-700 absolute translate-y-11 overflow-hidden"
129
+ data-popper-reference-hidden=""
130
+ data-popper-escaped=""
131
+ data-popper-placement="bottom"
132
+ aria-orientation="vertical"
133
+ aria-labelledby="country-button"
134
+ tabindex="-1"
135
+ >
136
+ <ul
137
+ class="text-sm text-gray-700 dark:text-gray-200 max-h-48 overflow-y-auto"
138
+ aria-labelledby="countries-button"
139
+ role="listbox"
140
+ >
141
+ {#if true}
142
+ <input
143
+ aria-autocomplete="list"
144
+ type="text"
145
+ class="px-4 py-2 text-gray-900 focus:outline-none w-full sticky top-0"
146
+ bind:value={searchText}
147
+ />
148
+ {/if}
149
+ {#each filteredItems as country (country.id)}
150
+ {@const isActive = isSelected(country, selected)}
151
+ <li role="option" aria-selected={isActive}>
152
+ <button
153
+ type="button"
154
+ class="inline-flex py-2 px-4 w-full text-sm hover:bg-gray-100 dark:hover:bg-gray-600
155
+ active:bg-gray-800 dark:active:bg-gray-800 overflow-hidden
156
+ {isActive
157
+ ? 'bg-gray-600 dark:text-white'
158
+ : 'dark:hover:text-white dark:text-gray-400'}"
159
+ on:click={(e) => {
160
+ handleSelect(country, e);
161
+ }}
162
+ >
163
+ <div class="inline-flex items-center text-left">
164
+ <span
165
+ class="flag flag-{country.iso2.toLowerCase()} flex-shrink-0 mr-3"
166
+ />
167
+ <span class="mr-2">{country.name}</span>
168
+ <span class=" text-gray-500">+{country.dialCode}</span>
169
+ </div>
170
+ </button>
171
+ </li>
172
+ {/each}
173
+ </ul>
174
+ </div>
175
+ {/if}
176
+
177
+ <TelInput
178
+ id="tel-input"
179
+ country={selected?.iso2}
180
+ bind:parsedTelInput
181
+ class="border border-gray-300 border-l-gray-100 dark:border-l-gray-700 dark:border-gray-600 {isValid
182
+ ? `bg-gray-50 dark:bg-gray-700
183
+ dark:placeholder-gray-400 dark:text-white text-gray-900`
184
+ : `dark:bg-gray-700`} text-sm rounded-r-lg block w-full p-2.5
185
+ focus:outline-none"
186
+ />
187
+ </div>
@@ -0,0 +1,24 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { NormalizedTelNumber, Country } from '../../types';
3
+ declare const __propDef: {
4
+ props: {
5
+ searchText?: string | undefined;
6
+ selected?: Country | null | undefined;
7
+ clickOutside?: boolean | undefined;
8
+ closeOnClick?: boolean | undefined;
9
+ disabled?: boolean | undefined;
10
+ parsedTelInput?: NormalizedTelNumber | null | undefined;
11
+ };
12
+ events: {
13
+ change: CustomEvent<any>;
14
+ } & {
15
+ [evt: string]: CustomEvent<any>;
16
+ };
17
+ slots: {};
18
+ };
19
+ export declare type AdvancedTelInputProps = typeof __propDef.props;
20
+ export declare type AdvancedTelInputEvents = typeof __propDef.events;
21
+ export declare type AdvancedTelInputSlots = typeof __propDef.slots;
22
+ export default class AdvancedTelInput extends SvelteComponentTyped<AdvancedTelInputProps, AdvancedTelInputEvents, AdvancedTelInputSlots> {
23
+ }
24
+ export {};
@@ -1,33 +1,33 @@
1
1
  <script>import { watcher } from '../../stores';
2
2
  import { PhoneNumberParseError } from '../../types';
3
- import { isNumber, normalizePhoneInput } from '../../utils/helpers';
3
+ import { normalizeTelInput } from '../../utils/helpers';
4
4
  import { parsePhoneNumberWithError, ParseError } from 'libphonenumber-js';
5
5
  import { onMount } from 'svelte';
6
- export let defaultCountry = null;
7
- export let rawPhoneInput = null;
8
- export let parsedPhoneInput = null;
6
+ export let country = null;
7
+ export let rawTelInput = null;
8
+ export let parsedTelInput = null;
9
9
  export let disabled = false;
10
10
  export let id = null;
11
11
  export let name = null;
12
12
  onMount(() => {
13
- if (parsedPhoneInput !== null) {
14
- rawPhoneInput = parsedPhoneInput.nationalNumber;
15
- handleParsePhoneNumber(defaultCountry, parsedPhoneInput.phoneNumber);
13
+ if (parsedTelInput !== null) {
14
+ rawTelInput = parsedTelInput.nationalNumber;
15
+ handleParsePhoneNumber(country, parsedTelInput.phoneNumber);
16
16
  }
17
17
  });
18
18
  const handleInput = (event) => {
19
19
  const inputVal = event.target.value.replace(/\s/g, '');
20
- rawPhoneInput = inputVal;
21
- handleParsePhoneNumber(defaultCountry, inputVal);
20
+ rawTelInput = inputVal;
21
+ handleParsePhoneNumber(country, inputVal);
22
22
  };
23
23
  const handleParsePhoneNumber = (country, input) => {
24
24
  try {
25
- parsedPhoneInput = normalizePhoneInput(parsePhoneNumberWithError(input, country || undefined));
25
+ parsedTelInput = normalizeTelInput(parsePhoneNumberWithError(input, country || undefined));
26
26
  }
27
27
  catch (err) {
28
28
  if (err instanceof ParseError) {
29
29
  // Not a phone number, non-existent country, etc.
30
- parsedPhoneInput = {
30
+ parsedTelInput = {
31
31
  isValid: false,
32
32
  error: PhoneNumberParseError[err.message]
33
33
  };
@@ -38,18 +38,18 @@ const handleParsePhoneNumber = (country, input) => {
38
38
  }
39
39
  };
40
40
  const watchFunction = () => {
41
- if (rawPhoneInput !== null)
42
- handleParsePhoneNumber(defaultCountry, rawPhoneInput);
41
+ if (rawTelInput !== null)
42
+ handleParsePhoneNumber(country, rawTelInput);
43
43
  };
44
44
  const countryChangeWatch = watcher(null, watchFunction);
45
- $: $countryChangeWatch = defaultCountry;
45
+ $: $countryChangeWatch = country;
46
46
  </script>
47
47
 
48
48
  <input
49
49
  {id}
50
50
  {name}
51
51
  {disabled}
52
- value={parsedPhoneInput?.formatOriginal ?? rawPhoneInput ?? ''}
52
+ value={parsedTelInput?.formatOriginal ?? rawTelInput ?? ''}
53
53
  type="tel"
54
54
  class={$$props.class}
55
55
  {...$$restProps}
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { NormalizedPhoneNumber } from '../../types/interfaces/Phone.interface';
2
+ import type { NormalizedTelNumber } from '../../types/interfaces/Phone.interface';
3
3
  import { type CountryCode } from 'libphonenumber-js';
4
4
  declare const __propDef: {
5
5
  props: {
6
6
  [x: string]: any;
7
- defaultCountry?: CountryCode | null | undefined;
8
- rawPhoneInput?: string | null | undefined;
9
- parsedPhoneInput?: Partial<NormalizedPhoneNumber> | null | undefined;
7
+ country?: CountryCode | null | undefined;
8
+ rawTelInput?: string | null | undefined;
9
+ parsedTelInput?: Partial<NormalizedTelNumber> | null | undefined;
10
10
  disabled?: boolean | undefined;
11
11
  id?: string | null | undefined;
12
12
  name?: string | null | undefined;
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as TelInput } from './components/Input/TelInput.svelte';
2
+ export { getCurrentCountry, isSelected } from './utils/helpers';
3
+ export { clickOutsideAction } from './utils/directives/clickOutsideAction';
4
+ export { normalizedCountries } from './assets';
package/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { default as TelInput } from './components/Input/TelInput.svelte';
2
+ export { getCurrentCountry, isSelected } from './utils/helpers';
3
+ export { clickOutsideAction } from './utils/directives/clickOutsideAction';
4
+ export { normalizedCountries } from './assets';