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 3.5KB

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