import { useAppConfig } from '@/components/AppStateProvider'; import { FormHelperText, InputLabel, Stack } from '@mui/material'; import { useTheme } from '@mui/material/styles'; import React, { PropsWithChildren, ReactElement } from 'react'; import { CommonInputProps, FieldTitle, useInput, useTranslate } from 'react-admin'; function LabeledInput({ label, children, display = 'label', helperText, sx, addLabel, divider = false, ...props }: LabeledInputProps): JSX.Element { const theme = useTheme(); const translate = useTranslate(); const { getCurrentDialog } = useAppConfig(); const { source, resource, isRequired, chip } = props; const { fieldState: { invalid } } = useInput(props); const dialogResource = getCurrentDialog(); return ( {display === 'label' && label !== false && addLabel !== false && ( )} {React.isValidElement(children) ? React.cloneElement(children, { // @ts-ignore ...children.props, ...props, chip: chip && typeof chip === 'function' ? React.createElement(chip) : chip, label: display === 'legend' ? label : false }) : children} {helperText ? ( {React.isValidElement(helperText) ? helperText : typeof helperText === 'string' ? translate(helperText, { _: helperText }) : helperText} ) : null} ); } type LabeledInputProps = PropsWithChildren< CommonInputProps & { sx?: any; label?: string | ReactElement | false; addLabel?: boolean; resource?: string; isRequired?: boolean; display?: 'legend' | 'label'; helperText?: string | boolean | React.ReactElement | null; divider?: boolean; chip?: any; } >; export { LabeledInput }; export type { LabeledInputProps };