1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __decorate, __extends } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { polyfill } from "react-lifecycles-compat";
|
20 | import { AbstractPureComponent2, Classes, DISPLAYNAME_PREFIX } from "../../common";
|
21 | import { Icon } from "../icon/icon";
|
22 | import { normalizeKeyCombo } from "./hotkeyParser";
|
23 | var KeyIcons = {
|
24 | alt: { icon: "key-option", iconTitle: "Alt/Option key" },
|
25 | cmd: { icon: "key-command", iconTitle: "Command key" },
|
26 | ctrl: { icon: "key-control", iconTitle: "Control key" },
|
27 | delete: { icon: "key-delete", iconTitle: "Delete key" },
|
28 | down: { icon: "arrow-down", iconTitle: "Down key" },
|
29 | enter: { icon: "key-enter", iconTitle: "Enter key" },
|
30 | left: { icon: "arrow-left", iconTitle: "Left key" },
|
31 | meta: { icon: "key-command", iconTitle: "Command key" },
|
32 | right: { icon: "arrow-right", iconTitle: "Right key" },
|
33 | shift: { icon: "key-shift", iconTitle: "Shift key" },
|
34 | up: { icon: "arrow-up", iconTitle: "Up key" },
|
35 | };
|
36 | var KeyCombo = (function (_super) {
|
37 | __extends(KeyCombo, _super);
|
38 | function KeyCombo() {
|
39 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
40 | _this.renderKey = function (key, index) {
|
41 | var _a;
|
42 | var icon = KeyIcons[key];
|
43 | var reactKey = "key-" + index;
|
44 | return (React.createElement("kbd", { className: classNames(Classes.KEY, (_a = {}, _a[Classes.MODIFIER_KEY] = icon != null, _a)), key: reactKey },
|
45 | icon != null && React.createElement(Icon, { icon: icon.icon, title: icon.iconTitle }),
|
46 | key));
|
47 | };
|
48 | _this.renderMinimalKey = function (key, index) {
|
49 | var icon = KeyIcons[key];
|
50 | return icon == null ? key : React.createElement(Icon, { icon: icon.icon, title: icon.iconTitle, key: "key-" + index });
|
51 | };
|
52 | return _this;
|
53 | }
|
54 | KeyCombo.prototype.render = function () {
|
55 | var _a = this.props, className = _a.className, combo = _a.combo, minimal = _a.minimal;
|
56 | var keys = normalizeKeyCombo(combo)
|
57 | .map(function (key) { return (key.length === 1 ? key.toUpperCase() : key); })
|
58 | .map(minimal ? this.renderMinimalKey : this.renderKey);
|
59 | return React.createElement("span", { className: classNames(Classes.KEY_COMBO, className) }, keys);
|
60 | };
|
61 | KeyCombo.displayName = DISPLAYNAME_PREFIX + ".KeyCombo";
|
62 | KeyCombo = __decorate([
|
63 | polyfill
|
64 | ], KeyCombo);
|
65 | return KeyCombo;
|
66 | }(AbstractPureComponent2));
|
67 | export { KeyCombo };
|
68 |
|
\ | No newline at end of file |