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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. toggledIconName = 'icon-tiles-many toggled';
  35. tooltip = 'toolbar.tileViewToggle';
  36. /**
  37. * Handles clicking / pressing the button.
  38. *
  39. * @override
  40. * @protected
  41. * @returns {void}
  42. */
  43. _handleClick() {
  44. const { _tileViewEnabled, dispatch } = this.props;
  45. sendAnalytics(createToolbarEvent(
  46. 'tileview.button',
  47. {
  48. 'is_enabled': _tileViewEnabled
  49. }));
  50. dispatch(setTileView(!_tileViewEnabled));
  51. }
  52. /**
  53. * Indicates whether this button is in toggled state or not.
  54. *
  55. * @override
  56. * @protected
  57. * @returns {boolean}
  58. */
  59. _isToggled() {
  60. return this.props._tileViewEnabled;
  61. }
  62. }
  63. /**
  64. * Maps (parts of) the redux state to the associated props for the
  65. * {@code TileViewButton} component.
  66. *
  67. * @param {Object} state - The Redux state.
  68. * @returns {{
  69. * _tileViewEnabled: boolean
  70. * }}
  71. */
  72. function _mapStateToProps(state) {
  73. return {
  74. _tileViewEnabled: state['features/video-layout'].tileViewEnabled
  75. };
  76. }
  77. export default translate(connect(_mapStateToProps)(TileViewButton));