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.

FullscreenButton.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // @flow
  2. import { translate } from '../../../base/i18n';
  3. import { IconExitFullScreen, IconFullScreen } from '../../../base/icons';
  4. import { connect } from '../../../base/redux';
  5. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  6. type Props = AbstractButtonProps & {
  7. /**
  8. * Whether or not the app is currently in full screen.
  9. */
  10. _fullScreen: boolean,
  11. /**
  12. * External handler for click action.
  13. */
  14. handleClick: Function
  15. };
  16. /**
  17. * Implementation of a button for toggling fullscreen state.
  18. */
  19. class FullscreenButton extends AbstractButton<Props, *> {
  20. accessibilityLabel = 'toolbar.accessibilityLabel.fullScreen';
  21. label = 'toolbar.enterFullScreen';
  22. toggledLabel = 'toolbar.exitFullScreen'
  23. /**
  24. * Retrieves icon dynamically.
  25. */
  26. get icon() {
  27. if (this._isToggled()) {
  28. return IconExitFullScreen;
  29. }
  30. return IconFullScreen;
  31. }
  32. /**
  33. * Required by linter due to AbstractButton overwritten prop being writable.
  34. *
  35. * @param {string} value - The value.
  36. */
  37. set icon(value) {
  38. return value;
  39. }
  40. /**
  41. * Retrieves icon dynamically.
  42. */
  43. get tooltip() {
  44. if (this._isToggled()) {
  45. return 'toolbar.exitFullScreen';
  46. }
  47. return 'toolbar.enterFullScreen';
  48. }
  49. /**
  50. * Required by linter due to AbstractButton overwritten prop being writable.
  51. *
  52. * @param {string} value - The value.
  53. */
  54. set tooltip(value) {
  55. return value;
  56. }
  57. /**
  58. * Handles clicking / pressing the button, and opens the appropriate dialog.
  59. *
  60. * @protected
  61. * @returns {void}
  62. */
  63. _handleClick() {
  64. this.props.handleClick();
  65. }
  66. /**
  67. * Indicates whether this button is in toggled state or not.
  68. *
  69. * @override
  70. * @protected
  71. * @returns {boolean}
  72. */
  73. _isToggled() {
  74. return this.props._fullScreen;
  75. }
  76. }
  77. /**
  78. * Function that maps parts of Redux state tree into component props.
  79. *
  80. * @param {Object} state - Redux state.
  81. * @returns {Object}
  82. */
  83. const mapStateToProps = state => {
  84. return {
  85. _fullScreen: state['features/toolbox'].fullScreen
  86. };
  87. };
  88. export default translate(connect(mapStateToProps)(FullscreenButton));