// @flow import React, { Component } from 'react'; import { connect } from 'react-redux'; import Emoji from 'react-emoji-render'; import type { Dispatch } from 'redux'; import { sendMessage } from '../../actions'; import SmileysPanel from './SmileysPanel'; /** * The type of the React {@code Component} props of {@link ChatInput}. */ type Props = { /** * Invoked to send chat messages. */ dispatch: Dispatch, /** * Optional callback to get a reference to the chat input element. */ getChatInputRef?: Function }; /** * The type of the React {@code Component} state of {@link ChatInput}. */ type State = { /** * User provided nickname when the input text is provided in the view. */ message: string, /** * Whether or not the smiley selector is visible. */ showSmileysPanel: boolean }; /** * Implements a React Component for drafting and submitting a chat message. * * @extends Component */ class ChatInput extends Component { _textArea: ?HTMLTextAreaElement; state = { message: '', showSmileysPanel: false }; /** * Initializes a new {@code ChatInput} instance. * * @param {Object} props - The read-only properties with which the new * instance is to be initialized. */ constructor(props: Props) { super(props); this._textArea = null; // Bind event handlers so they are only bound once for every instance. this._onDetectSubmit = this._onDetectSubmit.bind(this); this._onMessageChange = this._onMessageChange.bind(this); this._onSmileySelect = this._onSmileySelect.bind(this); this._onToggleSmileysPanel = this._onToggleSmileysPanel.bind(this); this._setTextAreaRef = this._setTextAreaRef.bind(this); } /** * Implements React's {@link Component#componentDidMount()}. * * @inheritdoc */ componentDidMount() { /** * HTML Textareas do not support autofocus. Simulate autofocus by * manually focusing. */ this.focus(); } /** * Implements React's {@link Component#render()}. * * @inheritdoc * @returns {ReactElement} */ render() { const smileysPanelClassName = `${this.state.showSmileysPanel ? 'show-smileys' : 'hide-smileys'} smileys-panel`; return (