| 3719 |
stevensc |
1 |
import React from 'react';
|
|
|
2 |
import { FormControl, InputAdornment, InputBase, InputLabel, Typography } from '@mui/material';
|
|
|
3 |
import { Controller, useFormContext } from 'react-hook-form';
|
|
|
4 |
|
|
|
5 |
export function FormInput({ icon, name, rules, label, disabled, endAdornment, ...props }) {
|
|
|
6 |
const { control } = useFormContext();
|
|
|
7 |
|
|
|
8 |
return (
|
|
|
9 |
<Controller
|
|
|
10 |
name={name}
|
|
|
11 |
control={control}
|
|
|
12 |
disabled={disabled}
|
|
|
13 |
rules={rules}
|
|
|
14 |
render={({ field, fieldState: { error } }) => (
|
|
|
15 |
<FormControl variant='standard' fullWidth>
|
|
|
16 |
{label && <InputLabel shrink>{label}</InputLabel>}
|
|
|
17 |
<InputBase
|
|
|
18 |
{...field}
|
|
|
19 |
startAdornment={icon && <InputAdornment>{icon}</InputAdornment>}
|
|
|
20 |
endAdornment={endAdornment && <InputAdornment>{endAdornment}</InputAdornment>}
|
|
|
21 |
fullWidth
|
|
|
22 |
{...props}
|
|
|
23 |
/>
|
|
|
24 |
{error && (
|
|
|
25 |
<Typography sx={{ color: 'red', fontSize: '0.75rem' }}>{error.message}</Typography>
|
|
|
26 |
)}
|
|
|
27 |
</FormControl>
|
|
|
28 |
)}
|
|
|
29 |
/>
|
|
|
30 |
);
|
|
|
31 |
}
|