asma-ui-core 3.111.0 → 3.112.0

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.
@@ -1,171 +1,171 @@
1
- import { cn as l } from "../../../helpers/cn.js";
2
- import { resolveSx as v } from "../../../helpers/sx.js";
3
- import { CloseIcon as pt } from "../../icons/close-icon/CloseIcon.js";
4
- import { CharacterCounter as gt } from "../../../helpers/CharacterCounter.js";
5
- import { HelperRow as re } from "../../../helpers/HelperRow.js";
1
+ import { cn as s } from "../../../helpers/cn.js";
2
+ import { resolveSx as F } from "../../../helpers/sx.js";
3
+ import { CloseIcon as mt } from "../../icons/close-icon/CloseIcon.js";
4
+ import { CharacterCounter as pt } from "../../../helpers/CharacterCounter.js";
5
+ import { HelperRow as gt } from "../../../helpers/HelperRow.js";
6
6
  import { useHelperRowBudget as ft } from "../../../helpers/useHelperRowBudget.js";
7
7
  import { useHelperSlot as xt } from "../../../helpers/useHelperSlot.js";
8
- import { fieldLabelAboveClass as bt, fieldWidthStyle as yt, floatingLabelClass as Lt, floatingLabelLayoutStyle as St, notchedLegendClass as vt, notchedOutlineClass as de, singleLineInputLayoutStyle as Ht, singleLineShellLayoutStyle as It } from "../field-styles.js";
9
- import b from "./StyledInputField.module.js";
10
- import { Children as Nt, useCallback as ce, useId as At, useLayoutEffect as B, useRef as G, useState as M } from "react";
11
- import { jsx as o, jsxs as p } from "react/jsx-runtime";
12
- import { useMergeRefs as he } from "@floating-ui/react";
13
- var Ot = ({ dataTest: y, label: r, labelPlacement: me = "above", value: g, defaultValue: L, onChange: ue, onBlur: pe, onFocus: ge, error: h, helperText: E, reserveHelperText: fe, expandHelperText: xe = !0, maxLength: be, counter: ye, locale: Le, disabled: d, readOnly: n, required: H, allowClear: Se, onClear: ve, type: He = "text", placeholder: Ie, name: Ne, id: Ae, autoComplete: Ce, autoFocus: Re, multiline: i, rows: I, minRows: k, maxRows: T, size: we = "medium", width: J = "full", fullWidth: Ct, className: Fe, style: _e, sx: Be, inputRef: Me, slotProps: t, InputProps: Q, onKeyDown: V, onClick: Ee, variant: Rt }) => {
14
- const ke = At(), D = Ae ?? ke, W = `${D}-helper-text`, $ = G(null), j = G(0), X = G(null), [Te, De] = M(void 0), [N, Z] = M(!1), [We, q] = M(L != null && L !== ""), [$e, je] = M(String(L ?? "").length), A = g !== void 0, O = A ? g !== "" && g != null : We, ze = !!d || !!n, z = t?.input?.startAdornment ?? Q?.startAdornment, S = Nt.count(z) > 0, m = S && Array.isArray(z), f = t?.input?.endAdornment ?? Q?.endAdornment, C = !!(Se && O && !ze), { ref: Ue, ...a } = t?.htmlInput ?? {}, Ke = Me ?? Ue, { className: Pe, style: U, ref: Ye } = t?.input ?? {}, Ge = he([Ye]), Je = t?.input?.onMouseDown, ee = t?.input?.onClick, Qe = ee ? { onClick: ee } : {}, Ve = Ce ?? a.autoComplete, Xe = Ne ?? a.name, K = a.id ?? D, R = be ?? a.maxLength, te = `${D}-counter`, P = !!(ye && R && !n), Ze = A ? String(g ?? "").length : $e, w = me === "floating" && !!r, F = N || O || S, u = ce(() => {
15
- const e = $.current;
16
- if (!(!i || !e) && (j.current = e.offsetWidth, j.current !== 0)) {
17
- if (e.removeAttribute("data-scrollable"), I != null && !n) e.style.height = "";
8
+ import { fieldLabelAboveClass as bt, fieldWidthStyle as yt, floatingLabelClass as Lt, floatingLabelLayoutStyle as St, notchedLegendClass as vt, notchedOutlineClass as se, singleLineInputLayoutStyle as Ht, singleLineShellLayoutStyle as It } from "../field-styles.js";
9
+ import x from "./StyledInputField.module.js";
10
+ import { Children as At, useCallback as re, useId as Ct, useLayoutEffect as _, useRef as U, useState as B } from "react";
11
+ import { jsx as o, jsxs as b } from "react/jsx-runtime";
12
+ import { useMergeRefs as de } from "@floating-ui/react";
13
+ var Ot = ({ dataTest: y, label: r, labelPlacement: ce = "above", value: m, defaultValue: L, onChange: ue, onBlur: he, onFocus: me, error: p, helperText: K, reserveHelperText: pe, expandHelperText: ge = !0, maxLength: fe, counter: xe, locale: be, disabled: d, readOnly: n, required: v, allowClear: ye, onClear: Le, type: Se = "text", placeholder: ve, name: He, id: Ie, autoComplete: Ae, autoFocus: Ce, multiline: i, rows: H, minRows: M, maxRows: k, size: Ne = "medium", width: Y = "full", fullWidth: Nt, className: Re, style: we, sx: Fe, inputRef: _e, slotProps: t, InputProps: G, onKeyDown: J, onClick: Be, variant: Rt }) => {
14
+ const Me = Ct(), E = Ie ?? Me, Q = `${E}-helper-text`, T = U(null), D = U(0), V = U(null), [ke, Ee] = B(void 0), [I, X] = B(!1), [Te, Z] = B(L != null && L !== ""), [De, We] = B(String(L ?? "").length), A = m !== void 0, q = A ? m !== "" && m != null : Te, $e = !!d || !!n, W = t?.input?.startAdornment ?? G?.startAdornment, S = At.count(W) > 0, u = S && Array.isArray(W), g = t?.input?.endAdornment ?? G?.endAdornment, C = !!(ye && q && !$e), { ref: ze, ...l } = t?.htmlInput ?? {}, je = _e ?? ze, { className: Pe, style: $, ref: Ue } = t?.input ?? {}, Ke = de([Ue]), Ye = t?.input?.onMouseDown, O = t?.input?.onClick, Ge = O ? { onClick: O } : {}, Je = Ae ?? l.autoComplete, Qe = He ?? l.name, z = l.id ?? E, N = fe ?? l.maxLength, ee = `${E}-counter`, te = xe !== !1 && !!N, Ve = A ? String(m ?? "").length : De, R = ce === "floating" && !!r, w = I || q || S, h = re(() => {
15
+ const e = T.current;
16
+ if (!(!i || !e) && (D.current = e.offsetWidth, D.current !== 0)) {
17
+ if (e.removeAttribute("data-scrollable"), H != null && !n) e.style.height = "";
18
18
  else {
19
19
  if (e.style.height = "auto", e.scrollHeight === 0) {
20
20
  e.style.height = "";
21
21
  return;
22
22
  }
23
- const s = getComputedStyle(e), c = Number.parseFloat(s.lineHeight) || 24, ae = Number.parseFloat(s.paddingTop) + Number.parseFloat(s.paddingBottom), se = I ?? k, mt = se ? se * c + ae : 0, ut = n || !T ? Number.POSITIVE_INFINITY : T * c + ae;
24
- e.style.height = `${Math.min(ut, Math.max(mt, e.scrollHeight))}px`;
23
+ const a = getComputedStyle(e), c = Number.parseFloat(a.lineHeight) || 24, le = Number.parseFloat(a.paddingTop) + Number.parseFloat(a.paddingBottom), ae = H ?? M, ut = ae ? ae * c + le : 0, ht = n || !k ? Number.POSITIVE_INFINITY : k * c + le;
24
+ e.style.height = `${Math.min(ht, Math.max(ut, e.scrollHeight))}px`;
25
25
  }
26
26
  e.scrollHeight > e.clientHeight + 1 && e.setAttribute("data-scrollable", "true");
27
27
  }
28
28
  }, [
29
- T,
30
29
  k,
30
+ M,
31
31
  i,
32
32
  n,
33
- I
34
- ]), qe = (e) => {
35
- n || (A || (q(e.target.value !== ""), je(e.target.value.length), u()), ue?.(e));
36
- }, Oe = (e) => {
37
- !d && !n && Z(!0), ge?.(e);
38
- }, et = (e) => {
39
- !d && !n && Z(!1), pe?.(e);
33
+ H
34
+ ]), Xe = (e) => {
35
+ n || (A || (Z(e.target.value !== ""), We(e.target.value.length), h()), ue?.(e));
36
+ }, Ze = (e) => {
37
+ !d && !n && X(!0), me?.(e);
38
+ }, qe = (e) => {
39
+ !d && !n && X(!1), he?.(e);
40
40
  };
41
- B(() => {
42
- u();
41
+ _(() => {
42
+ h();
43
43
  }, [
44
- u,
44
+ h,
45
45
  L,
46
- g
47
- ]), B(() => {
46
+ m
47
+ ]), _(() => {
48
48
  if (!i || !document.fonts) return;
49
- const e = () => u();
49
+ const e = () => h();
50
50
  return document.fonts.addEventListener("loadingdone", e), () => document.fonts.removeEventListener("loadingdone", e);
51
- }, [i, u]), B(() => {
52
- const e = $.current;
51
+ }, [i, h]), _(() => {
52
+ const e = T.current;
53
53
  if (!i || !e || typeof ResizeObserver > "u") return;
54
- let s = 0;
54
+ let a = 0;
55
55
  const c = new ResizeObserver(() => {
56
- e.offsetWidth !== j.current && (cancelAnimationFrame(s), s = requestAnimationFrame(u));
56
+ e.offsetWidth !== D.current && (cancelAnimationFrame(a), a = requestAnimationFrame(h));
57
57
  });
58
58
  return c.observe(e), () => {
59
- cancelAnimationFrame(s), c.disconnect();
59
+ cancelAnimationFrame(a), c.disconnect();
60
60
  };
61
- }, [i, u]);
62
- const ne = he([Ke, ce((e) => {
63
- $.current = e instanceof HTMLTextAreaElement ? e : null;
64
- }, [])]), { style: Y, ...tt } = a, x = !i && !m, { height: wt, minHeight: Ft, maxHeight: _t, paddingTop: Bt, paddingBottom: Mt, ...nt } = U ?? {}, ot = x ? {
65
- ...nt,
61
+ }, [i, h]);
62
+ const ne = de([je, re((e) => {
63
+ T.current = e instanceof HTMLTextAreaElement ? e : null;
64
+ }, [])]), { style: j, ...Oe } = l, f = !i && !u, { height: wt, minHeight: Ft, maxHeight: _t, paddingTop: Bt, paddingBottom: Mt, ...et } = $ ?? {}, tt = f ? {
65
+ ...et,
66
66
  ...It()
67
- } : m ? {
67
+ } : u ? {
68
68
  boxSizing: "border-box",
69
69
  minHeight: 40,
70
- ...U
71
- } : U, { height: Et, minHeight: kt, maxHeight: Tt, paddingTop: Dt, paddingBottom: Wt, paddingLeft: $t, paddingRight: it, ...lt } = Y ?? {}, at = x ? {
72
- ...lt,
70
+ ...$
71
+ } : $, { height: kt, minHeight: Et, maxHeight: Tt, paddingTop: Dt, paddingBottom: Wt, paddingLeft: $t, paddingRight: nt, ...ot } = j ?? {}, it = f ? {
72
+ ...ot,
73
73
  ...Ht({
74
74
  paddingLeft: S ? 40 : 14,
75
- paddingRight: it ?? Te ?? (C || f ? 40 : 14)
75
+ paddingRight: nt ?? ke ?? (C || g ? 40 : 14)
76
76
  })
77
- } : Y;
78
- B(() => {
79
- if (!x) return;
80
- const e = X.current, s = e ? Math.ceil(e.getBoundingClientRect().width) + 20 : void 0;
81
- De((c) => c === s ? c : s);
77
+ } : j;
78
+ _(() => {
79
+ if (!f) return;
80
+ const e = V.current, a = e ? Math.ceil(e.getBoundingClientRect().width) + 20 : void 0;
81
+ Ee((c) => c === a ? c : a);
82
82
  }, [
83
- x,
83
+ f,
84
84
  C,
85
- f
85
+ g
86
86
  ]);
87
- const st = F || !w, { show: _, role: oe } = xt("StyledInputField", h, E, fe, n), { fieldRef: rt, rowRef: dt, rowStyle: ct } = ft(xe && _ && !P), ie = {
88
- ...tt,
89
- style: x ? at : Y,
90
- id: K,
91
- name: Xe,
92
- maxLength: R,
93
- placeholder: st ? Ie : void 0,
87
+ const lt = w || !R, { show: P, role: at } = xt("StyledInputField", p, K, pe, n), { fieldRef: st, rowRef: rt, rowStyle: dt } = ft(ge && P), oe = {
88
+ ...Oe,
89
+ style: f ? it : j,
90
+ id: z,
91
+ name: Qe,
92
+ maxLength: N,
93
+ placeholder: lt ? ve : void 0,
94
94
  disabled: d,
95
95
  readOnly: n,
96
- required: H,
97
- autoComplete: Ve,
98
- autoFocus: Re,
99
- value: g,
96
+ required: v,
97
+ autoComplete: Je,
98
+ autoFocus: Ce,
99
+ value: m,
100
100
  defaultValue: L,
101
- "aria-invalid": h ? !0 : void 0,
102
- "aria-label": a["aria-label"] ?? (a["aria-labelledby"] ? void 0 : typeof r == "string" && r !== "" ? r : void 0),
103
- "aria-describedby": [_ ? W : a["aria-describedby"], P ? te : void 0].filter(Boolean).join(" ") || void 0,
104
- onChange: qe,
105
- onFocus: Oe,
106
- onBlur: et,
107
- onKeyDown: a.onKeyDown || V ? (e) => {
108
- V?.(e), e.defaultPrevented || a.onKeyDown?.(e);
101
+ "aria-invalid": p ? !0 : void 0,
102
+ "aria-label": l["aria-label"] ?? (l["aria-labelledby"] ? void 0 : typeof r == "string" && r !== "" ? r : void 0),
103
+ "aria-describedby": [P ? Q : l["aria-describedby"], te ? ee : void 0].filter(Boolean).join(" ") || void 0,
104
+ onChange: Xe,
105
+ onFocus: Ze,
106
+ onBlur: qe,
107
+ onKeyDown: l.onKeyDown || J ? (e) => {
108
+ J?.(e), e.defaultPrevented || l.onKeyDown?.(e);
109
109
  } : void 0
110
- }, le = l(b.Input, "peer border-0 bg-transparent text-base tracking-[0.00938em] text-delta-800 outline-none placeholder:text-delta-500", m ? "box-border h-8 min-w-[60px] flex-1 py-0 pl-0 pr-0 leading-[23px]" : i ? l("w-full resize-none p-0 pl-0 pr-0 leading-[23px]", b["Input--multiline"]) : l("w-full", b["Input--singleLine"]), "disabled:text-delta-300", n && "text-delta-800", Pe), ht = !i && !m ? {
110
+ }, ie = s(x.Input, "peer border-0 bg-transparent text-base tracking-[0.00938em] text-delta-800 outline-none placeholder:text-delta-500", u ? "box-border h-8 min-w-[60px] flex-1 py-0 pl-0 pr-0 leading-[23px]" : i ? s("w-full resize-none p-0 pl-0 pr-0 leading-[23px]", x["Input--multiline"]) : s("w-full", x["Input--singleLine"]), "disabled:text-delta-300", n && "text-delta-800", Pe), ct = !i && !u ? {
111
111
  "data-start-adornment": S ? "true" : void 0,
112
- "data-end-adornment": C || f ? "true" : void 0
112
+ "data-end-adornment": C || g ? "true" : void 0
113
113
  } : {};
114
- return /* @__PURE__ */ p("div", {
115
- ref: rt,
116
- className: l("group relative min-w-0 flex-col", Fe),
117
- onClick: Ee,
118
- "data-field-width": J,
114
+ return /* @__PURE__ */ b("div", {
115
+ ref: st,
116
+ className: s("group relative min-w-0 flex-col", Re),
117
+ onClick: Be,
118
+ "data-field-width": Y,
119
119
  style: {
120
120
  display: "flex",
121
- ...yt(J),
121
+ ...yt(Y),
122
122
  fontFamily: "Roboto, Helvetica, Arial, sans-serif",
123
123
  letterSpacing: "0.00938em",
124
- ...v(Be),
125
- ..._e
124
+ ...F(Fe),
125
+ ...we
126
126
  },
127
127
  children: [
128
- r && !w && /* @__PURE__ */ o("div", {
129
- className: l(bt({ disabled: d }), t?.inputLabel?.className),
128
+ r && !R && /* @__PURE__ */ o("div", {
129
+ className: s(bt({ disabled: d }), t?.inputLabel?.className),
130
130
  style: {
131
- ...v(t?.inputLabel?.sx),
131
+ ...F(t?.inputLabel?.sx),
132
132
  ...t?.inputLabel?.style
133
133
  },
134
- children: /* @__PURE__ */ p("label", {
135
- htmlFor: K,
136
- children: [r, H && /* @__PURE__ */ o("span", {
134
+ children: /* @__PURE__ */ b("label", {
135
+ htmlFor: z,
136
+ children: [r, v && /* @__PURE__ */ o("span", {
137
137
  "aria-hidden": "true",
138
138
  children: " *"
139
139
  })]
140
140
  })
141
141
  }),
142
- /* @__PURE__ */ p("div", {
142
+ /* @__PURE__ */ b("div", {
143
143
  className: "relative overflow-visible",
144
- children: [/* @__PURE__ */ p("div", {
145
- className: l("relative flex", x && b.InputShell, i && "box-border items-center px-[14px] py-[16.5px]", m && l(b.AdornmentList, f && b["AdornmentList--endAdornment"]), n && "rounded bg-delta-50"),
146
- ref: Ge,
147
- onMouseDown: Je,
148
- ...Qe,
149
- style: ot,
150
- "data-testid": m ? `${y}-adornment-list` : `${y}-shell`,
144
+ children: [/* @__PURE__ */ b("div", {
145
+ className: s("relative flex", f && x.InputShell, i && "box-border items-center px-[14px] py-[16.5px]", u && s(x.AdornmentList, g && x["AdornmentList--endAdornment"]), n && "rounded bg-delta-50"),
146
+ ref: Ke,
147
+ onMouseDown: Ye,
148
+ ...Ge,
149
+ style: tt,
150
+ "data-testid": u ? `${y}-adornment-list` : `${y}-shell`,
151
151
  children: [
152
152
  S && /* @__PURE__ */ o("span", {
153
- className: l("items-center text-delta-500", m ? "contents" : "absolute left-3 flex"),
154
- children: z
153
+ className: s("items-center text-delta-500", u ? "contents" : "absolute left-3 flex"),
154
+ children: W
155
155
  }),
156
156
  i ? /* @__PURE__ */ o("textarea", {
157
- ...ie,
157
+ ...oe,
158
158
  ref: ne,
159
159
  "data-testid": y,
160
- rows: I ?? k ?? 2,
161
- className: le
160
+ rows: H ?? M ?? 2,
161
+ className: ie
162
162
  }) : /* @__PURE__ */ o("input", {
163
- ...ie,
164
- ...ht,
163
+ ...oe,
164
+ ...ct,
165
165
  ref: ne,
166
166
  "data-testid": y,
167
- type: He,
168
- className: le
167
+ type: Se,
168
+ className: ie
169
169
  }),
170
170
  C ? /* @__PURE__ */ o("button", {
171
171
  type: "button",
@@ -174,92 +174,82 @@ var Ot = ({ dataTest: y, label: r, labelPlacement: me = "above", value: g, defau
174
174
  "data-testid": `${y}-clear`,
175
175
  className: "asma-pressable absolute right-4 z-40 flex items-center justify-center rounded-full border-0 bg-transparent p-[2px] duration-300 hover:bg-gama-100",
176
176
  onClick: (e) => {
177
- e.stopPropagation(), e.preventDefault(), A || q(!1), ve?.();
177
+ e.stopPropagation(), e.preventDefault(), A || Z(!1), Le?.();
178
178
  },
179
- children: /* @__PURE__ */ o(pt, {
179
+ children: /* @__PURE__ */ o(mt, {
180
180
  width: 18,
181
181
  height: 18
182
182
  })
183
- }) : f && /* @__PURE__ */ o("span", {
184
- ref: X,
183
+ }) : g && /* @__PURE__ */ o("span", {
184
+ ref: V,
185
185
  className: "absolute inset-y-0 right-[14px] flex max-w-[calc(100%-28px)] items-center gap-1",
186
- children: f
186
+ children: g
187
187
  }),
188
- w ? /* @__PURE__ */ o("fieldset", {
188
+ R ? /* @__PURE__ */ o("fieldset", {
189
189
  "aria-hidden": !0,
190
- className: de({
191
- focused: N,
192
- error: h,
190
+ className: se({
191
+ focused: I,
192
+ error: p,
193
193
  disabled: d,
194
194
  readOnly: n,
195
195
  notched: !0
196
196
  }),
197
197
  children: /* @__PURE__ */ o("legend", {
198
- className: vt(F),
199
- children: /* @__PURE__ */ p("span", {
198
+ className: vt(w),
199
+ children: /* @__PURE__ */ b("span", {
200
200
  className: "inline-block px-[5px]",
201
- children: [r, H && " *"]
201
+ children: [r, v && " *"]
202
202
  })
203
203
  })
204
204
  }) : /* @__PURE__ */ o("div", {
205
205
  "aria-hidden": !0,
206
- className: de({
207
- focused: N,
208
- error: h,
206
+ className: se({
207
+ focused: I,
208
+ error: p,
209
209
  disabled: d,
210
210
  readOnly: n,
211
211
  notched: !1
212
212
  })
213
213
  })
214
214
  ]
215
- }), w && /* @__PURE__ */ p("label", {
216
- htmlFor: K,
217
- className: l(Lt({
218
- shrink: F,
219
- focused: N,
220
- error: h,
215
+ }), R && /* @__PURE__ */ b("label", {
216
+ htmlFor: z,
217
+ className: s(Lt({
218
+ shrink: w,
219
+ focused: I,
220
+ error: p,
221
221
  disabled: d,
222
222
  readOnly: n,
223
- size: we
223
+ size: Ne
224
224
  }), t?.inputLabel?.className),
225
225
  style: {
226
- ...v(t?.inputLabel?.sx),
226
+ ...F(t?.inputLabel?.sx),
227
227
  ...t?.inputLabel?.style,
228
- ...St(F)
228
+ ...St(w)
229
229
  },
230
- children: [r, H && " *"]
230
+ children: [r, v && " *"]
231
231
  })]
232
232
  }),
233
- P && R ? /* @__PURE__ */ p("div", {
234
- className: "flex items-start justify-between gap-4",
235
- children: [_ && /* @__PURE__ */ o(re, {
236
- id: W,
237
- role: oe,
238
- error: h,
239
- message: E,
240
- hideErrorIcon: t?.formHelperText?.hideErrorIcon,
241
- className: l("box-border min-w-0 flex-1 items-start", t?.formHelperText?.className),
242
- style: v(t?.formHelperText?.sx)
243
- }), /* @__PURE__ */ o(gt, {
244
- id: te,
245
- length: Ze,
246
- limit: R,
247
- locale: Le,
248
- className: "ml-auto shrink-0 whitespace-nowrap pt-1"
249
- })]
250
- }) : _ && /* @__PURE__ */ o(re, {
251
- ref: dt,
252
- id: W,
253
- role: oe,
254
- error: h,
255
- message: E,
233
+ P && /* @__PURE__ */ o(gt, {
234
+ ref: rt,
235
+ id: Q,
236
+ role: at,
237
+ error: p,
238
+ message: K,
256
239
  hideErrorIcon: t?.formHelperText?.hideErrorIcon,
257
- className: l("mr-[14px] box-border items-start", t?.formHelperText?.className),
240
+ className: s("mr-[14px] box-border items-start", t?.formHelperText?.className),
258
241
  style: {
259
- ...ct,
260
- ...v(t?.formHelperText?.sx)
242
+ ...dt,
243
+ ...F(t?.formHelperText?.sx)
261
244
  }
262
- })
245
+ }),
246
+ te && N ? /* @__PURE__ */ o(pt, {
247
+ id: ee,
248
+ length: Ve,
249
+ limit: N,
250
+ locale: be,
251
+ className: "pt-1"
252
+ }) : null
263
253
  ]
264
254
  });
265
255
  };
@@ -1,72 +1,71 @@
1
- import { CharacterCounter as R } from "../../../helpers/CharacterCounter.js";
2
- import { useHelperSlot as U } from "../../../helpers/useHelperSlot.js";
3
- import { fieldWidthStyle as V } from "../field-styles.js";
1
+ import { CharacterCounter as U } from "../../../helpers/CharacterCounter.js";
2
+ import { useHelperSlot as V } from "../../../helpers/useHelperSlot.js";
3
+ import { fieldWidthStyle as X } from "../field-styles.js";
4
4
  import t from "./StyledTextarea.module.js";
5
- import { useEffect as X, useId as m, useRef as Y } from "react";
6
- import { jsx as e, jsxs as Z } from "react/jsx-runtime";
7
- var nt = ({ id: A, variant: h = "active", label: s = "", labelClassName: M = "", description: n = "", reserveHelperText: F, value: a = "", minRows: r = 3, maxRows: i = 1 / 0, disabled: x, error: l, errorMessage: _, containerClassName: j = "", className: w = "", maxLength: B = 1 / 0, counter: C, refLink: E, dataTest: k, counterLimit: g, width: y = "full", locale: W, ...d }) => {
8
- const q = Y(null), c = E ?? q, f = !!(C && g), u = m(), b = m(), z = m(), $ = A ?? z, I = l ? _ : n, { show: N, role: D } = U("StyledTextarea", l, I, F);
9
- X(() => {
10
- const o = c.current;
11
- if (!o) return;
12
- const p = window.getComputedStyle(o), v = parseFloat(p.lineHeight) || 24, T = parseFloat(p.paddingTop), H = parseFloat(p.paddingBottom);
13
- o.style.height = "auto";
14
- const K = o.scrollHeight - T - H, O = Math.max(1, Math.ceil(K / v)), Q = Math.min(Math.max(O, r), i);
15
- o.style.height = `${Q * v + T + H}px`;
5
+ import { useEffect as Y, useId as x, useRef as Z } from "react";
6
+ import { jsx as e, jsxs as L } from "react/jsx-runtime";
7
+ var it = ({ id: F, variant: s = "active", label: d = "", labelClassName: M = "", description: n = "", reserveHelperText: B, value: o = "", minRows: i = 3, maxRows: r = 1 / 0, disabled: y, error: a, errorMessage: _, containerClassName: j = "", className: w = "", maxLength: c = 1 / 0, counter: C, refLink: E, dataTest: k, counterLimit: R, width: g = "full", locale: W, ...f }) => {
8
+ const q = Z(null), p = E ?? q, m = R ?? (Number.isFinite(c) ? c : void 0), h = C !== !1 && !!m, b = x(), $ = x(), z = x(), v = F ?? z, I = a ? _ : n, { show: N, role: D } = V("StyledTextarea", a, I, B);
9
+ Y(() => {
10
+ const l = p.current;
11
+ if (!l) return;
12
+ const u = window.getComputedStyle(l), T = parseFloat(u.lineHeight) || 24, H = parseFloat(u.paddingTop), A = parseFloat(u.paddingBottom);
13
+ l.style.height = "auto";
14
+ const K = l.scrollHeight - H - A, O = Math.max(1, Math.ceil(K / T)), Q = Math.min(Math.max(O, i), r);
15
+ l.style.height = `${Q * T + H + A}px`;
16
16
  }, [
17
- c,
18
- a,
19
- r,
17
+ p,
18
+ o,
20
19
  i,
21
- f
22
- ]), i < r && (r = i);
23
- const G = l ? "error" : "active", S = l ? "error" : x ? "disabled" : "active", J = typeof s != "string" || s.trim() !== "" ? void 0 : typeof n == "string" && n.trim() !== "" ? n : d.placeholder;
24
- return /* @__PURE__ */ Z("div", {
20
+ r,
21
+ h
22
+ ]), r < i && (i = r);
23
+ const G = a ? "error" : "active", S = a ? "error" : y ? "disabled" : "active", J = typeof d != "string" || d.trim() !== "" ? void 0 : typeof n == "string" && n.trim() !== "" ? n : f.placeholder;
24
+ return /* @__PURE__ */ L("div", {
25
25
  className: `relative flex flex-col gap-1 ${j}`,
26
26
  "data-testid": k,
27
- "data-field-width": y,
28
- style: V(y),
27
+ "data-field-width": g,
28
+ style: X(g),
29
29
  children: [
30
30
  /* @__PURE__ */ e("label", {
31
- htmlFor: $,
31
+ htmlFor: v,
32
32
  className: `${t.label} ${t[S]} ${M}`,
33
- children: s
33
+ children: d
34
34
  }),
35
35
  N && /* @__PURE__ */ e("span", {
36
- id: u,
36
+ id: b,
37
37
  role: D,
38
38
  className: `${t.description} ${t[S]} min-h-[24px]`,
39
39
  children: I
40
40
  }),
41
- h === "view_only" ? /* @__PURE__ */ e("div", {
41
+ s === "view_only" ? /* @__PURE__ */ e("div", {
42
42
  className: "pt-3 font-roboto text-base font-normal text-delta-700",
43
- children: a
44
- }) : h === "not_editable" ? /* @__PURE__ */ e("div", {
43
+ children: o
44
+ }) : s === "not_editable" ? /* @__PURE__ */ e("div", {
45
45
  className: "rounded bg-delta-50 p-3 font-roboto text-base font-normal text-delta-700",
46
- children: a
46
+ children: o
47
47
  }) : /* @__PURE__ */ e("textarea", {
48
- ...d,
49
- "aria-describedby": [N ? u : null, f ? b : null].filter(Boolean).join(" ") || void 0,
50
- "aria-invalid": l,
51
- "aria-label": d["aria-label"] ?? J,
52
- id: $,
53
- ref: c,
48
+ ...f,
49
+ "aria-describedby": [N ? b : null, h ? $ : null].filter(Boolean).join(" ") || void 0,
50
+ "aria-invalid": a,
51
+ "aria-label": f["aria-label"] ?? J,
52
+ id: v,
53
+ ref: p,
54
54
  className: `${t.textarea} ${t[G]} ${w}`,
55
55
  wrap: "soft",
56
- value: a,
57
- disabled: x,
58
- maxLength: B
56
+ value: o,
57
+ disabled: y,
58
+ maxLength: c
59
59
  }),
60
- f && /* @__PURE__ */ e(R, {
61
- id: b,
62
- length: a.length,
63
- limit: g,
64
- locale: W,
65
- className: "self-end"
66
- })
60
+ h && m && s === "active" ? /* @__PURE__ */ e(U, {
61
+ id: $,
62
+ length: o.length,
63
+ limit: m,
64
+ locale: W
65
+ }) : null
67
66
  ]
68
67
  });
69
68
  };
70
69
  export {
71
- nt as StyledTextarea
70
+ it as StyledTextarea
72
71
  };
@@ -44,7 +44,10 @@ export interface StyledInputFieldProps {
44
44
  expandHelperText?: boolean;
45
45
  /** Character limit; also readable from `slotProps.htmlInput.maxLength`. */
46
46
  maxLength?: number;
47
- /** Shows the count against `maxLength` as the user types, for free text with a limit. */
47
+ /**
48
+ * Count against `maxLength`, on by default whenever the field has a limit (WID-12). Pass `false`
49
+ * for a fixed format such as a postal code, whose length the label or hint already states.
50
+ */
48
51
  counter?: boolean;
49
52
  /** Language of the counter text. */
50
53
  locale?: UiCoreLocale;
@@ -11,6 +11,7 @@ export interface CharacterCounterProps {
11
11
  }
12
12
  /**
13
13
  * The count of a free-text field with a character limit, such as *12 av 100 tegn* (field width
14
- * pattern WID-2, Q12), so typed text is never cut without notice.
14
+ * pattern WID-2, WID-12), so typed text is never cut without notice.
15
+ * @figmaNode wXrXt5uKNNzV2DnQCgyYZH#45907-218317
15
16
  */
16
17
  export declare const CharacterCounter: ({ id, length, limit, locale, className }: CharacterCounterProps) => JSX.Element;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.111.0",
6
+ "version": "3.112.0",
7
7
  "type": "module",
8
8
  "sideEffects": [
9
9
  "**/*.css",