Rev 3000 | Rev 3238 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react'
import {
FormControl,
InputAdornment,
InputBase,
InputLabel
} from '@mui/material'
import { Controller } from 'react-hook-form'
import FormErrorFeedback from '../form/FormErrorFeedback'
const Input = ({
name,
control,
label,
rules,
defaultValue,
onChange,
value,
icon,
accept,
error,
style,
...props
}) => {
if (control) {
return (
<Controller
name={name}
control={control}
defaultValue={defaultValue}
rules={rules}
render={({ field }) => (
<FormControl variant='standard' fullWidth>
{label && <InputLabel shrink>{label}</InputLabel>}
<InputBase
{...field}
inputProps={{
accept
}}
startAdornment={
icon ? <InputAdornment>{icon}</InputAdornment> : null
}
fullWidth
sx={style}
{...props}
/>
{error ? <FormErrorFeedback>{error}</FormErrorFeedback> : null}
</FormControl>
)}
/>
)
}
return (
<FormControl variant='standard' fullWidth>
{label && <InputLabel shrink>{label}</InputLabel>}
<InputBase
name={name}
onChange={onChange}
defaultValue={defaultValue}
value={value}
inputProps={{
accept
}}
startAdornment={icon ? <InputAdornment>{icon}</InputAdornment> : null}
fullWidth
sx={style}
{...props}
/>
{error ? <FormErrorFeedback>{error}</FormErrorFeedback> : null}
</FormControl>
)
}
export default Input