Skip to content
Snippets Groups Projects
Verified Commit 071c1f52 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Document components using styleguidist

parent b55181b8
No related branches found
No related tags found
1 merge request!26Documentation
Wrapper for any input field
```js
import { SubmitHandler, useForm } from 'react-hook-form';
const { control } = useForm();
<InputField
name="password"
control={control}
rules={{
minLength: 8,
maxLength: 60,
required: {
value: true,
message: 'Insert valid password',
},
}}
label="Password"
error={false}
errorMessage="Insert valid password"
/>
```
...@@ -4,16 +4,29 @@ import { Control, Controller, FieldValues } from 'react-hook-form'; ...@@ -4,16 +4,29 @@ import { Control, Controller, FieldValues } from 'react-hook-form';
type Props = { type Props = {
/** /**
* Name of the elemement. ex. email, password * Name of the elemement. (ex. email, password).
*/ */
name: string; name: string;
/**
* Aria label.
*/
label: string; label: string;
/**
* Takes error from react-hook-form and is thrown if
* the component is not valid.
*/
error: boolean; error: boolean;
/**
* Message to display if the component is not valid.
*/
errorMessage: string; errorMessage: string;
/** /**
* react-hook-form control * React-hook-form control.
*/ */
control: Control<FieldValues> | undefined; control: Control<FieldValues> | undefined;
/**
* Validation rules.
*/
rules: Partial<unknown>; rules: Partial<unknown>;
}; };
......
...@@ -3,7 +3,6 @@ import axios from 'axios'; ...@@ -3,7 +3,6 @@ import axios from 'axios';
import { SubmitHandler, useForm } from 'react-hook-form'; import { SubmitHandler, useForm } from 'react-hook-form';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import { Button } from '@material-ui/core'; import { Button } from '@material-ui/core';
import { DevTool } from '@hookform/devtools';
import { InputField } from 'components/AuthUser/SignInForm/InputField/InputField'; import { InputField } from 'components/AuthUser/SignInForm/InputField/InputField';
const useStyles = makeStyles((theme: Theme) => const useStyles = makeStyles((theme: Theme) =>
...@@ -104,7 +103,6 @@ export const SignInForm: FC = () => { ...@@ -104,7 +103,6 @@ export const SignInForm: FC = () => {
Sign In Sign In
</Button> </Button>
</form> </form>
<DevTool control={control} /> {/* set up the dev tool */}
</> </>
); );
}; };
export const isEmailValid = (email: string): boolean => {
/**
* The following is the RFC 5322 valid email regex
* Hinted from question https://stackoverflow.com/questions/201323/how-to-validate-an-email-address-using-a-regular-expression
* More on http://emailregex.com/
*/
// eslint-disable-next-line
const VALID_EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return VALID_EMAIL_REGEX.test(String(email).toLowerCase());
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment