Rev 3476 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { FormControl, InputLabel } from '@mui/material';
import { FilePicker } from '../file-picker';
export function FormFilePicker({
label = '',
name = 'file',
type = 'image',
multiple = false,
maxFiles = 1,
description = 'Arrastra el archivo aqui, o haga click para seleccionar',
rules = {}
}) {
const { control } = useFormContext();
return (
<Controller
control={control}
name={name}
rules={rules}
render={({ field: { onChange, value } }) => (
<FormControl variant='standard' fullWidth>
{label && <InputLabel shrink>{label}</InputLabel>}
<FilePicker
type={type}
multiple={multiple}
maxFiles={maxFiles}
description={description}
defaultFiles={multiple ? value : [value]}
onChange={onChange}
/>
</FormControl>
)}
/>
);
}