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

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