Skip to content

Commit

Permalink
Release v0.1.0 GH-18
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomVancyan authored Mar 3, 2023
2 parents f6667c9 + efc7437 commit 6474d4b
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 143 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Tests

on: push

jobs:
tests:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: yarn && yarn install

- name: Run tests
run: yarn test
102 changes: 101 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,102 @@
# antd-phone-input
Advanced Phone Number Input for Ant Design

Advanced Phone Number Input for [Ant Design](https://github.com/ant-design/ant-design).

[![npm](https://img.shields.io/npm/v/antd-phone-input)](https://www.npmjs.com/package/antd-phone-input)
[![types](https://img.shields.io/npm/types/antd-phone-input)](https://www.npmjs.com/package/antd-phone-input)
[![License](https://img.shields.io/npm/l/antd-phone-input)](https://github.com/ArtyomVancyan/antd-phone-input/blob/master/LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://makeapullrequest.com)
[![Tests](https://github.com/ArtyomVancyan/antd-phone-input/actions/workflows/tests.yml/badge.svg)](https://github.com/ArtyomVancyan/antd-phone-input/actions/workflows/tests.yml)

## Install

```shell
npm i antd-phone-input
```

```shell
yarn add antd-phone-input
```

## Usage

### Antd 4.x

```javascript
import React from "react";
import PhoneInput from "antd-phone-input";
import FormItem from "antd/es/form/FormItem";

const Demo = () => {
return (
<FormItem name="phone">
<PhoneInput enableSearch/>
</FormItem>
)
}
```

### Antd 5.x

```ascii
v5.x does not have support yet
this issue is covered in GH-20
```

## Value

The value of the component is an object containing the parts of a phone number. This format of value gives a wide range
of opportunities for handling the data in your custom way. For example, you can easily merge the parts of the phone
number into a single string.

```json
{
"countryCode": 1,
"areaCode": 702,
"phoneNumber": "1234567",
"isoCode": "us"
}
```

## Props

| Property | Description | Type |
|--------------------|---------------------------------------------------------------------------------------------------------------------------------|---------------------|
| size | Either `large`, `middle` or `small`. Default value is `middle`. See at ant [docs][antInputProps] for more. | string |
| value | An object containing the parts of phone number. E.g. `value={{countryCode: 1, areaCode: 702, phoneNumber: "1234567"}}`. | object |
| style | Applies CSS styles to the container element. | CSSProperties |
| className | The value will be assigned to the container element. | string |
| disabled | Disables the whole input component. | boolean |
| enableSearch | Enables search in the country selection dropdown menu. Default value is `false`. | boolean |
| disableDropdown | Disables the manual country selection through the dropdown menu. | boolean |
| inputProps | [HTML properties of input][htmlInputProps] to pass into the input. E.g. `inputProps={{autoFocus: true}}`. | InputHTMLAttributes |
| searchPlaceholder | The value is shown if `enableSearch` is `true`. Default value is `search`. | string |
| searchNotFound | The value is shown if `enableSearch` is `true` and the query does not match any country. Default value is `No entries to show`. | string |
| placeholder | Custom placeholder. Default placeholder is `1 (702) 123-4567`. | string |
| country | Country code to be selected by default. By default, it will show the flag of the user's country. | string |
| regions | Show only the countries of the specified regions. See the list of [available regions][reactPhoneRegions]. | string[] |
| onlyCountries | Country codes to be included in the list. E.g. `onlyCountries={['us', 'ca', 'uk']}`. | string[] |
| excludeCountries | Country codes to be excluded from the list of countries. E.g. `excludeCountries={['us', 'ca', 'uk']}`. | string[] |
| preferredCountries | Country codes to be at the top of the list. E.g. `preferredCountries={['us', 'ca', 'uk']}`. | string[] |
| onChange | Callback when the user is inputting. See at ant [docs][antInputProps] for more. | function(value, e) |
| onPressEnter | The callback function that is triggered when <kbd>Enter</kbd> key is pressed. | function(e) |
| onFocus | The callback is triggered when the input element is focused. | function(e, value) |
| onClick | The callback is triggered when the user clicks on the input element. | function(e, value) |
| onBlur | The callback is triggered when the input element gets blurred or unfocused. | function(e, value) |
| onKeyDown | The callback is triggered when any key is pressed down. | function(e) |
| onMount | The callback is triggered once the component gets mounted. | function(e) |

## Contribute

Any contribution is welcome. If you have any ideas or suggestions, feel free to open an issue or a pull request. And
don't forget to add tests for your changes.

## License

Copyright (C) 2023 Artyom Vancyan. [MIT](LICENSE)

[antInputProps]:https://ant.design/components/input#input

[reactPhoneRegions]:https://github.com/bl00mber/react-phone-input-2#regions

[htmlInputProps]:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes
26 changes: 23 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
{
"version": "0.1.0",
"name": "antd-phone-input",
"version": "0.0.2",
"description": "Advanced Phone Number Input for Ant Design",
"keywords": [
"ant",
"antd",
"react",
"design",
"frontend",
"component",
"components",
"phone-input",
"phone-number"
],
"homepage": "https://github.com/ArtyomVancyan/antd-phone-input",
"bugs": {
"url": "https://github.com/ArtyomVancyan/antd-phone-input/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/ArtyomVancyan/antd-phone-input"
},
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
Expand All @@ -21,11 +41,12 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-typescript": "^11.0.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.4.0",
"@types/node": "^18.14.1",
"@types/react": "^18.0.28",
"@types/rollup-plugin-less": "^1.1.2",
"antd": "^5.2.2",
"antd": "^4.24.8",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.4.3",
Expand All @@ -35,7 +56,6 @@
"rollup": "3.17.2",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-less": "^1.1.3",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-postcss": "^4.0.2",
"ts-jest": "^29.0.5",
"tslib": "^2.5.0",
Expand Down
13 changes: 6 additions & 7 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import dts from "rollup-plugin-dts";
import less from "rollup-plugin-less";
import json from "@rollup/plugin-json";
import postcss from "rollup-plugin-postcss";
import resolve from "rollup-plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import {readFileSync} from "fs";

Expand All @@ -14,19 +13,19 @@ const esmOutput = {file: pkg.module, format: "es"};
const dtsOutput = {file: pkg.types, format: "es"};

const jsonPlugin = json();
const cssPlugin = postcss();
const tsPlugin = typescript();
const resolvePlugin = resolve();
const lessPlugin = less({insert: true, output: false});
const cssPlugin = postcss({exclude: /\.less$/, include: /\.css$/});
const lessPlugin = less({insert: true, output: false, option: {javascriptEnabled: true}});

const external = [
...Object.keys({...pkg.dependencies, ...pkg.peerDependencies}),
/^react($|\/)/,
/^antd($|\/)/,
/\.css$/,
];

export default [
{input, output: cjsOutput, plugins: [tsPlugin, jsonPlugin, resolvePlugin, cssPlugin], external},
{input, output: esmOutput, plugins: [tsPlugin, jsonPlugin, resolvePlugin, cssPlugin], external},
{input, output: dtsOutput, plugins: [dts(), lessPlugin], external: [/\.(?:le|c)ss$/]},
{input, output: cjsOutput, plugins: [tsPlugin, jsonPlugin, cssPlugin, lessPlugin], external},
{input, output: esmOutput, plugins: [tsPlugin, jsonPlugin, cssPlugin, lessPlugin], external},
{input, output: dtsOutput, plugins: [dts()], external: [/\.(le|c)ss$/]},
];
164 changes: 86 additions & 78 deletions src/index.less
Original file line number Diff line number Diff line change
@@ -1,79 +1,87 @@
@import "~react-phone-input-2/lib/style.css";
@import "../node_modules/antd/lib/style/themes/variable";
@import "../node_modules/antd/lib/input/style/index";

//.phone-number-form-item {
//
// &.ant-form-item-has-error {
// .react-tel-input {
// .form-control {
// border-color: @error-color;
//
// &:hover {
// border-color: @error-color;
// }
//
// &:focus {
// border-color: @error-color;
// }
// }
// }
// }
//
// .react-tel-input {
//
// .form-control {
// z-index: 3;
// width: 100%;
// border-radius: @border-radius-base;
// line-height: @line-height-base;
// height: inherit;
// background: transparent;
// border-color: @border-color-base;
//
// &:hover {
// border-color: @input-hover-border-color;
// }
//
// &:focus {
// border-color: @primary-color;
// }
// }
//
// .country-list {
// margin: 3px;
// border-radius: 2px;
// width: calc(100% - 6px);
// box-shadow: 0 3px 6px -4px rgba(0, 0, 0, .12),
// 0 6px 16px 0 rgba(0, 0, 0, .08),
// 0 9px 28px 8px rgba(0, 0, 0, .05);
//
// .search {
// padding: @spacing-2 @spacing-2 @spacing-1 @spacing-2;
//
// .search-box {
// .ant-input();
// }
// }
// }
//
// .flag-dropdown,
// .flag-dropdown.open {
// border: 0;
// width: 100%;
// border-radius: 0;
// background-color: transparent;
//
// .arrow {
// display: none;
// }
//
// .selected-flag {
// z-index: 4;
// padding: 0;
// display: flex;
// justify-content: center;
// border-right: @border-base;
// background-color: transparent;
// }
// }
// }
//}
.ant-form-item {
&.ant-form-item-has-error {
.react-tel-input {
.form-control {
border-color: @error-color;

&:hover {
border-color: @error-color;
}

&:focus {
border-color: @error-color;
}
}
}
}
}

.react-tel-input {
.form-control {
z-index: 3;
width: 100%;
border-radius: @border-radius-base;
line-height: @line-height-base;
height: inherit;
background: transparent;
border-color: @border-color-base;

&:hover {
border-color: @input-hover-border-color;
}

&:focus {
border-color: @primary-color;
}

&.open {
z-index: 6 !important;
transition: 0s !important;
}
}

.country-list {
margin: 3px;
border-radius: 2px;
width: calc(100% - 6px);
box-shadow: 0 3px 6px -4px rgba(0, 0, 0, .12),
0 6px 16px 0 rgba(0, 0, 0, .08),
0 9px 28px 8px rgba(0, 0, 0, .05);

.search {
padding: 10px 10px 5px 10px;

.search-box {
.ant-input();
}
}
}

.flag-dropdown,
.flag-dropdown.open {
border: 0;
width: 100%;
border-radius: 0;
background-color: @component-background;

.arrow {
display: none;
}

.selected-flag {
z-index: 4;
padding: 0;
display: flex;
justify-content: center;
background-color: transparent;
border-right: @border-width-base @border-style-base @border-color-base;
}
}

.flag-dropdown.open {
z-index: 5 !important;
}
}
Loading

0 comments on commit 6474d4b

Please sign in to comment.