@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tedi-design-system/react",
3
- "version": "17.0.0-rc.4",
3
+ "version": "17.0.0-rc.5",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime"),d=require("../../../../../external/classnames/index.cjs.js"),r=require("react"),N=require("../textfield/textfield.cjs.js"),l=require("./textarea.module.scss.cjs.js"),x=r.forwardRef((h,m)=>{const{className:f,helper:n=[],characterLimit:t,onChange:e,onChangeEvent:s,value:a,defaultValue:p,...g}=h,[u,y]=r.useState(p??""),A=r.useCallback(o=>{!a&&!(e||s)&&y(o),e==null||e(o)},[a,e,s]),c=r.useMemo(()=>a??u,[a,u]),i=c.length,C=t?`${i}/${t}`:"",T=[...Array.isArray(n)?n:[n],...t?[{type:i>t?"error":"hint",text:C,position:"right",className:d.default(l.default["tedi-textarea__character-count"])}]:[]];return q.jsx(N.TextField,{...g,ref:m,"data-name":"textarea",inputClassName:l.default["tedi-textarea__input"],isTextArea:!0,className:d.default(l.default["tedi-textarea"],f),value:c,onChange:A,onChangeEvent:s,helper:T})});x.displayName="TextArea";exports.TextArea=x;
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 A } from "react/jsx-runtime";
2
- import u from "../../../../../external/classnames/index.es.js";
3
- import n, { forwardRef as g } from "react";
4
- import { TextField as T } from "../textfield/textfield.es.js";
5
- import o from "./textarea.module.scss.es.js";
6
- const v = g((p, h) => {
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: x,
9
- helper: r = [],
10
- characterLimit: t,
11
- onChange: e,
12
- onChangeEvent: s,
13
- value: a,
14
- defaultValue: d,
15
- ...f
16
- } = p, [l, C] = n.useState(d ?? ""), N = n.useCallback(
17
- (m) => {
18
- !a && !(e || s) && C(m), e == null || e(m);
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
- [a, e, s]
21
- ), c = n.useMemo(() => a ?? l, [a, l]), i = c.length, _ = t ? `${i}/${t}` : "", y = [
22
- ...Array.isArray(r) ? r : [r],
23
- ...t ? [
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: i > t ? "error" : "hint",
26
- text: _,
68
+ type: T > i ? "error" : "hint",
69
+ text: $,
27
70
  position: "right",
28
- className: u(o["tedi-textarea__character-count"])
71
+ className: w(p["tedi-textarea__character-count"])
29
72
  }
30
73
  ] : []
31
74
  ];
32
- return /* @__PURE__ */ A(
33
- T,
75
+ return /* @__PURE__ */ q(
76
+ P,
34
77
  {
35
- ...f,
36
- ref: h,
78
+ ...b,
79
+ ref: I,
37
80
  "data-name": "textarea",
38
- inputClassName: o["tedi-textarea__input"],
81
+ inputClassName: w(p["tedi-textarea__input"], {
82
+ [p["tedi-textarea__input--auto-grow"]]: e
83
+ }),
39
84
  isTextArea: !0,
40
- className: u(o["tedi-textarea"], x),
41
- value: c,
42
- onChange: N,
43
- onChangeEvent: s,
44
- helper: y
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
- v.displayName = "TextArea";
94
+ Y.displayName = "TextArea";
49
95
  export {
50
- v as TextArea
96
+ Y as TextArea
51
97
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e={"tedi-textarea__input":"tedi-textarea__input-8c740e37","tedi-textarea__character-count":"tedi-textarea__character-count-c5b62b38"};exports.default=e;
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;
@@ -1,5 +1,6 @@
1
1
  const t = {
2
2
  "tedi-textarea__input": "tedi-textarea__input-8c740e37",
3
+ "tedi-textarea__input--auto-grow": "tedi-textarea__input--auto-grow-dddcdb8a",
3
4
  "tedi-textarea__character-count": "tedi-textarea__character-count-c5b62b38"
4
5
  };
5
6
  export {