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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // @flow
  2. import React from 'react';
  3. import { createVideoBlurEvent, sendAnalytics } from '../../analytics';
  4. import { translate } from '../../base/i18n';
  5. import { connect } from '../../base/redux';
  6. import { AbstractButton, BetaTag } from '../../base/toolbox';
  7. import type { AbstractButtonProps } from '../../base/toolbox';
  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. iconName = 'icon-blur-background';
  28. label = 'toolbar.startvideoblur';
  29. tooltip = 'toolbar.startvideoblur';
  30. toggledLabel = 'toolbar.stopvideoblur';
  31. /**
  32. * Helper function to be implemented by subclasses, which returns
  33. * a React Element to display (a beta tag) at the end of the button.
  34. *
  35. * @override
  36. * @protected
  37. * @returns {ReactElement}
  38. */
  39. _getElementAfter() {
  40. return <BetaTag />;
  41. }
  42. /**
  43. * Handles clicking / pressing the button, and toggles the blur effect
  44. * state accordingly.
  45. *
  46. * @protected
  47. * @returns {void}
  48. */
  49. _handleClick() {
  50. const { _isVideoBlurred, dispatch } = this.props;
  51. const value = !_isVideoBlurred;
  52. sendAnalytics(createVideoBlurEvent(value ? 'started' : 'stopped'));
  53. dispatch(toggleBlurEffect(value));
  54. }
  55. /**
  56. * Returns {@code boolean} value indicating if the blur effect is
  57. * enabled or not.
  58. *
  59. * @protected
  60. * @returns {boolean}
  61. */
  62. _isToggled() {
  63. return this.props._isVideoBlurred;
  64. }
  65. }
  66. /**
  67. * Maps (parts of) the redux state to the associated props for the
  68. * {@code VideoBlurButton} component.
  69. *
  70. * @param {Object} state - The Redux state.
  71. * @private
  72. * @returns {{
  73. * _isVideoBlurred: boolean
  74. * }}
  75. */
  76. function _mapStateToProps(state): Object {
  77. return {
  78. _isVideoBlurred: Boolean(state['features/blur'].blurEnabled)
  79. };
  80. }
  81. export default translate(connect(_mapStateToProps)(VideoBlurButton));