Skip to content

Commit

Permalink
feat(tel-input): implement TelInput
Browse files Browse the repository at this point in the history
  • Loading branch information
jigsawye committed Jan 25, 2019
1 parent ab6e332 commit 0fdb7e1
Show file tree
Hide file tree
Showing 11 changed files with 1,433 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"rc-time-picker": "^3.4.0",
"react-dropzone": "^7.0.1",
"react-html-attributes": "^1.4.3",
"react-intl-tel-input": "^6.1.0",
"react-select": "^2.3.0",
"react-spring": "^7.2.10",
"react-textarea-autosize": "^7.1.0",
Expand Down
35 changes: 35 additions & 0 deletions src/TelInput/TelInput.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: TelInput
menu: Components
route: /components/tel-input
---

import { PropsTable, Playground } from 'docz';

import TelInput from './';

# TelInput

Entering and validating international telephone numbers.

## When To Use

- you want to format and validating the user's phone numbers.

## Examples

```js
import { TelInput } from 'tailor-ui';
```

### Basic

<Playground>
<TelInput onChange={console.log} />
</Playground>

## API

<PropsTable of={TelInput} />

The component is based on `react-intl-tel-input`, please check more API on it's [document](https://patw0929.github.io/react-intl-tel-input/).
40 changes: 40 additions & 0 deletions src/TelInput/TelInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import IntlTelInput from 'react-intl-tel-input';
import React, { FunctionComponent, MouseEventHandler } from 'react';

import StyledTelInput from './style';

interface ITelInputProps {
id?: string;
name?: string;
value?: string;
defaultValue?: string;
onChange?: (
isValid: boolean,
value: string,
phoneInfo: object,
fullPhoneNumber: string
) => void;
onBlur?: MouseEventHandler;
}

const TelInput: FunctionComponent<ITelInputProps> = ({
id,
name,
onChange,
onBlur,
...props
}) => (
<StyledTelInput>
<IntlTelInput
fieldId={id}
fieldName={name}
onPhoneNumberChange={onChange}
onPhoneNumberBlur={onBlur}
format
preferredCountries={['tw']}
{...props}
/>
</StyledTelInput>
);

export default TelInput;
3 changes: 3 additions & 0 deletions src/TelInput/flags.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/TelInput/flags@2x.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/TelInput/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './TelInput';
Loading

0 comments on commit 0fdb7e1

Please sign in to comment.