@brightlocal/ui-components 2.17.1 → 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 (61) 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/sheet.cjs +1 -1
  46. package/dist/sheet.d.ts +17 -2
  47. package/dist/sheet.d.ts.map +1 -1
  48. package/dist/sheet.js +29 -27
  49. package/package.json +3 -3
  50. package/src/blocks/input-list.tsx +8 -1
  51. package/src/components/alert-dialog.tsx +38 -4
  52. package/src/components/card.tsx +56 -9
  53. package/src/components/chip.tsx +1 -4
  54. package/src/components/dialog.tsx +39 -6
  55. package/src/components/dropdown-menu.tsx +7 -1
  56. package/src/components/field.tsx +6 -0
  57. package/src/components/link.tsx +103 -27
  58. package/src/components/map.tsx +1 -2
  59. package/src/components/progress.tsx +12 -6
  60. package/src/components/sheet.tsx +30 -5
  61. package/src/hooks/use-prefers-reduced-motion.ts +35 -5
@@ -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>
@@ -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
  }