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.

VideoBlurButton.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // @flow
  2. import { createVideoBlurEvent, sendAnalytics } from '../../analytics';
  3. import { translate } from '../../base/i18n';
  4. import { IconBlurBackground } from '../../base/icons';
  5. import { connect } from '../../base/redux';
  6. import { AbstractButton } from '../../base/toolbox/components';
  7. import type { AbstractButtonProps } from '../../base/toolbox/components';
  8. import { toggleBlurEffect } from '../actions';
  9. /**
  10. * The type of the React {@code Component} props of {@link VideoBlurButton}.
  11. */
  12. type Props = AbstractButtonProps & {
  13. /**
  14. * True if the video background is blurred or false if it is not.
  15. */
  16. _isVideoBlurred: boolean,
  17. /**
  18. * The redux {@code dispatch} function.
  19. */
  20. dispatch: Function
  21. };
  22. /**
  23. * An abstract implementation of a button that toggles the video blur effect.
  24. */
  25. class VideoBlurButton extends AbstractButton<Props, *> {
  26. accessibilityLabel = 'toolbar.accessibilityLabel.videoblur';
  27. icon = IconBlurBackground;
  28. label = 'toolbar.startvideoblur';
  29. tooltip = 'toolbar.startvideoblur';
  30. toggledLabel = 'toolbar.stopvideoblur';
  31. /**
  32. * Handles clicking / pressing the button, and toggles the blur effect
  33. * state accordingly.
  34. *
  35. * @protected
  36. * @returns {void}
  37. */
  38. _handleClick() {
  39. const { _isVideoBlurred, dispatch } = this.props;
  40. const value = !_isVideoBlurred;
  41. sendAnalytics(createVideoBlurEvent(value ? 'started' : 'stopped'));
  42. dispatch(toggleBlurEffect(value));
  43. }
  44. /**
  45. * Returns {@code boolean} value indicating if the blur effect is
  46. * enabled or not.
  47. *
  48. * @protected
  49. * @returns {boolean}
  50. */
  51. _isToggled() {
  52. return this.props._isVideoBlurred;
  53. }
  54. }
  55. /**
  56. * Maps (parts of) the redux state to the associated props for the
  57. * {@code VideoBlurButton} component.
  58. *
  59. * @param {Object} state - The Redux state.
  60. * @private
  61. * @returns {{
  62. * _isVideoBlurred: boolean
  63. * }}
  64. */
  65. function _mapStateToProps(state): Object {
  66. return {
  67. _isVideoBlurred: Boolean(state['features/blur'].blurEnabled)
  68. };
  69. }
  70. export default translate(connect(_mapStateToProps)(VideoBlurButton));