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

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