@tedi-design-system/react 17.0.0-rc.4 → 17.0.0-rc.5
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/bundle-stats.html +1 -1
- package/index.css +1 -1
- package/package.json +1 -1
- package/src/tedi/components/form/textarea/textarea.cjs.js +1 -1
- package/src/tedi/components/form/textarea/textarea.d.ts +29 -0
- package/src/tedi/components/form/textarea/textarea.es.js +82 -36
- package/src/tedi/components/form/textarea/textarea.module.scss.cjs.js +1 -1
- package/src/tedi/components/form/textarea/textarea.module.scss.es.js +1 -0
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react/jsx-runtime"),w=require("../../../../../external/classnames/index.cjs.js"),a=require("react"),O=require("../textfield/textfield.cjs.js"),d=require("./textarea.module.scss.cjs.js"),M=a.forwardRef((N,o)=>{const{className:_,helper:p=[],characterLimit:s,onChange:n,onChangeEvent:g,value:l,defaultValue:b,autoGrow:t=!1,minRows:u=3,maxRows:y=12,height:H="7.5rem",maxHeight:i,...q}=N,[T,F]=a.useState(b??""),c=a.useRef(null),[v,E]=a.useState("auto"),j=a.useCallback(e=>{!l&&!(n||g)&&F(e),n==null||n(e)},[l,n,g]),m=a.useMemo(()=>l??T,[l,T]),r=a.useCallback(()=>{if(!t||!c.current)return;const e=c.current,$=e.style.overflow;e.style.overflow="hidden";const f=window.getComputedStyle(e);let h=parseFloat(f.lineHeight);isNaN(h)&&(h=(parseFloat(f.fontSize)||16)*1.5);const S=parseFloat(f.paddingTop),A=parseFloat(f.paddingBottom),B=e.scrollHeight-S-A;let x=Math.ceil(B/h);x=Math.min(Math.max(x,u),y);const R=`${x*h+S+A}px`;e.style.height=R,E(R),e.style.overflow=$,e.style.overflowY=e.scrollHeight>e.clientHeight?"auto":"hidden"},[t,u,y]);a.useEffect(()=>{t&&requestAnimationFrame(()=>{r()})},[m,t,r]),a.useEffect(()=>{t&&c.current&&r()},[t,r]);const k=a.useCallback(e=>{o&&(typeof o=="function"?o(e):o.current=e),e!=null&&e.input&&e.input instanceof HTMLTextAreaElement&&(c.current=e.input,t&&setTimeout(r,0))},[o,t,r]),z=a.useMemo(()=>t?{rows:u,style:{...i?{maxHeight:i}:{},overflow:"hidden",height:v}}:{style:{height:H,...i?{maxHeight:i}:{},overflow:"auto"}},[t,u,i,H,v]),C=m.length,I=s?`${C}/${s}`:"",V=[...Array.isArray(p)?p:[p],...s?[{type:C>s?"error":"hint",text:I,position:"right",className:w.default(d.default["tedi-textarea__character-count"])}]:[]];return L.jsx(O.TextField,{...q,ref:k,"data-name":"textarea",inputClassName:w.default(d.default["tedi-textarea__input"],{[d.default["tedi-textarea__input--auto-grow"]]:t}),isTextArea:!0,className:w.default(d.default["tedi-textarea"],_),value:m,onChange:j,onChangeEvent:g,helper:V,input:z})});M.displayName="TextArea";exports.TextArea=M;
|
|
@@ -5,6 +5,35 @@ export interface TextAreaProps extends TextFieldProps {
|
|
|
5
5
|
* Maximum number of characters allowed in the textarea.
|
|
6
6
|
*/
|
|
7
7
|
characterLimit?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Enable automatic height adjustment based on content.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
autoGrow?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Minimum number of rows (only used when autoGrow = true).
|
|
15
|
+
* @default 3
|
|
16
|
+
*/
|
|
17
|
+
minRows?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Maximum number of rows before scrolling (only used when autoGrow = true).
|
|
20
|
+
* @default 12
|
|
21
|
+
*/
|
|
22
|
+
maxRows?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Fixed height for the textarea (e.g. '200px', '12rem', 240).
|
|
25
|
+
* Ignored when autoGrow = true.
|
|
26
|
+
*
|
|
27
|
+
* @default 7.5rem
|
|
28
|
+
*/
|
|
29
|
+
height?: string | number;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum height of the textarea.
|
|
32
|
+
*
|
|
33
|
+
* - When `autoGrow` is enabled, this limits how tall the textarea can grow.
|
|
34
|
+
* - When `autoGrow` is disabled, this limits the fixed height.
|
|
35
|
+
*/
|
|
36
|
+
maxHeight?: string | number;
|
|
8
37
|
}
|
|
9
38
|
export declare const TextArea: React.ForwardRefExoticComponent<TextAreaProps & React.RefAttributes<TextFieldForwardRef>>;
|
|
10
39
|
export default TextArea;
|
|
@@ -1,51 +1,97 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { TextField as
|
|
5
|
-
import
|
|
6
|
-
const
|
|
1
|
+
import { jsx as q } from "react/jsx-runtime";
|
|
2
|
+
import w from "../../../../../external/classnames/index.es.js";
|
|
3
|
+
import a, { forwardRef as G, useRef as O, useEffect as R } from "react";
|
|
4
|
+
import { TextField as P } from "../textfield/textfield.es.js";
|
|
5
|
+
import p from "./textarea.module.scss.es.js";
|
|
6
|
+
const Y = G((S, r) => {
|
|
7
7
|
const {
|
|
8
|
-
className:
|
|
9
|
-
helper:
|
|
10
|
-
characterLimit:
|
|
11
|
-
onChange:
|
|
12
|
-
onChangeEvent:
|
|
13
|
-
value:
|
|
14
|
-
defaultValue:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
className: F,
|
|
9
|
+
helper: f = [],
|
|
10
|
+
characterLimit: i,
|
|
11
|
+
onChange: s,
|
|
12
|
+
onChangeEvent: g,
|
|
13
|
+
value: l,
|
|
14
|
+
defaultValue: M,
|
|
15
|
+
autoGrow: e = !1,
|
|
16
|
+
minRows: c = 3,
|
|
17
|
+
maxRows: H = 12,
|
|
18
|
+
height: y = "7.5rem",
|
|
19
|
+
maxHeight: n,
|
|
20
|
+
...b
|
|
21
|
+
} = S, [v, k] = a.useState(M ?? ""), u = O(null), [C, z] = a.useState("auto"), E = a.useCallback(
|
|
22
|
+
(t) => {
|
|
23
|
+
!l && !(s || g) && k(t), s == null || s(t);
|
|
19
24
|
},
|
|
20
|
-
[
|
|
21
|
-
),
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
[l, s, g]
|
|
26
|
+
), x = a.useMemo(() => l ?? v, [l, v]), o = a.useCallback(() => {
|
|
27
|
+
if (!e || !u.current) return;
|
|
28
|
+
const t = u.current, L = t.style.overflow;
|
|
29
|
+
t.style.overflow = "hidden";
|
|
30
|
+
const h = window.getComputedStyle(t);
|
|
31
|
+
let m = parseFloat(h.lineHeight);
|
|
32
|
+
isNaN(m) && (m = (parseFloat(h.fontSize) || 16) * 1.5);
|
|
33
|
+
const N = parseFloat(h.paddingTop), _ = parseFloat(h.paddingBottom), j = t.scrollHeight - N - _;
|
|
34
|
+
let d = Math.ceil(j / m);
|
|
35
|
+
d = Math.min(Math.max(d, c), H);
|
|
36
|
+
const A = `${d * m + N + _}px`;
|
|
37
|
+
t.style.height = A, z(A), t.style.overflow = L, t.style.overflowY = t.scrollHeight > t.clientHeight ? "auto" : "hidden";
|
|
38
|
+
}, [e, c, H]);
|
|
39
|
+
R(() => {
|
|
40
|
+
e && requestAnimationFrame(() => {
|
|
41
|
+
o();
|
|
42
|
+
});
|
|
43
|
+
}, [x, e, o]), R(() => {
|
|
44
|
+
e && u.current && o();
|
|
45
|
+
}, [e, o]);
|
|
46
|
+
const I = a.useCallback(
|
|
47
|
+
(t) => {
|
|
48
|
+
r && (typeof r == "function" ? r(t) : r.current = t), t != null && t.input && t.input instanceof HTMLTextAreaElement && (u.current = t.input, e && setTimeout(o, 0));
|
|
49
|
+
},
|
|
50
|
+
[r, e, o]
|
|
51
|
+
), V = a.useMemo(() => e ? {
|
|
52
|
+
rows: c,
|
|
53
|
+
style: {
|
|
54
|
+
...n ? { maxHeight: n } : {},
|
|
55
|
+
overflow: "hidden",
|
|
56
|
+
height: C
|
|
57
|
+
}
|
|
58
|
+
} : {
|
|
59
|
+
style: {
|
|
60
|
+
height: y,
|
|
61
|
+
...n ? { maxHeight: n } : {},
|
|
62
|
+
overflow: "auto"
|
|
63
|
+
}
|
|
64
|
+
}, [e, c, n, y, C]), T = x.length, $ = i ? `${T}/${i}` : "", B = [
|
|
65
|
+
...Array.isArray(f) ? f : [f],
|
|
66
|
+
...i ? [
|
|
24
67
|
{
|
|
25
|
-
type:
|
|
26
|
-
text:
|
|
68
|
+
type: T > i ? "error" : "hint",
|
|
69
|
+
text: $,
|
|
27
70
|
position: "right",
|
|
28
|
-
className:
|
|
71
|
+
className: w(p["tedi-textarea__character-count"])
|
|
29
72
|
}
|
|
30
73
|
] : []
|
|
31
74
|
];
|
|
32
|
-
return /* @__PURE__ */
|
|
33
|
-
|
|
75
|
+
return /* @__PURE__ */ q(
|
|
76
|
+
P,
|
|
34
77
|
{
|
|
35
|
-
...
|
|
36
|
-
ref:
|
|
78
|
+
...b,
|
|
79
|
+
ref: I,
|
|
37
80
|
"data-name": "textarea",
|
|
38
|
-
inputClassName:
|
|
81
|
+
inputClassName: w(p["tedi-textarea__input"], {
|
|
82
|
+
[p["tedi-textarea__input--auto-grow"]]: e
|
|
83
|
+
}),
|
|
39
84
|
isTextArea: !0,
|
|
40
|
-
className:
|
|
41
|
-
value:
|
|
42
|
-
onChange:
|
|
43
|
-
onChangeEvent:
|
|
44
|
-
helper:
|
|
85
|
+
className: w(p["tedi-textarea"], F),
|
|
86
|
+
value: x,
|
|
87
|
+
onChange: E,
|
|
88
|
+
onChangeEvent: g,
|
|
89
|
+
helper: B,
|
|
90
|
+
input: V
|
|
45
91
|
}
|
|
46
92
|
);
|
|
47
93
|
});
|
|
48
|
-
|
|
94
|
+
Y.displayName = "TextArea";
|
|
49
95
|
export {
|
|
50
|
-
|
|
96
|
+
Y as TextArea
|
|
51
97
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t={"tedi-textarea__input":"tedi-textarea__input-8c740e37","tedi-textarea__input--auto-grow":"tedi-textarea__input--auto-grow-dddcdb8a","tedi-textarea__character-count":"tedi-textarea__character-count-c5b62b38"};exports.default=t;
|