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: "key-option",
|
25 | cmd: "key-command",
|
26 | ctrl: "key-control",
|
27 | delete: "key-delete",
|
28 | down: "arrow-down",
|
29 | enter: "key-enter",
|
30 | left: "arrow-left",
|
31 | meta: "key-command",
|
32 | right: "arrow-right",
|
33 | shift: "key-shift",
|
34 | up: "arrow-up",
|
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 icon = KeyIcons[key];
|
42 | var reactKey = "key-" + index;
|
43 | return icon == null ? (React.createElement("kbd", { className: Classes.KEY, key: reactKey }, key)) : (React.createElement("kbd", { className: classNames(Classes.KEY, Classes.MODIFIER_KEY), key: reactKey },
|
44 | React.createElement(Icon, { icon: icon }),
|
45 | " ",
|
46 | key));
|
47 | };
|
48 | _this.renderMinimalKey = function (key, index) {
|
49 | var icon = KeyIcons[key];
|
50 | return icon == null ? key : React.createElement(Icon, { icon: icon, 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 |