@brightlocal/ui-components 2.20.0 → 2.22.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 (66) hide show
  1. package/AI_USAGE.md +2 -0
  2. package/README.md +26 -13
  3. package/component-meta.json +41 -14
  4. package/dist/blocks/data-table.cjs +1 -1
  5. package/dist/blocks/data-table.d.ts +35 -3
  6. package/dist/blocks/data-table.d.ts.map +1 -1
  7. package/dist/blocks/data-table.js +178 -154
  8. package/dist/blocks/sidebar.cjs +1 -1
  9. package/dist/blocks/sidebar.d.ts +2 -2
  10. package/dist/blocks/sidebar.js +18 -18
  11. package/dist/breadcrumb.cjs +1 -1
  12. package/dist/breadcrumb.d.ts +1 -1
  13. package/dist/breadcrumb.d.ts.map +1 -1
  14. package/dist/breadcrumb.js +9 -6
  15. package/dist/button.cjs +1 -1
  16. package/dist/button.d.ts.map +1 -1
  17. package/dist/button.js +12 -12
  18. package/dist/hover-card.cjs +1 -1
  19. package/dist/hover-card.d.ts.map +1 -1
  20. package/dist/hover-card.js +45 -45
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +69 -68
  23. package/dist/lib/utils.cjs +1 -1
  24. package/dist/lib/utils.d.ts +1 -0
  25. package/dist/lib/utils.d.ts.map +1 -1
  26. package/dist/lib/utils.js +7 -5
  27. package/dist/logo.cjs +1 -1
  28. package/dist/logo.d.ts +1 -1
  29. package/dist/logo.js +2 -2
  30. package/dist/navigation-menu.cjs +1 -1
  31. package/dist/navigation-menu.d.ts +17 -0
  32. package/dist/navigation-menu.d.ts.map +1 -1
  33. package/dist/navigation-menu.js +120 -90
  34. package/dist/pagination.cjs +1 -1
  35. package/dist/pagination.d.ts +12 -8
  36. package/dist/pagination.d.ts.map +1 -1
  37. package/dist/pagination.js +117 -113
  38. package/dist/progress.cjs +1 -1
  39. package/dist/progress.d.ts +28 -2
  40. package/dist/progress.d.ts.map +1 -1
  41. package/dist/progress.js +90 -49
  42. package/dist/skeleton.cjs +1 -1
  43. package/dist/skeleton.js +1 -1
  44. package/dist/sonner.d.ts +1 -1
  45. package/dist/table.cjs +1 -1
  46. package/dist/table.d.ts +22 -2
  47. package/dist/table.d.ts.map +1 -1
  48. package/dist/table.js +57 -43
  49. package/dist/tooltip.cjs +1 -1
  50. package/dist/tooltip.d.ts.map +1 -1
  51. package/dist/tooltip.js +36 -36
  52. package/package.json +7 -3
  53. package/src/blocks/data-table.tsx +56 -4
  54. package/src/blocks/sidebar.tsx +5 -5
  55. package/src/components/breadcrumb.tsx +6 -3
  56. package/src/components/button.tsx +7 -1
  57. package/src/components/hover-card.tsx +6 -3
  58. package/src/components/logo.tsx +3 -3
  59. package/src/components/navigation-menu.tsx +113 -32
  60. package/src/components/pagination.tsx +47 -67
  61. package/src/components/progress.tsx +118 -14
  62. package/src/components/skeleton.tsx +1 -1
  63. package/src/components/sonner.tsx +1 -1
  64. package/src/components/table.tsx +44 -7
  65. package/src/components/tooltip.tsx +8 -5
  66. package/src/lib/utils.ts +3 -0
@@ -15,12 +15,20 @@ interface NavigationMenuProps extends React.ComponentPropsWithoutRef<
15
15
  > {
16
16
  dataHook: string;
17
17
  className?: string;
18
+ /**
19
+ * Delay in ms before a hovered trigger opens its menu. Overrides Radix's
20
+ * laggy 200ms default with Base UI's snappier value.
21
+ * @default 50
22
+ */
23
+ delayDuration?: number;
18
24
  }
19
25
 
20
26
  const NavigationMenu = React.forwardRef<
21
27
  React.ElementRef<typeof NavigationMenuPrimitive.Root>,
22
28
  NavigationMenuProps
23
- >(({ className, children, dataHook, ...props }, ref) => (
29
+ >(({ className, children, dataHook, delayDuration = 50, ...props }, ref) => (
30
+ // Radix defaults delayDuration to 200ms, which reads as a laggy hover-open.
31
+ // Match Base UI's snappier 50ms default (still overridable via props).
24
32
  <NavigationMenuPrimitive.Root
25
33
  ref={ref}
26
34
  className={cn(
@@ -29,6 +37,7 @@ const NavigationMenu = React.forwardRef<
29
37
  )}
30
38
  data-hook={dataHook}
31
39
  data-slot="navigation-menu"
40
+ delayDuration={delayDuration}
32
41
  {...props}
33
42
  >
34
43
  {children}
@@ -82,42 +91,104 @@ type NavigationMenuTriggerProps = React.ComponentPropsWithoutRef<
82
91
  typeof NavigationMenuPrimitive.Trigger
83
92
  >;
84
93
 
94
+ /**
95
+ * Window (ms) after the pointer enters an open trigger during which a mouse
96
+ * click is treated as instinctive and is NOT allowed to close the menu. Based
97
+ * on Base UI's "patient click" threshold (PATIENT_CLICK_THRESHOLD = 500), tuned
98
+ * slightly shorter so the trigger becomes a deliberate toggle a touch sooner.
99
+ */
100
+ const PATIENT_CLICK_THRESHOLD_MS = 400;
101
+
85
102
  /**
86
103
  * Trigger button that opens a dropdown menu
87
104
  * Includes chevron icon that rotates when open
105
+ *
106
+ * Radix opens the menu on hover and then *toggles it closed* on the next click.
107
+ * Mouse users routinely click a trigger they have just hovered open, which
108
+ * closes it immediately (see radix-ui/primitives#1630).
109
+ *
110
+ * We port Base UI's "patient click" behaviour: an instinctive mouse click made
111
+ * within {@link PATIENT_CLICK_THRESHOLD_MS} of the pointer entering an open
112
+ * trigger keeps the menu open (calling `preventDefault()` makes Radix's internal
113
+ * `composeEventHandlers` skip its toggle). A deliberate click after that window
114
+ * still toggles the menu shut, and touch taps and keyboard activation are left
115
+ * untouched so they can toggle it too.
88
116
  */
89
117
  const NavigationMenuTrigger = React.forwardRef<
90
118
  React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
91
119
  NavigationMenuTriggerProps
92
- >(({ className, children, ...props }, ref) => (
93
- <NavigationMenuPrimitive.Trigger
94
- ref={ref}
95
- className={cn(
96
- [
97
- "group inline-flex h-9 w-max items-center justify-center gap-1",
98
- "rounded-md px-4 py-2",
99
- "text-sm font-medium",
100
- "text-foreground",
101
- "transition-colors",
102
- "hover:bg-accent hover:text-accent-foreground",
103
- "focus:bg-accent focus:text-accent-foreground",
104
- "focus-visible:bg-accent focus-visible:ring-ring focus-visible:shadow-[0_0_0_4px_rgba(163,163,163,0.1)] focus-visible:ring-1 focus-visible:outline-none",
105
- "disabled:pointer-events-none disabled:opacity-50",
106
- "data-[state=open]:bg-accent/50",
107
- ],
108
- className
109
- )}
110
- data-slot="navigation-menu-trigger"
111
- {...props}
112
- >
113
- {children}
114
- <ChevronDown
115
- aria-hidden="true"
116
- className="relative top-[1px] ml-1 transition duration-300 group-data-[state=open]:rotate-180"
117
- size={12}
118
- />
119
- </NavigationMenuPrimitive.Trigger>
120
- ));
120
+ >(
121
+ (
122
+ { className, children, onClick, onPointerDown, onPointerEnter, ...props },
123
+ ref
124
+ ) => {
125
+ // Pointer type of the interaction, so the keep-open behaviour only applies
126
+ // to mouse (the only input that hover-opens before a click).
127
+ const lastPointerTypeRef = React.useRef<string>("");
128
+ // Timestamp of the last pointer enter, used to measure whether a click is
129
+ // "instinctive" (right after hover) or "patient" (deliberate). Captured from
130
+ // the SAME `event.timeStamp` clock the click uses so the subtraction is
131
+ // valid — never compare against `performance.now()`, which is a different
132
+ // origin and makes every click read as "patient" (i.e. always closes).
133
+ const pointerEnterAtRef = React.useRef(0);
134
+
135
+ return (
136
+ <NavigationMenuPrimitive.Trigger
137
+ ref={ref}
138
+ className={cn(
139
+ [
140
+ "group inline-flex h-9 w-max items-center justify-center gap-1",
141
+ "rounded-md px-4 py-2",
142
+ "text-sm font-medium",
143
+ "text-foreground",
144
+ "transition-colors",
145
+ "hover:bg-accent hover:text-accent-foreground",
146
+ "focus:bg-accent focus:text-accent-foreground",
147
+ "focus-visible:bg-accent focus-visible:ring-ring focus-visible:shadow-[0_0_0_4px_rgba(163,163,163,0.1)] focus-visible:ring-1 focus-visible:outline-none",
148
+ "disabled:pointer-events-none disabled:opacity-50",
149
+ "data-[state=open]:bg-accent/50",
150
+ ],
151
+ className
152
+ )}
153
+ data-slot="navigation-menu-trigger"
154
+ onClick={(event) => {
155
+ // `data-state` is "open" only when hover already opened this trigger.
156
+ // `event.detail > 0` excludes keyboard-synthesised clicks (detail === 0).
157
+ const isOpen =
158
+ event.currentTarget.getAttribute("data-state") === "open";
159
+ const isInstinctiveClick =
160
+ event.timeStamp - pointerEnterAtRef.current <
161
+ PATIENT_CLICK_THRESHOLD_MS;
162
+ if (
163
+ lastPointerTypeRef.current === "mouse" &&
164
+ event.detail > 0 &&
165
+ isOpen &&
166
+ isInstinctiveClick
167
+ ) {
168
+ event.preventDefault();
169
+ }
170
+ onClick?.(event);
171
+ }}
172
+ onPointerDown={(event) => {
173
+ lastPointerTypeRef.current = event.pointerType;
174
+ onPointerDown?.(event);
175
+ }}
176
+ onPointerEnter={(event) => {
177
+ pointerEnterAtRef.current = event.timeStamp;
178
+ onPointerEnter?.(event);
179
+ }}
180
+ {...props}
181
+ >
182
+ {children}
183
+ <ChevronDown
184
+ aria-hidden="true"
185
+ className="relative top-[1px] ml-1 transition duration-300 group-data-[state=open]:rotate-180"
186
+ size={12}
187
+ />
188
+ </NavigationMenuPrimitive.Trigger>
189
+ );
190
+ }
191
+ );
121
192
 
122
193
  NavigationMenuTrigger.displayName = "NavigationMenuTrigger";
123
194
 
@@ -144,6 +215,10 @@ const NavigationMenuContent = React.forwardRef<
144
215
  "data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out",
145
216
  "data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52",
146
217
  "data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52",
218
+ // Match the viewport's easeOutQuint timing so the directional slide and
219
+ // the container morph feel like one motion (kept snappy so content
220
+ // appears without a perceptible fade-in delay).
221
+ "duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
147
222
  "md:absolute md:w-auto",
148
223
  ],
149
224
  className
@@ -205,8 +280,14 @@ const NavigationMenuViewport = React.forwardRef<
205
280
  [
206
281
  "origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)]",
207
282
  "bg-popover text-popover-foreground w-full overflow-hidden rounded-md border shadow-sm",
208
- "data-[state=open]:animate-in data-[state=closed]:animate-out",
209
- "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90",
283
+ // Base UI-style size morph: smoothly animate width/height between items
284
+ // with an easeOutQuint curve. The enter/exit stays snappy (200ms in,
285
+ // 150ms out) so the panel and its content appear immediately rather
286
+ // than fading in slowly. Reduced motion is neutralised globally by the
287
+ // token preset, so no per-element motion-reduce guard is needed.
288
+ "transition-[width,height] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
289
+ "data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
290
+ "data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:duration-150",
210
291
  "md:w-[var(--radix-navigation-menu-viewport-width)]",
211
292
  ],
212
293
  className
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import { ChevronLeft, ChevronRight, MoreHorizontal } from "@brightlocal/icons";
3
3
  import { cva, type VariantProps } from "class-variance-authority";
4
4
  import { cn } from "@brightlocal/ui-components/lib/utils";
5
+ import { useIsBelowBreakpoint } from "@brightlocal/ui-components/hooks/use-breakpoint";
5
6
 
6
7
  /**
7
8
  * Pagination item variants
@@ -20,10 +21,6 @@ export interface UsePaginationParams {
20
21
  page: number;
21
22
  /** Total number of pages */
22
23
  totalPages: number;
23
- /** Number of siblings to show on each side of current page */
24
- siblingCount?: number;
25
- /** Number of boundary pages to show at start and end */
26
- boundaryCount?: number;
27
24
  }
28
25
 
29
26
  /**
@@ -32,88 +29,66 @@ export interface UsePaginationParams {
32
29
  type PaginationItemType = number | "previous" | "next" | "ellipsis";
33
30
 
34
31
  /**
35
- * Custom hook for pagination logic
36
- * Returns an ordered list of pagination items to render
32
+ * Custom hook for pagination logic.
33
+ * Returns a fixed-width list of pagination items — the count never changes
34
+ * as the user navigates. Page 1 and totalPages are always visible as boundary
35
+ * anchors. Ellipsis only appears when hiding 2+ pages.
37
36
  *
38
37
  * @example
39
- * const items = usePagination({ page: 5, totalPages: 10, siblingCount: 1, boundaryCount: 1 });
38
+ * const items = usePagination({ page: 2, totalPages: 10 });
39
+ * // Returns: ["previous", 1, 2, 3, 4, 5, "ellipsis", 10, "next"]
40
+ *
41
+ * const items = usePagination({ page: 5, totalPages: 10 });
40
42
  * // Returns: ["previous", 1, "ellipsis", 4, 5, 6, "ellipsis", 10, "next"]
43
+ *
44
+ * // Automatically uses 5 slots below the `sm` breakpoint (640px)
45
+ * const items = usePagination({ page, totalPages });
41
46
  */
42
47
  export function usePagination({
43
48
  page,
44
49
  totalPages,
45
- siblingCount = 1,
46
- boundaryCount = 1,
47
50
  }: UsePaginationParams): PaginationItemType[] {
51
+ const isCompact = useIsBelowBreakpoint("sm");
52
+ const maxVisible = isCompact ? 5 : 7;
53
+
48
54
  const items: PaginationItemType[] = React.useMemo(() => {
55
+ const slots = Math.max(5, maxVisible);
49
56
  const result: PaginationItemType[] = [];
50
57
 
51
- // Add previous button
52
58
  result.push("previous");
53
59
 
54
- // Calculate ranges
55
- const leftSiblingIndex = Math.max(page - siblingCount, boundaryCount + 1);
56
- const rightSiblingIndex = Math.min(
57
- page + siblingCount,
58
- totalPages - boundaryCount
59
- );
60
-
61
- const showLeftEllipsis = leftSiblingIndex > boundaryCount + 2;
62
- const showRightEllipsis =
63
- rightSiblingIndex < totalPages - boundaryCount - 1;
64
-
65
- // Add first boundary pages
66
- for (let i = 1; i <= Math.min(boundaryCount, totalPages); i++) {
67
- result.push(i);
68
- }
69
-
70
- // Add left ellipsis if needed
71
- if (showLeftEllipsis) {
72
- result.push("ellipsis");
73
- } else if (boundaryCount + 1 < leftSiblingIndex) {
74
- // Add pages between boundary and left sibling
75
- for (let i = boundaryCount + 1; i < leftSiblingIndex; i++) {
76
- result.push(i);
77
- }
78
- }
79
-
80
- // Add sibling pages around current page
81
- for (let i = leftSiblingIndex; i <= rightSiblingIndex; i++) {
82
- if (i > boundaryCount && i <= totalPages - boundaryCount) {
60
+ if (totalPages <= slots) {
61
+ for (let i = 1; i <= totalPages; i++) {
83
62
  result.push(i);
84
63
  }
85
- }
86
-
87
- // Add right ellipsis if needed
88
- if (showRightEllipsis) {
89
- result.push("ellipsis");
90
- } else if (rightSiblingIndex < totalPages - boundaryCount) {
91
- // Add pages between right sibling and boundary
92
- for (
93
- let i = rightSiblingIndex + 1;
94
- i < totalPages - boundaryCount + 1;
95
- i++
96
- ) {
97
- result.push(i);
98
- }
99
- }
100
-
101
- // Add last boundary pages
102
- for (
103
- let i = Math.max(totalPages - boundaryCount + 1, boundaryCount + 1);
104
- i <= totalPages;
105
- i++
106
- ) {
107
- if (i > boundaryCount) {
108
- result.push(i);
64
+ } else {
65
+ const siblings = Math.floor((slots - 5) / 2);
66
+ const startThreshold = slots - 3; // e.g. 4 for slots=7, 2 for slots=5
67
+ const endThreshold = totalPages - startThreshold;
68
+
69
+ if (page <= startThreshold) {
70
+ for (let i = 1; i <= slots - 2; i++) {
71
+ result.push(i);
72
+ }
73
+ result.push("ellipsis", totalPages);
74
+ } else if (page >= endThreshold) {
75
+ result.push(1, "ellipsis");
76
+ for (let i = totalPages - (slots - 3); i <= totalPages; i++) {
77
+ result.push(i);
78
+ }
79
+ } else {
80
+ result.push(1, "ellipsis");
81
+ for (let i = page - siblings; i <= page + siblings; i++) {
82
+ result.push(i);
83
+ }
84
+ result.push("ellipsis", totalPages);
109
85
  }
110
86
  }
111
87
 
112
- // Add next button
113
88
  result.push("next");
114
89
 
115
90
  return result;
116
- }, [page, totalPages, siblingCount, boundaryCount]);
91
+ }, [page, totalPages, maxVisible]);
117
92
 
118
93
  return items;
119
94
  }
@@ -125,7 +100,7 @@ const paginationItemVariants = cva(
125
100
  "h-9 w-9",
126
101
  "rounded-full",
127
102
  "text-sm font-medium",
128
- "transition-colors",
103
+ "transition-colors duration-200 ease-out",
129
104
  "focus-visible:outline-none focus-visible:shadow-default",
130
105
  ],
131
106
  {
@@ -154,7 +129,12 @@ const paginationItemVariants = cva(
154
129
  // Disabled state
155
130
  "aria-disabled:opacity-50 aria-disabled:cursor-default aria-disabled:pointer-events-none",
156
131
  ],
157
- ellipsis: ["cursor-default", "text-foreground", "pointer-events-none"],
132
+ ellipsis: [
133
+ "relative",
134
+ "cursor-default",
135
+ "text-foreground",
136
+ "pointer-events-none",
137
+ ],
158
138
  },
159
139
  },
160
140
  defaultVariants: {
@@ -7,6 +7,71 @@ import { motion } from "framer-motion";
7
7
  import { cn } from "@brightlocal/ui-components/lib/utils";
8
8
  import { usePrefersReducedMotion } from "@brightlocal/ui-components/hooks/use-prefers-reduced-motion";
9
9
 
10
+ /**
11
+ * Brand color for the progress indicator, drawn from the shared brand palette.
12
+ * - `green` — strong / healthy / complete
13
+ * - `yellow` — moderate / acceptable
14
+ * - `orange` — weak / needs attention
15
+ * - `red` — critical / urgent
16
+ */
17
+ type ProgressColor = "green" | "red" | "orange" | "yellow";
18
+
19
+ /**
20
+ * Track and indicator color classes for each brand color.
21
+ * Single source of truth — the `/20` track tint blends with the surface so it
22
+ * adapts automatically to light and dark modes.
23
+ */
24
+ const COLOR_STYLES: Record<
25
+ ProgressColor,
26
+ { track: string; indicator: string }
27
+ > = {
28
+ green: {
29
+ track: "bg-brand-primary-foreground/20",
30
+ indicator: "bg-green-400",
31
+ },
32
+ red: {
33
+ track: "bg-brand-red/20",
34
+ indicator: "bg-brand-red",
35
+ },
36
+ orange: {
37
+ track: "bg-brand-orange/20",
38
+ indicator: "bg-brand-orange",
39
+ },
40
+ yellow: {
41
+ track: "bg-brand-yellow/20",
42
+ indicator: "bg-brand-yellow",
43
+ },
44
+ };
45
+
46
+ /**
47
+ * Formats the numeric value shown beside the progress bar.
48
+ * - Percentage form (`unit === "%"`): the value as a percentage of `max`,
49
+ * clamped to 0–100 to match the bar fill, e.g. `90` of `100` → `"90%"`,
50
+ * `3` of `5` → `"60%"`
51
+ * - Fraction form (any other unit): `"3 / 5 steps"`, `"45 / 60 min"`, `"90 / 100"`
52
+ * - No value: falls back to `"–"` so the row layout stays consistent.
53
+ * @param value - Current progress value.
54
+ * @param max - Maximum progress value (denominator).
55
+ * @param unit - Optional unit/suffix, e.g. `"%"`, `"steps"`, `"min"`.
56
+ */
57
+ function formatProgressValue(
58
+ value: number | null | undefined,
59
+ max: number,
60
+ unit: string
61
+ ): string {
62
+ if (value === null || value === undefined) {
63
+ return "–";
64
+ }
65
+ if (unit === "%") {
66
+ const percentage =
67
+ max > 0 ? Math.min(100, Math.max(0, Math.round((value / max) * 100))) : 0;
68
+ return `${percentage}%`;
69
+ }
70
+ // Only show the denominator when max is a meaningful positive number.
71
+ const suffix = unit ? ` ${unit}` : "";
72
+ return max > 0 ? `${value} / ${max}${suffix}` : `${value}${suffix}`;
73
+ }
74
+
10
75
  /**
11
76
  * Props for the Progress component.
12
77
  */
@@ -31,9 +96,27 @@ interface ProgressProps extends React.ComponentProps<
31
96
  */
32
97
  ariaLabel?: string;
33
98
  /**
34
- * Optional visible label text displayed above the progress bar
99
+ * Optional visible label text displayed to the left of the progress bar
35
100
  */
36
101
  label?: string;
102
+ /**
103
+ * Brand color for the indicator.
104
+ * @default "green"
105
+ */
106
+ color?: ProgressColor;
107
+ /**
108
+ * Whether to render the numeric value to the right of the progress bar.
109
+ * Falls back to `–` when no value is provided so the layout stays consistent.
110
+ * @default false
111
+ */
112
+ showValue?: boolean;
113
+ /**
114
+ * Unit/suffix appended to the displayed value. Use `"%"` for percentage form
115
+ * (value as a percentage of `max`, e.g. `90%`); any other unit renders
116
+ * fraction form (`3 / 5 steps`).
117
+ * @default "%"
118
+ */
119
+ unit?: string;
37
120
  /**
38
121
  * Custom class name for the indicator (progress fill)
39
122
  * Use this to customize the color, e.g., "bg-red-500"
@@ -58,11 +141,15 @@ const Progress = React.forwardRef<
58
141
  {
59
142
  className,
60
143
  value,
144
+ max = 100,
61
145
  dataHook,
62
146
  trackingEl,
63
147
  trackingLabel,
64
148
  ariaLabel = "Progress",
65
149
  label,
150
+ color = "green",
151
+ showValue = false,
152
+ unit = "%",
66
153
  indicatorClassName,
67
154
  disabled,
68
155
  ...props
@@ -73,6 +160,10 @@ const Progress = React.forwardRef<
73
160
  const hasVisibleLabel = !!label;
74
161
  const prefersReducedMotion = usePrefersReducedMotion();
75
162
 
163
+ const colorStyles = COLOR_STYLES[color] ?? COLOR_STYLES.green;
164
+ const percentage =
165
+ max > 0 ? Math.min(100, Math.max(0, ((value ?? 0) / max) * 100)) : 0;
166
+
76
167
  const progressBar = (
77
168
  <ProgressPrimitive.Root
78
169
  ref={ref}
@@ -80,23 +171,26 @@ const Progress = React.forwardRef<
80
171
  aria-labelledby={hasVisibleLabel ? labelId : undefined}
81
172
  className={cn(
82
173
  "relative h-2 w-full overflow-hidden rounded-full",
83
- "bg-primary/20",
84
- !hasVisibleLabel && disabled && "opacity-50",
174
+ colorStyles.track,
175
+ !hasVisibleLabel && !showValue && disabled && "opacity-50",
85
176
  className
86
177
  )}
87
178
  data-hook={dataHook}
88
179
  data-slot="progress"
89
180
  data-tracking-el={trackingEl}
90
181
  data-tracking-label={trackingLabel}
182
+ max={max}
183
+ value={value}
91
184
  {...props}
92
185
  >
93
186
  <ProgressPrimitive.Indicator asChild>
94
187
  <motion.div
95
188
  animate={{
96
- transform: `translateX(-${100 - (value || 0)}%)`,
189
+ transform: `translateX(-${100 - percentage}%)`,
97
190
  }}
98
191
  className={cn(
99
- "h-full w-full flex-1 bg-green-400",
192
+ "h-full w-full flex-1",
193
+ colorStyles.indicator,
100
194
  indicatorClassName
101
195
  )}
102
196
  data-slot="progress-indicator"
@@ -116,7 +210,7 @@ const Progress = React.forwardRef<
116
210
  </ProgressPrimitive.Root>
117
211
  );
118
212
 
119
- if (!label) {
213
+ if (!hasVisibleLabel && !showValue) {
120
214
  return progressBar;
121
215
  }
122
216
 
@@ -128,14 +222,24 @@ const Progress = React.forwardRef<
128
222
  )}
129
223
  data-slot="progress-wrapper"
130
224
  >
131
- <span
132
- className="text-foreground text-sm leading-normal font-medium"
133
- data-slot="progress-label"
134
- id={labelId}
135
- >
136
- {label}
137
- </span>
225
+ {hasVisibleLabel && (
226
+ <span
227
+ className="text-foreground text-xs leading-none font-medium"
228
+ data-slot="progress-label"
229
+ id={labelId}
230
+ >
231
+ {label}
232
+ </span>
233
+ )}
138
234
  {progressBar}
235
+ {showValue && (
236
+ <span
237
+ className="text-muted-foreground shrink-0 text-xs leading-none tabular-nums"
238
+ data-slot="progress-value"
239
+ >
240
+ {formatProgressValue(value, max, unit)}
241
+ </span>
242
+ )}
139
243
  </div>
140
244
  );
141
245
  }
@@ -144,4 +248,4 @@ const Progress = React.forwardRef<
144
248
  Progress.displayName = "Progress";
145
249
 
146
250
  export { Progress };
147
- export type { ProgressProps };
251
+ export type { ProgressProps, ProgressColor };
@@ -39,7 +39,7 @@ const Skeleton = React.forwardRef<HTMLDivElement, SkeletonProps>(
39
39
  <div
40
40
  ref={ref}
41
41
  aria-busy="true"
42
- className={cn("bg-accent animate-pulse rounded-md", className)}
42
+ className={cn("bg-accent relative animate-pulse rounded-md", className)}
43
43
  data-hook={dataHook}
44
44
  data-slot="skeleton"
45
45
  data-tracking-el={trackingEl}
@@ -402,7 +402,7 @@ Sonner.displayName = "Sonner";
402
402
  * // Show loading toast
403
403
  * sonner({
404
404
  * title: "Uploading...",
405
- * description: "Please wait while we upload your file.",
405
+ * description: "Uploading your file.",
406
406
  * icon: "loading",
407
407
  * id: loadingToastId
408
408
  * });