import React from "react"; import classnames from "classnames"; import { isEmpty } from "lodash"; import TooltipWrapper from "components/TooltipWrapper"; // all form-field styles are defined in _global.scss, which apply here and elsewhere const baseClass = "form-field"; export interface IFormFieldProps { children: JSX.Element; className: string; error: string; helpText: Array | JSX.Element | string; label: Array | JSX.Element | string; name: string; type: string; tooltip?: React.ReactNode; } const FormField = ({ children, className, error, helpText, label, name, type, tooltip, }: IFormFieldProps): JSX.Element => { const renderLabel = () => { const labelWrapperClasses = classnames(`${baseClass}__label`, { [`${baseClass}__label--error`]: !isEmpty(error), }); if (!label) { return false; } return ( ); }; const renderHelpText = () => { if (helpText) { return {helpText}; } return false; }; const formFieldClass = classnames( baseClass, { [`${baseClass}--${type}`]: !isEmpty(type), }, className ); return (
{renderLabel()} {children} {renderHelpText()}
); }; export default FormField;