@brightlocal/ui-components 2.17.0 → 2.18.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 (65) hide show
  1. package/README.md +83 -1
  2. package/component-meta.json +20 -7
  3. package/dist/alert-dialog.cjs +1 -1
  4. package/dist/alert-dialog.d.ts +23 -2
  5. package/dist/alert-dialog.d.ts.map +1 -1
  6. package/dist/alert-dialog.js +21 -19
  7. package/dist/blocks/input-list.cjs +2 -2
  8. package/dist/blocks/input-list.d.ts.map +1 -1
  9. package/dist/blocks/input-list.js +64 -63
  10. package/dist/card.cjs +1 -1
  11. package/dist/card.d.ts +22 -2
  12. package/dist/card.d.ts.map +1 -1
  13. package/dist/card.js +93 -72
  14. package/dist/chip.cjs +1 -1
  15. package/dist/chip.d.ts.map +1 -1
  16. package/dist/chip.js +1 -7
  17. package/dist/dialog.cjs +1 -1
  18. package/dist/dialog.d.ts +23 -3
  19. package/dist/dialog.d.ts.map +1 -1
  20. package/dist/dialog.js +44 -42
  21. package/dist/dropdown-menu.cjs +1 -1
  22. package/dist/dropdown-menu.d.ts +10 -0
  23. package/dist/dropdown-menu.d.ts.map +1 -1
  24. package/dist/dropdown-menu.js +30 -29
  25. package/dist/field.cjs +1 -1
  26. package/dist/field.d.ts +5 -1
  27. package/dist/field.d.ts.map +1 -1
  28. package/dist/field.js +9 -7
  29. package/dist/hooks/use-prefers-reduced-motion.cjs +1 -1
  30. package/dist/hooks/use-prefers-reduced-motion.d.ts +25 -2
  31. package/dist/hooks/use-prefers-reduced-motion.d.ts.map +1 -1
  32. package/dist/hooks/use-prefers-reduced-motion.js +17 -11
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +38 -37
  35. package/dist/link.cjs +1 -1
  36. package/dist/link.d.ts +13 -2
  37. package/dist/link.d.ts.map +1 -1
  38. package/dist/link.js +110 -53
  39. package/dist/map.cjs +1 -1
  40. package/dist/map.d.ts.map +1 -1
  41. package/dist/map.js +1 -1
  42. package/dist/progress.cjs +1 -1
  43. package/dist/progress.d.ts.map +1 -1
  44. package/dist/progress.js +26 -25
  45. package/dist/rating.cjs +1 -1
  46. package/dist/rating.d.ts.map +1 -1
  47. package/dist/rating.js +27 -21
  48. package/dist/sheet.cjs +1 -1
  49. package/dist/sheet.d.ts +17 -2
  50. package/dist/sheet.d.ts.map +1 -1
  51. package/dist/sheet.js +29 -27
  52. package/package.json +1 -1
  53. package/src/blocks/input-list.tsx +8 -1
  54. package/src/components/alert-dialog.tsx +38 -4
  55. package/src/components/card.tsx +56 -9
  56. package/src/components/chip.tsx +1 -4
  57. package/src/components/dialog.tsx +39 -6
  58. package/src/components/dropdown-menu.tsx +7 -1
  59. package/src/components/field.tsx +6 -0
  60. package/src/components/link.tsx +103 -27
  61. package/src/components/map.tsx +1 -2
  62. package/src/components/progress.tsx +12 -6
  63. package/src/components/rating.tsx +4 -1
  64. package/src/components/sheet.tsx +30 -5
  65. package/src/hooks/use-prefers-reduced-motion.ts +35 -5
@@ -35,8 +35,8 @@ const DialogTrigger = React.forwardRef<
35
35
  >(({ dataHook, ...props }, ref) => (
36
36
  <DialogPrimitive.Trigger
37
37
  ref={ref}
38
- data-hook={dataHook}
39
38
  data-slot="dialog-trigger"
39
+ {...(dataHook != null && { "data-hook": dataHook })}
40
40
  {...props}
41
41
  />
42
42
  ));
@@ -191,34 +191,62 @@ const DialogFooter = React.forwardRef<
191
191
  ));
192
192
  DialogFooter.displayName = "DialogFooter";
193
193
 
194
+ /**
195
+ * Props for the DialogTitle component
196
+ */
197
+ interface DialogTitleProps extends React.ComponentProps<
198
+ typeof DialogPrimitive.Title
199
+ > {
200
+ /**
201
+ * Data hook for automated testing
202
+ * @example "dialog-title"
203
+ */
204
+ dataHook?: string;
205
+ }
206
+
194
207
  /**
195
208
  * DialogTitle - The title of the dialog
196
209
  * @description Renders an accessible title for the dialog
197
210
  */
198
211
  const DialogTitle = React.forwardRef<
199
212
  React.ComponentRef<typeof DialogPrimitive.Title>,
200
- React.ComponentProps<typeof DialogPrimitive.Title>
201
- >(({ className, ...props }, ref) => (
213
+ DialogTitleProps
214
+ >(({ className, dataHook, ...props }, ref) => (
202
215
  <DialogPrimitive.Title
203
216
  ref={ref}
204
217
  className={cn("text-lg leading-none font-semibold", className)}
218
+ data-hook={dataHook}
205
219
  data-slot="dialog-title"
206
220
  {...props}
207
221
  />
208
222
  ));
209
223
  DialogTitle.displayName = "DialogTitle";
210
224
 
225
+ /**
226
+ * Props for the DialogDescription component
227
+ */
228
+ interface DialogDescriptionProps extends React.ComponentProps<
229
+ typeof DialogPrimitive.Description
230
+ > {
231
+ /**
232
+ * Data hook for automated testing
233
+ * @example "dialog-description"
234
+ */
235
+ dataHook?: string;
236
+ }
237
+
211
238
  /**
212
239
  * DialogDescription - The description of the dialog
213
240
  * @description Renders an accessible description for the dialog
214
241
  */
215
242
  const DialogDescription = React.forwardRef<
216
243
  React.ComponentRef<typeof DialogPrimitive.Description>,
217
- React.ComponentProps<typeof DialogPrimitive.Description>
218
- >(({ className, ...props }, ref) => (
244
+ DialogDescriptionProps
245
+ >(({ className, dataHook, ...props }, ref) => (
219
246
  <DialogPrimitive.Description
220
247
  ref={ref}
221
248
  className={cn("text-muted-foreground text-sm", className)}
249
+ data-hook={dataHook}
222
250
  data-slot="dialog-description"
223
251
  {...props}
224
252
  />
@@ -238,4 +266,9 @@ export {
238
266
  DialogTrigger,
239
267
  };
240
268
 
241
- export type { DialogContentProps, DialogTriggerProps };
269
+ export type {
270
+ DialogContentProps,
271
+ DialogDescriptionProps,
272
+ DialogTitleProps,
273
+ DialogTriggerProps,
274
+ };
@@ -364,6 +364,11 @@ DropdownMenuRadioItem.displayName = "DropdownMenuRadioItem";
364
364
  type DropdownMenuLabelProps = React.ComponentPropsWithoutRef<
365
365
  typeof DropdownMenuPrimitive.Label
366
366
  > & {
367
+ /**
368
+ * Data hook for automated testing
369
+ * @example "dropdown-menu-label"
370
+ */
371
+ dataHook?: string;
367
372
  /**
368
373
  * Indent the label (for hierarchical menus)
369
374
  */
@@ -376,7 +381,7 @@ type DropdownMenuLabelProps = React.ComponentPropsWithoutRef<
376
381
  const DropdownMenuLabel = React.forwardRef<
377
382
  React.ComponentRef<typeof DropdownMenuPrimitive.Label>,
378
383
  DropdownMenuLabelProps
379
- >(({ className, inset, ...props }, ref) => {
384
+ >(({ className, inset, dataHook, ...props }, ref) => {
380
385
  return (
381
386
  <DropdownMenuPrimitive.Label
382
387
  ref={ref}
@@ -387,6 +392,7 @@ const DropdownMenuLabel = React.forwardRef<
387
392
  ],
388
393
  className
389
394
  )}
395
+ data-hook={dataHook}
390
396
  data-inset={inset}
391
397
  data-slot="dropdown-menu-label"
392
398
  {...props}
@@ -127,6 +127,10 @@ const fieldVariants = cva(
127
127
  */
128
128
  interface FieldProps
129
129
  extends React.ComponentProps<"div">, VariantProps<typeof fieldVariants> {
130
+ /**
131
+ * Data hook for automated testing
132
+ */
133
+ dataHook?: string;
130
134
  /**
131
135
  * Controls the grid column sizing for horizontal orientation.
132
136
  * - `"start"` (default): `auto 1fr` — control left, content right
@@ -140,6 +144,7 @@ function Field({
140
144
  orientation = "vertical",
141
145
  variant = "default",
142
146
  align = "start",
147
+ dataHook,
143
148
  ...props
144
149
  }: FieldProps) {
145
150
  return (
@@ -151,6 +156,7 @@ function Field({
151
156
  "grid-cols-[1fr_auto]",
152
157
  className
153
158
  )}
159
+ data-hook={dataHook}
154
160
  data-orientation={orientation}
155
161
  data-slot="field"
156
162
  data-variant={variant}
@@ -5,38 +5,108 @@ import { cva, type VariantProps } from "class-variance-authority";
5
5
 
6
6
  import { cn } from "@brightlocal/ui-components/lib/utils";
7
7
 
8
- const linkVariants = cva([
9
- "inline-flex",
10
- "items-center",
11
- "gap-1",
12
- // Color tokens (light mode: #2563EB, dark mode: #3B82F6)
13
- "text-link",
14
- "dark:text-link-dark",
15
- // States
8
+ // Shared base for the button-styled variants (filled, outline, ghost).
9
+ // Mirrors the Button component's `size="default"` look so the treatments stay
10
+ // visually identical across both components.
11
+ const buttonStyledBase = [
12
+ "justify-center",
13
+ "h-9",
14
+ "px-4",
15
+ "py-2",
16
+ "rounded-full",
17
+ "text-sm",
18
+ "font-semibold",
16
19
  "no-underline",
17
- "hover:underline",
18
- "hover:underline-offset-4",
19
- "active:text-link/80",
20
- "visited:text-link-visited",
21
- "visited:dark:text-link-visited-dark",
22
- // Transitions
23
- "transition-[text-decoration,text-decoration-color,text-underline-offset,color]",
24
- "duration-300",
25
- "cursor-pointer",
26
- // Focus state
27
- "rounded-sm",
28
- "outline-none",
20
+ "whitespace-nowrap",
21
+ "shrink-0",
22
+ "[&_svg]:pointer-events-none",
23
+ "[&_svg]:shrink-0",
24
+ "transition-[color,background-color,border-color,box-shadow]",
25
+ "duration-150",
26
+ "ease-in-out",
29
27
  "focus-visible:shadow-default",
30
- ]);
28
+ ];
31
29
 
32
- export interface LinkProps
33
- extends
34
- React.AnchorHTMLAttributes<HTMLAnchorElement>,
35
- VariantProps<typeof linkVariants> {
30
+ const linkVariants = cva(
31
+ // `gap-2` (spacing/2) keeps the icon–text gap consistent across all variants.
32
+ ["inline-flex", "items-center", "gap-2", "cursor-pointer", "outline-none"],
33
+ {
34
+ variants: {
35
+ variant: {
36
+ // Inline text link (default) — the original Link styling.
37
+ inline: [
38
+ "rounded-sm",
39
+ // Color tokens (light mode: #2563EB, dark mode: #3B82F6)
40
+ "text-link",
41
+ "dark:text-link-dark",
42
+ // States
43
+ "no-underline",
44
+ "hover:underline",
45
+ "hover:underline-offset-4",
46
+ "active:text-link/80",
47
+ "visited:text-link-visited",
48
+ "visited:dark:text-link-visited-dark",
49
+ // Transitions
50
+ "transition-[text-decoration,text-decoration-color,text-underline-offset,color]",
51
+ "duration-300",
52
+ // Focus state
53
+ "focus-visible:shadow-default",
54
+ ],
55
+ // Button-styled, filled (maps to Button `secondary`).
56
+ filled: [
57
+ ...buttonStyledBase,
58
+ "bg-secondary",
59
+ "text-secondary-foreground",
60
+ "hover:bg-secondary/80",
61
+ ],
62
+ // Button-styled, bordered. Uses the `input` border token in both modes
63
+ // and keeps that border on focus (focus is the shared shadow ring only).
64
+ outline: [
65
+ ...buttonStyledBase,
66
+ "border",
67
+ "border-input",
68
+ "border-solid",
69
+ "bg-background",
70
+ "text-foreground",
71
+ "hover:bg-accent",
72
+ "hover:text-accent-foreground",
73
+ "dark:bg-input/30",
74
+ "dark:border-input",
75
+ "dark:hover:bg-input/50",
76
+ "dark:hover:border-input",
77
+ ],
78
+ // Button-styled, transparent (maps to Button `ghost`).
79
+ ghost: [
80
+ ...buttonStyledBase,
81
+ "bg-transparent",
82
+ "text-foreground",
83
+ "hover:bg-accent",
84
+ ],
85
+ },
86
+ },
87
+ defaultVariants: {
88
+ variant: "inline",
89
+ },
90
+ }
91
+ );
92
+
93
+ /** Supported visual style variants for the Link component. */
94
+ export type LinkVariant = NonNullable<
95
+ VariantProps<typeof linkVariants>["variant"]
96
+ >;
97
+
98
+ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
36
99
  /**
37
100
  * Data hook for automated testing (REQUIRED)
38
101
  */
39
102
  dataHook: string;
103
+ /**
104
+ * Visual style variant. `inline` renders a standard text link; `filled`,
105
+ * `outline` and `ghost` render button-styled treatments for inline actions
106
+ * and high-priority navigation.
107
+ * @default "inline"
108
+ */
109
+ variant?: LinkVariant;
40
110
  /**
41
111
  * Tracking element identifier for analytics
42
112
  */
@@ -65,6 +135,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(
65
135
  (
66
136
  {
67
137
  className,
138
+ variant = "inline",
68
139
  dataHook,
69
140
  trackingEl,
70
141
  trackingLabel,
@@ -80,12 +151,17 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(
80
151
  ? { target: "_blank", rel: "noopener noreferrer" }
81
152
  : {};
82
153
 
154
+ // Preserve the historical "link-default" tracking id for the inline
155
+ // variant (backwards compatible); button-styled variants get a distinct id.
156
+ const defaultTrackingEl =
157
+ variant === "inline" ? "link-default" : `link-${variant}`;
158
+
83
159
  const sharedProps = {
84
160
  ref,
85
- className: cn(linkVariants(), className),
161
+ className: cn(linkVariants({ variant }), className),
86
162
  "data-hook": dataHook,
87
163
  "data-slot": "link" as const,
88
- "data-tracking-el": trackingEl || "link-default",
164
+ "data-tracking-el": trackingEl || defaultTrackingEl,
89
165
  "data-tracking-label": trackingLabel,
90
166
  ...externalProps,
91
167
  ...props,
@@ -825,8 +825,7 @@ const MapLocationPin = React.forwardRef<HTMLDivElement, MapLocationPinProps>(
825
825
  aria-hidden="true"
826
826
  className={cn(
827
827
  "relative flex size-full",
828
- animateIn &&
829
- "animate-pop-in origin-bottom will-change-transform motion-reduce:animate-none"
828
+ animateIn && "animate-pop-in origin-bottom will-change-transform"
830
829
  )}
831
830
  >
832
831
  <svg
@@ -5,6 +5,7 @@ import * as ProgressPrimitive from "@radix-ui/react-progress";
5
5
  import { motion } from "framer-motion";
6
6
 
7
7
  import { cn } from "@brightlocal/ui-components/lib/utils";
8
+ import { usePrefersReducedMotion } from "@brightlocal/ui-components/hooks/use-prefers-reduced-motion";
8
9
 
9
10
  /**
10
11
  * Props for the Progress component.
@@ -70,6 +71,7 @@ const Progress = React.forwardRef<
70
71
  ) => {
71
72
  const labelId = React.useId();
72
73
  const hasVisibleLabel = !!label;
74
+ const prefersReducedMotion = usePrefersReducedMotion();
73
75
 
74
76
  const progressBar = (
75
77
  <ProgressPrimitive.Root
@@ -99,12 +101,16 @@ const Progress = React.forwardRef<
99
101
  )}
100
102
  data-slot="progress-indicator"
101
103
  initial={false}
102
- transition={{
103
- type: "spring",
104
- stiffness: 80,
105
- damping: 20,
106
- mass: 1,
107
- }}
104
+ transition={
105
+ prefersReducedMotion
106
+ ? { duration: 0 }
107
+ : {
108
+ type: "spring",
109
+ stiffness: 80,
110
+ damping: 20,
111
+ mass: 1,
112
+ }
113
+ }
108
114
  />
109
115
  </ProgressPrimitive.Indicator>
110
116
  </ProgressPrimitive.Root>
@@ -110,7 +110,10 @@ const Rating = React.forwardRef<HTMLDivElement, RatingProps>(
110
110
  width: `${fillPercentage}%`,
111
111
  }}
112
112
  >
113
- <StarRating size={starSize} />
113
+ <StarRating
114
+ className="fill-yellow-400 stroke-yellow-400"
115
+ size={starSize}
116
+ />
114
117
  </div>
115
118
  )}
116
119
  </div>
@@ -111,8 +111,8 @@ const SheetTrigger = React.forwardRef<
111
111
  >(({ dataHook, ...props }, ref) => (
112
112
  <SheetPrimitive.Trigger
113
113
  ref={ref}
114
- data-hook={dataHook}
115
114
  data-slot="sheet-trigger"
115
+ {...(dataHook != null && { "data-hook": dataHook })}
116
116
  {...props}
117
117
  />
118
118
  ));
@@ -280,6 +280,11 @@ SheetFooter.displayName = "SheetFooter";
280
280
  interface SheetTitleProps extends React.ComponentProps<
281
281
  typeof SheetPrimitive.Title
282
282
  > {
283
+ /**
284
+ * Data hook for automated testing
285
+ * @example "sheet-title"
286
+ */
287
+ dataHook?: string;
283
288
  /**
284
289
  * Optional icon rendered before the title text.
285
290
  * Pass any React node (typically a DS icon component).
@@ -295,7 +300,7 @@ interface SheetTitleProps extends React.ComponentProps<
295
300
  const SheetTitle = React.forwardRef<
296
301
  React.ComponentRef<typeof SheetPrimitive.Title>,
297
302
  SheetTitleProps
298
- >(({ className, icon, children, ...props }, ref) => (
303
+ >(({ className, icon, children, dataHook, ...props }, ref) => (
299
304
  <SheetPrimitive.Title
300
305
  ref={ref}
301
306
  className={cn(
@@ -303,6 +308,7 @@ const SheetTitle = React.forwardRef<
303
308
  icon && "flex items-center gap-2",
304
309
  className
305
310
  )}
311
+ data-hook={dataHook}
306
312
  data-slot="sheet-title"
307
313
  {...props}
308
314
  >
@@ -316,17 +322,31 @@ const SheetTitle = React.forwardRef<
316
322
  ));
317
323
  SheetTitle.displayName = "SheetTitle";
318
324
 
325
+ /**
326
+ * Props for the SheetDescription component
327
+ */
328
+ interface SheetDescriptionProps extends React.ComponentProps<
329
+ typeof SheetPrimitive.Description
330
+ > {
331
+ /**
332
+ * Data hook for automated testing
333
+ * @example "sheet-description"
334
+ */
335
+ dataHook?: string;
336
+ }
337
+
319
338
  /**
320
339
  * Sheet description component for additional context.
321
340
  * Should be used within SheetHeader below SheetTitle.
322
341
  */
323
342
  const SheetDescription = React.forwardRef<
324
343
  React.ComponentRef<typeof SheetPrimitive.Description>,
325
- React.ComponentProps<typeof SheetPrimitive.Description>
326
- >(({ className, ...props }, ref) => (
344
+ SheetDescriptionProps
345
+ >(({ className, dataHook, ...props }, ref) => (
327
346
  <SheetPrimitive.Description
328
347
  ref={ref}
329
348
  className={cn("text-muted-foreground text-sm", className)}
349
+ data-hook={dataHook}
330
350
  data-slot="sheet-description"
331
351
  {...props}
332
352
  />
@@ -346,4 +366,9 @@ export {
346
366
  SheetTrigger,
347
367
  };
348
368
 
349
- export type { SheetContentProps, SheetTitleProps, SheetTriggerProps };
369
+ export type {
370
+ SheetContentProps,
371
+ SheetDescriptionProps,
372
+ SheetTitleProps,
373
+ SheetTriggerProps,
374
+ };
@@ -1,9 +1,23 @@
1
1
  "use client";
2
2
 
3
- import { useSyncExternalStore } from "react";
3
+ import { createContext, useContext, useSyncExternalStore } from "react";
4
4
 
5
5
  const QUERY = "(prefers-reduced-motion: reduce)";
6
6
 
7
+ /**
8
+ * Optional override for the resolved reduced-motion value.
9
+ *
10
+ * - `null` (default): no override — {@link usePrefersReducedMotion} follows the
11
+ * OS/browser `prefers-reduced-motion` preference.
12
+ * - `true` / `false`: force the resolved value, ignoring the OS. Intended for
13
+ * tools that need to preview both states without changing OS settings (e.g.
14
+ * the Storybook "Reduce Motion" toolbar) — **not** for production app code.
15
+ *
16
+ * The override takes precedence so a component can never tell whether the value
17
+ * came from the OS or an override.
18
+ */
19
+ export const ReducedMotionOverrideContext = createContext<boolean | null>(null);
20
+
7
21
  function subscribe(callback: () => void) {
8
22
  const mql = window.matchMedia(QUERY);
9
23
  mql.addEventListener("change", callback);
@@ -19,10 +33,26 @@ function getServerSnapshot() {
19
33
  }
20
34
 
21
35
  /**
22
- * Returns `true` when the user prefers reduced motion.
23
- * Listens to OS/browser preference changes in real time.
36
+ * Returns `true` when reduced motion should be applied.
37
+ *
38
+ * Resolves from a layered source: an optional override (via
39
+ * {@link ReducedMotionOverrideContext}) wins; with no override it follows the
40
+ * OS/browser `prefers-reduced-motion` media query and updates in real time. The
41
+ * consuming component only ever sees the final boolean and cannot tell which
42
+ * layer produced it.
43
+ *
44
+ * Use it to gate any animation — framer-motion, CSS classes, or SVG. Note that
45
+ * raw CSS `@media (prefers-reduced-motion)` / Tailwind `motion-reduce:` bypass
46
+ * this hook (and any override) because they read the OS directly.
47
+ *
24
48
  * SSR-safe: defaults to `false` on the server.
25
49
  */
26
- export function usePrefersReducedMotion() {
27
- return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
50
+ export function usePrefersReducedMotion(): boolean {
51
+ const override = useContext(ReducedMotionOverrideContext);
52
+ const osPrefersReducedMotion = useSyncExternalStore(
53
+ subscribe,
54
+ getSnapshot,
55
+ getServerSnapshot
56
+ );
57
+ return override ?? osPrefersReducedMotion;
28
58
  }