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