import { Children, ReactElement, ReactNode, isValidElement, useMemo } from 'react'; import { Box, Button, Divider, Grid, useTheme } from '@mui/material'; import { MainCard } from '@/components/MainCard'; import { Toolbar } from './Toolbar'; import { useTranslate } from 'react-admin'; import _ from 'lodash'; import { useWizardFormContext } from './Provider'; import { Stepper } from './Stepper'; import { walkChildren } from '@/utils'; interface ContentProps { title?: ReactNode | string; subheader?: ReactNode | string; secondary?: ReactNode | string; toolbar?: ReactElement; progress?: ReactNode; isSmall: boolean; modal: boolean; sx?: any; setCurrentStep: (step: number) => void; } function Content({ title, subheader, secondary, toolbar, progress, isSmall, modal, sx, setCurrentStep }: ContentProps) { const { currentStep, steps } = useWizardFormContext(); const translate = useTranslate(); const theme = useTheme(); const isHorizontal = isSmall || modal; const cancelButton = useMemo(() => { if (!toolbar) return null; return Children.toArray(toolbar.props.children).find( (child) => isValidElement(child) && child.type === Button && child.props?.children === translate('ra.action.cancel') ); }, [toolbar, translate]); const stepFields: Array> = steps.map((step: ReactElement) => { const fields: Array = []; const { sources } = step.props; if (sources !== undefined) { fields.push(...sources); } else { walkChildren(step, (el) => { if (el?.props?.source !== undefined) { fields.push(el.props.source); } }); } return fields; }); return ( {progress || } {modal ? : null} {steps[currentStep]} {toolbar && !cancelButton ? toolbar : } ); } export { Content };