@egov3/system-design 1.3.243 → 1.3.245
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.
|
@@ -6,14 +6,33 @@ var joinClasses = require('../../utils/joinClasses.js');
|
|
|
6
6
|
var index = require('../BaseField/index.js');
|
|
7
7
|
var BaseField_module = require('../BaseField/BaseField.module.css.js');
|
|
8
8
|
|
|
9
|
+
const TEXTAREA_MIN_HEIGHT = "24px";
|
|
10
|
+
const resizeTextarea = (textarea) => {
|
|
11
|
+
textarea.style.height = TEXTAREA_MIN_HEIGHT;
|
|
12
|
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
13
|
+
};
|
|
9
14
|
const TextareaField = React.forwardRef((props, ref) => {
|
|
10
15
|
const { id, labelText, value, readOnly, onChange, variant = "default", isFocused, setIsFocused, isClearable, inputLeftIcon, hintText, isError, ...htmlProps } = props;
|
|
16
|
+
const textareaRef = React.useRef(null);
|
|
17
|
+
const setTextareaRef = React.useCallback((node) => {
|
|
18
|
+
textareaRef.current = node;
|
|
19
|
+
if (typeof ref === "function") {
|
|
20
|
+
return ref(node);
|
|
21
|
+
}
|
|
22
|
+
if (ref) {
|
|
23
|
+
ref.current = node;
|
|
24
|
+
}
|
|
25
|
+
}, [ref]);
|
|
26
|
+
React.useLayoutEffect(() => {
|
|
27
|
+
if (!textareaRef.current) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
resizeTextarea(textareaRef.current);
|
|
31
|
+
}, [value]);
|
|
11
32
|
const handleAutoResize = (event) => {
|
|
12
|
-
|
|
13
|
-
textarea.style.height = "24px";
|
|
14
|
-
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
33
|
+
resizeTextarea(event.currentTarget);
|
|
15
34
|
};
|
|
16
|
-
return (jsxRuntime.jsx(index.BaseField, { ...props, onChange: onChange, value: value, isFocused: isFocused, setIsFocused: setIsFocused, isClearable: isClearable, inputLeftIcon: inputLeftIcon, hintText: hintText, isError: isError, children: ({ handleFocus, handleBlur, isShowPlaceholder, handleChange }) => (jsxRuntime.jsx("textarea", { "data-testid": "TextAreaField_TEXTAREA", ref:
|
|
35
|
+
return (jsxRuntime.jsx(index.BaseField, { ...props, onChange: onChange, value: value, isFocused: isFocused, setIsFocused: setIsFocused, isClearable: isClearable, inputLeftIcon: inputLeftIcon, hintText: hintText, isError: isError, children: ({ handleFocus, handleBlur, isShowPlaceholder, handleChange }) => (jsxRuntime.jsx("textarea", { "data-testid": "TextAreaField_TEXTAREA", ref: setTextareaRef, ...htmlProps, id: id, value: value, readOnly: readOnly, placeholder: isShowPlaceholder ? labelText : "", onInput: handleAutoResize, onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange, className: joinClasses.joinClasses(BaseField_module.default.input, variant === "code" && BaseField_module.default.code) })) }));
|
|
17
36
|
});
|
|
18
37
|
|
|
19
38
|
exports.TextareaField = TextareaField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/baseComponents/TextareaField/index.tsx"],"sourcesContent":[null],"names":["forwardRef","_jsx","BaseField","joinClasses","styles"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/baseComponents/TextareaField/index.tsx"],"sourcesContent":[null],"names":["forwardRef","useRef","useCallback","useLayoutEffect","_jsx","BaseField","joinClasses","styles"],"mappings":";;;;;;;;AAeA,MAAM,mBAAmB,GAAG,MAAM;AAElC,MAAM,cAAc,GAAG,CAAC,QAA6B,KAAI;AACvD,IAAA,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,mBAAmB;IAC3C,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC,YAAY,CAAA,EAAA,CAAI;AACtD,CAAC;AAuBM,MAAM,aAAa,GAAGA,gBAAU,CAGrC,CAAC,KAAK,EAAE,GAAG,KAAI;AACf,IAAA,MAAM,EACJ,EAAE,EACF,SAAS,EACT,KAAK,EACL,QAAQ,E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GACf,SAAS,EACb,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,iBAAiB,GAAG,SAAS,GAAG,EAAE,EAC/C,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAEE,uBAAW,CACpBC,wBAAM,CAAC,KAAK,EACZ,OAAO,KAAK,MAAM,IAAIA,wBAAM,CAAC,IAAI,CAClC,EAAA,CACD,CACH,EAAA,CACS;AAEhB,CAAC;;;;"}
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useCallback, useLayoutEffect } from 'react';
|
|
3
3
|
import { joinClasses } from '../../utils/joinClasses.js';
|
|
4
4
|
import { BaseField } from '../BaseField/index.js';
|
|
5
5
|
import styles from '../BaseField/BaseField.module.css.js';
|
|
6
6
|
|
|
7
|
+
const TEXTAREA_MIN_HEIGHT = "24px";
|
|
8
|
+
const resizeTextarea = (textarea) => {
|
|
9
|
+
textarea.style.height = TEXTAREA_MIN_HEIGHT;
|
|
10
|
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
11
|
+
};
|
|
7
12
|
const TextareaField = forwardRef((props, ref) => {
|
|
8
13
|
const { id, labelText, value, readOnly, onChange, variant = "default", isFocused, setIsFocused, isClearable, inputLeftIcon, hintText, isError, ...htmlProps } = props;
|
|
14
|
+
const textareaRef = useRef(null);
|
|
15
|
+
const setTextareaRef = useCallback((node) => {
|
|
16
|
+
textareaRef.current = node;
|
|
17
|
+
if (typeof ref === "function") {
|
|
18
|
+
return ref(node);
|
|
19
|
+
}
|
|
20
|
+
if (ref) {
|
|
21
|
+
ref.current = node;
|
|
22
|
+
}
|
|
23
|
+
}, [ref]);
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
if (!textareaRef.current) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
resizeTextarea(textareaRef.current);
|
|
29
|
+
}, [value]);
|
|
9
30
|
const handleAutoResize = (event) => {
|
|
10
|
-
|
|
11
|
-
textarea.style.height = "24px";
|
|
12
|
-
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
31
|
+
resizeTextarea(event.currentTarget);
|
|
13
32
|
};
|
|
14
|
-
return (jsx(BaseField, { ...props, onChange: onChange, value: value, isFocused: isFocused, setIsFocused: setIsFocused, isClearable: isClearable, inputLeftIcon: inputLeftIcon, hintText: hintText, isError: isError, children: ({ handleFocus, handleBlur, isShowPlaceholder, handleChange }) => (jsx("textarea", { "data-testid": "TextAreaField_TEXTAREA", ref:
|
|
33
|
+
return (jsx(BaseField, { ...props, onChange: onChange, value: value, isFocused: isFocused, setIsFocused: setIsFocused, isClearable: isClearable, inputLeftIcon: inputLeftIcon, hintText: hintText, isError: isError, children: ({ handleFocus, handleBlur, isShowPlaceholder, handleChange }) => (jsx("textarea", { "data-testid": "TextAreaField_TEXTAREA", ref: setTextareaRef, ...htmlProps, id: id, value: value, readOnly: readOnly, placeholder: isShowPlaceholder ? labelText : "", onInput: handleAutoResize, onFocus: handleFocus, onBlur: handleBlur, onChange: handleChange, className: joinClasses(styles.input, variant === "code" && styles.code) })) }));
|
|
15
34
|
});
|
|
16
35
|
|
|
17
36
|
export { TextareaField };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/baseComponents/TextareaField/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/baseComponents/TextareaField/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;AAeA,MAAM,mBAAmB,GAAG,MAAM;AAElC,MAAM,cAAc,GAAG,CAAC,QAA6B,KAAI;AACvD,IAAA,QAAQ,CAAC,KAAK,CAAC,MA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