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.

ParticipantsPaneButton.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState } from '../../../app/types';
  4. import { translate } from '../../../base/i18n/functions';
  5. import { IconUsers } from '../../../base/icons/svg';
  6. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  7. import {
  8. close as closeParticipantsPane,
  9. open as openParticipantsPane
  10. } from '../../../participants-pane/actions.web';
  11. import { closeOverflowMenuIfOpen } from '../../../toolbox/actions.web';
  12. import { isParticipantsPaneEnabled } from '../../functions';
  13. import ParticipantsCounter from './ParticipantsCounter';
  14. /**
  15. * The type of the React {@code Component} props of {@link ParticipantsPaneButton}.
  16. */
  17. interface IProps extends AbstractButtonProps {
  18. /**
  19. * Whether or not the participants pane is open.
  20. */
  21. _isOpen: boolean;
  22. /**
  23. * Whether participants feature is enabled or not.
  24. */
  25. _isParticipantsPaneEnabled: boolean;
  26. }
  27. /**
  28. * Implementation of a button for accessing participants pane.
  29. */
  30. class ParticipantsPaneButton extends AbstractButton<IProps> {
  31. accessibilityLabel = 'toolbar.accessibilityLabel.participants';
  32. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.closeParticipantsPane';
  33. icon = IconUsers;
  34. label = 'toolbar.participants';
  35. tooltip = 'toolbar.participants';
  36. toggledTooltip = 'toolbar.closeParticipantsPane';
  37. /**
  38. * Indicates whether this button is in toggled state or not.
  39. *
  40. * @override
  41. * @protected
  42. * @returns {boolean}
  43. */
  44. _isToggled() {
  45. return this.props._isOpen;
  46. }
  47. /**
  48. * Handles clicking the button, and toggles the participants pane.
  49. *
  50. * @private
  51. * @returns {void}
  52. */
  53. _handleClick() {
  54. const { dispatch, _isOpen } = this.props;
  55. dispatch(closeOverflowMenuIfOpen());
  56. if (_isOpen) {
  57. dispatch(closeParticipantsPane());
  58. } else {
  59. dispatch(openParticipantsPane());
  60. }
  61. }
  62. /**
  63. * Overrides AbstractButton's {@link Component#render()}.
  64. *
  65. * @override
  66. * @protected
  67. * @returns {React$Node}
  68. */
  69. render() {
  70. const { _isParticipantsPaneEnabled } = this.props;
  71. if (!_isParticipantsPaneEnabled) {
  72. return null;
  73. }
  74. return (
  75. <div
  76. className = 'toolbar-button-with-badge'>
  77. { super.render() }
  78. <ParticipantsCounter />
  79. </div>
  80. );
  81. }
  82. }
  83. /**
  84. * Maps part of the Redux state to the props of this component.
  85. *
  86. * @param {Object} state - The Redux state.
  87. * @returns {IProps}
  88. */
  89. function mapStateToProps(state: IReduxState) {
  90. const { isOpen } = state['features/participants-pane'];
  91. return {
  92. _isOpen: isOpen,
  93. _isParticipantsPaneEnabled: isParticipantsPaneEnabled(state)
  94. };
  95. }
  96. export default translate(connect(mapStateToProps)(ParticipantsPaneButton));