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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { IconChat } 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. * External handler for click action.
  18. */
  19. handleClick: Function
  20. };
  21. /**
  22. * Implementation of a button for accessing chat pane.
  23. */
  24. class ChatButton extends AbstractButton<Props, *> {
  25. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  26. icon = IconChat;
  27. label = 'toolbar.openChat';
  28. toggledLabel = 'toolbar.closeChat';
  29. /**
  30. * Retrieves tooltip dynamically.
  31. */
  32. get tooltip() {
  33. if (this._isToggled()) {
  34. return 'toolbar.closeChat';
  35. }
  36. return 'toolbar.openChat';
  37. }
  38. /**
  39. * Required by linter due to AbstractButton overwritten prop being writable.
  40. *
  41. * @param {string} value - The value.
  42. */
  43. set tooltip(value) {
  44. return value;
  45. }
  46. /**
  47. * Handles clicking / pressing the button, and opens the appropriate dialog.
  48. *
  49. * @protected
  50. * @returns {void}
  51. */
  52. _handleClick() {
  53. this.props.handleClick();
  54. }
  55. /**
  56. * Indicates whether this button is in toggled state or not.
  57. *
  58. * @override
  59. * @protected
  60. * @returns {boolean}
  61. */
  62. _isToggled() {
  63. return this.props._chatOpen;
  64. }
  65. /**
  66. * Overrides AbstractButton's {@link Component#render()}.
  67. *
  68. * @override
  69. * @protected
  70. * @returns {boReact$Nodeolean}
  71. */
  72. render(): React$Node {
  73. return (
  74. <div
  75. className = 'toolbar-button-with-badge'
  76. key = 'chatcontainer'>
  77. {super.render()}
  78. <ChatCounter />
  79. </div>
  80. );
  81. }
  82. }
  83. /**
  84. * Function that maps parts of Redux state tree into component props.
  85. *
  86. * @param {Object} state - Redux state.
  87. * @returns {Object}
  88. */
  89. const mapStateToProps = state => {
  90. return {
  91. _chatOpen: state['features/chat'].isOpen
  92. };
  93. };
  94. export default translate(connect(mapStateToProps)(ChatButton));