@availity/phone 1.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/CHANGELOG.md +411 -0
- package/README.md +25 -0
- package/index.d.ts +15 -0
- package/index.js +2 -0
- package/jest.config.js +7 -0
- package/package.json +49 -0
- package/project.json +38 -0
- package/src/Phone.d.ts +21 -0
- package/src/Phone.js +83 -0
- package/src/validatePhone.js +22 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
# 1.0.0 (2024-08-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **phone:** remove yup.number validation method, remove async from test ([b346896](https://github.com/Availity/availity-react/commit/b346896414fc71c208be4f39cf6ac77412c5fea0))
|
|
11
|
+
* **phone:** typings for PhoneProps and ExtensionProps should extend FieldProps ([cdd467b](https://github.com/Availity/availity-react/commit/cdd467b3158dead419c3bfa6f551e5badf6edf3c))
|
|
12
|
+
* **phone:** update types ([30c7fc8](https://github.com/Availity/availity-react/commit/30c7fc885b1b91b04a5153fbf796e8c136692be4))
|
|
13
|
+
* upgrade yup and update sb stories ([68aeafe](https://github.com/Availity/availity-react/commit/68aeafe4fd7d90d7c88dbb24636ba7770fe87aa3))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
* feat(phone)!: upgrade to yup 0.32.0 ([dadde41](https://github.com/Availity/availity-react/commit/dadde41e7535ee444a0737a7ba31d5467a34133f))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* **form:** add currency input ([fa9eea6](https://github.com/Availity/availity-react/commit/fa9eea6a3b3dd2ef741a0658c102e36c6db5288c))
|
|
22
|
+
* move storybook, stories, and fix hmr ([2f65f71](https://github.com/Availity/availity-react/commit/2f65f71769d2d981e22700b87a09516833588f64))
|
|
23
|
+
* **phone:** add types ([b5cf0e6](https://github.com/Availity/availity-react/commit/b5cf0e62871266cc2e5689258912b1ba533bceb5))
|
|
24
|
+
* **phone:** initial commit for phone package ([76b7227](https://github.com/Availity/availity-react/commit/76b7227adee750265daa4e65486606d102a1e5c2))
|
|
25
|
+
* **phone:** initial format value ([#1447](https://github.com/Availity/availity-react/issues/1447)) ([3398a65](https://github.com/Availity/availity-react/commit/3398a65973bc46152ccd302f14b458e0af4d59d1))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### BREAKING CHANGES
|
|
29
|
+
|
|
30
|
+
* must be using yup 0.32.0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# [2.2.0](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.4...@availity/phone@2.2.0) (2024-08-01)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* **phone:** initial format value ([#1447](https://github.com/Availity/availity-react/issues/1447)) ([3398a65](https://github.com/Availity/availity-react/commit/3398a65973bc46152ccd302f14b458e0af4d59d1))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## [2.1.4](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.3...@availity/phone@2.1.4) (2023-10-30)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## [2.1.3](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.2...@availity/phone@2.1.3) (2023-10-09)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## [2.1.2](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.1...@availity/phone@2.1.2) (2023-02-22)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## [2.1.1](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.0...@availity/phone@2.1.1) (2022-06-14)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# [2.1.0](https://github.com/Availity/availity-react/compare/@availity/phone@2.0.1...@availity/phone@2.1.0) (2022-06-14)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
* **form:** add currency input ([fa9eea6](https://github.com/Availity/availity-react/commit/fa9eea6a3b3dd2ef741a0658c102e36c6db5288c))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## [2.0.1](https://github.com/Availity/availity-react/compare/@availity/phone@2.0.0...@availity/phone@2.0.1) (2022-06-10)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# [2.0.0](https://github.com/Availity/availity-react/compare/@availity/phone@1.2.5...@availity/phone@2.0.0) (2022-05-24)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### Bug Fixes
|
|
76
|
+
|
|
77
|
+
* upgrade yup and update sb stories ([68aeafe](https://github.com/Availity/availity-react/commit/68aeafe4fd7d90d7c88dbb24636ba7770fe87aa3))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
* feat(phone)!: upgrade to yup 0.32.0 ([dadde41](https://github.com/Availity/availity-react/commit/dadde41e7535ee444a0737a7ba31d5467a34133f))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### BREAKING CHANGES
|
|
84
|
+
|
|
85
|
+
* must be using yup 0.32.0
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## 1.2.5 (2022-03-09)
|
|
90
|
+
|
|
91
|
+
**Note:** Version bump only for package @availity/phone
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## [1.2.4](https://github.com/Availity/availity-react/compare/@availity/phone@1.2.3...@availity/phone@1.2.4) (2022-02-11)
|
|
98
|
+
|
|
99
|
+
**Note:** Version bump only for package @availity/phone
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
## [1.2.3](https://github.com/Availity/availity-react/compare/@availity/phone@1.2.2...@availity/phone@1.2.3) (2021-12-20)
|
|
106
|
+
|
|
107
|
+
**Note:** Version bump only for package @availity/phone
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## 1.2.2 (2021-12-14)
|
|
114
|
+
|
|
115
|
+
**Note:** Version bump only for package @availity/phone
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## 1.2.1 (2021-11-30)
|
|
122
|
+
|
|
123
|
+
**Note:** Version bump only for package @availity/phone
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# [1.2.0](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.31...@availity/phone@1.2.0) (2021-11-15)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### Features
|
|
133
|
+
|
|
134
|
+
* move storybook, stories, and fix hmr ([2f65f71](https://github.com/Availity/availity-react/commit/2f65f71769d2d981e22700b87a09516833588f64))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
## [1.1.32](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.31...@availity/phone@1.1.32) (2021-11-12)
|
|
141
|
+
|
|
142
|
+
**Note:** Version bump only for package @availity/phone
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## [1.1.31](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.29...@availity/phone@1.1.31) (2021-11-05)
|
|
149
|
+
|
|
150
|
+
**Note:** Version bump only for package @availity/phone
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## [1.1.30](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.29...@availity/phone@1.1.30) (2021-10-28)
|
|
157
|
+
|
|
158
|
+
**Note:** Version bump only for package @availity/phone
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
## 1.1.29 (2021-10-28)
|
|
165
|
+
|
|
166
|
+
**Note:** Version bump only for package @availity/phone
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
## 1.1.28 (2021-10-19)
|
|
173
|
+
|
|
174
|
+
**Note:** Version bump only for package @availity/phone
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## [1.1.27](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.26...@availity/phone@1.1.27) (2021-10-19)
|
|
181
|
+
|
|
182
|
+
**Note:** Version bump only for package @availity/phone
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## [1.1.26](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.25...@availity/phone@1.1.26) (2021-10-19)
|
|
189
|
+
|
|
190
|
+
**Note:** Version bump only for package @availity/phone
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
## 1.1.25 (2021-10-19)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
### Bug Fixes
|
|
200
|
+
|
|
201
|
+
* **phone:** update types ([30c7fc8](https://github.com/Availity/availity-react/commit/30c7fc885b1b91b04a5153fbf796e8c136692be4))
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## [1.1.24](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.23...@availity/phone@1.1.24) (2021-10-04)
|
|
208
|
+
|
|
209
|
+
**Note:** Version bump only for package @availity/phone
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
## [1.1.23](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.22...@availity/phone@1.1.23) (2021-10-01)
|
|
216
|
+
|
|
217
|
+
**Note:** Version bump only for package @availity/phone
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
## 1.1.22 (2021-09-28)
|
|
224
|
+
|
|
225
|
+
**Note:** Version bump only for package @availity/phone
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
## 1.1.21 (2021-06-01)
|
|
232
|
+
|
|
233
|
+
**Note:** Version bump only for package @availity/phone
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
## 1.1.20 (2021-04-20)
|
|
240
|
+
|
|
241
|
+
**Note:** Version bump only for package @availity/phone
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
## 1.1.19 (2020-11-17)
|
|
248
|
+
|
|
249
|
+
**Note:** Version bump only for package @availity/phone
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
## 1.1.18 (2020-04-30)
|
|
256
|
+
|
|
257
|
+
**Note:** Version bump only for package @availity/phone
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
## 1.1.17 (2020-04-30)
|
|
264
|
+
|
|
265
|
+
**Note:** Version bump only for package @availity/phone
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
## 1.1.16 (2020-04-28)
|
|
272
|
+
|
|
273
|
+
**Note:** Version bump only for package @availity/phone
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
## 1.1.15 (2020-04-17)
|
|
280
|
+
|
|
281
|
+
**Note:** Version bump only for package @availity/phone
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
## 1.1.14 (2020-04-09)
|
|
288
|
+
|
|
289
|
+
**Note:** Version bump only for package @availity/phone
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
## 1.1.13 (2020-04-08)
|
|
296
|
+
|
|
297
|
+
**Note:** Version bump only for package @availity/phone
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
## 1.1.12 (2020-04-08)
|
|
304
|
+
|
|
305
|
+
**Note:** Version bump only for package @availity/phone
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
## 1.1.11 (2020-04-07)
|
|
312
|
+
|
|
313
|
+
**Note:** Version bump only for package @availity/phone
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
## 1.1.10 (2020-04-07)
|
|
320
|
+
|
|
321
|
+
**Note:** Version bump only for package @availity/phone
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
## 1.1.9 (2020-04-06)
|
|
328
|
+
|
|
329
|
+
**Note:** Version bump only for package @availity/phone
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
## 1.1.8 (2020-04-06)
|
|
336
|
+
|
|
337
|
+
**Note:** Version bump only for package @availity/phone
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
## 1.1.7 (2020-04-06)
|
|
344
|
+
|
|
345
|
+
**Note:** Version bump only for package @availity/phone
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
## 1.1.6 (2020-04-06)
|
|
352
|
+
|
|
353
|
+
**Note:** Version bump only for package @availity/phone
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
## 1.1.5 (2020-04-03)
|
|
360
|
+
|
|
361
|
+
**Note:** Version bump only for package @availity/phone
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
## 1.1.4 (2020-04-03)
|
|
368
|
+
|
|
369
|
+
**Note:** Version bump only for package @availity/phone
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
## 1.1.3 (2020-04-02)
|
|
376
|
+
|
|
377
|
+
**Note:** Version bump only for package @availity/phone
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
## 1.1.2 (2020-04-02)
|
|
384
|
+
|
|
385
|
+
**Note:** Version bump only for package @availity/phone
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
## [1.1.1](https://github.com/Availity/availity-react/compare/@availity/phone@1.1.0...@availity/phone@1.1.1) (2020-02-24)
|
|
392
|
+
|
|
393
|
+
**Note:** Version bump only for package @availity/phone
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
# 1.1.0 (2020-02-11)
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
### Bug Fixes
|
|
403
|
+
|
|
404
|
+
* **phone:** remove yup.number validation method, remove async from test ([b346896](https://github.com/Availity/availity-react/commit/b346896414fc71c208be4f39cf6ac77412c5fea0))
|
|
405
|
+
* **phone:** typings for PhoneProps and ExtensionProps should extend FieldProps ([cdd467b](https://github.com/Availity/availity-react/commit/cdd467b3158dead419c3bfa6f551e5badf6edf3c))
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
### Features
|
|
409
|
+
|
|
410
|
+
* **phone:** add types ([b5cf0e6](https://github.com/Availity/availity-react/commit/b5cf0e62871266cc2e5689258912b1ba533bceb5))
|
|
411
|
+
* **phone:** initial commit for phone package ([76b7227](https://github.com/Availity/availity-react/commit/76b7227adee750265daa4e65486606d102a1e5c2))
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @availity/phone
|
|
2
|
+
|
|
3
|
+
> Availity Phone component using Formik and Yup
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/phone)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/phone)
|
|
7
|
+
[](https://github.com/Availity/availity-react/blob/master/packages/phone/package.json)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
### NPM
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @availity/phone
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Yarn
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @availity/phone
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
Check out more documentation at [availity.github.io](https://availity.github.io/availity-react/form/phone/index)
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { default as Phone, PhoneProps } from './src/Phone';
|
|
2
|
+
export { default as validatePhone } from './src/validatePhone';
|
|
3
|
+
|
|
4
|
+
declare module 'yup' {
|
|
5
|
+
import { AnyObject, Maybe } from 'yup/lib/types';
|
|
6
|
+
import BaseSchema from 'yup/lib/schema';
|
|
7
|
+
|
|
8
|
+
interface StringSchema<
|
|
9
|
+
TType extends Maybe<string> = string | undefined,
|
|
10
|
+
TContext extends AnyObject = AnyObject,
|
|
11
|
+
TOut extends TType = TType
|
|
12
|
+
> extends BaseSchema<TType, TContext, TOut> {
|
|
13
|
+
validatePhone(message?: string, strict?: boolean, country?: string): StringSchema<TType, TContext>;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/index.js
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/phone",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Availity Phone component using Formik and Yup",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"availity",
|
|
7
|
+
"yup",
|
|
8
|
+
"formik"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://availity.github.io/availity-react/form/phone/index",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Availity/availity-react/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/Availity/availity-react.git",
|
|
17
|
+
"directory": "packages/phone"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Christopher Havekost <Christopher.Havekost@availity.com>",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"types": "index.d.ts",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
25
|
+
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"libphonenumber-js": "^1.11.5",
|
|
29
|
+
"prop-types": "^15.8.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@availity/form": "1.0.0",
|
|
33
|
+
"formik": "^2.4.6",
|
|
34
|
+
"react": "^18.3.1",
|
|
35
|
+
"react-dom": "^18.3.1",
|
|
36
|
+
"reactstrap": "^8.10.1",
|
|
37
|
+
"yup": "^0.32.11"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@availity/form": "^1.1.0",
|
|
41
|
+
"formik": "^2.0.1",
|
|
42
|
+
"react": ">=16.8.3",
|
|
43
|
+
"reactstrap": "^8.0.0",
|
|
44
|
+
"yup": "^0.32.0"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/phone",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"projectType": "library",
|
|
5
|
+
"targets": {
|
|
6
|
+
"test": {
|
|
7
|
+
"executor": "@nx/jest:jest",
|
|
8
|
+
"outputs": ["{workspaceRoot}/coverage/phone"],
|
|
9
|
+
"options": {
|
|
10
|
+
"jestConfig": "packages/phone/jest.config.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"version": {
|
|
14
|
+
"executor": "@jscutlery/semver:version",
|
|
15
|
+
"options": {
|
|
16
|
+
"preset": "angular",
|
|
17
|
+
"commitMessageFormat": "chore({projectName}): release version ${version} [skip ci]",
|
|
18
|
+
"tagPrefix": "@availity/{projectName}@",
|
|
19
|
+
"baseBranch": "master"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"lint": {
|
|
23
|
+
"executor": "@nx/eslint:lint",
|
|
24
|
+
"options": {
|
|
25
|
+
"eslintConfig": ".eslintrc.yaml",
|
|
26
|
+
"silent": false,
|
|
27
|
+
"fix": false,
|
|
28
|
+
"cache": true,
|
|
29
|
+
"cacheLocation": "./node_modules/.cache/phone/.eslintcache",
|
|
30
|
+
"maxWarnings": -1,
|
|
31
|
+
"quiet": false,
|
|
32
|
+
"noEslintrc": false,
|
|
33
|
+
"hasTypeAwareRules": true,
|
|
34
|
+
"cacheStrategy": "metadata"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/Phone.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FieldProps } from '@availity/form';
|
|
2
|
+
|
|
3
|
+
interface ExtensionProps extends FieldProps {
|
|
4
|
+
name: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
extColProps?: object;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PhoneProps extends FieldProps {
|
|
10
|
+
name: string;
|
|
11
|
+
id?: string;
|
|
12
|
+
country?: string;
|
|
13
|
+
showExtension?: boolean;
|
|
14
|
+
phoneColProps?: object;
|
|
15
|
+
extProps?: ExtensionProps;
|
|
16
|
+
formatInitialValue?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare const Phone: (props: PhoneProps) => JSX.Element;
|
|
20
|
+
|
|
21
|
+
export default Phone;
|
package/src/Phone.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { Field } from '@availity/form';
|
|
4
|
+
import { useFormikContext } from 'formik';
|
|
5
|
+
import { AsYouType } from 'libphonenumber-js';
|
|
6
|
+
import { Row, Col } from 'reactstrap';
|
|
7
|
+
|
|
8
|
+
const Phone = ({
|
|
9
|
+
name,
|
|
10
|
+
label,
|
|
11
|
+
country = 'US',
|
|
12
|
+
showExtension = false,
|
|
13
|
+
extProps,
|
|
14
|
+
phoneColProps,
|
|
15
|
+
formatInitialValue,
|
|
16
|
+
...restPhoneProps
|
|
17
|
+
}) => {
|
|
18
|
+
const { setFieldValue, setFieldTouched, values } = useFormikContext();
|
|
19
|
+
|
|
20
|
+
let ext = null;
|
|
21
|
+
if (showExtension) {
|
|
22
|
+
const { name, label, extColProps, ...restExtProps } = extProps;
|
|
23
|
+
|
|
24
|
+
ext = (
|
|
25
|
+
<Col {...extColProps}>
|
|
26
|
+
<Field name={name} label={label} {...restExtProps} />
|
|
27
|
+
</Col>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const asYouFormat = (phoneString) => {
|
|
32
|
+
// Use AsYouType instead of parsePhoneNumberFromString.format() so partial values can still be formatted
|
|
33
|
+
const asYouType = new AsYouType(country);
|
|
34
|
+
asYouType.input(phoneString);
|
|
35
|
+
|
|
36
|
+
return asYouType.formattedOutput;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (formatInitialValue) {
|
|
41
|
+
setFieldValue(name, asYouFormat(values[name]), false);
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
const formatPhoneOnBlur = ({ target: { value } }) => {
|
|
47
|
+
setFieldValue(name, asYouFormat(value), true);
|
|
48
|
+
setFieldTouched(name, true, true);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Row>
|
|
53
|
+
<Col xs={showExtension ? 10 : 12} {...phoneColProps}>
|
|
54
|
+
<Field name={name} label={label} onBlur={formatPhoneOnBlur} {...restPhoneProps} />
|
|
55
|
+
</Col>
|
|
56
|
+
{ext}
|
|
57
|
+
</Row>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
Phone.propTypes = {
|
|
62
|
+
/** Identifies the field and matches the validation schema. */
|
|
63
|
+
name: PropTypes.string.isRequired,
|
|
64
|
+
/** Used to pass props to the extension field when it is enabled. */
|
|
65
|
+
extProps: PropTypes.shape({
|
|
66
|
+
name: PropTypes.string.isRequired,
|
|
67
|
+
label: PropTypes.string,
|
|
68
|
+
/** Used to control props on `<Col />` for the extension field, if needed. The extension column has no default size value, so it's default will effectively be size: { 12 - phoneColSize } unless otherwise specified. */
|
|
69
|
+
extColProps: PropTypes.object,
|
|
70
|
+
}),
|
|
71
|
+
/** Displays a Reactstrap `<Label />` for the field. */
|
|
72
|
+
label: PropTypes.string,
|
|
73
|
+
/** Enable the phone extension field. */
|
|
74
|
+
showExtension: PropTypes.bool,
|
|
75
|
+
/** Default country for parsing national numbers. [This is the two letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). */
|
|
76
|
+
country: PropTypes.string,
|
|
77
|
+
/** Used to control props on the `<Col />` for the phone field, if needed. The phone column defaults to xs: { size: 12 } when not rendering an extension field, and defaults to xs: { size: 10 } when rendering an extension field. */
|
|
78
|
+
phoneColProps: PropTypes.object,
|
|
79
|
+
/** When true, when the field is first rendered, it will trigger the formatter to update the value. */
|
|
80
|
+
formatInitialValue: PropTypes.bool,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default Phone;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { addMethod, string } from 'yup';
|
|
2
|
+
import { AsYouType } from 'libphonenumber-js';
|
|
3
|
+
|
|
4
|
+
export default function validatePhone(msg, strict = false, country = 'US') {
|
|
5
|
+
return this.test({
|
|
6
|
+
name: 'validatePhone',
|
|
7
|
+
exclusive: true,
|
|
8
|
+
message: msg || 'This field is invalid.',
|
|
9
|
+
test(phoneValue) {
|
|
10
|
+
if (!phoneValue) return true;
|
|
11
|
+
|
|
12
|
+
const asYouType = new AsYouType(country);
|
|
13
|
+
asYouType.input(phoneValue);
|
|
14
|
+
if (strict) {
|
|
15
|
+
return asYouType.getNumber() && asYouType.getNumber().isValid();
|
|
16
|
+
}
|
|
17
|
+
return asYouType.getNumber() && asYouType.getNumber().isPossible();
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
addMethod(string, 'validatePhone', validatePhone);
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
+
"allowJs": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
|
|
10
|
+
}
|