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.

TileViewButton.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import {
  4. createToolbarEvent,
  5. sendAnalytics
  6. } from '../../analytics';
  7. import { translate } from '../../base/i18n';
  8. import {
  9. AbstractButton,
  10. type AbstractButtonProps
  11. } from '../../base/toolbox';
  12. import { setTileView } from '../actions';
  13. /**
  14. * The type of the React {@code Component} props of {@link TileViewButton}.
  15. */
  16. type Props = AbstractButtonProps & {
  17. /**
  18. * Whether or not tile view layout has been enabled as the user preference.
  19. */
  20. _tileViewEnabled: boolean,
  21. /**
  22. * Used to dispatch actions from the buttons.
  23. */
  24. dispatch: Dispatch<*>
  25. };
  26. /**
  27. * Component that renders a toolbar button for toggling the tile layout view.
  28. *
  29. * @extends AbstractButton
  30. */
  31. class TileViewButton<P: Props> extends AbstractButton<P, *> {
  32. accessibilityLabel = 'toolbar.accessibilityLabel.tileView';
  33. iconName = 'icon-tiles-many';
  34. label = 'toolbar.enterTileView';
  35. toggledLabel = 'toolbar.exitTileView';
  36. toggledIconName = 'icon-tiles-many toggled';
  37. tooltip = 'toolbar.tileViewToggle';
  38. /**
  39. * Handles clicking / pressing the button.
  40. *
  41. * @override
  42. * @protected
  43. * @returns {void}
  44. */
  45. _handleClick() {
  46. const { _tileViewEnabled, dispatch } = this.props;
  47. sendAnalytics(createToolbarEvent(
  48. 'tileview.button',
  49. {
  50. 'is_enabled': _tileViewEnabled
  51. }));
  52. dispatch(setTileView(!_tileViewEnabled));
  53. }
  54. /**
  55. * Indicates whether this button is in toggled state or not.
  56. *
  57. * @override
  58. * @protected
  59. * @returns {boolean}
  60. */
  61. _isToggled() {
  62. return this.props._tileViewEnabled;
  63. }
  64. }
  65. /**
  66. * Maps (parts of) the redux state to the associated props for the
  67. * {@code TileViewButton} component.
  68. *
  69. * @param {Object} state - The Redux state.
  70. * @returns {{
  71. * _tileViewEnabled: boolean
  72. * }}
  73. */
  74. function _mapStateToProps(state) {
  75. return {
  76. _tileViewEnabled: state['features/video-layout'].tileViewEnabled
  77. };
  78. }
  79. export default translate(connect(_mapStateToProps)(TileViewButton));