@s-ui/react-molecule-phone-input
Version:
> Custom input component to handle phone validation. Gives the user a prefix selector and a phone number input. It also handles the phone number validation and the prefix selection.
52 lines (38 loc) • 2.11 kB
Markdown
# MoleculePhoneInput
> Custom input component to handle phone validation. Gives the user a prefix selector and a phone number input. It also handles the phone number validation and the prefix selection.
[](https://sui-components.vercel.app/workbench/molecule/phoneInput/)
[](https://github.com/SUI-Components/sui-components/issues/new?&projects=4&template=bug-report.yml&assignees=&template=report-a-bug.yml&title=🪲+&labels=bug,component,molecule,phoneInput)
[](https://www.npmjs.com/package/@s-ui/react-molecule-phone-input)
[](https://github.com/SUI-Components/sui-components/issues?q=is%3Aopen+label%3Acomponent+label%3AphoneInput)
[](https://github.com/SUI-Components/sui-components/blob/main/components/molecule/phoneInput/LICENSE.md)
## Installation
```sh
$ npm install @s-ui/react-molecule-phone-input
```
## Usage
### Basic usage
#### Import package and use the component
```js
import MoleculePhoneInput from '@s-ui/react-molecule-phone-input'
const [phone, setPhone] = useState('')
const icon = <IconArrowDown size="16" />
const prefixes = [
{value: 'ES', label: 'España', countryCode: '+34'},
{value: 'FR', label: 'Francia', countryCode: '+33'},
{value: 'PT', label: 'Portugal', countryCode: '+351'},
{value: 'AD', label: 'Andorra', countryCode: '+376'}
]
return (
<MoleculePhoneInput
value={phone}
onChange={setPhone}
dropdownIcon={icon}
prefixes={prefixes}
/>
)
```
#### Import the styles (Sass)
```css
@import '~@s-ui/theme/lib/index';
@import '~@s-ui/react-molecule-phone-input/lib/index';
```