2018-08-29 17:24:25 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { PureComponent } from 'react';
|
2018-12-03 18:01:40 +00:00
|
|
|
import Emoji from 'react-emoji-render';
|
2019-01-13 19:34:38 +00:00
|
|
|
import { smileys } from '../../smileys';
|
2018-08-29 17:24:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link SmileysPanel}.
|
|
|
|
*/
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to invoke when a smiley is selected. The smiley will be passed
|
|
|
|
* back.
|
|
|
|
*/
|
|
|
|
onSmileySelect: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React Component showing smileys that can be be shown in chat.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class SmileysPanel extends PureComponent<Props> {
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const smileyItems = Object.keys(smileys).map(smileyKey => {
|
|
|
|
const onSelectFunction = this._getOnSmileySelectCallback(smileyKey);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = 'smileyContainer'
|
|
|
|
id = { smileyKey }
|
|
|
|
key = { smileyKey }>
|
2018-12-03 18:01:40 +00:00
|
|
|
<Emoji
|
2018-08-29 17:24:25 +00:00
|
|
|
onClick = { onSelectFunction }
|
2018-12-03 18:01:40 +00:00
|
|
|
onlyEmojiClassName = 'smiley'
|
|
|
|
text = { smileys[smileyKey] } />
|
2018-08-29 17:24:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id = 'smileysContainer'>
|
|
|
|
{ smileyItems }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to bind a smiley's click handler.
|
|
|
|
*
|
|
|
|
* @param {string} smileyKey - The key from the {@link smileys} object
|
|
|
|
* that should be added to the chat message.
|
|
|
|
* @private
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
_getOnSmileySelectCallback(smileyKey) {
|
|
|
|
return () => this.props.onSmileySelect(smileys[smileyKey]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SmileysPanel;
|