/* tslint:disable:no-use-before-declare */ import { TooltipHost } from 'office-ui-fabric-react/lib-commonjs/Tooltip'; import { BaseComponent, IBaseProps } from 'office-ui-fabric-react/lib-commonjs/Utilities'; import * as React from 'react'; import * as _ from 'underscore'; import classNames from './form.classNames'; /* tslint:enable:no-use-before-declare */ export interface FormFieldAttributes { title: string; required?: boolean; placeholder?: string; inline?: boolean; tooltip?: string | (() => JSX.Element); error?: string | (() => JSX.Element); } export type FormFieldProps = FormFieldAttributes & IBaseProps; /** * Generic form field component */ export class FormField extends BaseComponent { constructor(props: FormFieldProps) { super(props); } public render(): JSX.Element { return (
{this.renderFieldInfo()}
{this.props.children}
); } private renderFieldInfo(): JSX.Element { const content = _.isString(this.props.tooltip) ? this.props.tooltip : null; const renderContent = (this.props.tooltip && !_.isString(this.props.tooltip)) ? this.props.tooltip : null; if (!renderContent) { return ( ); } return ( ); } }