1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | exports.__esModule = true;
|
6 | exports.ExpandingTextarea = exports["default"] = void 0;
|
7 |
|
8 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
9 |
|
10 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11 |
|
12 | var _core = require("@emotion/core");
|
13 |
|
14 | var _react = require("react");
|
15 |
|
16 | var _Input = _interopRequireDefault(require("../Input"));
|
17 |
|
18 |
|
19 | var Textarea = (0, _react.forwardRef)(function (props, ref) {
|
20 | return (0, _core.jsx)(_Input["default"], (0, _extends2["default"])({
|
21 | py: "8px",
|
22 | minHeight: "80px",
|
23 | lineHeight: "short",
|
24 | ref: ref,
|
25 | as: "textarea"
|
26 | }, props));
|
27 | });
|
28 | Textarea.displayName = "Textarea";
|
29 | var _default = Textarea;
|
30 | exports["default"] = _default;
|
31 | var ExpandingTextarea = (0, _react.forwardRef)(function (_ref, ref) {
|
32 | var _ref$minHeight = _ref.minHeight,
|
33 | minHeight = _ref$minHeight === void 0 ? "39px" : _ref$minHeight,
|
34 | onInput = _ref.onInput,
|
35 | props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, ["minHeight", "onInput"]);
|
36 |
|
37 | var _useState = (0, _react.useState)(0),
|
38 | height = _useState[0],
|
39 | setHeight = _useState[1];
|
40 |
|
41 | var ownRef = (0, _react.useRef)();
|
42 | var textareaRef = ref || ownRef;
|
43 | (0, _react.useLayoutEffect)(function () {
|
44 | if (textareaRef.current) {
|
45 | setHeight(textareaRef.current.scrollHeight);
|
46 | }
|
47 | }, [textareaRef]);
|
48 |
|
49 | var handleInput = function handleInput(event) {
|
50 | if (textareaRef.current) {
|
51 | setTimeout(function () {
|
52 | setHeight("auto");
|
53 | setHeight(textareaRef.current.scrollHeight);
|
54 | }, 0);
|
55 | }
|
56 |
|
57 | onInput && onInput(event);
|
58 | };
|
59 |
|
60 | return (0, _core.jsx)(Textarea, (0, _extends2["default"])({
|
61 | rows: "1",
|
62 | onInput: handleInput,
|
63 | css: {
|
64 | height: height,
|
65 | resize: "none",
|
66 | overflow: "hidden",
|
67 | minHeight: minHeight
|
68 | },
|
69 | ref: textareaRef
|
70 | }, props));
|
71 | });
|
72 | exports.ExpandingTextarea = ExpandingTextarea;
|
73 | ExpandingTextarea.displayName = "ExpandingTextarea"; |
\ | No newline at end of file |