UNPKG

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