import React from 'react'; import { MessageDescriptor } from 'react-intl'; import TextareaAutosize, { TextareaAutosizeProps } from 'react-textarea-autosize'; import clsx from 'clsx'; import { uniqueId, omit } from 'app/functions'; import { SKIN_DARK, COLOR_GREEN, Skin, Color } from 'app/components/ui'; import styles from './form.scss'; import FormInputComponent from './FormInputComponent'; interface OwnProps { placeholder?: string | MessageDescriptor; label?: string | MessageDescriptor; skin: Skin; color: Color; } export default class TextArea extends FormInputComponent> { static defaultProps = { color: COLOR_GREEN, skin: SKIN_DARK, }; elRef = React.createRef(); render() { const { color, skin, label: labelText, placeholder: placeholderText } = this.props; let label: React.ReactElement | undefined; let placeholder: string | undefined; const props = omit( { type: 'text', ...this.props, }, ['label', 'placeholder', 'error', 'skin', 'color'], ); if (labelText) { if (!props.id) { props.id = uniqueId('textarea'); } label = ( ); } if (placeholderText) { placeholder = this.formatMessage(placeholderText); } return (
{label}
{this.renderError()}
); } getValue() { const { current: el } = this.elRef; return el && el.value; } focus() { const { current: el } = this.elRef; if (!el) { return; } el.focus(); setTimeout(el.focus.bind(el), 10); } }