UNPKG

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