2019-10-10 06:42:00 +00:00
# EmailInput
2019-11-20 11:22:43 +00:00
Email entry field with advanced capabilities for validation based on settings
2019-10-10 06:42:00 +00:00
2019-10-14 14:04:16 +00:00
### Usage
```js
import { EmailInput } from "asc-web-components";
2019-11-20 11:22:43 +00:00
```
2019-10-10 06:42:00 +00:00
2019-11-20 11:22:43 +00:00
```jsx
2019-10-10 06:42:00 +00:00
< EmailInput
name="email"
placeholder="email"
2019-10-14 14:04:16 +00:00
onValidateInput={isValidEmail =>
2019-10-14 14:29:08 +00:00
console.log("isValidEmail = ", isValidEmail);
2019-10-14 14:04:16 +00:00
}
2019-10-14 14:29:08 +00:00
emailSettings={settings}
2019-10-10 06:42:00 +00:00
/>;
```
2019-10-14 14:04:16 +00:00
### Properties
You can apply all properties of the `TextInput` component to the component
2019-11-20 11:22:43 +00:00
| Props | Type | Required | Values | Default | Description |
| -------------------- | :-----------------------------------: | :------: | :----: | :-------------: | ------------------------------------------------------------------------ |
2019-11-27 13:59:27 +00:00
| `className` | `string` | - | - | - | Accepts class |
2019-12-19 07:35:25 +00:00
| `customValidateFunc` | `func` | - | - | - | Function for your custom validation input value. Function must return boolean result of validating |
2019-11-27 13:59:27 +00:00
| `emailSettings` | `Object` , `Instance of EmailSettings` | - | - | `EmailSettings` | Settings for validating email |
| `id` | `string` | - | - | - | Accepts id |
2019-11-20 11:22:43 +00:00
| `isValid` | `bool` | - | - | - | Used in your custom validation function for change border-color of input |
2019-11-27 13:59:27 +00:00
| `onChange` | `func` | - | - | - | Function for your custom handling changes in input |
| `onValidateInput` | `func` | - | - | - | Will be validate our value, return boolean validation result |
| `style` | `obj` , `array` | - | - | - | Accepts css style |
2019-10-14 14:04:16 +00:00
### Validate email
Our validation algorithm based on [An RFC 5322 email address parser ](https://www.npmjs.com/package/email-addresses ).
For email validating you should use plain Object or our email utility with following settings:
2019-11-20 11:22:43 +00:00
| Props | Type | Required | Default | Description |
| ------------------------ | :----: | :------: | :-----: | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
2019-11-27 13:59:27 +00:00
| `allowDomainIp` | `bool` | - | `false` | Allow email with IP address in domain, e. g. `user@[127.0.0.1]` is a valid email address |
2019-10-14 14:04:16 +00:00
| `allowDomainPunycode` | `bool` | - | `false` | Allow email with punycode symbols in domain, e. g. `example@джpу мла те с т.bр фa` and `example@mañana.com` are valid email addresses |
2019-11-27 13:59:27 +00:00
| `allowLocalDomainName` | `bool` | - | `false` | Allow local domain address, e. g. `admin@local` is a valid email address |
2019-10-14 14:04:16 +00:00
| `allowLocalPartPunycode` | `bool` | - | `false` | Allow email with punycode symbols in local part, e. g. `джумла@example.com` and `mañana@example.com` are valid email addresses |
2019-11-20 11:22:43 +00:00
| `allowName` | `bool` | - | `false` | Supports all features of RFC 5322, which means that `"Bob Example" <bob@example.com>` is a valid email address |
2019-11-27 13:59:27 +00:00
| `allowSpaces` | `bool` | - | `false` | Allow spaces in local part and domain, e. g. `" "@example.org` is a valid email address |
| `allowStrictLocalPart` | `bool` | - | `true` | Allow email, started with latin symbols and digits(`([a-zA-Z0-9]+)`) and also contains `_,-,.,+` . Used RegEx `/^([a-zA-Z0-9]+)([_\-\.\+][a-zA-Z0-9]+)\*\$/` |
2019-10-10 06:42:00 +00:00
2019-10-14 14:04:16 +00:00
### emailSettings prop
Plain object:
```js
const emailSettings = {
allowDomainPunycode: false,
allowLocalPartPunycode: false,
allowDomainIp: false,
allowStrictLocalPart: true,
allowSpaces: false,
allowName: false,
allowLocalDomainName: false
};
```
or instance of `EmailSettings` class:
```js
2019-12-11 13:41:38 +00:00
import { EmailInput, utils } from "asc-web-components";
const { EmailSettings } = utils.email;
2019-10-14 14:04:16 +00:00
const emailSettings = new EmailSettings();
2019-10-15 08:35:50 +00:00
emailSettings.getSettings(); /* returned Object with default settings:
2019-10-14 14:04:16 +00:00
{
allowDomainPunycode: false,
allowLocalPartPunycode: false,
allowDomainIp: false,
allowStrictLocalPart: true,
allowSpaces: false,
allowName: false,
allowLocalDomainName: false
}
*/
2019-10-15 08:35:50 +00:00
email.allowName = true; // set allowName setting to true
2019-10-14 14:04:16 +00:00
2019-10-15 08:35:50 +00:00
emailSettings.getSettings(); /* returned Object with NEW settings:
2019-10-14 14:04:16 +00:00
{
2019-10-15 08:35:50 +00:00
2019-10-14 14:04:16 +00:00
allowDomainPunycode: false,
allowLocalPartPunycode: false,
allowDomainIp: false,
allowStrictLocalPart: true,
allowSpaces: false,
allowName: true,
allowLocalDomainName: false
2019-10-15 08:35:50 +00:00
2019-10-14 14:04:16 +00:00
}
*/
```
### Custom validate email
You should use custom validation with the `customValidateFunc` prop. Also you can change state of validation with the help of `isValid` prop.
`isValid` prop allow you to change border-color of input.
How are applied colors in component:
| С omponent actions | isValid | border-color |
2019-11-20 11:22:43 +00:00
| ----------------- | :-----: | :----------: |
| `:focus` | `false` | #c30 |
2019-11-27 13:59:27 +00:00
| `:focus` | `true` | #2DA7DB |
| `:hover` | `false` | #c30 |
| `:hover` | `true` | #D0D5DA |
| `default` | `false` | #c30 |
| `default` | `true` | #D0D5DA |
2019-10-14 14:04:16 +00:00
```js
import React, { useState } from "react";
import { EmailInput } from "asc-web-components";
const [emailValid, setEmailValid] = useState(true);
const customChangeFunc = (e) => {
2019-10-14 14:29:08 +00:00
// your event handling
2019-10-14 14:04:16 +00:00
customValidateFunc(e.target.value);
}
const customValidateFunc = (value) => {
let validationResult;
2019-10-14 14:29:08 +00:00
// your validating function
2019-10-14 14:04:16 +00:00
setEmailValid(validationResult);
}
const onValidateInput = (isValidEmail) => {
console.log(`isValidEmail = ${isValidEmail}`);
}
return (
< EmailInput
isValid={emailValid}
onChange={customChangeFunc}
customValidateFunc={customValidateFunc}
onValidateInput={onValidateInput}
2019-10-14 14:29:08 +00:00
2019-10-14 14:04:16 +00:00
/>;
);
```
2019-10-14 14:29:08 +00:00
#### Email settings RFC 5321
2019-11-20 11:22:43 +00:00
2019-10-14 14:29:08 +00:00
```js
{
allowDomainPunycode: true,
allowLocalPartPunycode: true,
allowDomainIp: true,
allowStrictLocalPart: false,
allowSpaces: true,
allowName: false,
allowLocalDomainName: true
}
```