Skip to content

Commit cbce126

Browse files
Integrate react-phone-hooks (GH-71)
2 parents 445a961 + 873258c commit cbce126

File tree

20 files changed

+125
-37656
lines changed

20 files changed

+125
-37656
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Node
1717
uses: actions/setup-node@v3
1818
with:
19-
node-version: 16.x
19+
node-version: 20.x
2020
registry-url: https://registry.npmjs.org/
2121

2222
- name: Install dependencies

.github/workflows/update.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
resources
21
examples
32
scripts
43
tests

README.md

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,11 @@
66
[![License](https://img.shields.io/npm/l/antd-phone-input)](https://github.com/typesnippet/antd-phone-input/blob/master/LICENSE)
77
[![Tests](https://github.com/typesnippet/antd-phone-input/actions/workflows/tests.yml/badge.svg)](https://github.com/typesnippet/antd-phone-input/actions/workflows/tests.yml)
88

9-
Advanced phone input component for [Ant Design](https://github.com/ant-design/ant-design) that provides support for all
10-
countries and is compatible with [`antd`](https://github.com/ant-design/ant-design) 4 and 5 versions. It has built-in
11-
support for area codes and provides [strict validation](#validation) to ensure the entered numbers are valid. This
12-
open-source project is designed to simplify the process of collecting phone numbers from users.
13-
14-
## Installation
15-
16-
```shell
17-
npm i antd-phone-input
18-
```
19-
20-
```shell
21-
yarn add antd-phone-input
22-
```
23-
24-
## Usage
25-
26-
The library is designed to work with the `4.x` and `5.x` series of versions in the same way. It can be used as a regular
27-
Ant [Input](https://ant.design/components/input) (see the sample below). More usage examples can be found in
28-
the [examples](examples) directory.
29-
30-
```javascript
31-
import React from "react";
32-
import FormItem from "antd/es/form/FormItem";
33-
import PhoneInput from "antd-phone-input";
34-
35-
const Demo = () => {
36-
return (
37-
<FormItem name="phone">
38-
<PhoneInput enableSearch/>
39-
</FormItem>
40-
)
41-
}
42-
```
9+
Advanced phone input component for Material UI that leverages the [react-phone-hooks](https://www.npmjs.com/package/react-phone-hooks) supporting all countries. The package is compatible with [antd](https://github.com/ant-design/ant-design) 4 and 5 versions. It provides built-in support for area codes and strict validation.
4310

4411
## Value
4512

46-
The value of the component is an object containing the parts of the phone number. This format of value gives a wide
47-
range of opportunities for handling the data in your desired way.
13+
The value of the component is an object containing the parts of the phone number. This format of value gives a wide range of opportunities for handling the data in your desired way.
4814

4915
```javascript
5016
{
@@ -58,31 +24,35 @@ range of opportunities for handling the data in your desired way.
5824
5925
## Validation
6026
61-
The `valid` function of the value object returns the current validity of the entered phone number based on the selected
62-
country. So this can be used in a `validator` like this:
27+
The validation is checked by the `valid` function of the value object that returns a boolean value. An example with the [react-hook-form](https://www.npmjs.com/package/react-hook-form) is shown below:
6328
6429
```javascript
30+
import React from "react";
31+
import PhoneInput from "antd-phone-input";
32+
import FormItem from "antd/es/form/FormItem";
33+
6534
const validator = (_, {valid}) => {
6635
// if (valid(true)) return Promise.resolve(); // strict validation
6736
if (valid()) return Promise.resolve(); // non-strict validation
6837
return Promise.reject("Invalid phone number");
6938
}
7039

71-
return (
72-
<FormItem rules={[{validator}]}>
73-
<PhoneInput/>
74-
</FormItem>
75-
)
40+
const Demo = () => {
41+
return (
42+
<FormItem name="phone" rules={[{validator}]}>
43+
<PhoneInput enableSearch/>
44+
</FormItem>
45+
)
46+
}
47+
48+
export default Demo;
7649
```
7750
78-
By default, the `valid` function validates the phone number based on the possible supported lengths of the selected
79-
country. But it also supports a strict validation that apart from the length also checks if the area code is valid for
80-
the selected country. To enable strict validation, pass `true` as the first argument of the `valid` function.
51+
The `valid` function primarily checks if a phone number has a length appropriate for its specified country. In addition, a more comprehensive validation can be performed, including verifying the dial and area codes' accuracy for the selected country. To activate the strict validation, pass `true` as the first argument to the `valid` function.
8152
8253
## Props
8354
84-
Apart from the below-described phone-specific properties, all [Input](https://ant.design/components/input#input)
85-
properties that are supported by the used `antd` version, can be applied to the phone input component.
55+
Apart from the phone-specific properties described below, all [Input](https://ant.design/components/input#input) properties supported by the used Ant Design version can be applied to the phone input component.
8656
8757
| Property | Description | Type |
8858
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
@@ -100,8 +70,7 @@ properties that are supported by the used `antd` version, can be applied to the
10070
10171
## Contribute
10272
103-
Any contribution is welcome. If you have any ideas or suggestions, feel free to open an issue or a pull request. And
104-
don't forget to add tests for your changes.
73+
Any contribution is welcome. Don't hesitate to open an issue or discussion if you have questions about your project's usage and integration. For ideas or suggestions, please open a pull request. Your name will shine on our contributors' list. Be proud of what you build!
10574
10675
## License
10776

examples/antd4.x/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
"last 1 safari version"
3636
]
3737
}
38-
}
38+
}

examples/antd5.x/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
"last 1 safari version"
3434
]
3535
}
36-
}
36+
}

jestconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"transform": {
3-
"^.+\\.(t|j)sx?$": "ts-jest"
3+
"^.+\\.tsx?$": "ts-jest"
44
},
5-
"testRegex": "/tests/.*\\.test\\.([jt]sx?)$",
5+
"testRegex": "/tests/.*\\.test\\.(tsx?)$",
66
"moduleNameMapper": {
7-
"^.+\\.((?:c|le|s[ca])ss)$": "identity-obj-proxy"
7+
"^antd/es/(.+)$": "antd/lib/$1"
88
},
99
"modulePathIgnorePatterns": [
1010
"<rootDir>/examples"

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,31 @@
5353
"types*",
5454
"styles*",
5555
"LICENSE",
56-
"metadata",
56+
"resources",
5757
"README.md"
5858
],
5959
"scripts": {
6060
"rename": "bash -c 'for file in *.js; do mv $file \"${file%.js}.$0.js\"; done'",
6161
"build": "tsc --module commonjs && npm run rename -- cjs && tsc --declaration",
62-
"prebuild": "rm -r metadata index* types* styles* || true",
63-
"postbuild": "tsx scripts/prepare-styles.ts",
62+
"prebuild": "rm -r resources index* types* styles* || true",
6463
"postpack": "tsx scripts/prepare-package.ts",
65-
"test": "jest --config jestconfig.json"
64+
"test": "jest --config jestconfig.json",
65+
"postbuild": "cp -r src/resources ."
6666
},
6767
"license": "MIT",
6868
"peerDependencies": {
6969
"antd": ">=4",
7070
"react": ">=16"
7171
},
72+
"dependencies": {
73+
"react-phone-hooks": "^0.1.0-beta.1"
74+
},
7275
"devDependencies": {
7376
"@testing-library/react": "^14.0.0",
7477
"@testing-library/user-event": "^14.5.1",
7578
"@types/jest": "^29.5.7",
7679
"@types/react": "^18.2.34",
7780
"antd": "*",
78-
"identity-obj-proxy": "^3.0.0",
7981
"jest": "^29.7.0",
8082
"jest-environment-jsdom": "^29.7.0",
8183
"ts-jest": "^29.1.1",

0 commit comments

Comments
 (0)