@brightlocal/ui-components 3.3.0 → 3.5.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.
Files changed (207) hide show
  1. package/AI_USAGE.md +22 -3
  2. package/README.md +177 -109
  3. package/component-meta.json +1307 -113
  4. package/dist/alert-dialog.cjs +1 -1
  5. package/dist/alert-dialog.d.ts +13 -2
  6. package/dist/alert-dialog.d.ts.map +1 -1
  7. package/dist/alert-dialog.js +4 -3
  8. package/dist/banner.cjs +1 -1
  9. package/dist/banner.d.ts +47 -11
  10. package/dist/banner.d.ts.map +1 -1
  11. package/dist/banner.js +156 -79
  12. package/dist/blocks/empty-state.cjs +1 -1
  13. package/dist/blocks/empty-state.d.ts +40 -5
  14. package/dist/blocks/empty-state.d.ts.map +1 -1
  15. package/dist/blocks/empty-state.js +59 -52
  16. package/dist/blocks/input-list.cjs +1 -1
  17. package/dist/blocks/input-list.d.ts +1 -0
  18. package/dist/blocks/input-list.d.ts.map +1 -1
  19. package/dist/blocks/input-list.js +39 -39
  20. package/dist/blocks/sidebar.cjs +1 -1
  21. package/dist/blocks/sidebar.d.ts +12 -6
  22. package/dist/blocks/sidebar.d.ts.map +1 -1
  23. package/dist/blocks/sidebar.js +64 -63
  24. package/dist/button.cjs +1 -1
  25. package/dist/button.d.ts.map +1 -1
  26. package/dist/button.js +47 -43
  27. package/dist/card.cjs +1 -1
  28. package/dist/card.d.ts +12 -0
  29. package/dist/card.d.ts.map +1 -1
  30. package/dist/card.js +115 -97
  31. package/dist/chart.cjs +6 -6
  32. package/dist/chart.d.ts +6 -10
  33. package/dist/chart.d.ts.map +1 -1
  34. package/dist/chart.js +281 -296
  35. package/dist/combobox.cjs +3 -3
  36. package/dist/combobox.d.ts.map +1 -1
  37. package/dist/combobox.js +430 -343
  38. package/dist/command.cjs +1 -1
  39. package/dist/command.d.ts +23 -2
  40. package/dist/command.d.ts.map +1 -1
  41. package/dist/command.js +212 -207
  42. package/dist/count-indicator.cjs +1 -0
  43. package/dist/count-indicator.d.ts +85 -0
  44. package/dist/count-indicator.d.ts.map +1 -0
  45. package/dist/count-indicator.js +72 -0
  46. package/dist/data-table.cjs +1 -1
  47. package/dist/data-table.d.ts +101 -11
  48. package/dist/data-table.d.ts.map +1 -1
  49. package/dist/data-table.js +593 -523
  50. package/dist/description-list.cjs +1 -0
  51. package/dist/description-list.d.ts +142 -0
  52. package/dist/description-list.d.ts.map +1 -0
  53. package/dist/description-list.js +173 -0
  54. package/dist/dialog.cjs +1 -1
  55. package/dist/dialog.d.ts +26 -3
  56. package/dist/dialog.d.ts.map +1 -1
  57. package/dist/dialog.js +62 -47
  58. package/dist/drawer.cjs +1 -1
  59. package/dist/drawer.d.ts +8 -4
  60. package/dist/drawer.d.ts.map +1 -1
  61. package/dist/drawer.js +37 -38
  62. package/dist/file-upload.cjs +1 -0
  63. package/dist/file-upload.d.ts +546 -0
  64. package/dist/file-upload.d.ts.map +1 -0
  65. package/dist/file-upload.js +1103 -0
  66. package/dist/global-layout.cjs +1 -1
  67. package/dist/global-layout.d.ts +7 -2
  68. package/dist/global-layout.d.ts.map +1 -1
  69. package/dist/global-layout.js +52 -52
  70. package/dist/hooks/use-file-dropzone.cjs +1 -0
  71. package/dist/hooks/use-file-dropzone.d.ts +75 -0
  72. package/dist/hooks/use-file-dropzone.d.ts.map +1 -0
  73. package/dist/hooks/use-file-dropzone.js +133 -0
  74. package/dist/hover-card.cjs +1 -1
  75. package/dist/hover-card.d.ts +29 -16
  76. package/dist/hover-card.d.ts.map +1 -1
  77. package/dist/hover-card.js +153 -36
  78. package/dist/index.cjs +1 -1
  79. package/dist/index.d.ts +4 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +681 -623
  82. package/dist/input-chip.cjs +1 -1
  83. package/dist/input-chip.d.ts +30 -1
  84. package/dist/input-chip.d.ts.map +1 -1
  85. package/dist/input-chip.js +131 -115
  86. package/dist/input-group.cjs +1 -1
  87. package/dist/input-group.d.ts +37 -2
  88. package/dist/input-group.d.ts.map +1 -1
  89. package/dist/input-group.js +131 -114
  90. package/dist/input-password.cjs +1 -1
  91. package/dist/input-password.js +6 -6
  92. package/dist/lib/empty-canvas.cjs +1 -1
  93. package/dist/lib/empty-canvas.d.ts +27 -1
  94. package/dist/lib/empty-canvas.d.ts.map +1 -1
  95. package/dist/lib/empty-canvas.js +27 -23
  96. package/dist/lib/empty-chip.cjs +1 -1
  97. package/dist/lib/empty-chip.d.ts +19 -2
  98. package/dist/lib/empty-chip.d.ts.map +1 -1
  99. package/dist/lib/empty-chip.js +14 -9
  100. package/dist/lib/field-aria.cjs +1 -1
  101. package/dist/lib/field-aria.d.ts +4 -4
  102. package/dist/lib/field-aria.d.ts.map +1 -1
  103. package/dist/lib/field-aria.js +7 -5
  104. package/dist/lib/media-viewer-content.cjs +1 -1
  105. package/dist/lib/media-viewer-content.js +1 -1
  106. package/dist/lib/motion.cjs +1 -1
  107. package/dist/lib/motion.js +15 -10
  108. package/dist/lib/table-internal.cjs +1 -1
  109. package/dist/lib/table-internal.d.ts +19 -0
  110. package/dist/lib/table-internal.d.ts.map +1 -1
  111. package/dist/lib/table-internal.js +22 -7
  112. package/dist/list.cjs +1 -1
  113. package/dist/list.d.ts +230 -40
  114. package/dist/list.d.ts.map +1 -1
  115. package/dist/list.js +301 -66
  116. package/dist/logo-mark.cjs +1 -1
  117. package/dist/logo-mark.d.ts +18 -2
  118. package/dist/logo-mark.d.ts.map +1 -1
  119. package/dist/logo-mark.js +159 -79
  120. package/dist/media-empty.cjs +1 -1
  121. package/dist/media-empty.d.ts +50 -7
  122. package/dist/media-empty.d.ts.map +1 -1
  123. package/dist/media-empty.js +14 -13
  124. package/dist/media-viewer.cjs +1 -1
  125. package/dist/media-viewer.js +6 -6
  126. package/dist/multi-select-filter.cjs +1 -1
  127. package/dist/multi-select-filter.d.ts.map +1 -1
  128. package/dist/multi-select-filter.js +92 -101
  129. package/dist/pagination.cjs +1 -1
  130. package/dist/pagination.d.ts +11 -0
  131. package/dist/pagination.d.ts.map +1 -1
  132. package/dist/pagination.js +17 -17
  133. package/dist/relative-date.d.ts +6 -0
  134. package/dist/relative-date.d.ts.map +1 -1
  135. package/dist/resizable.d.ts +1 -1
  136. package/dist/result-count.cjs +1 -1
  137. package/dist/result-count.d.ts +13 -16
  138. package/dist/result-count.d.ts.map +1 -1
  139. package/dist/result-count.js +24 -33
  140. package/dist/route-progress.cjs +1 -1
  141. package/dist/route-progress.js +24 -23
  142. package/dist/sheet.cjs +1 -1
  143. package/dist/sheet.d.ts +22 -3
  144. package/dist/sheet.d.ts.map +1 -1
  145. package/dist/sheet.js +152 -125
  146. package/dist/single-select-filter.cjs +1 -1
  147. package/dist/single-select-filter.d.ts.map +1 -1
  148. package/dist/single-select-filter.js +67 -76
  149. package/dist/table.cjs +1 -1
  150. package/dist/table.d.ts.map +1 -1
  151. package/dist/table.js +77 -76
  152. package/dist/tabs.cjs +1 -1
  153. package/dist/tabs.d.ts +39 -3
  154. package/dist/tabs.d.ts.map +1 -1
  155. package/dist/tabs.js +127 -76
  156. package/dist/textarea.cjs +1 -1
  157. package/dist/textarea.d.ts +34 -0
  158. package/dist/textarea.d.ts.map +1 -1
  159. package/dist/textarea.js +115 -19
  160. package/dist/tooltip.cjs +1 -1
  161. package/dist/tooltip.d.ts.map +1 -1
  162. package/dist/tooltip.js +137 -131
  163. package/dist/typography-text.cjs +1 -1
  164. package/dist/typography-text.d.ts +6 -2
  165. package/dist/typography-text.d.ts.map +1 -1
  166. package/dist/typography-text.js +14 -13
  167. package/package.json +2 -3
  168. package/src/blocks/empty-state.tsx +108 -48
  169. package/src/blocks/input-list.tsx +15 -9
  170. package/src/blocks/sidebar.tsx +39 -16
  171. package/src/components/alert-dialog.tsx +18 -2
  172. package/src/components/banner.tsx +247 -68
  173. package/src/components/button.tsx +27 -10
  174. package/src/components/card.tsx +89 -7
  175. package/src/components/chart.tsx +47 -67
  176. package/src/components/combobox.tsx +221 -12
  177. package/src/components/command.tsx +83 -37
  178. package/src/components/count-indicator.tsx +188 -0
  179. package/src/components/data-table.tsx +506 -159
  180. package/src/components/description-list.tsx +445 -0
  181. package/src/components/dialog.tsx +74 -5
  182. package/src/components/drawer.tsx +52 -32
  183. package/src/components/file-upload.tsx +2574 -0
  184. package/src/components/global-layout.tsx +18 -5
  185. package/src/components/hover-card.tsx +395 -65
  186. package/src/components/input-chip.tsx +67 -2
  187. package/src/components/input-group.tsx +89 -6
  188. package/src/components/list.tsx +720 -72
  189. package/src/components/logo-mark.tsx +109 -25
  190. package/src/components/media-empty.tsx +62 -7
  191. package/src/components/multi-select-filter.tsx +9 -16
  192. package/src/components/pagination.tsx +15 -2
  193. package/src/components/relative-date.tsx +6 -0
  194. package/src/components/result-count.tsx +27 -54
  195. package/src/components/sheet.tsx +86 -8
  196. package/src/components/single-select-filter.tsx +9 -16
  197. package/src/components/table.tsx +16 -1
  198. package/src/components/tabs.tsx +223 -41
  199. package/src/components/textarea.tsx +271 -4
  200. package/src/components/tooltip.tsx +29 -2
  201. package/src/components/typography-text.tsx +7 -2
  202. package/src/hooks/use-file-dropzone.ts +325 -0
  203. package/src/index.ts +4 -0
  204. package/src/lib/empty-canvas.tsx +47 -20
  205. package/src/lib/empty-chip.tsx +38 -3
  206. package/src/lib/field-aria.tsx +11 -6
  207. package/src/lib/table-internal.ts +38 -0
@@ -5,12 +5,13 @@ import { cva } from "class-variance-authority";
5
5
 
6
6
  import { cn } from "@brightlocal/ui-components/lib/utils";
7
7
  import { useFieldDescribedBy } from "../lib/field-aria";
8
+ import { CountIndicator, type CountIndicatorLabels } from "./count-indicator";
8
9
 
9
10
  const textareaVariants = cva([
10
11
  // Layout & Size
11
12
  "flex w-full",
12
13
  // Appearance - Explicit background with isolation for contrast calculation
13
- "border border-input bg-background rounded-md",
14
+ "border border-input bg-background rounded-sm",
14
15
  "outline-none transition-[border-color,background-color,box-shadow] duration-fast ease-out",
15
16
  // Typography
16
17
  "text-field",
@@ -26,6 +27,66 @@ const textareaVariants = cva([
26
27
  "placeholder:text-muted-foreground",
27
28
  ]);
28
29
 
30
+ /**
31
+ * True when the browser sizes a textarea to its content with CSS
32
+ * (`field-sizing: content`). Elsewhere the height is measured on input.
33
+ */
34
+ function supportsFieldSizing() {
35
+ return (
36
+ typeof CSS !== "undefined" &&
37
+ typeof CSS.supports === "function" &&
38
+ CSS.supports("field-sizing", "content")
39
+ );
40
+ }
41
+
42
+ /** A React style length (number = px) as an inline CSS value; "" clears it. */
43
+ function toCssLength(value: string | number | undefined) {
44
+ if (value === undefined) return "";
45
+ return typeof value === "number" ? `${value}px` : value;
46
+ }
47
+
48
+ /**
49
+ * Sets min/max height from the row counts and, where `field-sizing` is not
50
+ * supported, the height itself from the content. Reads the computed line
51
+ * height, padding and border so className overrides and the touch font bump
52
+ * in `text-field` stay correct.
53
+ */
54
+ function syncAutosizeHeight(
55
+ el: HTMLTextAreaElement,
56
+ minRows: number,
57
+ maxRows: number,
58
+ fieldSizing: boolean
59
+ ) {
60
+ const style = window.getComputedStyle(el);
61
+ const fontSize = parseFloat(style.fontSize) || 16;
62
+ const lineHeight = parseFloat(style.lineHeight) || fontSize * 1.2;
63
+ const chrome =
64
+ (parseFloat(style.paddingTop) || 0) +
65
+ (parseFloat(style.paddingBottom) || 0) +
66
+ (parseFloat(style.borderTopWidth) || 0) +
67
+ (parseFloat(style.borderBottomWidth) || 0);
68
+ const min = minRows * lineHeight + chrome;
69
+ const max = Math.max(maxRows, minRows) * lineHeight + chrome;
70
+
71
+ el.style.minHeight = `${min}px`;
72
+ el.style.maxHeight = `${max}px`;
73
+
74
+ if (fieldSizing) {
75
+ // CSS sizes the box; drop any height set before detection ran.
76
+ el.style.height = "";
77
+ return;
78
+ }
79
+
80
+ // Measure-on-input fallback: collapse to the minimum, then read the
81
+ // content height (scrollHeight excludes the border).
82
+ el.style.height = `${min}px`;
83
+ const borders =
84
+ (parseFloat(style.borderTopWidth) || 0) +
85
+ (parseFloat(style.borderBottomWidth) || 0);
86
+ const next = Math.min(Math.max(el.scrollHeight + borders, min), max);
87
+ el.style.height = `${next}px`;
88
+ }
89
+
29
90
  interface TextareaProps extends Omit<
30
91
  React.ComponentProps<"textarea">,
31
92
  "dataHook" | "id"
@@ -42,6 +103,39 @@ interface TextareaProps extends Omit<
42
103
  * Whether the textarea has an error state
43
104
  */
44
105
  error?: boolean;
106
+ /**
107
+ * Shows a count such as `120 / 750` inside the field, bottom right. It
108
+ * counts characters and never blocks typing: over the limit the count turns
109
+ * red and the border takes the error colour. Show the error message and stop
110
+ * the save yourself. Pass a controlled `value` so the count stays in step.
111
+ */
112
+ limit?: number;
113
+ /**
114
+ * Screen reader copy for the count. Pass translations here; omitted entries
115
+ * use English. Only used with `limit`.
116
+ */
117
+ countLabels?: Partial<CountIndicatorLabels>;
118
+ /**
119
+ * Grow the textarea with its content, from `minRows` up to `maxRows`, then
120
+ * scroll. Uses CSS `field-sizing: content` where the browser supports it and
121
+ * measures on input elsewhere. Works with controlled and uncontrolled values
122
+ * and follows width changes. Turns off the manual resize handle; `rows` is
123
+ * ignored (use `minRows`). While on, it owns the inline `height`,
124
+ * `minHeight` and `maxHeight`; switching it off restores those from `style`.
125
+ * @default false
126
+ */
127
+ autosize?: boolean;
128
+ /**
129
+ * Smallest height in text lines when `autosize` is on.
130
+ * @default 3
131
+ */
132
+ minRows?: number;
133
+ /**
134
+ * Largest height in text lines when `autosize` is on; longer content
135
+ * scrolls. Never less than `minRows`.
136
+ * @default 10
137
+ */
138
+ maxRows?: number;
45
139
  /**
46
140
  * Optional tracking prop for analytics tracking element identifier
47
141
  */
@@ -58,13 +152,37 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
58
152
  className,
59
153
  dataHook,
60
154
  error,
155
+ limit,
156
+ countLabels,
157
+ autosize = false,
158
+ minRows = 3,
159
+ maxRows = 10,
160
+ rows,
161
+ onInput,
61
162
  trackingEl,
62
163
  trackingLabel,
63
164
  "aria-describedby": ariaDescribedBy,
165
+ onChange,
64
166
  ...props
65
167
  },
66
168
  ref
67
169
  ) => {
170
+ const countId = React.useId();
171
+ const hasLimit = limit !== undefined;
172
+ // Controlled: count the value. Uncontrolled: follow the typing.
173
+ const isControlled = props.value !== undefined;
174
+ const [typedLength, setTypedLength] = React.useState(
175
+ () => String(props.defaultValue ?? "").length
176
+ );
177
+ const length = isControlled ? String(props.value).length : typedLength;
178
+
179
+ const isOver = hasLimit && length > limit;
180
+
181
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
182
+ if (!isControlled) setTypedLength(event.target.value.length);
183
+ onChange?.(event);
184
+ };
185
+
68
186
  // Support both error prop and aria-invalid for backwards compatibility
69
187
  const hasError =
70
188
  error ||
@@ -73,28 +191,177 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
73
191
 
74
192
  // Inside a Field, point aria-describedby at the FieldError and
75
193
  // FieldDescription automatically; a hand-wired value is kept and merged.
76
- const describedBy = useFieldDescribedBy(ariaDescribedBy);
194
+ const fieldDescribedBy = useFieldDescribedBy(ariaDescribedBy);
195
+ // The count is always part of the description, in or out of a Field.
196
+ const describedBy = hasLimit
197
+ ? [
198
+ ...new Set([
199
+ ...(fieldDescribedBy?.split(/\s+/).filter(Boolean) ?? []),
200
+ countId,
201
+ ]),
202
+ ].join(" ")
203
+ : fieldDescribedBy;
77
204
 
78
- return (
205
+ const innerRef = React.useRef<HTMLTextAreaElement | null>(null);
206
+ // Returns a cleanup (React 19) so a consumer callback ref's own cleanup
207
+ // still runs on detach; refs without one are called with null instead.
208
+ const setRefs = React.useCallback(
209
+ (node: HTMLTextAreaElement | null) => {
210
+ innerRef.current = node;
211
+ let cleanup: unknown;
212
+ if (typeof ref === "function") cleanup = ref(node);
213
+ else if (ref) ref.current = node;
214
+ return () => {
215
+ innerRef.current = null;
216
+ if (typeof cleanup === "function") cleanup();
217
+ else if (typeof ref === "function") ref(null);
218
+ else if (ref) ref.current = null;
219
+ };
220
+ },
221
+ [ref]
222
+ );
223
+
224
+ const [fieldSizing, setFieldSizing] = React.useState(false);
225
+
226
+ const sync = React.useCallback(() => {
227
+ const el = innerRef.current;
228
+ if (!autosize || !el) return;
229
+ syncAutosizeHeight(el, minRows, maxRows, fieldSizing);
230
+ }, [autosize, minRows, maxRows, fieldSizing]);
231
+
232
+ // Feature-detect after mount so server and client markup match.
233
+ React.useLayoutEffect(() => {
234
+ if (autosize) setFieldSizing(supportsFieldSizing());
235
+ }, [autosize]);
236
+
237
+ // Re-measure when a controlled value or the row limits change.
238
+ React.useLayoutEffect(() => {
239
+ sync();
240
+ }, [sync, props.value]);
241
+
242
+ // When autosize is switched off, hand the sizes it owned back to the
243
+ // consumer's style prop. A Textarea that never autosized is left alone.
244
+ const wasAutosize = React.useRef(false);
245
+ const consumerStyle = React.useRef(props.style);
246
+ consumerStyle.current = props.style;
247
+ React.useLayoutEffect(() => {
248
+ const el = innerRef.current;
249
+ if (autosize) {
250
+ wasAutosize.current = true;
251
+ return;
252
+ }
253
+ if (!el || !wasAutosize.current) return;
254
+ wasAutosize.current = false;
255
+ const style = consumerStyle.current;
256
+ el.style.minHeight = toCssLength(style?.minHeight);
257
+ el.style.maxHeight = toCssLength(style?.maxHeight);
258
+ el.style.height = toCssLength(style?.height);
259
+ }, [autosize]);
260
+
261
+ // A form reset restores an uncontrolled value without an input event:
262
+ // re-measure once the native reset has finished.
263
+ React.useEffect(() => {
264
+ const form = innerRef.current?.form;
265
+ if (!autosize || fieldSizing || !form) return;
266
+ let frame = 0;
267
+ const onReset = () => {
268
+ cancelAnimationFrame(frame);
269
+ frame = requestAnimationFrame(sync);
270
+ };
271
+ form.addEventListener("reset", onReset);
272
+ return () => {
273
+ cancelAnimationFrame(frame);
274
+ form.removeEventListener("reset", onReset);
275
+ };
276
+ }, [autosize, fieldSizing, sync]);
277
+
278
+ // form.reset() restores defaultValue without firing change; re-read once
279
+ // the reset steps have run so the count and border follow.
280
+ React.useEffect(() => {
281
+ const form = innerRef.current?.form;
282
+ if (!form || isControlled || !hasLimit) return;
283
+ const handleReset = () =>
284
+ queueMicrotask(() =>
285
+ setTypedLength(innerRef.current?.value.length ?? 0)
286
+ );
287
+ form.addEventListener("reset", handleReset);
288
+ return () => form.removeEventListener("reset", handleReset);
289
+ }, [isControlled, hasLimit]);
290
+
291
+ // Line wrapping changes with width: re-measure when the box gets
292
+ // narrower or wider (height changes alone are ignored).
293
+ React.useEffect(() => {
294
+ const el = innerRef.current;
295
+ if (!autosize || !el || typeof ResizeObserver === "undefined") return;
296
+ let width = el.getBoundingClientRect().width;
297
+ const observer = new ResizeObserver(([entry]) => {
298
+ const next = entry?.contentRect.width ?? width;
299
+ if (next === width) return;
300
+ width = next;
301
+ sync();
302
+ });
303
+ observer.observe(el);
304
+ return () => observer.disconnect();
305
+ }, [autosize, sync]);
306
+
307
+ const textarea = (
79
308
  <textarea
80
- ref={ref}
309
+ ref={setRefs}
81
310
  aria-describedby={describedBy}
82
311
  aria-invalid={hasError ? "true" : undefined}
83
312
  className={cn(
84
313
  textareaVariants(),
314
+ autosize && "field-sizing-content resize-none overflow-y-auto",
85
315
  // scroll-mb-16 reserves room for a two-line error message under the
86
316
  // field, so a phone keyboard scrolls the message into view with it
87
317
  hasError &&
88
318
  "border-destructive-40 focus-visible:border-destructive-40 focus-visible:shadow-destructive scroll-mb-16",
319
+ // Over the limit the border shows the error; aria-invalid stays with
320
+ // the consumer's validation.
321
+ !hasError &&
322
+ isOver &&
323
+ "border-destructive-40 focus-visible:border-destructive-40 focus-visible:shadow-destructive",
324
+ // Room for the count (one 16px line) in the bottom padding, so the
325
+ // last line never runs under it
326
+ hasLimit && "pb-6",
89
327
  className
90
328
  )}
91
329
  data-hook={dataHook}
92
330
  data-slot="textarea"
93
331
  data-tracking-el={trackingEl}
94
332
  data-tracking-label={trackingLabel}
333
+ rows={autosize ? minRows : rows}
95
334
  {...props}
335
+ onChange={handleChange}
336
+ onInput={(event) => {
337
+ onInput?.(event);
338
+ // Uncontrolled typing: field-sizing grows on its own, the
339
+ // fallback measures here. Measure again after React has had the
340
+ // chance to restore a controlled value it rejected (that runs
341
+ // after this handler, before the microtask).
342
+ if (autosize && !fieldSizing) {
343
+ sync();
344
+ queueMicrotask(sync);
345
+ }
346
+ }}
96
347
  />
97
348
  );
349
+
350
+ if (!hasLimit) return textarea;
351
+
352
+ return (
353
+ <div className="relative w-full" data-slot="textarea-wrapper">
354
+ {textarea}
355
+ <CountIndicator
356
+ className="bg-background pointer-events-none absolute right-[9px] bottom-1.5 rounded-sm px-1"
357
+ count={length}
358
+ dataHook={`${dataHook}-count`}
359
+ id={countId}
360
+ labels={countLabels}
361
+ limit={limit}
362
+ />
363
+ </div>
364
+ );
98
365
  }
99
366
  );
100
367
 
@@ -90,6 +90,8 @@ interface TooltipContextValue {
90
90
  open: boolean;
91
91
  tooltipId: string;
92
92
  triggerRef: React.RefObject<HTMLElement | null>;
93
+ suppressDescribedBy: boolean;
94
+ setSuppressDescribedBy: (v: boolean) => void;
93
95
  onTriggerPointerEnter: (e: React.PointerEvent) => void;
94
96
  onTriggerPointerLeave: (e: React.PointerEvent) => void;
95
97
  onTriggerPointerDown: (e: React.PointerEvent) => void;
@@ -160,6 +162,7 @@ function Tooltip({
160
162
  const isControlled = controlledOpen !== undefined;
161
163
  const open = isControlled ? controlledOpen : uncontrolledOpen;
162
164
 
165
+ const [suppressDescribedBy, setSuppressDescribedBy] = React.useState(false);
163
166
  const hoverTimeout = React.useRef<ReturnType<typeof setTimeout>>(undefined);
164
167
  const delayTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
165
168
  const triggerRef = React.useRef<HTMLElement | null>(null);
@@ -313,6 +316,8 @@ function Tooltip({
313
316
  open,
314
317
  tooltipId,
315
318
  triggerRef,
319
+ suppressDescribedBy,
320
+ setSuppressDescribedBy,
316
321
  onTriggerPointerEnter,
317
322
  onTriggerPointerLeave,
318
323
  onTriggerPointerDown,
@@ -327,6 +332,7 @@ function Tooltip({
327
332
  [
328
333
  open,
329
334
  tooltipId,
335
+ suppressDescribedBy,
330
336
  onTriggerPointerEnter,
331
337
  onTriggerPointerLeave,
332
338
  onTriggerPointerDown,
@@ -389,6 +395,7 @@ const TooltipTrigger = React.forwardRef<HTMLButtonElement, TooltipTriggerProps>(
389
395
  open,
390
396
  tooltipId,
391
397
  triggerRef,
398
+ suppressDescribedBy,
392
399
  onTriggerPointerEnter,
393
400
  onTriggerPointerLeave,
394
401
  onTriggerPointerDown,
@@ -415,7 +422,9 @@ const TooltipTrigger = React.forwardRef<HTMLButtonElement, TooltipTriggerProps>(
415
422
  ref={setRefs}
416
423
  data-slot="tooltip-trigger"
417
424
  {...props}
418
- aria-describedby={open ? tooltipId : undefined}
425
+ aria-describedby={
426
+ open && !suppressDescribedBy ? tooltipId : undefined
427
+ }
419
428
  data-hook={dataHook}
420
429
  data-tracking-el={trackingEl}
421
430
  data-tracking-label={trackingLabel}
@@ -488,11 +497,29 @@ const TooltipContent = React.forwardRef<
488
497
  ) => {
489
498
  const {
490
499
  tooltipId,
500
+ triggerRef,
501
+ suppressDescribedBy,
502
+ setSuppressDescribedBy,
491
503
  onContentPointerEnter,
492
504
  onContentPointerLeave,
493
505
  onContentInteractOutside,
494
506
  } = useTooltipContext();
495
507
 
508
+ // Suppress aria-describedby when the tooltip text duplicates the
509
+ // trigger's accessible name — a screen reader would announce the
510
+ // same text twice otherwise (DS-1233).
511
+ const childrenText = typeof children === "string" ? children.trim() : null;
512
+
513
+ React.useLayoutEffect(() => {
514
+ const triggerLabel =
515
+ triggerRef.current?.getAttribute("aria-label") ?? null;
516
+ const redundant =
517
+ childrenText !== null &&
518
+ triggerLabel !== null &&
519
+ childrenText === triggerLabel.trim();
520
+ setSuppressDescribedBy(redundant);
521
+ });
522
+
496
523
  return (
497
524
  <PopoverPrimitive.Portal>
498
525
  <PopoverPrimitive.Content
@@ -526,7 +553,7 @@ const TooltipContent = React.forwardRef<
526
553
  onContentPointerLeave
527
554
  )}
528
555
  >
529
- <span id={tooltipId} role="tooltip">
556
+ <span id={suppressDescribedBy ? undefined : tooltipId} role="tooltip">
530
557
  {children}
531
558
  </span>
532
559
  {!hideArrow && (
@@ -33,8 +33,10 @@ type TypographyTextAlign = "left" | "center" | "right";
33
33
  * - `muted` — de-emphasis by color only; same size and weight.
34
34
  * - `destructive` — error/critical text; pair with an icon or wording, never
35
35
  * color alone.
36
+ * - `success` — positive/success text (e.g. sync confirmations, accepted
37
+ * states). Same family as Alert's success tokens.
36
38
  */
37
- type TypographyTextColor = "default" | "muted" | "destructive";
39
+ type TypographyTextColor = "default" | "muted" | "destructive" | "success";
38
40
 
39
41
  const typographyTextVariants = cva("", {
40
42
  variants: {
@@ -51,6 +53,7 @@ const typographyTextVariants = cva("", {
51
53
  // destructive-foreground is the legible error-text color in both modes
52
54
  // (text-destructive is the surface red used behind destructive fills)
53
55
  destructive: "text-destructive-foreground",
56
+ success: "text-score-strong-ink",
54
57
  },
55
58
  // Tri-state on purpose: `undefined` (the default) emits no class so the
56
59
  // text inherits its context — proportional everywhere except inside a
@@ -113,7 +116,9 @@ interface TypographyTextProps extends React.HTMLAttributes<HTMLElement> {
113
116
  * Color role: `muted` de-emphasises with color only (text-muted-foreground) —
114
117
  * the scale never de-emphasises via lighter weight or smaller size;
115
118
  * `destructive` is for error/critical text and must be paired with an icon
116
- * or wording (color is never the only indicator).
119
+ * or wording (color is never the only indicator);
120
+ * `success` is for positive/success text (e.g. sync confirmations, accepted
121
+ * states) — same family as Alert's success tokens.
117
122
  * @default "default"
118
123
  */
119
124
  color?: TypographyTextColor;