import {
JsonFormsCellRendererRegistryEntry,
JsonFormsRendererRegistryEntry,
JsonSchema,
OwnPropsOfRenderer,
} from ‘jsonforms/core’;
import { JsonFormsDispatch, useJsonForms } from ‘jsonforms/react’;
import { Hidden } from ‘mui/material’;
import Grid2 from ‘mui/material/Unstable_Grid2’;
export interface MaterialLayoutRendererProps extends OwnPropsOfRenderer {
elements: UISchemaElement;
direction: ‘row’ | ‘column’;
}
const MaterialLayoutRendererComponent =
({
visible,
elements,
schema,
path,
enabled,
direction,
renderers,
cells
}: MaterialLayoutRendererProps) => {
if (isEmpty(elements)) {
return null;
} else {
return (
<Grid2
container
direction={direction}
spacing={direction === 'row' ? 2 : 0}
justifyContent={'space-around'}
>
{
elements.map((child: any, index: number) => {
console.log("child : ", child, " index : ", index);
return (
<Grid2 key={`${path}-${index}`} xs={child?.config?.layout ? (child?.config?.layout.xs ? child?.config?.layout.xs : child?.config?.layout) : 12} sm={child?.config?.layout ? (child?.config?.layout.sm ? child?.config?.layout.sm : child?.config?.layout) : 12} md={child?.config?.layout ? (child?.config?.layout.md ? child?.config?.layout.md : child?.config?.layout) : 12} lg={child?.config?.layout ? (child?.config?.layout.lg ? child?.config?.layout.lg : child?.config?.layout) : 12}>
<JsonFormsDispatch
uischema={child}
schema={schema}
path={path}
enabled={enabled}
renderers={renderers}
cells={cells}
/>
</Grid2>
)
})
}
</Grid2>
);
}
};
export const MaterialLayoutRenderer = React.memo(MaterialLayoutRendererComponent);
import {
HorizontalLayout,
LayoutProps,
RankedTester,
rankWith,
uiTypeIs,
} from ‘@jsonforms/core’;
import { withJsonFormsLayoutProps } from ‘@jsonforms/react’;
import {
MaterialLayoutRenderer,
MaterialLayoutRendererProps
} from ‘./Horizontal’;
import { useContext } from ‘react’;
import { DataContext } from ‘…/context/Context’;
/**
- Default tester for a horizontal layout.
- @type {RankedTester}
*/
export const materialHorizontalLayoutTester: RankedTester = rankWith(
200,
uiTypeIs(‘HorizontalLayout’)
);
export const MaterialLayoutHorizontal = ({ uischema, renderers, cells, schema, path, enabled, visible }: LayoutProps) => {
const { theme } =
useContext(DataContext);
const layout = uischema as HorizontalLayout;
const childProps: MaterialLayoutRendererProps = {
elements: layout.elements,
schema,
path,
enabled,
direction: ‘row’,
visible
};
return (<MaterialLayoutRenderer {…childProps} renderers={renderers} cells={cells} />);
};
export default withJsonFormsLayoutProps(MaterialLayoutHorizontal);