選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PictureInPictureButton.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 = 'Picture in picture';
  23. iconName = 'icon-menu-down';
  24. label = 'toolbar.pip';
  25. /**
  26. * Handles clicking / pressing the button.
  27. *
  28. * @private
  29. * @returns {void}
  30. */
  31. _handleClick() {
  32. this.props.dispatch(enterPictureInPicture());
  33. }
  34. /**
  35. * Indicates whether this button is disabled or not.
  36. *
  37. * @override
  38. * @private
  39. * @returns {boolean}
  40. */
  41. _isDisabled() {
  42. return false;
  43. }
  44. /**
  45. * Implements React's {@link Component#render()}.
  46. *
  47. * @inheritdoc
  48. * @returns {?ReactElement}
  49. */
  50. render() {
  51. if (!this.props._enabled) {
  52. // $FlowFixMe
  53. return null;
  54. }
  55. return super.render();
  56. }
  57. }
  58. /**
  59. * Maps (parts of) the redux state to the associated props for the
  60. * {@code PictureInPictureButton} component.
  61. *
  62. * @param {Object} state - The Redux state.
  63. * @private
  64. * @returns {{
  65. * _enabled: boolean
  66. * }}
  67. */
  68. function _mapStateToProps(state): Object {
  69. return {
  70. _enabled: Boolean(getAppProp(state, 'pictureInPictureEnabled'))
  71. };
  72. }
  73. export default translate(connect(_mapStateToProps)(PictureInPictureButton));