@availity/phone 2.1.3 → 2.2.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 +13 -0
- package/package.json +2 -2
- package/src/Phone.d.ts +1 -0
- package/src/Phone.js +21 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [2.2.0](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.4...@availity/phone@2.2.0) (2024-08-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **phone:** initial format value ([#1447](https://github.com/Availity/availity-react/issues/1447)) ([3398a65](https://github.com/Availity/availity-react/commit/3398a65973bc46152ccd302f14b458e0af4d59d1))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.1.4](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.3...@availity/phone@2.1.4) (2023-10-30)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
5
18
|
## [2.1.3](https://github.com/Availity/availity-react/compare/@availity/phone@2.1.2...@availity/phone@2.1.3) (2023-10-09)
|
|
6
19
|
|
|
7
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/phone",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Availity Phone component using Formik and Yup",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"availity",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prop-types": "^15.8.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@availity/form": "1.
|
|
32
|
+
"@availity/form": "1.9.0",
|
|
33
33
|
"formik": "^2.4.4",
|
|
34
34
|
"react": "^18.2.0",
|
|
35
35
|
"react-dom": "^18.2.0",
|
package/src/Phone.d.ts
CHANGED
package/src/Phone.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { Field } from '@availity/form';
|
|
4
4
|
import { useFormikContext } from 'formik';
|
|
5
5
|
import { AsYouType } from 'libphonenumber-js';
|
|
6
6
|
import { Row, Col } from 'reactstrap';
|
|
7
7
|
|
|
8
|
-
const Phone = ({
|
|
9
|
-
|
|
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();
|
|
10
19
|
|
|
11
20
|
let ext = null;
|
|
12
21
|
if (showExtension) {
|
|
@@ -27,6 +36,13 @@ const Phone = ({ name, label, country = 'US', showExtension = false, extProps, p
|
|
|
27
36
|
return asYouType.formattedOutput;
|
|
28
37
|
};
|
|
29
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
|
+
|
|
30
46
|
const formatPhoneOnBlur = ({ target: { value } }) => {
|
|
31
47
|
setFieldValue(name, asYouFormat(value), true);
|
|
32
48
|
setFieldTouched(name, true, true);
|
|
@@ -60,6 +76,8 @@ Phone.propTypes = {
|
|
|
60
76
|
country: PropTypes.string,
|
|
61
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. */
|
|
62
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,
|
|
63
81
|
};
|
|
64
82
|
|
|
65
83
|
export default Phone;
|