import QuestionCircleOutlined from '@ant-design/icons/QuestionCircleOutlined'; import Tooltip from 'antd/lib/tooltip'; import classNames from 'classnames'; import React, { Children, cloneElement, isValidElement, ReactElement, ReactNode, } from 'react'; import { connectField, filterDOMProps, HTMLFieldProps } from 'uniforms'; import ListAddField from './ListAddField'; import ListItemField from './ListItemField'; export type ListFieldProps = HTMLFieldProps< unknown[], HTMLDivElement, { addIcon?: ReactNode; children?: ReactNode; info?: string; itemProps?: object; labelCol?: any; wrapperCol?: any; } >; const defaultStyle = { marginBottom: '5px', marginTop: '5px', padding: '10px', }; const errorStyle = { borderColor: 'rgb(255, 85, 0)' }; function List({ children = , className, error, errorMessage, info, itemProps, label, labelCol, showInlineError, style = defaultStyle, value, wrapperCol, ...props }: ListFieldProps) { const wrapperStyle = error ? style ? { ...errorStyle, ...style } : errorStyle : style; return (
{!!label && (
{label} {!!info && (   )}
)} {!!(error && showInlineError) &&
{errorMessage}
} {value?.map((item, itemIndex) => Children.map(children, (child, childIndex) => isValidElement(child) ? cloneElement(child as ReactElement, { key: `${itemIndex}-${childIndex}`, name: child.props.name?.replace('$', '' + itemIndex), labelCol, wrapperCol, ...itemProps, }) : child, ), )}
); } export default connectField(List);