@brightlocal/ui-components 3.0.0 → 3.2.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 (235) hide show
  1. package/README.md +7 -1
  2. package/component-meta.json +749 -53
  3. package/deprecations.json +114 -4
  4. package/dist/accordion.cjs +1 -1
  5. package/dist/accordion.d.ts +36 -0
  6. package/dist/accordion.d.ts.map +1 -1
  7. package/dist/accordion.js +74 -61
  8. package/dist/alert-dialog.cjs +1 -1
  9. package/dist/alert-dialog.d.ts +32 -3
  10. package/dist/alert-dialog.d.ts.map +1 -1
  11. package/dist/alert-dialog.js +61 -58
  12. package/dist/alert.cjs +1 -1
  13. package/dist/alert.d.ts.map +1 -1
  14. package/dist/alert.js +58 -57
  15. package/dist/badge.cjs +1 -1
  16. package/dist/badge.d.ts +9 -0
  17. package/dist/badge.d.ts.map +1 -1
  18. package/dist/badge.js +50 -30
  19. package/dist/banner.cjs +1 -0
  20. package/dist/banner.d.ts +81 -0
  21. package/dist/banner.d.ts.map +1 -0
  22. package/dist/banner.js +176 -0
  23. package/dist/blocks/empty-state.cjs +1 -1
  24. package/dist/blocks/empty-state.d.ts +4 -3
  25. package/dist/blocks/empty-state.d.ts.map +1 -1
  26. package/dist/blocks/empty-state.js +50 -57
  27. package/dist/blocks/progress-state.d.ts +2 -2
  28. package/dist/blocks/sidebar.cjs +1 -1
  29. package/dist/blocks/sidebar.d.ts +17 -0
  30. package/dist/blocks/sidebar.d.ts.map +1 -1
  31. package/dist/blocks/sidebar.js +8 -2
  32. package/dist/brand-illustration-motif.d.ts +1 -1
  33. package/dist/button-group.cjs +1 -0
  34. package/dist/button-group.d.ts +36 -0
  35. package/dist/button-group.d.ts.map +1 -0
  36. package/dist/button-group.js +47 -0
  37. package/dist/button.cjs +1 -1
  38. package/dist/button.js +1 -1
  39. package/dist/card.cjs +1 -1
  40. package/dist/card.d.ts +105 -7
  41. package/dist/card.d.ts.map +1 -1
  42. package/dist/card.js +198 -101
  43. package/dist/chart.cjs +3 -3
  44. package/dist/chart.d.ts +270 -24
  45. package/dist/chart.d.ts.map +1 -1
  46. package/dist/chart.js +497 -322
  47. package/dist/checkbox.cjs +1 -1
  48. package/dist/checkbox.d.ts +1 -1
  49. package/dist/checkbox.d.ts.map +1 -1
  50. package/dist/checkbox.js +2 -1
  51. package/dist/chip.cjs +1 -1
  52. package/dist/chip.d.ts +38 -4
  53. package/dist/chip.d.ts.map +1 -1
  54. package/dist/chip.js +95 -81
  55. package/dist/combobox.cjs +1 -1
  56. package/dist/combobox.js +2 -2
  57. package/dist/command.cjs +1 -1
  58. package/dist/command.d.ts +23 -1
  59. package/dist/command.d.ts.map +1 -1
  60. package/dist/command.js +251 -225
  61. package/dist/data-table.cjs +1 -1
  62. package/dist/data-table.d.ts +201 -23
  63. package/dist/data-table.d.ts.map +1 -1
  64. package/dist/data-table.js +712 -568
  65. package/dist/date-picker.cjs +1 -1
  66. package/dist/date-picker.d.ts +13 -5
  67. package/dist/date-picker.d.ts.map +1 -1
  68. package/dist/date-picker.js +54 -53
  69. package/dist/field.cjs +1 -1
  70. package/dist/field.d.ts +8 -1
  71. package/dist/field.d.ts.map +1 -1
  72. package/dist/field.js +79 -52
  73. package/dist/global-layout.cjs +1 -1
  74. package/dist/global-layout.d.ts +105 -13
  75. package/dist/global-layout.d.ts.map +1 -1
  76. package/dist/global-layout.js +146 -129
  77. package/dist/grid.d.ts +26 -3
  78. package/dist/grid.d.ts.map +1 -1
  79. package/dist/hooks/use-breakpoint.cjs +1 -1
  80. package/dist/hooks/use-breakpoint.d.ts +1 -1
  81. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  82. package/dist/hooks/use-breakpoint.js +1 -0
  83. package/dist/hooks/use-mobile.cjs +1 -0
  84. package/dist/hooks/use-mobile.js +8 -0
  85. package/dist/index.cjs +1 -1
  86. package/dist/index.d.ts +6 -0
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +594 -553
  89. package/dist/info-tooltip.cjs +1 -0
  90. package/dist/info-tooltip.d.ts +39 -0
  91. package/dist/info-tooltip.d.ts.map +1 -0
  92. package/dist/info-tooltip.js +41 -0
  93. package/dist/input-chip.cjs +1 -1
  94. package/dist/input-chip.js +1 -1
  95. package/dist/input-group.cjs +1 -1
  96. package/dist/input-group.d.ts +33 -2
  97. package/dist/input-group.d.ts.map +1 -1
  98. package/dist/input-group.js +167 -54
  99. package/dist/input-otp.cjs +1 -1
  100. package/dist/input-otp.js +9 -9
  101. package/dist/input-password.cjs +1 -1
  102. package/dist/input-password.d.ts +45 -15
  103. package/dist/input-password.d.ts.map +1 -1
  104. package/dist/input-password.js +31 -30
  105. package/dist/input.cjs +1 -1
  106. package/dist/input.js +10 -10
  107. package/dist/lib/block-illustration.cjs +1 -1
  108. package/dist/lib/block-illustration.d.ts +4 -1
  109. package/dist/lib/block-illustration.d.ts.map +1 -1
  110. package/dist/lib/block-illustration.js +12 -11
  111. package/dist/lib/empty-chip.cjs +1 -0
  112. package/dist/lib/empty-chip.d.ts +4 -0
  113. package/dist/lib/empty-chip.d.ts.map +1 -0
  114. package/dist/lib/empty-chip.js +13 -0
  115. package/dist/lib/utils.cjs +1 -1
  116. package/dist/lib/utils.d.ts.map +1 -1
  117. package/dist/lib/utils.js +4 -3
  118. package/dist/list.cjs +1 -1
  119. package/dist/list.js +1 -1
  120. package/dist/multi-select-filter.cjs +1 -0
  121. package/dist/multi-select-filter.d.ts +178 -0
  122. package/dist/multi-select-filter.d.ts.map +1 -0
  123. package/dist/multi-select-filter.js +463 -0
  124. package/dist/pagination.cjs +1 -1
  125. package/dist/pagination.d.ts +3 -0
  126. package/dist/pagination.d.ts.map +1 -1
  127. package/dist/pagination.js +57 -57
  128. package/dist/progress.cjs +1 -1
  129. package/dist/progress.d.ts +123 -16
  130. package/dist/progress.d.ts.map +1 -1
  131. package/dist/progress.js +89 -75
  132. package/dist/rating.cjs +1 -1
  133. package/dist/rating.js +18 -18
  134. package/dist/relative-date.cjs +1 -0
  135. package/dist/relative-date.d.ts +65 -0
  136. package/dist/relative-date.d.ts.map +1 -0
  137. package/dist/relative-date.js +128 -0
  138. package/dist/scroll-area.cjs +1 -1
  139. package/dist/scroll-area.d.ts +15 -6
  140. package/dist/scroll-area.d.ts.map +1 -1
  141. package/dist/scroll-area.js +38 -36
  142. package/dist/select.cjs +2 -2
  143. package/dist/select.d.ts +24 -3
  144. package/dist/select.d.ts.map +1 -1
  145. package/dist/select.js +130 -110
  146. package/dist/sheet.cjs +1 -1
  147. package/dist/sheet.d.ts +78 -2
  148. package/dist/sheet.d.ts.map +1 -1
  149. package/dist/sheet.js +192 -85
  150. package/dist/single-select-filter.cjs +1 -0
  151. package/dist/single-select-filter.d.ts +81 -0
  152. package/dist/single-select-filter.d.ts.map +1 -0
  153. package/dist/single-select-filter.js +226 -0
  154. package/dist/sonner.cjs +1 -1
  155. package/dist/sonner.d.ts.map +1 -1
  156. package/dist/sonner.js +22 -22
  157. package/dist/split-layout.cjs +1 -1
  158. package/dist/split-layout.d.ts +1 -1
  159. package/dist/split-layout.js +13 -13
  160. package/dist/table.cjs +1 -1
  161. package/dist/table.d.ts +45 -4
  162. package/dist/table.d.ts.map +1 -1
  163. package/dist/table.js +90 -73
  164. package/dist/tabs.cjs +1 -1
  165. package/dist/tabs.d.ts +12 -1
  166. package/dist/tabs.d.ts.map +1 -1
  167. package/dist/tabs.js +148 -126
  168. package/dist/textarea.cjs +1 -1
  169. package/dist/textarea.js +1 -1
  170. package/dist/tooltip.cjs +1 -1
  171. package/dist/tooltip.d.ts +38 -36
  172. package/dist/tooltip.d.ts.map +1 -1
  173. package/dist/tooltip.js +262 -73
  174. package/dist/typography-heading.cjs +1 -1
  175. package/dist/typography-heading.d.ts +13 -0
  176. package/dist/typography-heading.d.ts.map +1 -1
  177. package/dist/typography-heading.js +32 -21
  178. package/dist/typography-text.cjs +1 -1
  179. package/dist/typography-text.d.ts +15 -2
  180. package/dist/typography-text.d.ts.map +1 -1
  181. package/dist/typography-text.js +35 -24
  182. package/dist/typography.d.ts +1 -1
  183. package/package.json +5 -6
  184. package/src/blocks/empty-state.tsx +17 -24
  185. package/src/blocks/progress-state.tsx +2 -2
  186. package/src/blocks/sidebar.tsx +26 -2
  187. package/src/components/accordion.tsx +82 -27
  188. package/src/components/alert-dialog.tsx +50 -5
  189. package/src/components/alert.tsx +16 -8
  190. package/src/components/badge.tsx +40 -3
  191. package/src/components/banner.tsx +288 -0
  192. package/src/components/brand-illustration-motif.tsx +1 -1
  193. package/src/components/button-group.tsx +112 -0
  194. package/src/components/button.tsx +1 -1
  195. package/src/components/card.tsx +249 -27
  196. package/src/components/chart.tsx +586 -53
  197. package/src/components/checkbox.tsx +1 -1
  198. package/src/components/chip.tsx +83 -10
  199. package/src/components/combobox.tsx +2 -2
  200. package/src/components/command.tsx +56 -4
  201. package/src/components/data-table.tsx +842 -199
  202. package/src/components/date-picker.tsx +18 -7
  203. package/src/components/field.tsx +81 -12
  204. package/src/components/global-layout.tsx +176 -38
  205. package/src/components/grid.tsx +34 -3
  206. package/src/components/info-tooltip.tsx +94 -0
  207. package/src/components/input-chip.tsx +1 -1
  208. package/src/components/input-group.tsx +246 -11
  209. package/src/components/input-otp.tsx +1 -1
  210. package/src/components/input-password.tsx +56 -22
  211. package/src/components/input.tsx +1 -1
  212. package/src/components/list.tsx +1 -1
  213. package/src/components/multi-select-filter.tsx +912 -0
  214. package/src/components/pagination.tsx +10 -3
  215. package/src/components/progress.tsx +190 -31
  216. package/src/components/rating.tsx +1 -1
  217. package/src/components/relative-date.tsx +230 -0
  218. package/src/components/scroll-area.tsx +23 -10
  219. package/src/components/select.tsx +65 -11
  220. package/src/components/sheet.tsx +240 -4
  221. package/src/components/single-select-filter.tsx +443 -0
  222. package/src/components/sonner.tsx +16 -5
  223. package/src/components/split-layout.tsx +2 -2
  224. package/src/components/table.tsx +71 -11
  225. package/src/components/tabs.tsx +93 -46
  226. package/src/components/textarea.tsx +1 -1
  227. package/src/components/tooltip.tsx +440 -68
  228. package/src/components/typography-heading.tsx +24 -0
  229. package/src/components/typography-text.tsx +27 -3
  230. package/src/components/typography.tsx +1 -1
  231. package/src/hooks/use-breakpoint.ts +2 -1
  232. package/src/index.ts +6 -0
  233. package/src/lib/block-illustration.tsx +5 -1
  234. package/src/lib/empty-chip.ts +24 -0
  235. package/src/lib/utils.ts +1 -0
@@ -442,6 +442,9 @@ interface PaginationControlsProps extends Omit<
442
442
  * Controlled: the consumer holds `page` and updates it from `onPageChange`.
443
443
  * Pass `totalItems` + `pageSize` to get the results caption; the caption sits
444
444
  * on the left with the nav pushed right, and without one the nav centres.
445
+ * Below the `sm` viewport breakpoint the caption is removed and the nav
446
+ * centres, and from `sm` up the bar wraps inside narrow containers instead of
447
+ * overflowing — the same responsive rules as `DataTablePagination` (DS-998).
445
448
  *
446
449
  * There is nothing to navigate on a single page, so the nav hides itself at
447
450
  * `totalPages <= 1` and the component renders nothing at all when the caption
@@ -507,8 +510,12 @@ const PaginationControls = React.forwardRef<
507
510
  ref
508
511
  ) => {
509
512
  const items = usePagination({ page, totalPages });
513
+ const isMobile = useIsBelowBreakpoint("sm");
510
514
 
511
515
  const caption = (() => {
516
+ // Below `sm` the caption is removed so the page buttons get the full
517
+ // width and centre (DS-998) — same rule as `DataTablePagination`.
518
+ if (isMobile) return null;
512
519
  if (renderCaption === null) return null;
513
520
  if (totalItems === undefined || pageSize === undefined) return null;
514
521
  // A page size that isn't a positive number, or a negative total, can only
@@ -550,7 +557,7 @@ const PaginationControls = React.forwardRef<
550
557
  <div
551
558
  ref={ref}
552
559
  className={cn(
553
- "flex min-h-9 w-full items-center gap-4",
560
+ "flex min-h-9 w-full flex-wrap items-center gap-x-4 gap-y-2",
554
561
  caption == null ? "justify-center" : "justify-between",
555
562
  className
556
563
  )}
@@ -562,7 +569,7 @@ const PaginationControls = React.forwardRef<
562
569
  >
563
570
  {caption != null && (
564
571
  <span
565
- className="text-body-sm text-muted-foreground"
572
+ className="text-body-sm text-muted-foreground whitespace-nowrap"
566
573
  data-slot="pagination-caption"
567
574
  >
568
575
  {caption}
@@ -571,7 +578,7 @@ const PaginationControls = React.forwardRef<
571
578
  {showNav && (
572
579
  <Pagination
573
580
  ariaLabel={ariaLabel}
574
- className={cn(caption != null && "mx-0 w-auto justify-end")}
581
+ className={cn(caption != null && "mx-0 w-auto grow justify-end")}
575
582
  dataHook={`${dataHook}-nav`}
576
583
  >
577
584
  <PaginationContent>
@@ -106,9 +106,31 @@ function formatProgressValue(
106
106
  }
107
107
 
108
108
  /**
109
- * Props for the Progress component.
109
+ * Formats the value shown beside the bar — and, through Radix's
110
+ * `getValueLabel`, the `aria-valuetext` screen readers announce — from the raw
111
+ * `value` and `max`. Receives `null` / `undefined` when the row has no value
112
+ * yet, so it picks its own placeholder (the built-in forms use `–`).
113
+ * @param value - Current value, or none.
114
+ * @param max - Maximum value (denominator).
115
+ * @example (value) => value?.toLocaleString() ?? "–"
110
116
  */
111
- interface ProgressProps extends React.ComponentProps<
117
+ type ProgressValueFormatter = (
118
+ value: number | null | undefined,
119
+ max: number
120
+ ) => string;
121
+
122
+ /**
123
+ * A `label` that is rendered but cannot name the bar — an element such as a
124
+ * `Rating` or an icon (wrap several in a fragment). Always paired with
125
+ * `ariaLabel`. Text and numbers are not node labels: they name the bar
126
+ * themselves.
127
+ */
128
+ type ProgressNodeLabel = React.ReactElement;
129
+
130
+ /**
131
+ * Props shared by every Progress, whatever its label is.
132
+ */
133
+ interface ProgressBaseProps extends React.ComponentProps<
112
134
  typeof ProgressPrimitive.Root
113
135
  > {
114
136
  /**
@@ -116,24 +138,27 @@ interface ProgressProps extends React.ComponentProps<
116
138
  */
117
139
  dataHook: string;
118
140
  /**
119
- * Optional tracking element identifier for analytics
141
+ * Current value, measured against `max`. Drives the fill, the value column
142
+ * and `aria-valuenow`; out-of-range values are clamped to `0–max` for the
143
+ * bar while the column prints the raw figure. Omit it (or pass `null`) for a
144
+ * placeholder row — the bar stays empty and the column shows `–`.
120
145
  */
121
- trackingEl?: string;
146
+ value?: number | null;
122
147
  /**
123
- * Optional tracking label for analytics
148
+ * Maximum value — the denominator for the fill and the displayed value. For
149
+ * a set of rows that share one scale (a review breakdown), pass the same
150
+ * `max` to every row.
151
+ * @default 100
124
152
  */
125
- trackingLabel?: string;
153
+ max?: number;
126
154
  /**
127
- * Accessible label for the progress bar for screen readers
128
- * @default "Progress"
155
+ * Optional tracking element identifier for analytics
129
156
  */
130
- ariaLabel?: string;
157
+ trackingEl?: string;
131
158
  /**
132
- * Optional visible label text displayed to the left of the progress bar.
133
- * Rendered inside a fixed-width column (see `labelWidth`); longer labels
134
- * wrap onto further lines while the bar and value stay in their columns.
159
+ * Optional tracking label for analytics
135
160
  */
136
- label?: string;
161
+ trackingLabel?: string;
137
162
  /**
138
163
  * Width of the label column: `"20%"` … `"50%"` of the row in 10% steps, or
139
164
  * `"auto"`. Every row that uses the same percentage starts its bar at the
@@ -167,6 +192,21 @@ interface ProgressProps extends React.ComponentProps<
167
192
  * @default "%"
168
193
  */
169
194
  unit?: string;
195
+ /**
196
+ * Replaces the built-in `unit` forms with your own text for the value column,
197
+ * e.g. a raw count (`1,234`) or a remaining amount (`15 min left`). The same
198
+ * text is announced as the bar's `aria-valuetext` (unless you pass Radix's
199
+ * own `getValueLabel`). The column is sized to the wider of
200
+ * `valueFormatter(0, max)` and `valueFormatter(max, max)` so rows still end
201
+ * at the same x-position — the formatter's widest output must be at one of
202
+ * the two extremes, which holds for counts, percentages and remaining
203
+ * amounts. Pair
204
+ * it with a `value` / `max` that describe the real measurement — a count out
205
+ * of the largest count — rather than a precomputed percentage, so
206
+ * `aria-valuenow` stays honest.
207
+ * @example (value) => value?.toLocaleString() ?? "–"
208
+ */
209
+ valueFormatter?: ProgressValueFormatter;
170
210
  /**
171
211
  * Custom class name for the indicator (progress fill)
172
212
  * Use this to customize the color, e.g., "bg-chart-red"
@@ -179,6 +219,81 @@ interface ProgressProps extends React.ComponentProps<
179
219
  disabled?: boolean;
180
220
  }
181
221
 
222
+ /**
223
+ * The label column and the bar's accessible name, as a pair.
224
+ *
225
+ * A text `label` names the bar by itself (`aria-labelledby` points at it). Any
226
+ * other node — a Rating, an icon — is visible but cannot name anything, so it
227
+ * must come with an explicit `ariaLabel`; the union makes TypeScript insist on
228
+ * that pairing instead of letting a bar ship with an empty accessible name.
229
+ */
230
+ /**
231
+ * Text label: names the bar on its own, so `ariaLabel` is optional.
232
+ */
233
+ interface ProgressTextLabelProps {
234
+ /**
235
+ * Optional visible label text displayed to the left of the progress bar.
236
+ * Rendered inside a fixed-width column (see `labelWidth`); longer labels
237
+ * wrap onto further lines while the bar and value stay in their columns.
238
+ */
239
+ label?: string | number;
240
+ /**
241
+ * Accessible label for the progress bar for screen readers. Only used when
242
+ * there is no visible text `label`.
243
+ * @default "Progress"
244
+ */
245
+ ariaLabel?: string;
246
+ }
247
+
248
+ /**
249
+ * Element label: cannot name the bar, so `ariaLabel` is required.
250
+ */
251
+ interface ProgressNodeLabelProps {
252
+ /**
253
+ * Visible label rendered as an element — a `Rating`, an icon — in the same
254
+ * fixed-width column a text label uses (see `labelWidth`), vertically
255
+ * centred against the bar. Mark decorative icons `aria-hidden`.
256
+ */
257
+ label: ProgressNodeLabel;
258
+ /**
259
+ * Accessible name for the bar — required with a node label, because the
260
+ * node cannot name it: `aria-labelledby` would resolve to nothing.
261
+ * @example "4 star reviews"
262
+ */
263
+ ariaLabel: string;
264
+ }
265
+
266
+ /**
267
+ * What the component's JSX signature accepts: the label pair is a union, so an
268
+ * element `label` cannot be passed without its `ariaLabel`. Use this type when
269
+ * a wrapper should carry the same guarantee; `Omit`/`Pick` over the union would
270
+ * collapse it.
271
+ */
272
+ type ProgressStrictProps = ProgressBaseProps &
273
+ (ProgressTextLabelProps | ProgressNodeLabelProps);
274
+
275
+ /**
276
+ * Props for the Progress component — the extendable, loose form (`interface X
277
+ * extends ProgressProps` keeps working). `label` is text, a number or an
278
+ * element; the element ⇒ `ariaLabel` pairing is enforced where it matters, on
279
+ * the component's own signature (`ProgressStrictProps`), so a value typed as
280
+ * `ProgressProps` with an element label must be narrowed before it is spread
281
+ * into `<Progress>`.
282
+ */
283
+ interface ProgressProps extends ProgressBaseProps {
284
+ /**
285
+ * Visible label: text (wraps inside the label column), a number, or an
286
+ * element such as a `Rating` or an icon — an element requires `ariaLabel`.
287
+ */
288
+ label?: string | number | ProgressNodeLabel;
289
+ /**
290
+ * Accessible label for the progress bar. Optional with a text label (the
291
+ * text names the bar); required with an element label.
292
+ * @default "Progress"
293
+ */
294
+ ariaLabel?: string;
295
+ }
296
+
182
297
  /**
183
298
  * Progress component for displaying loading states and task completion.
184
299
  * Built on Radix UI Progress primitive with Framer Motion animation.
@@ -187,11 +302,13 @@ interface ProgressProps extends React.ComponentProps<
187
302
  * a fixed-width label column, the bar filling the remaining space, and a
188
303
  * right-aligned value column sized to the widest value it can show — so rows
189
304
  * stacked in a card share the same bar start position and width, even when
190
- * a label wraps onto two lines.
305
+ * a label wraps onto two lines. The label may be text or any node (a Rating,
306
+ * an icon — then `ariaLabel` is required), and `valueFormatter` replaces the
307
+ * built-in percentage / fraction forms with any text.
191
308
  */
192
309
  const Progress = React.forwardRef<
193
310
  React.ComponentRef<typeof ProgressPrimitive.Root>,
194
- ProgressProps
311
+ ProgressStrictProps
195
312
  >(
196
313
  (
197
314
  {
@@ -208,6 +325,7 @@ const Progress = React.forwardRef<
208
325
  size = "sm",
209
326
  showValue = false,
210
327
  unit = "%",
328
+ valueFormatter,
211
329
  indicatorClassName,
212
330
  disabled,
213
331
  ...props
@@ -215,7 +333,20 @@ const Progress = React.forwardRef<
215
333
  ref
216
334
  ) => {
217
335
  const labelId = React.useId();
218
- const hasVisibleLabel = !!label;
336
+ const hasVisibleLabel =
337
+ label !== undefined && label !== null && label !== "";
338
+ /* Only text can name the bar: `aria-labelledby` reads the label's text
339
+ content, and a Rating or an aria-hidden icon has none. Node labels fall
340
+ back to the (type-required) `ariaLabel`. */
341
+ const labelIsText = typeof label === "string" || typeof label === "number";
342
+ const labelledByText = hasVisibleLabel && labelIsText;
343
+ const formatValue: ProgressValueFormatter =
344
+ valueFormatter ?? ((v, m) => formatProgressValue(v, m, unit));
345
+ /* What the value column shows is also what assistive tech is told: Radix
346
+ would otherwise announce a percentage over a "3 / 5 steps" or "1,234"
347
+ column, and "0%" over a value-less row's "–". Closes over the raw value
348
+ because Radix only hands the callback its validated (never null) one. */
349
+ const valueText = formatValue(value, max);
219
350
  const prefersReducedMotion = usePrefersReducedMotion();
220
351
 
221
352
  const colorStyles = COLOR_STYLES[color] ?? COLOR_STYLES.green;
@@ -226,14 +357,18 @@ const Progress = React.forwardRef<
226
357
  column parent's main axis and override the size's height, rendering an
227
358
  8px bar at whatever the row is tall. */
228
359
  const inRow = hasVisibleLabel || showValue;
229
- const percentage =
230
- max > 0 ? Math.min(100, Math.max(0, ((value ?? 0) / max) * 100)) : 0;
360
+ /* Radix rejects a value outside 0–max outright — it logs an error, nulls
361
+ the value and announces the bar as indeterminate — so the bar gets the
362
+ same clamped measurement its fill is drawn from. The value column still
363
+ prints the raw figure. */
364
+ const clampedValue = Math.min(max, Math.max(0, value ?? 0));
365
+ const percentage = max > 0 ? (clampedValue / max) * 100 : 0;
231
366
 
232
367
  const progressBar = (
233
368
  <ProgressPrimitive.Root
234
369
  ref={ref}
235
- aria-label={hasVisibleLabel ? undefined : ariaLabel}
236
- aria-labelledby={hasVisibleLabel ? labelId : undefined}
370
+ aria-label={labelledByText ? undefined : ariaLabel}
371
+ aria-labelledby={labelledByText ? labelId : undefined}
237
372
  className={cn(
238
373
  "relative w-full overflow-hidden rounded-full",
239
374
  // Inside the row wrapper the bar fills whatever the fixed label and
@@ -248,13 +383,16 @@ const Progress = React.forwardRef<
248
383
  data-slot="progress"
249
384
  data-tracking-el={trackingEl}
250
385
  data-tracking-label={trackingLabel}
386
+ /* Default announcement = what the column shows. A consumer's own
387
+ Radix `getValueLabel` (in `...props`) still wins. */
388
+ getValueLabel={() => valueText}
251
389
  max={max}
252
390
  /* Always a number, never null: null is how Radix marks a bar
253
391
  indeterminate and drops aria-valuenow, and this bar is always
254
392
  measuring something. A value-less bar is a placeholder row — it
255
393
  keeps the layout and shows "–" — so it stays determinate rather
256
394
  than being announced as indeterminate over an empty track. */
257
- value={value ?? 0}
395
+ value={clampedValue}
258
396
  {...props}
259
397
  >
260
398
  <ProgressPrimitive.Indicator asChild>
@@ -289,7 +427,7 @@ const Progress = React.forwardRef<
289
427
  data-slot="progress-wrapper"
290
428
  >
291
429
  {hasVisibleLabel && (
292
- <span
430
+ <div
293
431
  // Fixed column: `shrink-0` + explicit width. Long labels wrap
294
432
  // (`break-words` also splits a single overlong word) instead of
295
433
  // pushing the bar around.
@@ -298,6 +436,9 @@ const Progress = React.forwardRef<
298
436
  // `auto`: hug the text but never take more than 40% of the row,
299
437
  // so an overlong label still wraps instead of squeezing the bar.
300
438
  labelHugs && "max-w-2/5",
439
+ // A node label (Rating, icon) sits on the row's centre line like
440
+ // text would; text keeps inline flow so it can wrap.
441
+ !labelIsText && "flex items-center",
301
442
  sizeStyles.text
302
443
  )}
303
444
  data-label-width={labelHugs ? "auto" : undefined}
@@ -306,7 +447,7 @@ const Progress = React.forwardRef<
306
447
  style={labelHugs ? undefined : { width: labelWidth }}
307
448
  >
308
449
  {label}
309
- </span>
450
+ </div>
310
451
  )}
311
452
  {progressBar}
312
453
  {showValue && (
@@ -318,24 +459,33 @@ const Progress = React.forwardRef<
318
459
  data-slot="progress-value"
319
460
  >
320
461
  {/*
321
- Invisible sizer holding the widest value this row can show
322
- (`100%`, `100 / 100 steps`), stacked under the real value in the
323
- same grid cell. Every row with the same `max`/`unit` gets the same
324
- value-column width — never below the 40px `min-w-10` floor that
325
- the Figma component also uses — so bars end at the same x-position.
462
+ Invisible sizers holding the value text at both extremes of the
463
+ scale (`0%` / `100%`, `0 / 100 steps` / `100 / 100 steps`,
464
+ `60 min left` / `0 min left`), stacked under the real value in
465
+ the same grid cell, so the cell takes the wider one. Every row
466
+ with the same `max`/`unit`/formatter gets the same value-column
467
+ width — never below the 40px `min-w-10` floor that the Figma
468
+ component also uses — so bars end at the same x-position.
326
469
  */}
327
470
  <span
328
471
  aria-hidden="true"
329
472
  className="invisible col-start-1 row-start-1"
330
473
  data-slot="progress-value-sizer"
331
474
  >
332
- {formatProgressValue(max, max, unit)}
475
+ {formatValue(max, max)}
476
+ </span>
477
+ <span
478
+ aria-hidden="true"
479
+ className="invisible col-start-1 row-start-1"
480
+ data-slot="progress-value-sizer-min"
481
+ >
482
+ {formatValue(0, max)}
333
483
  </span>
334
484
  <span
335
485
  className="col-start-1 row-start-1"
336
486
  data-slot="progress-value-text"
337
487
  >
338
- {formatProgressValue(value, max, unit)}
488
+ {valueText}
339
489
  </span>
340
490
  </span>
341
491
  )}
@@ -349,4 +499,13 @@ const Progress = React.forwardRef<
349
499
  Progress.displayName = "Progress";
350
500
 
351
501
  export { Progress };
352
- export type { ProgressProps, ProgressColor, ProgressSize, ProgressLabelWidth };
502
+ export type {
503
+ ProgressProps,
504
+ ProgressStrictProps,
505
+ ProgressBaseProps,
506
+ ProgressColor,
507
+ ProgressSize,
508
+ ProgressLabelWidth,
509
+ ProgressValueFormatter,
510
+ ProgressNodeLabel,
511
+ };
@@ -111,7 +111,7 @@ const Rating = React.forwardRef<HTMLDivElement, RatingProps>(
111
111
  }}
112
112
  >
113
113
  <StarRating
114
- className="fill-yellow-400 stroke-yellow-400"
114
+ className="fill-rating stroke-rating"
115
115
  size={starSize}
116
116
  />
117
117
  </div>
@@ -0,0 +1,230 @@
1
+ "use client";
2
+
3
+ import { forwardRef, useEffect, useState } from "react";
4
+ import { cn } from "@brightlocal/ui-components/lib/utils";
5
+ import {
6
+ Tooltip,
7
+ TooltipContent,
8
+ TooltipTrigger,
9
+ } from "@brightlocal/ui-components/tooltip";
10
+
11
+ export interface RelativeDateLabels {
12
+ /** @default "just now" */
13
+ justNow: string;
14
+ /** @default "1 minute ago" */
15
+ minuteAgo: string;
16
+ /**
17
+ * `{n}` is replaced with the count.
18
+ * @default "{n} minutes ago"
19
+ */
20
+ minutesAgo: string;
21
+ /** @default "1 hour ago" */
22
+ hourAgo: string;
23
+ /**
24
+ * `{n}` is replaced with the count.
25
+ * @default "{n} hours ago"
26
+ */
27
+ hoursAgo: string;
28
+ /** @default "today" */
29
+ today: string;
30
+ /** @default "yesterday" */
31
+ yesterday: string;
32
+ /**
33
+ * `{n}` is replaced with the count.
34
+ * @default "{n} days ago"
35
+ */
36
+ daysAgo: string;
37
+ /** @default "unknown" */
38
+ unknown: string;
39
+ }
40
+
41
+ export const DEFAULT_RELATIVE_DATE_LABELS: RelativeDateLabels = {
42
+ justNow: "just now",
43
+ minuteAgo: "1 minute ago",
44
+ minutesAgo: "{n} minutes ago",
45
+ hourAgo: "1 hour ago",
46
+ hoursAgo: "{n} hours ago",
47
+ today: "today",
48
+ yesterday: "yesterday",
49
+ daysAgo: "{n} days ago",
50
+ unknown: "unknown",
51
+ };
52
+
53
+ export interface RelativeDateProps {
54
+ /**
55
+ * When it happened. An ISO 8601 timestamp (UTC from the API) or a Date for
56
+ * a value with a time of day; a plain `YYYY-MM-DD` string for a calendar
57
+ * date with no time of day. `null` or `undefined` renders the `unknown`
58
+ * label, plain.
59
+ */
60
+ value: string | Date | null | undefined;
61
+ /**
62
+ * Contextual label rendered before the value (e.g. "Last updated").
63
+ * The component owns its styling — consumers never need to style it.
64
+ */
65
+ label?: string;
66
+ /**
67
+ * Translatable words. Each key defaults to its English value.
68
+ * @default DEFAULT_RELATIVE_DATE_LABELS
69
+ */
70
+ labels?: Partial<RelativeDateLabels>;
71
+ /** Outer layout only (margin, placement). The look is the component's. */
72
+ className?: string;
73
+ /** Required test hook identifier */
74
+ dataHook: string;
75
+ /** Analytics element identifier */
76
+ trackingEl?: string;
77
+ /** Analytics label */
78
+ trackingLabel?: string;
79
+ }
80
+
81
+ const SECOND = 1000;
82
+ const MINUTE = 60 * SECOND;
83
+ const HOUR = 60 * MINUTE;
84
+ const DAY = 24 * HOUR;
85
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
86
+
87
+ export function isDateOnly(value: string | Date): boolean {
88
+ return typeof value === "string" && DATE_ONLY.test(value);
89
+ }
90
+
91
+ export function toDate(value: string | Date): Date {
92
+ if (value instanceof Date) return value;
93
+ return new Date(isDateOnly(value) ? `${value}T00:00:00` : value);
94
+ }
95
+
96
+ const startOfDay = (d: Date) =>
97
+ new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
98
+
99
+ const fill = (label: string, n: number) => label.replace("{n}", String(n));
100
+
101
+ export function dateLabel(date: Date, now = new Date()): string {
102
+ return date.toLocaleDateString("en-US", {
103
+ month: "long",
104
+ day: "numeric",
105
+ ...(date.getFullYear() === now.getFullYear() ? {} : { year: "numeric" }),
106
+ });
107
+ }
108
+
109
+ export function exactText(date: Date, dateOnly: boolean): string {
110
+ const day = date.toLocaleDateString("en-US", {
111
+ month: "long",
112
+ day: "numeric",
113
+ year: "numeric",
114
+ });
115
+ if (dateOnly) return day;
116
+ const time = date.toLocaleTimeString("en-US", {
117
+ hour: "numeric",
118
+ minute: "2-digit",
119
+ });
120
+ const offsetMinutes = -date.getTimezoneOffset();
121
+ const sign = offsetMinutes >= 0 ? "+" : "-";
122
+ const hours = Math.floor(Math.abs(offsetMinutes) / 60);
123
+ const minutes = Math.abs(offsetMinutes) % 60;
124
+ const offset = `${sign}${hours}${minutes ? `:${String(minutes).padStart(2, "0")}` : ""}`;
125
+ return `${day} at ${time} UTC${offset}`;
126
+ }
127
+
128
+ export function relativeWords(
129
+ value: string | Date,
130
+ now: Date,
131
+ labels: RelativeDateLabels = DEFAULT_RELATIVE_DATE_LABELS
132
+ ): string {
133
+ const date = toDate(value);
134
+ if (isDateOnly(value)) {
135
+ const days = Math.max(
136
+ 0,
137
+ Math.round((startOfDay(now) - startOfDay(date)) / DAY)
138
+ );
139
+ if (days === 0) return labels.today;
140
+ if (days === 1) return labels.yesterday;
141
+ if (days < 7) return fill(labels.daysAgo, days);
142
+ return dateLabel(date, now);
143
+ }
144
+ const distance = Math.max(0, now.getTime() - date.getTime());
145
+ const s = distance / SECOND;
146
+ const min = distance / MINUTE;
147
+ const h = distance / HOUR;
148
+ const d = distance / DAY;
149
+ if (s < 45) return labels.justNow;
150
+ if (s < 90) return labels.minuteAgo;
151
+ if (min < 45) return fill(labels.minutesAgo, Math.round(min));
152
+ if (min < 90) return labels.hourAgo;
153
+ if (h < 22) return fill(labels.hoursAgo, Math.round(h));
154
+ if (h < 36) return labels.yesterday;
155
+ if (d < 7) return fill(labels.daysAgo, Math.round(d));
156
+ return dateLabel(date, now);
157
+ }
158
+
159
+ export function useNow(every = 30 * SECOND): Date {
160
+ const [now, setNow] = useState(() => new Date());
161
+ useEffect(() => {
162
+ const tick = () => setNow(new Date());
163
+ const id = window.setInterval(tick, every);
164
+ const onVisible = () => {
165
+ if (document.visibilityState === "visible") tick();
166
+ };
167
+ document.addEventListener("visibilitychange", onVisible);
168
+ return () => {
169
+ window.clearInterval(id);
170
+ document.removeEventListener("visibilitychange", onVisible);
171
+ };
172
+ }, [every]);
173
+ return now;
174
+ }
175
+
176
+ export const RelativeDate = forwardRef<HTMLElement, RelativeDateProps>(
177
+ function RelativeDate(
178
+ { value, label, labels, className, dataHook, trackingEl, trackingLabel },
179
+ ref
180
+ ) {
181
+ const now = useNow();
182
+ const words = { ...DEFAULT_RELATIVE_DATE_LABELS, ...labels };
183
+
184
+ if (value === null || value === undefined) {
185
+ return (
186
+ <span
187
+ ref={ref as React.Ref<HTMLSpanElement>}
188
+ className={cn("text-body-xs text-muted-foreground", className)}
189
+ data-hook={dataHook}
190
+ data-slot="relative-date"
191
+ data-tracking-el={trackingEl}
192
+ data-tracking-label={trackingLabel}
193
+ >
194
+ {label && <>{label} </>}
195
+ {words.unknown}
196
+ </span>
197
+ );
198
+ }
199
+
200
+ const dateOnly = isDateOnly(value);
201
+ const date = toDate(value);
202
+ const iso = dateOnly
203
+ ? `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`
204
+ : date.toISOString();
205
+
206
+ return (
207
+ <span
208
+ ref={ref as React.Ref<HTMLSpanElement>}
209
+ className={cn("text-body-xs text-muted-foreground", className)}
210
+ data-hook={dataHook}
211
+ data-slot="relative-date"
212
+ data-tracking-el={trackingEl}
213
+ data-tracking-label={trackingLabel}
214
+ >
215
+ {label && <>{label} </>}
216
+ <Tooltip>
217
+ <TooltipTrigger
218
+ className="focus-visible:shadow-default cursor-default rounded-xs underline decoration-dotted decoration-1 underline-offset-4 focus-visible:outline-none"
219
+ dataHook={`${dataHook}-trigger`}
220
+ >
221
+ <time dateTime={iso}>{relativeWords(value, now, words)}</time>
222
+ </TooltipTrigger>
223
+ <TooltipContent dataHook={`${dataHook}-tooltip`} side="bottom">
224
+ {exactText(date, dateOnly)}
225
+ </TooltipContent>
226
+ </Tooltip>
227
+ </span>
228
+ );
229
+ }
230
+ );