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

SettingsButton.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  4. import { translate } from '../../../base/i18n';
  5. import { AbstractButton } from '../../../base/toolbox';
  6. import type { AbstractButtonProps } from '../../../base/toolbox';
  7. import { openDeviceSelectionDialog } from '../../../device-selection';
  8. import { toggleSettings } from '../../../side-panel';
  9. declare var interfaceConfig: Object;
  10. /**
  11. * The type of the React {@code Component} props of {@link SettingsButton}.
  12. */
  13. type Props = AbstractButtonProps & {
  14. /**
  15. * Whether we are in filmstrip only mode or not.
  16. */
  17. _filmstripOnly: boolean,
  18. /**
  19. * Array containing the enabled settings sections.
  20. */
  21. _sections: Array<string>,
  22. /**
  23. * The redux {@code dispatch} function.
  24. */
  25. dispatch: Function
  26. };
  27. /**
  28. * An abstract implementation of a button for accessing settings.
  29. */
  30. class SettingsButton extends AbstractButton<Props, *> {
  31. accessibilityLabel = 'Settings';
  32. iconName = 'icon-settings';
  33. label = 'toolbar.Settings';
  34. tooltip = 'toolbar.Settings';
  35. /**
  36. * Handles clicking / pressing the button, and opens the appropriate dialog.
  37. *
  38. * @protected
  39. * @returns {void}
  40. */
  41. _handleClick() {
  42. const { _filmstripOnly, _sections, dispatch } = this.props;
  43. sendAnalytics(createToolbarEvent('settings'));
  44. if (_filmstripOnly
  45. || (_sections.length === 1 && _sections.includes('devices'))) {
  46. dispatch(openDeviceSelectionDialog());
  47. } else {
  48. dispatch(toggleSettings());
  49. }
  50. }
  51. }
  52. /**
  53. * Maps (parts of) the redux state to the associated props for the
  54. * {@code SettingsButton} component.
  55. *
  56. * @param {Object} state - The Redux state.
  57. * @private
  58. * @returns {{
  59. * _filmstripOnly: boolean
  60. * }}
  61. */
  62. function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
  63. // XXX: We are not currently using state here, but in the future, when
  64. // interfaceConfig is part of redux we will.
  65. return {
  66. _filmstripOnly: Boolean(interfaceConfig.filmStripOnly),
  67. _sections: interfaceConfig.SETTINGS_SECTIONS || []
  68. };
  69. }
  70. export default translate(connect(_mapStateToProps)(SettingsButton));