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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  18. * Implementation of a button for accessing chat pane.
  19. */
  20. class ChatButton extends AbstractButton<Props, *> {
  21. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  22. icon = IconChat;
  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. return value;
  41. }
  42. /**
  43. * Handles clicking / pressing the button, and opens the appropriate dialog.
  44. *
  45. * @protected
  46. * @returns {void}
  47. */
  48. _handleClick() {
  49. const { handleClick } = this.props;
  50. if (handleClick) {
  51. handleClick();
  52. return;
  53. }
  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));