-
Notifications
You must be signed in to change notification settings - Fork 29
/
FormGroup.tsx
50 lines (46 loc) · 2.04 KB
/
FormGroup.tsx
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
47
48
49
50
import React from 'react'
import FormLabel from '@mui/material/FormLabel'
import FormControl from '@mui/material/FormControl'
import MuiFormGroup from '@mui/material/FormGroup'
import { useTheme } from '@mui/material/styles'
import { extractValue } from '@ui-schema/react/UIStore'
import { memo } from '@ui-schema/react/Utils/memo'
import { WidgetProps } from '@ui-schema/react/Widgets'
import { TranslateTitle } from '@ui-schema/react/TranslateTitle'
import { SchemaValidatorContext } from '@ui-schema/system/SchemaPluginStack'
import { LeafsRenderMapping } from '@tactic-ui/react/LeafsEngine'
export const FormGroupBase =
<P extends WidgetProps & SchemaValidatorContext & { renderMap: LeafsRenderMapping<{}, {}> }>(props: P): React.ReactElement<P> => {
const {storeKeys, renderMap} = props
const {spacing} = useTheme()
let {schema} = props
// deleting the `widget` to directly use `WidgetEngine` for nesting
// with `widget` it would lead to an endless loop
// using e.g. default `object` renderer then
// @ts-ignore
schema = schema.delete('widget')
const Widget = schema.get('type') ? renderMap.leafs['type:' + schema.get('type')] : undefined
return <FormControl
component="fieldset"
style={{
display: 'block',
marginBottom: spacing(1),
}}
>
<FormLabel component="legend">
<TranslateTitle schema={schema} storeKeys={storeKeys}/>
</FormLabel>
<MuiFormGroup
style={{
marginTop: spacing(1),
marginBottom: spacing(1),
}}
>
{/* todo: re-use the next widget matcher */}
{/* @ts-ignore */}
{Widget ? <Widget {...props} schema={schema}/> : '-'}
</MuiFormGroup>
{/*<FormHelperText>Be careful</FormHelperText>*/}
</FormControl>
}
export const FormGroup = extractValue(memo(FormGroupBase)) as typeof FormGroupBase