import classnames from 'classnames'; import omit from 'lodash/omit'; import React, { HTMLProps, ReactNode } from 'react'; import { Override, filterDOMProps } from 'uniforms'; import gridClassName from './gridClassName'; type WrapperProps = Override< Omit, 'onChange'>, { changed?: boolean; error?: unknown; errorMessage?: string; grid?: number | string | Record; help?: string; helpClassName?: string; label?: ReactNode; labelClassName?: string | string[]; showInlineError?: boolean; value?: boolean | string | number | string[] | undefined; wrapClassName?: string; } >; export default function wrapField( { changed, className, disabled, error, errorMessage, grid, // Grid is either an number between 1 and 11 or an object with keys like xs and md. help, // Help text. helpClassName, // Help text class name. id, label, labelClassName, // Label class name (String|Array[String]). required, showInlineError, // Show inline error message? wrapClassName, // Input wrapper class name. ...props }: WrapperProps, children: ReactNode, ) { const hasWrap = !!(grid || wrapClassName); const blockError = !!(error && showInlineError) && ( {errorMessage} ); const blockHelp = !!help && ( {help} ); const isValid = !error && changed; return (
{label && ( )} {hasWrap && (
{children} {blockHelp} {blockError}
)} {!hasWrap && children} {!hasWrap && blockHelp} {!hasWrap && blockError}
); } declare module 'uniforms' { interface FilterDOMProps { grid: never; } }