1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __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 { HOTKEYS_HOTKEY_CHILDREN } from "../../common/errors";
|
22 | import { isElementOfType, isReactChildrenElementOrElements } from "../../common/utils";
|
23 | import { H4 } from "../html/html";
|
24 | import { Hotkey } from "./hotkey";
|
25 | var Hotkeys = (function (_super) {
|
26 | __extends(Hotkeys, _super);
|
27 | function Hotkeys() {
|
28 | return _super !== null && _super.apply(this, arguments) || this;
|
29 | }
|
30 | Hotkeys.prototype.render = function () {
|
31 | if (!isReactChildrenElementOrElements(this.props.children)) {
|
32 | return null;
|
33 | }
|
34 | var hotkeys = React.Children.map(this.props.children, function (child) { return child.props; });
|
35 |
|
36 | hotkeys.sort(function (a, b) {
|
37 | if (a.global === b.global && a.group && b.group) {
|
38 | return a.group.localeCompare(b.group);
|
39 | }
|
40 | return a.global ? -1 : 1;
|
41 | });
|
42 | var lastGroup;
|
43 | var elems = [];
|
44 | for (var _i = 0, hotkeys_1 = hotkeys; _i < hotkeys_1.length; _i++) {
|
45 | var hotkey = hotkeys_1[_i];
|
46 | var groupLabel = hotkey.group;
|
47 | if (groupLabel !== lastGroup) {
|
48 | elems.push(React.createElement(H4, { key: "group-" + elems.length }, groupLabel));
|
49 | lastGroup = groupLabel;
|
50 | }
|
51 | elems.push(React.createElement(Hotkey, __assign({ key: elems.length }, hotkey)));
|
52 | }
|
53 | var rootClasses = classNames(Classes.HOTKEY_COLUMN, this.props.className);
|
54 | return React.createElement("div", { className: rootClasses }, elems);
|
55 | };
|
56 | Hotkeys.prototype.validateProps = function (props) {
|
57 | if (!isReactChildrenElementOrElements(props.children)) {
|
58 | return;
|
59 | }
|
60 | React.Children.forEach(props.children, function (child) {
|
61 | if (!isElementOfType(child, Hotkey)) {
|
62 | throw new Error(HOTKEYS_HOTKEY_CHILDREN);
|
63 | }
|
64 | });
|
65 | };
|
66 | Hotkeys.displayName = DISPLAYNAME_PREFIX + ".Hotkeys";
|
67 | Hotkeys.defaultProps = {
|
68 | tabIndex: 0,
|
69 | };
|
70 | Hotkeys = __decorate([
|
71 | polyfill
|
72 | ], Hotkeys);
|
73 | return Hotkeys;
|
74 | }(AbstractPureComponent2));
|
75 | export { Hotkeys };
|
76 |
|
\ | No newline at end of file |