UNPKG

3.35 kBJavaScriptView Raw
1/*
2 * Copyright 2017 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, __decorate, __extends, __rest } from "tslib";
17import classNames from "classnames";
18import * as React from "react";
19import { polyfill } from "react-lifecycles-compat";
20import { AbstractPureComponent2, Classes } from "../../common";
21import { DISPLAYNAME_PREFIX } from "../../common/props";
22// TODO: write tests (ignoring for now to get a build passing quickly)
23/* istanbul ignore next */
24var FileInput = /** @class */ (function (_super) {
25 __extends(FileInput, _super);
26 function FileInput() {
27 var _this = _super !== null && _super.apply(this, arguments) || this;
28 _this.handleInputChange = function (e) {
29 var _a, _b, _c, _d;
30 (_b = (_a = _this.props).onInputChange) === null || _b === void 0 ? void 0 : _b.call(_a, e);
31 (_d = (_c = _this.props.inputProps) === null || _c === void 0 ? void 0 : _c.onChange) === null || _d === void 0 ? void 0 : _d.call(_c, e);
32 };
33 return _this;
34 }
35 FileInput.prototype.render = function () {
36 var _a, _b, _c;
37 var _d = this.props, buttonText = _d.buttonText, className = _d.className, disabled = _d.disabled, fill = _d.fill, hasSelection = _d.hasSelection, inputProps = _d.inputProps, large = _d.large, onInputChange = _d.onInputChange, text = _d.text, htmlProps = __rest(_d, ["buttonText", "className", "disabled", "fill", "hasSelection", "inputProps", "large", "onInputChange", "text"]);
38 var rootClasses = classNames(Classes.FILE_INPUT, (_a = {},
39 _a[Classes.FILE_INPUT_HAS_SELECTION] = hasSelection,
40 _a[Classes.DISABLED] = disabled,
41 _a[Classes.FILL] = fill,
42 _a[Classes.LARGE] = large,
43 _a), className);
44 var NS = Classes.getClassNamespace();
45 var uploadProps = (_b = {},
46 _b[NS + "-button-text"] = buttonText,
47 _b.className = classNames(Classes.FILE_UPLOAD_INPUT, (_c = {},
48 _c[Classes.FILE_UPLOAD_INPUT_CUSTOM_TEXT] = !!buttonText,
49 _c)),
50 _b);
51 return (React.createElement("label", __assign({}, htmlProps, { className: rootClasses }),
52 React.createElement("input", __assign({}, inputProps, { onChange: this.handleInputChange, type: "file", disabled: disabled })),
53 React.createElement("span", __assign({}, uploadProps), text)));
54 };
55 FileInput.displayName = DISPLAYNAME_PREFIX + ".FileInput";
56 FileInput.defaultProps = {
57 hasSelection: false,
58 inputProps: {},
59 text: "Choose file...",
60 };
61 FileInput = __decorate([
62 polyfill
63 ], FileInput);
64 return FileInput;
65}(AbstractPureComponent2));
66export { FileInput };
67//# sourceMappingURL=fileInput.js.map
\No newline at end of file