import * as React from 'react' import classNames from 'classnames' import TextArea, { TextAreaProps } from 'semantic-ui-react/dist/commonjs/addons/TextArea/TextArea' import Icon from 'semantic-ui-react/dist/commonjs/elements/Icon/Icon' import { getInputValueLength } from '../../lib/input' import { InfoTooltip, InfoTooltipProps } from '../InfoTooltip' import './TextAreaField.css' export type TextAreaFieldProps = TextAreaProps & { label?: string maxLength?: number error?: string warning?: string info?: string tooltip?: InfoTooltipProps } function renderMessage(props: TextAreaFieldProps) { const { error, warning, info } = props if (error) { return ( <> {error} ) } if (warning) { return ( <> {warning} ) } if (info) { return ( <> {info} ) } } export const TextAreaField = (props: TextAreaFieldProps): JSX.Element => { const { error, warning, info, ...restOfProps } = props delete restOfProps['label'] return (
{props.label || props.maxLength !== undefined ? (
{props.label ? : null} {props.label && props.tooltip ? ( ) : null} {props.maxLength ? ( {getInputValueLength(props.value)}/{props.maxLength} ) : null}
) : null}