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