UNPKG

4.02 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.AnchorButton = exports.Button = void 0;
19var tslib_1 = require("tslib");
20// HACKHACK: these components should go in separate files
21/* eslint-disable max-classes-per-file */
22var React = tslib_1.__importStar(require("react"));
23var props_1 = require("../../common/props");
24var refs_1 = require("../../common/refs");
25var abstractButton_1 = require("./abstractButton");
26/**
27 * Button component.
28 *
29 * @see https://blueprintjs.com/docs/#core/components/button
30 */
31var Button = /** @class */ (function (_super) {
32 tslib_1.__extends(Button, _super);
33 function Button() {
34 var _this = _super !== null && _super.apply(this, arguments) || this;
35 // need to keep this ref so that we can access it in AbstractButton#handleKeyUp
36 _this.buttonRef = null;
37 _this.handleRef = (0, refs_1.refHandler)(_this, "buttonRef", _this.props.elementRef);
38 return _this;
39 }
40 Button.prototype.render = function () {
41 return (React.createElement("button", tslib_1.__assign({ type: "button", ref: this.handleRef }, (0, props_1.removeNonHTMLProps)(this.props), this.getCommonButtonProps()), this.renderChildren()));
42 };
43 Button.prototype.componentDidUpdate = function (prevProps) {
44 if (prevProps.elementRef !== this.props.elementRef) {
45 (0, refs_1.setRef)(prevProps.elementRef, null);
46 this.handleRef = (0, refs_1.refHandler)(this, "buttonRef", this.props.elementRef);
47 (0, refs_1.setRef)(this.props.elementRef, this.buttonRef);
48 }
49 };
50 Button.displayName = "".concat(props_1.DISPLAYNAME_PREFIX, ".Button");
51 return Button;
52}(abstractButton_1.AbstractButton));
53exports.Button = Button;
54/**
55 * AnchorButton component.
56 *
57 * @see https://blueprintjs.com/docs/#core/components/button
58 */
59var AnchorButton = /** @class */ (function (_super) {
60 tslib_1.__extends(AnchorButton, _super);
61 function AnchorButton() {
62 var _this = _super !== null && _super.apply(this, arguments) || this;
63 // need to keep this ref so that we can access it in AbstractButton#handleKeyUp
64 _this.buttonRef = null;
65 _this.handleRef = (0, refs_1.refHandler)(_this, "buttonRef", _this.props.elementRef);
66 return _this;
67 }
68 AnchorButton.prototype.render = function () {
69 var _a = this.props, href = _a.href, _b = _a.tabIndex, tabIndex = _b === void 0 ? 0 : _b;
70 var commonProps = this.getCommonButtonProps();
71 return (React.createElement("a", tslib_1.__assign({ role: "button", ref: this.handleRef }, (0, props_1.removeNonHTMLProps)(this.props), commonProps, { href: commonProps.disabled ? undefined : href, tabIndex: commonProps.disabled ? -1 : tabIndex }), this.renderChildren()));
72 };
73 AnchorButton.prototype.componentDidUpdate = function (prevProps) {
74 if (prevProps.elementRef !== this.props.elementRef) {
75 (0, refs_1.setRef)(prevProps.elementRef, null);
76 this.handleRef = (0, refs_1.refHandler)(this, "buttonRef", this.props.elementRef);
77 (0, refs_1.setRef)(this.props.elementRef, this.buttonRef);
78 }
79 };
80 AnchorButton.displayName = "".concat(props_1.DISPLAYNAME_PREFIX, ".AnchorButton");
81 return AnchorButton;
82}(abstractButton_1.AbstractButton));
83exports.AnchorButton = AnchorButton;
84//# sourceMappingURL=buttons.js.map
\No newline at end of file