1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __extends } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { AbstractPureComponent2, Classes, Keys, Utils, } from "../../common";
|
20 | import { Icon, IconSize } from "../icon/icon";
|
21 | import { Spinner } from "../spinner/spinner";
|
22 | var AbstractButton = (function (_super) {
|
23 | __extends(AbstractButton, _super);
|
24 | function AbstractButton() {
|
25 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
26 | _this.state = {
|
27 | isActive: false,
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | _this.handleKeyDown = function (e) {
|
34 | var _a, _b;
|
35 |
|
36 |
|
37 | if (Keys.isKeyboardClick(e.which)) {
|
38 | e.preventDefault();
|
39 | if (e.which !== _this.currentKeyDown) {
|
40 | _this.setState({ isActive: true });
|
41 | }
|
42 | }
|
43 | _this.currentKeyDown = e.which;
|
44 | (_b = (_a = _this.props).onKeyDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
45 | };
|
46 | _this.handleKeyUp = function (e) {
|
47 | var _a, _b, _c;
|
48 |
|
49 |
|
50 | if (Keys.isKeyboardClick(e.which)) {
|
51 | _this.setState({ isActive: false });
|
52 | (_a = _this.buttonRef) === null || _a === void 0 ? void 0 : _a.click();
|
53 | }
|
54 | _this.currentKeyDown = undefined;
|
55 | (_c = (_b = _this.props).onKeyUp) === null || _c === void 0 ? void 0 : _c.call(_b, e);
|
56 | };
|
57 | _this.handleBlur = function (e) {
|
58 | var _a, _b;
|
59 | if (_this.state.isActive) {
|
60 | _this.setState({ isActive: false });
|
61 | }
|
62 | (_b = (_a = _this.props).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
63 | };
|
64 | return _this;
|
65 | }
|
66 | AbstractButton.prototype.getCommonButtonProps = function () {
|
67 | var _a;
|
68 | var _b = this.props, active = _b.active, alignText = _b.alignText, fill = _b.fill, large = _b.large, loading = _b.loading, outlined = _b.outlined, minimal = _b.minimal, small = _b.small, tabIndex = _b.tabIndex;
|
69 | var disabled = this.props.disabled || loading;
|
70 | var className = classNames(Classes.BUTTON, (_a = {},
|
71 | _a[Classes.ACTIVE] = !disabled && (active || this.state.isActive),
|
72 | _a[Classes.DISABLED] = disabled,
|
73 | _a[Classes.FILL] = fill,
|
74 | _a[Classes.LARGE] = large,
|
75 | _a[Classes.LOADING] = loading,
|
76 | _a[Classes.MINIMAL] = minimal,
|
77 | _a[Classes.OUTLINED] = outlined,
|
78 | _a[Classes.SMALL] = small,
|
79 | _a), Classes.alignmentClass(alignText), Classes.intentClass(this.props.intent), this.props.className);
|
80 | return {
|
81 | className: className,
|
82 | disabled: disabled,
|
83 | onBlur: this.handleBlur,
|
84 | onClick: disabled ? undefined : this.props.onClick,
|
85 | onKeyDown: this.handleKeyDown,
|
86 | onKeyUp: this.handleKeyUp,
|
87 | tabIndex: disabled ? -1 : tabIndex,
|
88 | };
|
89 | };
|
90 | AbstractButton.prototype.renderChildren = function () {
|
91 | var _a = this.props, children = _a.children, icon = _a.icon, loading = _a.loading, rightIcon = _a.rightIcon, text = _a.text;
|
92 | return [
|
93 | loading && React.createElement(Spinner, { key: "loading", className: Classes.BUTTON_SPINNER, size: IconSize.LARGE }),
|
94 | React.createElement(Icon, { key: "leftIcon", icon: icon }),
|
95 | (!Utils.isReactNodeEmpty(text) || !Utils.isReactNodeEmpty(children)) && (React.createElement("span", { key: "text", className: Classes.BUTTON_TEXT },
|
96 | text,
|
97 | children)),
|
98 | React.createElement(Icon, { key: "rightIcon", icon: rightIcon }),
|
99 | ];
|
100 | };
|
101 | return AbstractButton;
|
102 | }(AbstractPureComponent2));
|
103 | export { AbstractButton };
|
104 |
|
\ | No newline at end of file |