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