1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __extends, __rest } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { AbstractPureComponent2, Classes, refHandler, setRef } from "../../common";
|
20 | import { DISPLAYNAME_PREFIX } from "../../common/props";
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | var TextArea = (function (_super) {
|
29 | __extends(TextArea, _super);
|
30 | function TextArea() {
|
31 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
32 | _this.state = {};
|
33 |
|
34 | _this.textareaElement = null;
|
35 | _this.handleRef = refHandler(_this, "textareaElement", _this.props.inputRef);
|
36 | _this.maybeSyncHeightToScrollHeight = function () {
|
37 | if (_this.props.growVertically && _this.textareaElement != null) {
|
38 | var scrollHeight = _this.textareaElement.scrollHeight;
|
39 | if (scrollHeight > 0) {
|
40 | _this.setState({ height: scrollHeight });
|
41 | }
|
42 | }
|
43 | };
|
44 | _this.handleChange = function (e) {
|
45 | var _a, _b;
|
46 | _this.maybeSyncHeightToScrollHeight();
|
47 | (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
48 | };
|
49 | return _this;
|
50 | }
|
51 | TextArea.prototype.componentDidMount = function () {
|
52 | this.maybeSyncHeightToScrollHeight();
|
53 | };
|
54 | TextArea.prototype.componentDidUpdate = function (prevProps) {
|
55 | if (prevProps.inputRef !== this.props.inputRef) {
|
56 | setRef(prevProps.inputRef, null);
|
57 | this.handleRef = refHandler(this, "textareaElement", this.props.inputRef);
|
58 | setRef(this.props.inputRef, this.textareaElement);
|
59 | }
|
60 | if (prevProps.value !== this.props.value || prevProps.style !== this.props.style) {
|
61 | this.maybeSyncHeightToScrollHeight();
|
62 | }
|
63 | };
|
64 | TextArea.prototype.render = function () {
|
65 | var _a;
|
66 | var _b = this.props, className = _b.className, fill = _b.fill, inputRef = _b.inputRef, intent = _b.intent, large = _b.large, small = _b.small, growVertically = _b.growVertically, htmlProps = __rest(_b, ["className", "fill", "inputRef", "intent", "large", "small", "growVertically"]);
|
67 | var rootClasses = classNames(Classes.INPUT, Classes.intentClass(intent), (_a = {},
|
68 | _a[Classes.FILL] = fill,
|
69 | _a[Classes.LARGE] = large,
|
70 | _a[Classes.SMALL] = small,
|
71 | _a), className);
|
72 |
|
73 | var _c = htmlProps.style, style = _c === void 0 ? {} : _c;
|
74 | if (growVertically && this.state.height != null) {
|
75 |
|
76 |
|
77 | style = __assign(__assign({}, style), { height: "".concat(this.state.height, "px") });
|
78 | }
|
79 | return (React.createElement("textarea", __assign({}, htmlProps, { className: rootClasses, onChange: this.handleChange, ref: this.handleRef, style: style })));
|
80 | };
|
81 | TextArea.displayName = "".concat(DISPLAYNAME_PREFIX, ".TextArea");
|
82 | return TextArea;
|
83 | }(AbstractPureComponent2));
|
84 | export { TextArea };
|
85 |
|
\ | No newline at end of file |