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

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