UNPKG

3.5 kBJavaScriptView Raw
1/*
2 * Copyright 2016 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 */
16import { __assign, __extends } from "tslib";
17// HACKHACK: these components should go in separate files
18/* eslint-disable max-classes-per-file */
19import * as React from "react";
20import { DISPLAYNAME_PREFIX, removeNonHTMLProps } from "../../common/props";
21import { refHandler, setRef } from "../../common/refs";
22import { AbstractButton } from "./abstractButton";
23var Button = /** @class */ (function (_super) {
24 __extends(Button, _super);
25 function Button() {
26 var _this = _super !== null && _super.apply(this, arguments) || this;
27 // need to keep this ref so that we can access it in AbstractButton#handleKeyUp
28 _this.buttonRef = null;
29 _this.handleRef = refHandler(_this, "buttonRef", _this.props.elementRef);
30 return _this;
31 }
32 Button.prototype.render = function () {
33 return (React.createElement("button", __assign({ type: "button", ref: this.handleRef }, removeNonHTMLProps(this.props), this.getCommonButtonProps()), this.renderChildren()));
34 };
35 Button.prototype.componentDidUpdate = function (prevProps) {
36 if (prevProps.elementRef !== this.props.elementRef) {
37 setRef(prevProps.elementRef, null);
38 this.handleRef = refHandler(this, "buttonRef", this.props.elementRef);
39 setRef(this.props.elementRef, this.buttonRef);
40 }
41 };
42 Button.displayName = DISPLAYNAME_PREFIX + ".Button";
43 return Button;
44}(AbstractButton));
45export { Button };
46var AnchorButton = /** @class */ (function (_super) {
47 __extends(AnchorButton, _super);
48 function AnchorButton() {
49 var _this = _super !== null && _super.apply(this, arguments) || this;
50 // need to keep this ref so that we can access it in AbstractButton#handleKeyUp
51 _this.buttonRef = null;
52 _this.handleRef = refHandler(_this, "buttonRef", _this.props.elementRef);
53 return _this;
54 }
55 AnchorButton.prototype.render = function () {
56 var _a = this.props, href = _a.href, _b = _a.tabIndex, tabIndex = _b === void 0 ? 0 : _b;
57 var commonProps = this.getCommonButtonProps();
58 return (React.createElement("a", __assign({ role: "button", ref: this.handleRef }, removeNonHTMLProps(this.props), commonProps, { href: commonProps.disabled ? undefined : href, tabIndex: commonProps.disabled ? -1 : tabIndex }), this.renderChildren()));
59 };
60 AnchorButton.prototype.componentDidUpdate = function (prevProps) {
61 if (prevProps.elementRef !== this.props.elementRef) {
62 setRef(prevProps.elementRef, null);
63 this.handleRef = refHandler(this, "buttonRef", this.props.elementRef);
64 setRef(this.props.elementRef, this.buttonRef);
65 }
66 };
67 AnchorButton.displayName = DISPLAYNAME_PREFIX + ".AnchorButton";
68 return AnchorButton;
69}(AbstractButton));
70export { AnchorButton };
71//# sourceMappingURL=buttons.js.map
\No newline at end of file