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