Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3719 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3719 stevensc 1
import React from 'react';
2
import { Controller, useFormContext } from 'react-hook-form';
3
import { FormControl, InputLabel } from '@mui/material';
4
 
5
import { FilePicker } from '../file-picker';
6
 
7
export function FormFilePicker({
8
  label = '',
9
  name = 'file',
10
  type = 'image',
3736 stevensc 11
  description = 'Arrastra el archivo aqui, o haga click para seleccionar',
3719 stevensc 12
  multiple = false,
13
  rules = {}
14
}) {
15
  const { control } = useFormContext();
16
 
17
  return (
18
    <Controller
19
      control={control}
20
      name={name}
21
      rules={rules}
22
      render={({ field: { onChange, value } }) => (
23
        <FormControl variant='standard' fullWidth>
24
          {label && <InputLabel shrink>{label}</InputLabel>}
25
 
26
          <FilePicker
27
            type={type}
28
            description={description}
3736 stevensc 29
            defaultFiles={value}
30
            onChange={(files) => {
31
              if (multiple) {
32
                onChange(files);
33
              } else {
34
                onChange(files[0]);
35
              }
36
            }}
3719 stevensc 37
          />
38
        </FormControl>
39
      )}
40
    />
41
  );
42
}