@availity/phone 1.1.21 → 1.1.22
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 +8 -0
- package/index.d.ts +2 -0
- package/package.json +5 -4
- package/src/Phone.js +2 -15
- package/{typings → types}/Phone.d.ts +3 -2
- package/tests/Phone.test.js +0 -150
- package/typings/index.d.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.1.22 (2021-09-28)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @availity/phone
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## 1.1.21 (2021-06-01)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @availity/phone
|
package/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/phone",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.22",
|
|
4
4
|
"description": "Availity Phone component using Formik and Yup",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"keywords": [],
|
|
7
8
|
"author": "Christopher Havekost <Christopher.Havekost@availity.com>",
|
|
8
9
|
"license": "MIT",
|
|
@@ -14,19 +15,19 @@
|
|
|
14
15
|
"prop-types": "^15.7.2"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
18
|
+
"@availity/form": "^0.7.1",
|
|
17
19
|
"formik": "^2.2.8",
|
|
18
|
-
"libphonenumber-js": "^1.9.18",
|
|
19
20
|
"react": "^17.0.2",
|
|
20
21
|
"react-dom": "^17.0.2",
|
|
21
22
|
"reactstrap": "^8.9.0",
|
|
22
23
|
"yup": "^0.30.0"
|
|
23
24
|
},
|
|
24
25
|
"peerDependencies": {
|
|
26
|
+
"@availity/form": "^0.7.0",
|
|
25
27
|
"formik": "^2.0.1",
|
|
26
|
-
"libphonenumber-js": "^1.7.38",
|
|
27
28
|
"react": ">=16.8.3",
|
|
28
29
|
"reactstrap": "^8.4.1",
|
|
29
30
|
"yup": "^0.28.1"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "cbd7f7edc581a61f6cc9258f00946d3098c51eef"
|
|
32
33
|
}
|
package/src/Phone.js
CHANGED
|
@@ -5,15 +5,7 @@ import { useFormikContext } from 'formik';
|
|
|
5
5
|
import { AsYouType } from 'libphonenumber-js';
|
|
6
6
|
import { Row, Col } from 'reactstrap';
|
|
7
7
|
|
|
8
|
-
const Phone = ({
|
|
9
|
-
name,
|
|
10
|
-
label,
|
|
11
|
-
country = 'US',
|
|
12
|
-
showExtension = false,
|
|
13
|
-
extProps,
|
|
14
|
-
phoneColProps,
|
|
15
|
-
...restPhoneProps
|
|
16
|
-
}) => {
|
|
8
|
+
const Phone = ({ name, label, country = 'US', showExtension = false, extProps, phoneColProps, ...restPhoneProps }) => {
|
|
17
9
|
const { setFieldValue, setFieldTouched } = useFormikContext();
|
|
18
10
|
|
|
19
11
|
let ext = null;
|
|
@@ -43,12 +35,7 @@ const Phone = ({
|
|
|
43
35
|
return (
|
|
44
36
|
<Row>
|
|
45
37
|
<Col xs={showExtension ? 10 : 12} {...phoneColProps}>
|
|
46
|
-
<Field
|
|
47
|
-
name={name}
|
|
48
|
-
label={label}
|
|
49
|
-
onBlur={formatPhoneOnBlur}
|
|
50
|
-
{...restPhoneProps}
|
|
51
|
-
/>
|
|
38
|
+
<Field name={name} label={label} onBlur={formatPhoneOnBlur} {...restPhoneProps} />
|
|
52
39
|
</Col>
|
|
53
40
|
{ext}
|
|
54
41
|
</Row>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FieldProps } from '@availity/form/
|
|
2
|
+
import { FieldProps } from '@availity/form/types/Field';
|
|
3
3
|
|
|
4
4
|
interface ExtensionProps extends FieldProps {
|
|
5
5
|
name: string;
|
|
6
6
|
id?: string;
|
|
7
7
|
extColProps?: object;
|
|
8
8
|
}
|
|
9
|
+
|
|
9
10
|
export interface PhoneProps extends FieldProps {
|
|
10
11
|
name: string;
|
|
11
12
|
id?: string;
|
|
@@ -14,6 +15,6 @@ export interface PhoneProps extends FieldProps {
|
|
|
14
15
|
extProps?: ExtensionProps;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
declare const Phone: React.
|
|
18
|
+
declare const Phone: React.FC<PhoneProps>;
|
|
18
19
|
|
|
19
20
|
export default Phone;
|
package/tests/Phone.test.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import * as yup from 'yup';
|
|
3
|
-
import '../src/validatePhone';
|
|
4
|
-
import { render, fireEvent, waitFor, cleanup } from '@testing-library/react';
|
|
5
|
-
import { Form } from '@availity/form';
|
|
6
|
-
import { Phone } from '..';
|
|
7
|
-
|
|
8
|
-
const phoneProps = {
|
|
9
|
-
name: 'test_phone',
|
|
10
|
-
id: 'test_phone',
|
|
11
|
-
title: 'Please enter number in the following format: 201-555-0123',
|
|
12
|
-
label: 'AvPhone',
|
|
13
|
-
// showExtension: true,
|
|
14
|
-
phoneColProps: {
|
|
15
|
-
xs: { size: 9 },
|
|
16
|
-
},
|
|
17
|
-
extProps: {
|
|
18
|
-
name: 'test-ext',
|
|
19
|
-
id: 'test-ext',
|
|
20
|
-
label: 'Ext.',
|
|
21
|
-
extColProps: {
|
|
22
|
-
xs: { size: 3 },
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const renderPhone = (props, strictValidation = false) => {
|
|
28
|
-
const Component = () => (
|
|
29
|
-
<Form
|
|
30
|
-
initialValues={{
|
|
31
|
-
test_phone: '201',
|
|
32
|
-
}}
|
|
33
|
-
onSubmit={() => {}}
|
|
34
|
-
validationSchema={yup.object().shape({
|
|
35
|
-
test_phone: yup
|
|
36
|
-
.string()
|
|
37
|
-
.validatePhone('This field is invalid', strictValidation),
|
|
38
|
-
})}
|
|
39
|
-
>
|
|
40
|
-
<Phone name="test_phone" {...props} />
|
|
41
|
-
</Form>
|
|
42
|
-
);
|
|
43
|
-
return render(<Component />);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
describe('Phone', () => {
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
cleanup();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('Should render extension field', async () => {
|
|
52
|
-
const { getByText } = renderPhone({
|
|
53
|
-
...phoneProps,
|
|
54
|
-
showExtension: true,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
await expect(getByText('Ext.')).toBeDefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('Should format valid phone number', async () => {
|
|
61
|
-
const { getByDisplayValue } = renderPhone(phoneProps);
|
|
62
|
-
const testPhoneInput = getByDisplayValue('201');
|
|
63
|
-
|
|
64
|
-
// Set value
|
|
65
|
-
await fireEvent.change(testPhoneInput, {
|
|
66
|
-
target: {
|
|
67
|
-
name: 'test_phone',
|
|
68
|
-
value: '2015550123',
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Formatter runs onBlur for screen reader friendliness
|
|
73
|
-
await fireEvent.blur(testPhoneInput);
|
|
74
|
-
|
|
75
|
-
await expect(getByDisplayValue('(201) 555-0123')).toBeDefined();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('Should format partial phone number', async () => {
|
|
79
|
-
const { getByDisplayValue } = renderPhone(phoneProps);
|
|
80
|
-
const testPhoneInput = getByDisplayValue('201');
|
|
81
|
-
|
|
82
|
-
await fireEvent.change(testPhoneInput, {
|
|
83
|
-
target: {
|
|
84
|
-
name: 'test_phone',
|
|
85
|
-
value: '20155501',
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
await fireEvent.blur(testPhoneInput);
|
|
90
|
-
|
|
91
|
-
await expect(getByDisplayValue('(201) 555-01')).toBeDefined();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('Should not format invalid phone number', async () => {
|
|
95
|
-
const { getByDisplayValue } = renderPhone(phoneProps);
|
|
96
|
-
const testPhoneInput = getByDisplayValue('201');
|
|
97
|
-
|
|
98
|
-
await fireEvent.change(testPhoneInput, {
|
|
99
|
-
target: {
|
|
100
|
-
name: 'test_phone',
|
|
101
|
-
value: '22233344445',
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
await fireEvent.blur(testPhoneInput);
|
|
106
|
-
|
|
107
|
-
await expect(getByDisplayValue('22233344445')).toBeDefined();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('Should render error message with strict validation', async () => {
|
|
111
|
-
const { getByDisplayValue, getByText } = renderPhone(phoneProps, true);
|
|
112
|
-
const testPhoneInput = getByDisplayValue('201');
|
|
113
|
-
|
|
114
|
-
await fireEvent.change(testPhoneInput, {
|
|
115
|
-
target: {
|
|
116
|
-
name: 'test_phone',
|
|
117
|
-
value: '2223334444',
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
await fireEvent.blur(testPhoneInput);
|
|
122
|
-
|
|
123
|
-
await waitFor(() => {
|
|
124
|
-
expect(testPhoneInput.className).toContain('is-touched');
|
|
125
|
-
expect(testPhoneInput.className).toContain('is-invalid');
|
|
126
|
-
expect(getByDisplayValue('(222) 333-4444')).toBeDefined();
|
|
127
|
-
expect(getByText('This field is invalid')).toBeDefined();
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('Should not render error message with default lax validation', async () => {
|
|
132
|
-
const { getByDisplayValue } = renderPhone(phoneProps);
|
|
133
|
-
const testPhoneInput = getByDisplayValue('201');
|
|
134
|
-
|
|
135
|
-
await fireEvent.change(testPhoneInput, {
|
|
136
|
-
target: {
|
|
137
|
-
name: 'test_phone',
|
|
138
|
-
value: '2223334444',
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
await fireEvent.blur(testPhoneInput);
|
|
143
|
-
|
|
144
|
-
await waitFor(() => {
|
|
145
|
-
expect(testPhoneInput.className).toContain('is-touched');
|
|
146
|
-
expect(testPhoneInput.className).toContain('av-valid');
|
|
147
|
-
expect(getByDisplayValue('(222) 333-4444')).toBeDefined();
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
package/typings/index.d.ts
DELETED