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.

PictureInPictureButton.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import { getAppProp } from '../../../app';
  4. import { translate } from '../../../base/i18n';
  5. import { AbstractButton } from '../../../base/toolbox';
  6. import type { AbstractButtonProps } from '../../../base/toolbox';
  7. import { enterPictureInPicture } from '../actions';
  8. type Props = AbstractButtonProps & {
  9. /**
  10. * Whether Picture-in-Picture is enabled or not.
  11. */
  12. _enabled: boolean,
  13. /**
  14. * The redux {@code dispatch} function.
  15. */
  16. dispatch: Function
  17. };
  18. /**
  19. * An implementation of a button for entering Picture-in-Picture mode.
  20. */
  21. class PictureInPictureButton extends AbstractButton<Props, *> {
  22. accessibilityLabel = 'toolbar.accessibilityLabel.pip';
  23. iconName = 'icon-menu-down';
  24. label = 'toolbar.pip';
  25. /**
  26. * Handles clicking / pressing the button.
  27. *
  28. * @protected
  29. * @returns {void}
  30. */
  31. _handleClick() {
  32. this.props.dispatch(enterPictureInPicture());
  33. }
  34. /**
  35. * Implements React's {@link Component#render()}.
  36. *
  37. * @inheritdoc
  38. * @returns {React$Node}
  39. */
  40. render() {
  41. return this.props._enabled ? super.render() : null;
  42. }
  43. }
  44. /**
  45. * Maps (parts of) the redux state to the associated props for the
  46. * {@code PictureInPictureButton} component.
  47. *
  48. * @param {Object} state - The Redux state.
  49. * @private
  50. * @returns {{
  51. * _enabled: boolean
  52. * }}
  53. */
  54. function _mapStateToProps(state): Object {
  55. return {
  56. _enabled: Boolean(getAppProp(state, 'pictureInPictureEnabled'))
  57. };
  58. }
  59. export default translate(connect(_mapStateToProps)(PictureInPictureButton));