@happeouikit/form-elements 2.3.16 → 2.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/Textarea.js +40 -4
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
package/dist/Textarea.js
CHANGED
|
@@ -6,7 +6,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
6
6
|
|
|
7
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/* eslint-disable react/require-default-props */
|
|
10
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
10
11
|
import styled from "styled-components";
|
|
11
12
|
import { active, gray01, gray04, gray06 } from "@happeouikit/colors";
|
|
12
13
|
import PropTypes from "prop-types";
|
|
@@ -26,6 +27,30 @@ var Textarea = function Textarea(_ref) {
|
|
|
26
27
|
var accessibility = label ? {
|
|
27
28
|
"aria-labelledby": id
|
|
28
29
|
} : {};
|
|
30
|
+
var textareaRef = useRef(null);
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
var textarea = textareaRef.current;
|
|
33
|
+
|
|
34
|
+
if (textarea) {
|
|
35
|
+
textarea.style.height = "".concat(Math.min(textarea.scrollHeight, props.maxHeight), "px");
|
|
36
|
+
}
|
|
37
|
+
}, [props.maxHeight]);
|
|
38
|
+
|
|
39
|
+
var onChange = function onChange(event) {
|
|
40
|
+
// Handle auto height
|
|
41
|
+
if (props.autoHeight) {
|
|
42
|
+
var target = event.target; // First set height to inherit to allow textarea to contract
|
|
43
|
+
|
|
44
|
+
target.style.height = "inherit";
|
|
45
|
+
target.style.height = "".concat(target.scrollHeight, "px");
|
|
46
|
+
} // call props.onChange if exists
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (typeof props.onChange === "function") {
|
|
50
|
+
props.onChange(event);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
29
54
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
30
55
|
children: [!!label && /*#__PURE__*/_jsx(Label, {
|
|
31
56
|
id: id,
|
|
@@ -33,16 +58,27 @@ var Textarea = function Textarea(_ref) {
|
|
|
33
58
|
color: gray01,
|
|
34
59
|
children: label
|
|
35
60
|
})
|
|
36
|
-
}), /*#__PURE__*/_jsx(StyledTextarea, _objectSpread(_objectSpread({
|
|
61
|
+
}), /*#__PURE__*/_jsx(StyledTextarea, _objectSpread(_objectSpread(_objectSpread({
|
|
62
|
+
ref: textareaRef,
|
|
37
63
|
cols: cols,
|
|
38
64
|
rows: rows
|
|
39
|
-
}, accessibility), props)
|
|
65
|
+
}, accessibility), props), {}, {
|
|
66
|
+
style: _objectSpread(_objectSpread({}, props.style), {}, {
|
|
67
|
+
maxHeight: props.maxHeight
|
|
68
|
+
}),
|
|
69
|
+
onChange: onChange
|
|
70
|
+
}))]
|
|
40
71
|
});
|
|
41
72
|
};
|
|
42
73
|
|
|
43
74
|
Textarea.propTypes = {
|
|
44
75
|
rows: PropTypes.number,
|
|
45
|
-
cols: PropTypes.number
|
|
76
|
+
cols: PropTypes.number,
|
|
77
|
+
autoHeight: PropTypes.bool,
|
|
78
|
+
maxHeight: PropTypes.number
|
|
79
|
+
};
|
|
80
|
+
Textarea.defaultProps = {
|
|
81
|
+
maxHeight: 9999
|
|
46
82
|
};
|
|
47
83
|
var StyledTextarea = styled.textarea.withConfig({
|
|
48
84
|
displayName: "Textarea__StyledTextarea",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happeouikit/form-elements",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -44,5 +44,6 @@
|
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "f2782af0f34d915128c836831456ed9cf9c7b090"
|
|
48
49
|
}
|