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.

KeyboardShortcutsButton.ts 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { connect } from 'react-redux';
  2. import { createToolbarEvent } from '../../analytics/AnalyticsEvents';
  3. import { sendAnalytics } from '../../analytics/functions';
  4. import { IReduxState } from '../../app/types';
  5. import { isMobileBrowser } from '../../base/environment/utils';
  6. import { translate } from '../../base/i18n/functions';
  7. import { IconShortcuts } from '../../base/icons/svg';
  8. import AbstractButton, { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
  9. import { openSettingsDialog } from '../../settings/actions.web';
  10. import { SETTINGS_TABS } from '../../settings/constants';
  11. import { areKeyboardShortcutsEnabled } from '../functions';
  12. /**
  13. * Implementation of a button for opening keyboard shortcuts dialog.
  14. */
  15. class KeyboardShortcutsButton extends AbstractButton<AbstractButtonProps> {
  16. accessibilityLabel = 'toolbar.accessibilityLabel.shortcuts';
  17. icon = IconShortcuts;
  18. label = 'toolbar.shortcuts';
  19. tooltip = 'toolbar.shortcuts';
  20. /**
  21. * Handles clicking / pressing the button, and opens the appropriate dialog.
  22. *
  23. * @protected
  24. * @returns {void}
  25. */
  26. _handleClick() {
  27. const { dispatch } = this.props;
  28. sendAnalytics(createToolbarEvent('shortcuts'));
  29. dispatch(openSettingsDialog(SETTINGS_TABS.SHORTCUTS));
  30. }
  31. }
  32. /**
  33. * Function that maps parts of Redux state tree into component props.
  34. *
  35. * @param {Object} state - Redux state.
  36. * @returns {Object}
  37. */
  38. const mapStateToProps = (state: IReduxState) => {
  39. return {
  40. visible: !isMobileBrowser() && areKeyboardShortcutsEnabled(state)
  41. };
  42. };
  43. export default translate(connect(mapStateToProps)(KeyboardShortcutsButton));