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.

ChatButton.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { IconMessage } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  7. import ChatCounter from './ChatCounter';
  8. /**
  9. * The type of the React {@code Component} props of {@link ChatButton}.
  10. */
  11. type Props = AbstractButtonProps & {
  12. /**
  13. * Whether or not the chat feature is currently displayed.
  14. */
  15. _chatOpen: boolean,
  16. };
  17. /**
  18. * Implementation of a button for accessing chat pane.
  19. */
  20. class ChatButton extends AbstractButton<Props, *> {
  21. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  22. icon = IconMessage;
  23. label = 'toolbar.openChat';
  24. toggledLabel = 'toolbar.closeChat';
  25. /**
  26. * Retrieves tooltip dynamically.
  27. */
  28. get tooltip() {
  29. if (this._isToggled()) {
  30. return 'toolbar.closeChat';
  31. }
  32. return 'toolbar.openChat';
  33. }
  34. /**
  35. * Required by linter due to AbstractButton overwritten prop being writable.
  36. *
  37. * @param {string} _value - The value.
  38. */
  39. set tooltip(_value) {
  40. // Unused.
  41. }
  42. /**
  43. * Indicates whether this button is in toggled state or not.
  44. *
  45. * @override
  46. * @protected
  47. * @returns {boolean}
  48. */
  49. _isToggled() {
  50. return this.props._chatOpen;
  51. }
  52. /**
  53. * Overrides AbstractButton's {@link Component#render()}.
  54. *
  55. * @override
  56. * @protected
  57. * @returns {boReact$Nodeolean}
  58. */
  59. render(): React$Node {
  60. return (
  61. <div
  62. className = 'toolbar-button-with-badge'
  63. key = 'chatcontainer'>
  64. {super.render()}
  65. <ChatCounter />
  66. </div>
  67. );
  68. }
  69. }
  70. /**
  71. * Function that maps parts of Redux state tree into component props.
  72. *
  73. * @param {Object} state - Redux state.
  74. * @returns {Object}
  75. */
  76. const mapStateToProps = state => {
  77. return {
  78. _chatOpen: state['features/chat'].isOpen
  79. };
  80. };
  81. export default translate(connect(mapStateToProps)(ChatButton));