2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-11-13 22:58:00 +00:00
|
|
|
import Lozenge from '@atlaskit/lozenge';
|
2022-02-26 21:45:32 +00:00
|
|
|
import { withStyles } from '@material-ui/core/styles';
|
|
|
|
import clsx from 'clsx';
|
2017-11-13 22:58:00 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { Dialog } from '../../base/dialog';
|
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
2022-02-26 21:45:32 +00:00
|
|
|
/**
|
|
|
|
* An object containing the CSS classes.
|
|
|
|
*/
|
|
|
|
classes: Object,
|
|
|
|
|
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
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
shortcutDescriptions: Object,
|
2017-11-13 22:58:00 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
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}
|
|
|
|
*/
|
|
|
|
const styles = theme => {
|
|
|
|
return {
|
|
|
|
list: {
|
|
|
|
listStyleType: 'none',
|
|
|
|
padding: 0,
|
|
|
|
|
|
|
|
'& .shortcuts-list__item': {
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
marginBottom: theme.spacing(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which displays a dialog describing
|
|
|
|
* registered keyboard shortcuts.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
|
|
|
class KeyboardShortcutsDialog extends Component<Props> {
|
2017-11-13 22:58:00 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const shortcuts = Array.from(this.props.shortcutDescriptions)
|
|
|
|
.map(description => this._renderShortcutsListItem(...description));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
2019-03-06 17:23:53 +00:00
|
|
|
cancelKey = { 'dialog.close' }
|
2017-11-13 22:58:00 +00:00
|
|
|
submitDisabled = { true }
|
|
|
|
titleKey = 'keyboardShortcuts.keyboardShortcuts'
|
|
|
|
width = 'small'>
|
|
|
|
<div
|
|
|
|
id = 'keyboard-shortcuts'>
|
|
|
|
<ul
|
2022-02-26 21:45:32 +00:00
|
|
|
className = { clsx('shortcuts-list', this.props.classes.list) }
|
2017-11-13 22:58:00 +00:00
|
|
|
id = 'keyboard-shortcuts-list'>
|
|
|
|
{ shortcuts }
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</Dialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a {@code ReactElement} for describing a single keyboard shortcut.
|
|
|
|
*
|
|
|
|
* @param {string} keyboardKey - The keyboard key that triggers an action.
|
|
|
|
* @param {string} translationKey - A description of what the action does.
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderShortcutsListItem(keyboardKey, translationKey) {
|
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
|
|
|
|
aria-label = { this.props.t(translationKey) }
|
|
|
|
className = 'shortcuts-list__description'>
|
2017-11-13 22:58:00 +00:00
|
|
|
{ this.props.t(translationKey) }
|
|
|
|
</span>
|
|
|
|
<span className = 'item-action'>
|
|
|
|
<Lozenge isBold = { true }>
|
2021-07-13 06:50:08 +00:00
|
|
|
{ keyboardKey.startsWith(':')
|
|
|
|
? `${modifierKey} + ${keyboardKey.slice(1)}`
|
|
|
|
: keyboardKey }
|
2017-11-13 22:58:00 +00:00
|
|
|
</Lozenge>
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-26 21:45:32 +00:00
|
|
|
export default translate(withStyles(styles)(KeyboardShortcutsDialog));
|