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.handleChange = function (e) {
|
37 | if (_this.props.growVertically) {
|
38 | _this.setState({
|
39 | height: e.target.scrollHeight,
|
40 | });
|
41 | }
|
42 | if (_this.props.onChange != null) {
|
43 | _this.props.onChange(e);
|
44 | }
|
45 | };
|
46 | return _this;
|
47 | }
|
48 | TextArea.prototype.componentDidMount = function () {
|
49 | var _a;
|
50 | if (this.props.growVertically && this.textareaElement !== null) {
|
51 |
|
52 |
|
53 | this.setState({
|
54 | height: (_a = this.textareaElement) === null || _a === void 0 ? void 0 : _a.scrollHeight,
|
55 | });
|
56 | }
|
57 | };
|
58 | TextArea.prototype.componentDidUpdate = function (prevProps) {
|
59 | if (prevProps.inputRef !== this.props.inputRef) {
|
60 | setRef(prevProps.inputRef, null);
|
61 | this.handleRef = refHandler(this, "textareaElement", this.props.inputRef);
|
62 | setRef(this.props.inputRef, this.textareaElement);
|
63 | }
|
64 | };
|
65 | TextArea.prototype.render = function () {
|
66 | var _a;
|
67 | 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"]);
|
68 | var rootClasses = classNames(Classes.INPUT, Classes.intentClass(intent), (_a = {},
|
69 | _a[Classes.FILL] = fill,
|
70 | _a[Classes.LARGE] = large,
|
71 | _a[Classes.SMALL] = small,
|
72 | _a), className);
|
73 |
|
74 | var _c = htmlProps.style, style = _c === void 0 ? {} : _c;
|
75 | if (growVertically && this.state.height != null) {
|
76 |
|
77 |
|
78 | style = __assign(__assign({}, style), { height: "".concat(this.state.height, "px") });
|
79 | }
|
80 | return (React.createElement("textarea", __assign({}, htmlProps, { className: rootClasses, onChange: this.handleChange, ref: this.handleRef, style: style })));
|
81 | };
|
82 | TextArea.displayName = "".concat(DISPLAYNAME_PREFIX, ".TextArea");
|
83 | return TextArea;
|
84 | }(AbstractPureComponent2));
|
85 | export { TextArea };
|
86 |
|
\ | No newline at end of file |