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.

KeyboardShortcutsDialog.web.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import Lozenge from '@atlaskit/lozenge';
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { Dialog } from '../../base/dialog';
  5. import { translate } from '../../base/i18n';
  6. /**
  7. * Implements a React {@link Component} which displays a dialog describing
  8. * registered keyboard shortcuts.
  9. *
  10. * @extends Component
  11. */
  12. class KeyboardShortcutsDialog extends Component {
  13. /**
  14. * {@code KeyboardShortcutsDialog} component's property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * A Map with keyboard keys as keys and translation keys as values.
  21. */
  22. shortcutDescriptions: PropTypes.object,
  23. /**
  24. * Invoked to obtain translated strings.
  25. */
  26. t: PropTypes.func
  27. };
  28. /**
  29. * Implements React's {@link Component#render()}.
  30. *
  31. * @inheritdoc
  32. * @returns {ReactElement}
  33. */
  34. render() {
  35. const shortcuts = Array.from(this.props.shortcutDescriptions)
  36. .map(description => this._renderShortcutsListItem(...description));
  37. return (
  38. <Dialog
  39. cancelTitleKey = { 'dialog.close' }
  40. submitDisabled = { true }
  41. titleKey = 'keyboardShortcuts.keyboardShortcuts'
  42. width = 'small'>
  43. <div
  44. id = 'keyboard-shortcuts'>
  45. <ul
  46. className = 'shortcuts-list'
  47. id = 'keyboard-shortcuts-list'>
  48. { shortcuts }
  49. </ul>
  50. </div>
  51. </Dialog>
  52. );
  53. }
  54. /**
  55. * Creates a {@code ReactElement} for describing a single keyboard shortcut.
  56. *
  57. * @param {string} keyboardKey - The keyboard key that triggers an action.
  58. * @param {string} translationKey - A description of what the action does.
  59. * @private
  60. * @returns {ReactElement}
  61. */
  62. _renderShortcutsListItem(keyboardKey, translationKey) {
  63. return (
  64. <li
  65. className = 'shortcuts-list__item'
  66. key = { keyboardKey }>
  67. <span className = 'shortcuts-list__description'>
  68. { this.props.t(translationKey) }
  69. </span>
  70. <span className = 'item-action'>
  71. <Lozenge isBold = { true }>
  72. { keyboardKey }
  73. </Lozenge>
  74. </span>
  75. </li>
  76. );
  77. }
  78. }
  79. export default translate(KeyboardShortcutsDialog);