UNPKG

3.23 kBJavaScriptView Raw
1/*
2 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { __decorate, __extends } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20import { AbstractPureComponent2, Classes, DISPLAYNAME_PREFIX } from "../../common";
21import { Icon } from "../icon/icon";
22import { normalizeKeyCombo } from "./hotkeyParser";
23var 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};
36var KeyCombo = /** @class */ (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));
67export { KeyCombo };
68//# sourceMappingURL=keyCombo.js.map
\No newline at end of file