1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.InputGroup = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var classnames_1 = tslib_1.__importDefault(require("classnames"));
|
21 | var React = tslib_1.__importStar(require("react"));
|
22 | var common_1 = require("../../common");
|
23 | var Errors = tslib_1.__importStar(require("../../common/errors"));
|
24 | var props_1 = require("../../common/props");
|
25 | var icon_1 = require("../icon/icon");
|
26 | var asyncControllableInput_1 = require("./asyncControllableInput");
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | var InputGroup = (function (_super) {
|
33 | tslib_1.__extends(InputGroup, _super);
|
34 | function InputGroup() {
|
35 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
36 | _this.state = {};
|
37 | _this.leftElement = null;
|
38 | _this.rightElement = null;
|
39 | _this.refHandlers = {
|
40 | leftElement: function (ref) { return (_this.leftElement = ref); },
|
41 | rightElement: function (ref) { return (_this.rightElement = ref); },
|
42 | };
|
43 | return _this;
|
44 | }
|
45 | InputGroup.prototype.render = function () {
|
46 | var _a;
|
47 | var _b = this.props, _c = _b.asyncControl, asyncControl = _c === void 0 ? false : _c, className = _b.className, disabled = _b.disabled, fill = _b.fill, inputRef = _b.inputRef, intent = _b.intent, large = _b.large, round = _b.round, small = _b.small, _d = _b.tagName, tagName = _d === void 0 ? "div" : _d;
|
48 | var inputGroupClasses = (0, classnames_1.default)(common_1.Classes.INPUT_GROUP, common_1.Classes.intentClass(intent), (_a = {},
|
49 | _a[common_1.Classes.DISABLED] = disabled,
|
50 | _a[common_1.Classes.FILL] = fill,
|
51 | _a[common_1.Classes.LARGE] = large,
|
52 | _a[common_1.Classes.SMALL] = small,
|
53 | _a[common_1.Classes.ROUND] = round,
|
54 | _a), className);
|
55 | var style = tslib_1.__assign(tslib_1.__assign({}, this.props.style), { paddingLeft: this.state.leftElementWidth, paddingRight: this.state.rightElementWidth });
|
56 | var inputProps = tslib_1.__assign(tslib_1.__assign({ type: "text" }, (0, props_1.removeNonHTMLProps)(this.props)), { className: common_1.Classes.INPUT, style: style });
|
57 | var inputElement = asyncControl ? (React.createElement(asyncControllableInput_1.AsyncControllableInput, tslib_1.__assign({}, inputProps, { inputRef: inputRef }))) : (React.createElement("input", tslib_1.__assign({}, inputProps, { ref: inputRef })));
|
58 | return React.createElement(tagName, { className: inputGroupClasses }, this.maybeRenderLeftElement(), inputElement, this.maybeRenderRightElement());
|
59 | };
|
60 | InputGroup.prototype.componentDidMount = function () {
|
61 | this.updateInputWidth();
|
62 | };
|
63 | InputGroup.prototype.componentDidUpdate = function (prevProps) {
|
64 | var _a = this.props, leftElement = _a.leftElement, rightElement = _a.rightElement;
|
65 | if (prevProps.leftElement !== leftElement || prevProps.rightElement !== rightElement) {
|
66 | this.updateInputWidth();
|
67 | }
|
68 | };
|
69 | InputGroup.prototype.validateProps = function (props) {
|
70 | if (props.leftElement != null && props.leftIcon != null) {
|
71 | console.warn(Errors.INPUT_WARN_LEFT_ELEMENT_LEFT_ICON_MUTEX);
|
72 | }
|
73 | };
|
74 | InputGroup.prototype.maybeRenderLeftElement = function () {
|
75 | var _a = this.props, leftElement = _a.leftElement, leftIcon = _a.leftIcon;
|
76 | if (leftElement != null) {
|
77 | return (React.createElement("span", { className: common_1.Classes.INPUT_LEFT_CONTAINER, ref: this.refHandlers.leftElement }, leftElement));
|
78 | }
|
79 | else if (leftIcon != null) {
|
80 | return React.createElement(icon_1.Icon, { icon: leftIcon, "aria-hidden": true, tabIndex: -1 });
|
81 | }
|
82 | return undefined;
|
83 | };
|
84 | InputGroup.prototype.maybeRenderRightElement = function () {
|
85 | var rightElement = this.props.rightElement;
|
86 | if (rightElement == null) {
|
87 | return undefined;
|
88 | }
|
89 | return (React.createElement("span", { className: common_1.Classes.INPUT_ACTION, ref: this.refHandlers.rightElement }, rightElement));
|
90 | };
|
91 | InputGroup.prototype.updateInputWidth = function () {
|
92 | var _a = this.state, leftElementWidth = _a.leftElementWidth, rightElementWidth = _a.rightElementWidth;
|
93 | if (this.leftElement != null) {
|
94 | var clientWidth = this.leftElement.clientWidth;
|
95 |
|
96 | if (leftElementWidth === undefined || Math.abs(clientWidth - leftElementWidth) > 2) {
|
97 | this.setState({ leftElementWidth: clientWidth });
|
98 | }
|
99 | }
|
100 | else {
|
101 | this.setState({ leftElementWidth: undefined });
|
102 | }
|
103 | if (this.rightElement != null) {
|
104 | var clientWidth = this.rightElement.clientWidth;
|
105 |
|
106 | if (rightElementWidth === undefined || Math.abs(clientWidth - rightElementWidth) > 2) {
|
107 | this.setState({ rightElementWidth: clientWidth });
|
108 | }
|
109 | }
|
110 | else {
|
111 | this.setState({ rightElementWidth: undefined });
|
112 | }
|
113 | };
|
114 | InputGroup.displayName = "".concat(props_1.DISPLAYNAME_PREFIX, ".InputGroup");
|
115 | return InputGroup;
|
116 | }(common_1.AbstractPureComponent2));
|
117 | exports.InputGroup = InputGroup;
|
118 |
|
\ | No newline at end of file |