insomnia/packages/insomnia-app/app/ui/components/hotkey.js
Ricky Chandra bb8b48adc3 New data models for hotkeys and store the key bindings in settings (#1314)
* New data models for hotkeys and store the key bindings in settings

* Merge win and linux key bindings, remove generic key combinations, and add documents
2019-03-12 12:38:30 -04:00

39 lines
985 B
JavaScript

// @flow
import * as React from 'react';
import classnames from 'classnames';
import { ALT_SYM, CTRL_SYM, isMac, joinHotKeys, META_SYM, SHIFT_SYM } from '../../common/constants';
import type { KeyBindings } from '../../common/hotkeys';
import * as hotkeys from '../../common/hotkeys';
type Props = {
keyBindings: KeyBindings,
// Optional
className?: string,
};
class Hotkey extends React.PureComponent<Props> {
render() {
const { keyBindings, className } = this.props;
const keyComb = hotkeys.getPlatformKeyCombinations(keyBindings)[0];
const { ctrl, alt, shift, meta, keyCode } = keyComb;
const chars = [];
alt && chars.push(ALT_SYM);
shift && chars.push(SHIFT_SYM);
ctrl && chars.push(CTRL_SYM);
meta && chars.push(META_SYM);
chars.push(hotkeys.getChar(keyCode));
return (
<span className={classnames(className, { 'font-normal': isMac() })}>
{joinHotKeys(chars)}
</span>
);
}
}
export default Hotkey;