import React from 'react';
import { ArrayControlProps, UISchemaElement } from '@jsonforms/core';
import { JsonFormsDispatch } from '@jsonforms/react';
import {
Typography,
Box,
Divider,
useTheme,
AccordionProps,
styled,
AccordionSummaryProps,
Accordion,
AccordionSummary,
AccordionDetails,
} from '@mui/material';
import { isEmpty } from 'lodash';
import Grid from '@mui/material/Grid2';
import { isHidden } from '../common/getHiddenKeys';
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
const StyledAccordion = styled((props: AccordionProps) => (
))(({ theme }) => ({
border: `none`,
// boxShadow: `-5px 2px 5px #00000029`,
}));
const StyledAccordionSummary = styled((props: AccordionSummaryProps) => (
} {...props} />
))(({ theme }) => ({
flexDirection: 'row',
justifyContent: 'start',
border: 'none',
'& .MuiAccordionSummary-expandIconWrapper': {
'& .MuiSvgIcon-root': {
fontSize: theme.typography.fontSize * 2.3,
color: theme.palette.grey.A400,
},
},
'& .MuiAccordionSummary-expandIconWrapper.Mui-expanded': {
transform: 'rotate(90deg)',
},
'& .MuiAccordionSummary-content': {
flexGrow: 0,
},
}));
const WrapperContent = function WrapperContent({
path,
schema,
elements,
uischema,
renderers,
cells,
}: ArrayControlProps | any) {
const theme = useTheme();
const wrapperId = uischema?.config?.main?.wrapperId;
return (
{!isEmpty(elements) &&
elements.map((child: UISchemaElement | any, i: number) => {
if (isHidden(child, schema)) {
return null;
}
const updatedChild = {
...child,
config: {
...child.config,
main: {
...child.config?.main,
additionalData: {
...child.config?.main?.additionalData,
rowData: {
...uischema.config?.main?.additionalData?.rowData
}
}
}
}
};
return (
);
})}
);
};
const AccordionWrapper = function AccordionWrapper({
path,
schema,
elements,
uischema,
renderers,
cells,
}: ArrayControlProps | any) {
const theme = useTheme();
const [expanded, setExpanded] = React.useState(
uischema?.config?.main?.defaultClosed ? false : 'panel',
);
const handleAccordionChange =
(panel: string) => (event: React.SyntheticEvent, newExpanded: boolean) => {
setExpanded(newExpanded ? panel : false);
};
return (
);
};
const DefaultWrapper = function DefaultWrapper({
path,
schema,
elements,
uischema,
renderers,
cells,
}: ArrayControlProps | any) {
const theme = useTheme();
return (
<>
{uischema?.config?.main?.label && (
{uischema.config?.main?.label}
{uischema?.config?.main?.divider && (
)}
)}
>
);
};
const WrapperContainer = {
Accordion: AccordionWrapper,
Default: DefaultWrapper,
};
const Wrapper = function Wrapper({
path,
schema,
elements,
uischema,
renderers,
cells,
}: ArrayControlProps | any) {
const getWrapperType = (uischema: any) => {
if (uischema?.config?.main?.isAccordion) {
return 'Accordion';
}
return 'Default';
};
const GetWrapperComponent = WrapperContainer[getWrapperType(uischema)];
return (
);
};
export default Wrapper;