File size: 968 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import FormLabel from '@mui/material/FormLabel';
import React from 'react';
import type { HTMLFieldProps } from 'uniforms';
import { connectField } from 'uniforms';

import AutoField from './AutoField';
import wrapField from './wrapField';

// FIXME: wrapField is not typed correctly.
export type NestFieldProps = HTMLFieldProps<
  Record<string, any>,
  HTMLDivElement,
  {
    helperText?: string;
    itemProps?: Record<string, any>;
    fullWidth?: boolean;
    margin?: any;
  }
>;

function Nest({
  children,
  fields,
  fullWidth = true,
  itemProps,
  label,
  margin = 'dense',
  ...props
}: NestFieldProps) {
  return wrapField(
    {
      fullWidth,
      margin,
      ...props,
      component: undefined,
    },
    label && <FormLabel component="legend">{label}</FormLabel>,
    children ||
      fields.map((field) => (
        <AutoField key={field} name={field} {...itemProps} />
      ))
  );
}

export default connectField<NestFieldProps>(Nest);