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