You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SmileysPanel.web.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import Emoji from 'react-emoji-render';
  4. import { smileys } from '../smileys';
  5. /**
  6. * The type of the React {@code Component} props of {@link SmileysPanel}.
  7. */
  8. type Props = {
  9. /**
  10. * Callback to invoke when a smiley is selected. The smiley will be passed
  11. * back.
  12. */
  13. onSmileySelect: Function
  14. };
  15. /**
  16. * Implements a React Component showing smileys that can be be shown in chat.
  17. *
  18. * @extends Component
  19. */
  20. class SmileysPanel extends PureComponent<Props> {
  21. /**
  22. * Implements React's {@link Component#render()}.
  23. *
  24. * @inheritdoc
  25. * @returns {ReactElement}
  26. */
  27. render() {
  28. const smileyItems = Object.keys(smileys).map(smileyKey => {
  29. const onSelectFunction = this._getOnSmileySelectCallback(smileyKey);
  30. return (
  31. <div
  32. className = 'smileyContainer'
  33. id = { smileyKey }
  34. key = { smileyKey }>
  35. <Emoji
  36. onClick = { onSelectFunction }
  37. onlyEmojiClassName = 'smiley'
  38. text = { smileys[smileyKey] } />
  39. </div>
  40. );
  41. });
  42. return (
  43. <div id = 'smileysContainer'>
  44. { smileyItems }
  45. </div>
  46. );
  47. }
  48. /**
  49. * Helper method to bind a smiley's click handler.
  50. *
  51. * @param {string} smileyKey - The key from the {@link smileys} object
  52. * that should be added to the chat message.
  53. * @private
  54. * @returns {Function}
  55. */
  56. _getOnSmileySelectCallback(smileyKey) {
  57. return () => this.props.onSmileySelect(smileys[smileyKey]);
  58. }
  59. }
  60. export default SmileysPanel;