Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

KeyboardShortcutsDialog.tsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  5. import Dialog from '../../../base/ui/components/web/Dialog';
  6. /**
  7. * The type of the React {@code Component} props of
  8. * {@link KeyboardShortcutsDialog}.
  9. */
  10. interface IProps {
  11. /**
  12. * A Map with keyboard keys as keys and translation keys as values.
  13. */
  14. shortcutDescriptions: Map<string, string>;
  15. }
  16. /**
  17. * Creates the styles for the component.
  18. *
  19. * @param {Object} theme - The current UI theme.
  20. *
  21. * @returns {Object}
  22. */
  23. const useStyles = makeStyles()(theme => {
  24. return {
  25. list: {
  26. listStyleType: 'none',
  27. padding: 0,
  28. '& .shortcuts-list__item': {
  29. display: 'flex',
  30. justifyContent: 'space-between',
  31. alignItems: 'center',
  32. padding: `${theme.spacing(1)} 0`,
  33. ...withPixelLineHeight(theme.typography.bodyShortRegular),
  34. color: theme.palette.text01
  35. },
  36. '& .item-action': {
  37. backgroundColor: theme.palette.ui04,
  38. ...withPixelLineHeight(theme.typography.labelBold),
  39. padding: `${theme.spacing(1)} ${theme.spacing(2)}`,
  40. borderRadius: `${Number(theme.shape.borderRadius) / 2}px`
  41. }
  42. }
  43. };
  44. });
  45. const KeyboardShortcutsDialog = ({ shortcutDescriptions }: IProps) => {
  46. const { classes, cx } = useStyles();
  47. const { t } = useTranslation();
  48. // eslint-disable-next-line react/no-multi-comp
  49. const _renderShortcutsListItem = (keyboardKey: string, translationKey: string) => {
  50. let modifierKey = 'Alt';
  51. if (window.navigator?.platform) {
  52. if (window.navigator.platform.indexOf('Mac') !== -1) {
  53. modifierKey = '⌥';
  54. }
  55. }
  56. return (
  57. <li
  58. className = 'shortcuts-list__item'
  59. key = { keyboardKey }>
  60. <span
  61. aria-label = { t(translationKey) }
  62. className = 'shortcuts-list__description'>
  63. {t(translationKey)}
  64. </span>
  65. <span className = 'item-action'>
  66. {keyboardKey.startsWith(':')
  67. ? `${modifierKey} + ${keyboardKey.slice(1)}`
  68. : keyboardKey}
  69. </span>
  70. </li>
  71. );
  72. };
  73. return (
  74. <Dialog
  75. cancel = {{ hidden: true }}
  76. ok = {{ hidden: true }}
  77. titleKey = 'keyboardShortcuts.keyboardShortcuts'>
  78. <div
  79. id = 'keyboard-shortcuts'>
  80. <ul
  81. className = { cx('shortcuts-list', classes.list) }
  82. id = 'keyboard-shortcuts-list'>
  83. {Array.from(shortcutDescriptions)
  84. .map(description => _renderShortcutsListItem(...description))}
  85. </ul>
  86. </div>
  87. </Dialog>
  88. );
  89. };
  90. export default KeyboardShortcutsDialog;