1 | /*
|
2 | * Copyright 2021 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 | */
|
16 | import * as React from "react";
|
17 | import * as Errors from "../../common/errors";
|
18 | import { isNodeEnv } from "../../common/utils";
|
19 | import { useHotkeys } from "../../hooks";
|
20 | /**
|
21 | * Utility component which allows consumers to use the new `useHotkeys` hook inside
|
22 | * React component classes. The implementation simply passes through to the hook.
|
23 | */
|
24 | export var HotkeysTarget2 = function (_a) {
|
25 | var children = _a.children, hotkeys = _a.hotkeys, options = _a.options;
|
26 | var _b = useHotkeys(hotkeys, options), handleKeyDown = _b.handleKeyDown, handleKeyUp = _b.handleKeyUp;
|
27 | // run props validation
|
28 | React.useEffect(function () {
|
29 | if (!isNodeEnv("production")) {
|
30 | if (typeof children !== "function" && hotkeys.some(function (h) { return !h.global; })) {
|
31 | console.error(Errors.HOTKEYS_TARGET2_CHILDREN_LOCAL_HOTKEYS);
|
32 | }
|
33 | }
|
34 | }, [hotkeys]);
|
35 | if (typeof children === "function") {
|
36 | return children({ handleKeyDown: handleKeyDown, handleKeyUp: handleKeyUp });
|
37 | }
|
38 | else {
|
39 | return children;
|
40 | }
|
41 | };
|
42 | //# sourceMappingURL=hotkeysTarget2.js.map |
\ | No newline at end of file |