Debian Codegraph @

packages/mui/src/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx

raw
1 import { CSSProperties } from 'react';
2 import Box from '@mui/material/Box';
3 import Grid from '@mui/material/Grid';
4 import Paper from '@mui/material/Paper';
5 import { ArrayFieldTemplateItemType, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
6
7 /** The `ArrayFieldItemTemplate` component is the template used to render an items of an array.
8 *
9 * @param props - The `ArrayFieldTemplateItemType` props for the component
10 */
11 export default function ArrayFieldItemTemplate<
12 T = any,
13 S extends StrictRJSFSchema = RJSFSchema,
14 F extends FormContextType = any
15 >(props: ArrayFieldTemplateItemType<T, S, F>) {
16 const {
17 children,
18 disabled,
19 hasToolbar,
20 hasCopy,
21 hasMoveDown,
22 hasMoveUp,
23 hasRemove,
24 index,
25 onCopyIndexClick,
26 onDropIndexClick,
27 onReorderClick,
28 readonly,
29 uiSchema,
30 registry,
31 } = props;
32 const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates;
33 const btnStyle: CSSProperties = {
34 flex: 1,
35 paddingLeft: 6,
36 paddingRight: 6,
37 fontWeight: 'bold',
38 minWidth: 0,
39 };
40 return (
41 <Grid container={true} alignItems='center'>
42 <Grid item={true} xs style={{ overflow: 'auto' }}>
43 <Box mb={2}>
44 <Paper elevation={2}>
45 <Box p={2}>{children}</Box>
46 </Paper>
47 </Box>
48 </Grid>
49 {hasToolbar && (
50 <Grid item={true}>
51 {(hasMoveUp || hasMoveDown) && (
52 <MoveUpButton
53 style={btnStyle}
54 disabled={disabled || readonly || !hasMoveUp}
55 onClick={onReorderClick(index, index - 1)}
56 uiSchema={uiSchema}
57 registry={registry}
58 />
59 )}
60 {(hasMoveUp || hasMoveDown) && (
61 <MoveDownButton
62 style={btnStyle}
63 disabled={disabled || readonly || !hasMoveDown}
64 onClick={onReorderClick(index, index + 1)}
65 uiSchema={uiSchema}
66 registry={registry}
67 />
68 )}
69 {hasCopy && (
70 <CopyButton
71 style={btnStyle}
72 disabled={disabled || readonly}
73 onClick={onCopyIndexClick(index)}
74 uiSchema={uiSchema}
75 registry={registry}
76 />
77 )}
78 {hasRemove && (
79 <RemoveButton
80 style={btnStyle}
81 disabled={disabled || readonly}
82 onClick={onDropIndexClick(index)}
83 uiSchema={uiSchema}
84 registry={registry}
85 />
86 )}
87 </Grid>
88 )}
89 </Grid>
90 );
91 }