您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TileViewButton.js 2.1KB

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