@brightlocal/ui-components 2.20.0 → 2.21.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.
- package/AI_USAGE.md +2 -0
- package/README.md +26 -13
- package/component-meta.json +20 -10
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +14 -16
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +2 -2
- package/dist/blocks/sidebar.js +18 -18
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +1 -1
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +9 -6
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +12 -12
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +1 -1
- package/dist/logo.js +2 -2
- package/dist/navigation-menu.cjs +1 -1
- package/dist/navigation-menu.d.ts +19 -0
- package/dist/navigation-menu.d.ts.map +1 -1
- package/dist/navigation-menu.js +134 -96
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +12 -8
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +117 -113
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +28 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +90 -49
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.js +1 -1
- package/dist/sonner.d.ts +1 -1
- package/package.json +7 -3
- package/src/blocks/data-table.tsx +0 -2
- package/src/blocks/sidebar.tsx +5 -5
- package/src/components/breadcrumb.tsx +6 -3
- package/src/components/button.tsx +7 -1
- package/src/components/logo.tsx +3 -3
- package/src/components/navigation-menu.tsx +134 -32
- package/src/components/pagination.tsx +47 -67
- package/src/components/progress.tsx +118 -14
- package/src/components/skeleton.tsx +1 -1
- package/src/components/sonner.tsx +1 -1
|
@@ -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
|
|
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
|
-
|
|
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 -
|
|
189
|
+
transform: `translateX(-${100 - percentage}%)`,
|
|
97
190
|
}}
|
|
98
191
|
className={cn(
|
|
99
|
-
"h-full w-full flex-1
|
|
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 (!
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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: "
|
|
405
|
+
* description: "Uploading your file.",
|
|
406
406
|
* icon: "loading",
|
|
407
407
|
* id: loadingToastId
|
|
408
408
|
* });
|