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 { AbstractPureComponent, Classes, refHandler, setRef } from "../../common";
|
20 | import { DISPLAYNAME_PREFIX } from "../../common/props";
|
21 | import { AsyncControllableTextArea } from "./asyncControllableTextArea";
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var TextArea = (function (_super) {
|
30 | __extends(TextArea, _super);
|
31 | function TextArea() {
|
32 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
33 | _this.state = {};
|
34 |
|
35 | _this.textareaElement = null;
|
36 | _this.handleRef = refHandler(_this, "textareaElement", _this.props.inputRef);
|
37 | _this.maybeSyncHeightToScrollHeight = function () {
|
38 |
|
39 | var _a = _this.props, autoResize = _a.autoResize, growVertically = _a.growVertically;
|
40 | if (_this.textareaElement != null) {
|
41 | var scrollHeight = _this.textareaElement.scrollHeight;
|
42 | if (autoResize) {
|
43 |
|
44 |
|
45 | _this.textareaElement.style.height = "0px";
|
46 | _this.textareaElement.style.height = scrollHeight.toString() + "px";
|
47 | _this.setState({ height: scrollHeight });
|
48 | }
|
49 | else if (growVertically && scrollHeight > 0) {
|
50 |
|
51 | _this.setState({ height: scrollHeight });
|
52 | }
|
53 | }
|
54 | if (_this.props.autoResize && _this.textareaElement != null) {
|
55 |
|
56 |
|
57 | _this.textareaElement.style.height = "0px";
|
58 | var scrollHeight = _this.textareaElement.scrollHeight;
|
59 | _this.textareaElement.style.height = scrollHeight.toString() + "px";
|
60 | _this.setState({ height: scrollHeight });
|
61 | }
|
62 | };
|
63 | _this.handleChange = function (e) {
|
64 | var _a, _b;
|
65 | _this.maybeSyncHeightToScrollHeight();
|
66 | (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
67 | };
|
68 | return _this;
|
69 | }
|
70 | TextArea.prototype.componentDidMount = function () {
|
71 | this.maybeSyncHeightToScrollHeight();
|
72 | };
|
73 | TextArea.prototype.componentDidUpdate = function (prevProps) {
|
74 | if (prevProps.inputRef !== this.props.inputRef) {
|
75 | setRef(prevProps.inputRef, null);
|
76 | this.handleRef = refHandler(this, "textareaElement", this.props.inputRef);
|
77 | setRef(this.props.inputRef, this.textareaElement);
|
78 | }
|
79 | if (prevProps.value !== this.props.value || prevProps.style !== this.props.style) {
|
80 | this.maybeSyncHeightToScrollHeight();
|
81 | }
|
82 | };
|
83 | TextArea.prototype.render = function () {
|
84 | var _a;
|
85 | var _b = this.props, asyncControl = _b.asyncControl, autoResize = _b.autoResize, className = _b.className, fill = _b.fill,
|
86 |
|
87 | growVertically = _b.growVertically, inputRef = _b.inputRef, intent = _b.intent, large = _b.large, small = _b.small, htmlProps = __rest(_b, ["asyncControl", "autoResize", "className", "fill", "growVertically", "inputRef", "intent", "large", "small"]);
|
88 | var rootClasses = classNames(Classes.INPUT, Classes.TEXT_AREA, Classes.intentClass(intent), (_a = {},
|
89 | _a[Classes.FILL] = fill,
|
90 | _a[Classes.LARGE] = large,
|
91 | _a[Classes.SMALL] = small,
|
92 | _a[Classes.TEXT_AREA_AUTO_RESIZE] = autoResize,
|
93 | _a), className);
|
94 |
|
95 | var _c = htmlProps.style, style = _c === void 0 ? {} : _c;
|
96 | if ((autoResize || growVertically) && this.state.height != null) {
|
97 |
|
98 |
|
99 | style = __assign(__assign({}, style), { height: "".concat(this.state.height, "px") });
|
100 | }
|
101 | var TextAreaComponent = asyncControl ? AsyncControllableTextArea : "textarea";
|
102 | return (React.createElement(TextAreaComponent, __assign({}, htmlProps, { className: rootClasses, onChange: this.handleChange, style: style, ref: this.handleRef })));
|
103 | };
|
104 | TextArea.defaultProps = {
|
105 | autoResize: false,
|
106 | fill: false,
|
107 | large: false,
|
108 | small: false,
|
109 | };
|
110 | TextArea.displayName = "".concat(DISPLAYNAME_PREFIX, ".TextArea");
|
111 | return TextArea;
|
112 | }(AbstractPureComponent));
|
113 | export { TextArea };
|
114 |
|
\ | No newline at end of file |