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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { smileys } from '../smileys';
  4. /**
  5. * The type of the React {@code Component} props of {@link SmileysPanel}.
  6. */
  7. type Props = {
  8. /**
  9. * Callback to invoke when a smiley is selected. The smiley will be passed
  10. * back.
  11. */
  12. onSmileySelect: Function
  13. };
  14. /**
  15. * Implements a React Component showing smileys that can be be shown in chat.
  16. *
  17. * @extends Component
  18. */
  19. class SmileysPanel extends PureComponent<Props> {
  20. /**
  21. * Implements React's {@link Component#render()}.
  22. *
  23. * @inheritdoc
  24. * @returns {ReactElement}
  25. */
  26. render() {
  27. const smileyItems = Object.keys(smileys).map(smileyKey => {
  28. const onSelectFunction = this._getOnSmileySelectCallback(smileyKey);
  29. return (
  30. <div
  31. className = 'smileyContainer'
  32. id = { smileyKey }
  33. key = { smileyKey }>
  34. <img
  35. className = 'smiley'
  36. id = { smileyKey }
  37. onClick = { onSelectFunction }
  38. src = { `images/smileys/${smileyKey}.svg` } />
  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;