import React from "react"; import classnames from "classnames"; import { isEmpty } from "lodash"; import TooltipWrapper from "components/TooltipWrapper"; const baseClass = "form-field"; export interface IFormFieldProps { children: JSX.Element; className: string; error: string; hint: Array | JSX.Element | string; label: Array | JSX.Element | string; name: string; type: string; tooltip?: string; } const FormField = ({ children, className, error, hint, 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 renderHint = () => { if (hint) { return {hint}; } return false; }; const formFieldClass = classnames( baseClass, { [`${baseClass}--${type}`]: !isEmpty(type), }, className ); return (
{renderLabel()} {children} {renderHint()}
); }; export default FormField;