2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2022-10-18 10:56:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2017-11-13 22:58:00 +00:00
|
|
|
|
2022-10-18 10:56:26 +00:00
|
|
|
import { withPixelLineHeight } from '../../../base/styles/functions.web';
|
2022-09-29 10:26:34 +00:00
|
|
|
import Dialog from '../../../base/ui/components/web/Dialog';
|
2017-11-13 22:58:00 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link KeyboardShortcutsDialog}.
|
2017-11-13 22:58:00 +00:00
|
|
|
*/
|
2022-10-18 10:56:26 +00:00
|
|
|
interface Props {
|
2022-02-26 21:45:32 +00:00
|
|
|
|
2017-11-13 22:58:00 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* A Map with keyboard keys as keys and translation keys as values.
|
2017-11-13 22:58:00 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
shortcutDescriptions: Map<string, string>;
|
2022-08-25 11:35:19 +00:00
|
|
|
}
|
2017-11-13 22:58:00 +00:00
|
|
|
|
2022-02-26 21:45:32 +00:00
|
|
|
/**
|
|
|
|
* Creates the styles for the component.
|
|
|
|
*
|
|
|
|
* @param {Object} theme - The current UI theme.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-10-18 10:56:26 +00:00
|
|
|
const useStyles = makeStyles()((theme: Theme) => {
|
2022-02-26 21:45:32 +00:00
|
|
|
return {
|
|
|
|
list: {
|
|
|
|
listStyleType: 'none',
|
|
|
|
padding: 0,
|
|
|
|
|
|
|
|
'& .shortcuts-list__item': {
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'space-between',
|
2022-10-18 10:56:26 +00:00
|
|
|
marginBottom: theme.spacing(2),
|
|
|
|
...withPixelLineHeight(theme.typography.labelRegular),
|
|
|
|
color: theme.palette.text01
|
2022-08-04 10:39:22 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
'& .item-action': {
|
|
|
|
backgroundColor: theme.palette.ui04,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
padding: '1px 4px',
|
|
|
|
borderRadius: '4px'
|
2022-02-26 21:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-10-18 10:56:26 +00:00
|
|
|
});
|
2017-11-13 22:58:00 +00:00
|
|
|
|
2022-10-18 10:56:26 +00:00
|
|
|
const KeyboardShortcutsDialog = ({ shortcutDescriptions }: Props) => {
|
|
|
|
const { classes, cx } = useStyles();
|
|
|
|
const { t } = useTranslation();
|
2017-11-13 22:58:00 +00:00
|
|
|
|
2022-10-18 10:56:26 +00:00
|
|
|
// eslint-disable-next-line react/no-multi-comp
|
|
|
|
const _renderShortcutsListItem = (keyboardKey: string, translationKey: string) => {
|
2021-07-13 06:50:08 +00:00
|
|
|
let modifierKey = 'Alt';
|
|
|
|
|
|
|
|
if (window.navigator?.platform) {
|
|
|
|
if (window.navigator.platform.indexOf('Mac') !== -1) {
|
|
|
|
modifierKey = '⌥';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 22:58:00 +00:00
|
|
|
return (
|
|
|
|
<li
|
|
|
|
className = 'shortcuts-list__item'
|
|
|
|
key = { keyboardKey }>
|
2021-06-10 12:48:44 +00:00
|
|
|
<span
|
2022-10-18 10:56:26 +00:00
|
|
|
aria-label = { t(translationKey) }
|
2021-06-10 12:48:44 +00:00
|
|
|
className = 'shortcuts-list__description'>
|
2022-10-18 10:56:26 +00:00
|
|
|
{t(translationKey)}
|
2017-11-13 22:58:00 +00:00
|
|
|
</span>
|
|
|
|
<span className = 'item-action'>
|
2022-10-18 10:56:26 +00:00
|
|
|
{keyboardKey.startsWith(':')
|
2022-08-04 10:39:22 +00:00
|
|
|
? `${modifierKey} + ${keyboardKey.slice(1)}`
|
2022-10-18 10:56:26 +00:00
|
|
|
: keyboardKey}
|
2017-11-13 22:58:00 +00:00
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
);
|
2022-10-18 10:56:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
|
|
|
cancel = {{ hidden: true }}
|
|
|
|
ok = {{ hidden: true }}
|
|
|
|
titleKey = 'keyboardShortcuts.keyboardShortcuts'>
|
|
|
|
<div
|
|
|
|
id = 'keyboard-shortcuts'>
|
|
|
|
<ul
|
|
|
|
className = { cx('shortcuts-list', classes.list) }
|
|
|
|
id = 'keyboard-shortcuts-list'>
|
|
|
|
{Array.from(shortcutDescriptions)
|
|
|
|
.map(description => _renderShortcutsListItem(...description))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
};
|
2017-11-13 22:58:00 +00:00
|
|
|
|
2022-10-18 10:56:26 +00:00
|
|
|
export default KeyboardShortcutsDialog;
|