Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3670 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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