@brightlocal/ui-components 1.4.3 → 2.0.1

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 (63) hide show
  1. package/AI_USAGE.md +1 -1
  2. package/component-meta.json +1 -1
  3. package/dist/badge.cjs +1 -1
  4. package/dist/badge.d.ts +1 -1
  5. package/dist/badge.js +10 -10
  6. package/dist/button.cjs +1 -1
  7. package/dist/button.d.ts +5 -3
  8. package/dist/button.d.ts.map +1 -1
  9. package/dist/button.js +21 -21
  10. package/dist/card.cjs +1 -1
  11. package/dist/card.d.ts +2 -2
  12. package/dist/card.d.ts.map +1 -1
  13. package/dist/card.js +13 -13
  14. package/dist/combobox.cjs +1 -1
  15. package/dist/combobox.d.ts +1 -5
  16. package/dist/combobox.d.ts.map +1 -1
  17. package/dist/combobox.js +139 -152
  18. package/dist/hooks/use-debounce.cjs +1 -0
  19. package/dist/hooks/use-debounce.d.ts +16 -0
  20. package/dist/hooks/use-debounce.d.ts.map +1 -0
  21. package/dist/hooks/use-debounce.js +18 -0
  22. package/dist/hooks/use-mobile.cjs +1 -1
  23. package/dist/hooks/use-mobile.d.ts.map +1 -1
  24. package/dist/hooks/use-mobile.js +15 -10
  25. package/dist/index.cjs +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +44 -42
  29. package/dist/lib/use-dev-warning.cjs +1 -0
  30. package/dist/lib/use-dev-warning.d.ts +11 -0
  31. package/dist/lib/use-dev-warning.d.ts.map +1 -0
  32. package/dist/lib/use-dev-warning.js +12 -0
  33. package/dist/radio-group.cjs +1 -1
  34. package/dist/radio-group.d.ts +3 -3
  35. package/dist/radio-group.d.ts.map +1 -1
  36. package/dist/radio-group.js +46 -46
  37. package/dist/select.cjs +2 -1
  38. package/dist/select.d.ts.map +1 -1
  39. package/dist/select.js +71 -61
  40. package/dist/sonner.d.ts +7 -1
  41. package/dist/sonner.d.ts.map +1 -1
  42. package/dist/toggle-group.cjs +1 -1
  43. package/dist/toggle-group.d.ts +8 -8
  44. package/dist/toggle-group.d.ts.map +1 -1
  45. package/dist/toggle-group.js +19 -19
  46. package/dist/toggle.cjs +1 -1
  47. package/dist/toggle.d.ts +3 -3
  48. package/dist/toggle.d.ts.map +1 -1
  49. package/dist/toggle.js +12 -12
  50. package/package.json +8 -7
  51. package/src/components/badge.tsx +2 -2
  52. package/src/components/button.tsx +8 -5
  53. package/src/components/card.tsx +5 -5
  54. package/src/components/combobox.tsx +27 -43
  55. package/src/components/radio-group.tsx +13 -13
  56. package/src/components/select.tsx +17 -0
  57. package/src/components/sonner.tsx +8 -8
  58. package/src/components/toggle-group.tsx +6 -6
  59. package/src/components/toggle.tsx +4 -4
  60. package/src/hooks/use-debounce.ts +53 -0
  61. package/src/hooks/use-mobile.ts +17 -4
  62. package/src/index.ts +1 -0
  63. package/src/lib/use-dev-warning.ts +29 -0
@@ -6,7 +6,7 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
6
6
  /**
7
7
  * Card variant type
8
8
  */
9
- type CardVariant = "default" | "transparent" | "border" | "transparent-flush";
9
+ type CardVariant = "filled" | "transparent" | "border" | "transparent-flush";
10
10
 
11
11
  /**
12
12
  * Context to pass variant information to sub-components
@@ -26,7 +26,7 @@ const cardVariants = cva(
26
26
  {
27
27
  variants: {
28
28
  variant: {
29
- default: [
29
+ filled: [
30
30
  "bg-card",
31
31
  "text-card-foreground",
32
32
  "border",
@@ -43,7 +43,7 @@ const cardVariants = cva(
43
43
  },
44
44
  },
45
45
  defaultVariants: {
46
- variant: "default",
46
+ variant: "filled",
47
47
  },
48
48
  }
49
49
  );
@@ -54,7 +54,7 @@ const cardVariants = cva(
54
54
  type CardProps = React.ComponentProps<"div"> & {
55
55
  /**
56
56
  * Visual style variant of the card
57
- * @default "default"
57
+ * @default "filled"
58
58
  */
59
59
  variant?: CardVariant;
60
60
  /**
@@ -84,7 +84,7 @@ const Card = React.forwardRef<HTMLDivElement, CardProps>(
84
84
  (
85
85
  {
86
86
  className,
87
- variant = "default",
87
+ variant = "filled",
88
88
  dataHook,
89
89
  trackingEl,
90
90
  trackingLabel,
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from "react";
4
4
  import { ChevronsUpDown, Check } from "@brightlocal/icons";
5
- import { cva, type VariantProps } from "class-variance-authority";
5
+ import { cva } from "class-variance-authority";
6
6
  import { defaultFilter } from "cmdk";
7
7
 
8
8
  import { cn } from "@brightlocal/ui-components/lib/utils";
@@ -161,55 +161,40 @@ function Combobox({
161
161
  * Combobox Trigger
162
162
  * -----------------------------------------------------------------------------------------------*/
163
163
 
164
- const comboboxTriggerVariants = cva(
165
- [
166
- // Base layout
167
- "relative flex w-full items-center justify-between gap-2",
168
- "px-4 py-2 h-9",
164
+ const comboboxTriggerVariants = cva([
165
+ // Base layout
166
+ "relative flex w-full items-center justify-between gap-2",
167
+ "px-4 py-2 h-9",
169
168
 
170
- // Base appearance
171
- "border border-input rounded-md outline-none",
172
- "bg-neutral-50 shadow-xs",
173
- "dark:bg-white/5 dark:border-white/15",
169
+ // Base appearance
170
+ "border border-input rounded-md outline-none",
171
+ "bg-neutral-50 shadow-xs",
172
+ "dark:bg-white/5 dark:border-white/15",
174
173
 
175
- // Typography
176
- "text-sm font-normal font-sans text-foreground",
174
+ // Typography
175
+ "text-sm font-normal font-sans text-foreground",
177
176
 
178
- // Placeholder state
179
- "data-[placeholder=true]:text-muted-foreground",
177
+ // Placeholder state
178
+ "data-[placeholder=true]:text-muted-foreground",
180
179
 
181
- // Focus state
182
- "focus-visible:outline-none focus-visible:border-ring dark:focus-visible:border-neutral-500 focus-visible:bg-background",
183
- "focus-visible:shadow-default",
180
+ // Focus state
181
+ "focus-visible:outline-none focus-visible:border-ring dark:focus-visible:border-neutral-500 focus-visible:bg-background",
182
+ "focus-visible:shadow-default",
184
183
 
185
- // Open dropdown state
186
- "data-[state=open]:border-ring",
184
+ // Open dropdown state
185
+ "data-[state=open]:border-ring",
187
186
 
188
- // Disabled state
189
- "disabled:cursor-not-allowed disabled:opacity-50",
187
+ // Disabled state
188
+ "disabled:cursor-not-allowed disabled:opacity-50",
190
189
 
191
- // Transitions
192
- "transition-[background-color,border-color,box-shadow] duration-200 ease-out",
190
+ // Transitions
191
+ "transition-[background-color,border-color,box-shadow] duration-200 ease-out",
193
192
 
194
- // Icon styles
195
- "[&_svg]:pointer-events-none [&_svg]:shrink-0",
196
- ],
197
- {
198
- variants: {
199
- variant: {
200
- default: [],
201
- },
202
- },
203
- defaultVariants: {
204
- variant: "default",
205
- },
206
- }
207
- );
193
+ // Icon styles
194
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
195
+ ]);
208
196
 
209
- export interface ComboboxTriggerProps
210
- extends
211
- React.ButtonHTMLAttributes<HTMLButtonElement>,
212
- VariantProps<typeof comboboxTriggerVariants> {
197
+ export interface ComboboxTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
213
198
  /** Data hook for automated testing (REQUIRED) */
214
199
  dataHook: string;
215
200
  /** Accessible label for the combobox trigger. Use either aria-label or aria-labelledby for accessibility. */
@@ -231,7 +216,6 @@ const ComboboxTrigger = React.forwardRef<
231
216
  (
232
217
  {
233
218
  className,
234
- variant,
235
219
  dataHook,
236
220
  error,
237
221
  trackingEl,
@@ -260,7 +244,7 @@ const ComboboxTrigger = React.forwardRef<
260
244
  aria-haspopup="listbox"
261
245
  aria-invalid={hasError ? "true" : undefined}
262
246
  className={cn(
263
- comboboxTriggerVariants({ variant }),
247
+ comboboxTriggerVariants(),
264
248
  hasError &&
265
249
  "border-destructive-40 focus-visible:border-destructive-40 dark:focus-visible:border-destructive-40 focus-visible:shadow-destructive data-[state=open]:border-destructive-40 dark:data-[state=open]:border-destructive-40 data-[state=open]:shadow-destructive",
266
250
  className
@@ -12,14 +12,14 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
12
12
  const radioGroupVariants = cva("grid", {
13
13
  variants: {
14
14
  variant: {
15
- default: ["gap-3"],
15
+ simple: ["gap-3"],
16
16
  box: ["gap-3"],
17
17
  boxIconVertical: ["grid-flow-col auto-cols-fr gap-3"],
18
18
  boxIconHorizontal: ["gap-3"],
19
19
  },
20
20
  },
21
21
  defaultVariants: {
22
- variant: "default",
22
+ variant: "simple",
23
23
  },
24
24
  });
25
25
 
@@ -28,14 +28,14 @@ const radioGroupItemVariants = cva(
28
28
  {
29
29
  variants: {
30
30
  variant: {
31
- default: ["items-center"],
31
+ simple: ["items-center"],
32
32
  box: ["items-center"],
33
33
  boxIconVertical: ["items-center justify-center"],
34
34
  boxIconHorizontal: ["items-center justify-center"],
35
35
  },
36
36
  },
37
37
  defaultVariants: {
38
- variant: "default",
38
+ variant: "simple",
39
39
  },
40
40
  }
41
41
  );
@@ -45,7 +45,7 @@ const radioCircleVariants = cva(
45
45
  {
46
46
  variants: {
47
47
  variant: {
48
- default: [
48
+ simple: [
49
49
  "border-ring bg-background shadow-xs",
50
50
  "group-focus-visible:outline-none group-focus-visible:border-ring group-focus-visible:shadow-default",
51
51
  "group-data-[disabled]:opacity-50",
@@ -75,7 +75,7 @@ const radioCircleVariants = cva(
75
75
  },
76
76
  },
77
77
  defaultVariants: {
78
- variant: "default",
78
+ variant: "simple",
79
79
  },
80
80
  }
81
81
  );
@@ -84,13 +84,13 @@ const radioCircleVariants = cva(
84
84
 
85
85
  /**
86
86
  * Visual style variants for the radio group component.
87
- * - `default`: Standard radio group with minimal styling
87
+ * - `simple`: Standard radio group with minimal styling
88
88
  * - `box`: Radio items wrapped in styled card containers
89
89
  * - `boxIconVertical`: Radio items with icons displayed vertically above the label
90
90
  * - `boxIconHorizontal`: Radio items with icons displayed horizontally to the left
91
91
  */
92
92
  type RadioGroupVariant =
93
- | "default"
93
+ | "simple"
94
94
  | "box"
95
95
  | "boxIconVertical"
96
96
  | "boxIconHorizontal";
@@ -135,7 +135,7 @@ type RadioGroupItemProps = React.ComponentPropsWithoutRef<
135
135
  /* --------------------------------- Context -------------------------------- */
136
136
 
137
137
  const RadioGroupContext = React.createContext<RadioGroupContextValue>({
138
- variant: "default",
138
+ variant: "simple",
139
139
  });
140
140
 
141
141
  /* ------------------------------- RadioGroup ------------------------------- */
@@ -147,7 +147,7 @@ const RadioGroup = React.forwardRef<
147
147
  (
148
148
  {
149
149
  className,
150
- variant = "default",
150
+ variant = "simple",
151
151
  dataHook,
152
152
  trackingEl,
153
153
  trackingLabel,
@@ -157,7 +157,7 @@ const RadioGroup = React.forwardRef<
157
157
  },
158
158
  ref
159
159
  ) => {
160
- const contextVariant = variant || "default";
160
+ const contextVariant = variant || "simple";
161
161
  // Support both error prop and aria-invalid for backwards compatibility
162
162
  const hasError =
163
163
  error ||
@@ -197,7 +197,7 @@ const RadioGroupItem = React.forwardRef<
197
197
  RadioGroupItemProps
198
198
  >(({ className, children, ...props }, ref) => {
199
199
  const { variant: ctxVariant, error } = React.useContext(RadioGroupContext);
200
- const variant = ctxVariant ?? "default";
200
+ const variant = ctxVariant ?? "simple";
201
201
 
202
202
  const isBoxIcon =
203
203
  variant === "boxIconVertical" || variant === "boxIconHorizontal";
@@ -226,7 +226,7 @@ const RadioGroupItem = React.forwardRef<
226
226
  >
227
227
  <Circle
228
228
  className={cn(
229
- variant === "default"
229
+ variant === "simple"
230
230
  ? "fill-primary text-primary"
231
231
  : "fill-background text-background"
232
232
  )}
@@ -6,6 +6,7 @@ import { Check, ChevronDown, ChevronUp } from "@brightlocal/icons";
6
6
  import { cva } from "class-variance-authority";
7
7
 
8
8
  import { cn } from "@brightlocal/ui-components/lib/utils";
9
+ import { useDevWarning } from "../lib/use-dev-warning";
9
10
 
10
11
  // ============================================================================
11
12
  // Types
@@ -184,6 +185,21 @@ function SelectContent({
184
185
  position = "popper",
185
186
  ...props
186
187
  }: React.ComponentProps<typeof SelectPrimitive.Content>) {
188
+ const viewportRef = React.useRef<HTMLDivElement>(null);
189
+
190
+ useDevWarning(
191
+ () => {
192
+ if (!viewportRef.current) return false;
193
+ return (
194
+ viewportRef.current.querySelectorAll('[data-slot="select-item"]')
195
+ .length >= 100
196
+ );
197
+ },
198
+ "Select contains many items. For large lists (100+), consider using <Combobox> which supports search and filtering.\n" +
199
+ 'Import: import { Combobox } from "@brightlocal/ui-components/combobox"',
200
+ [children]
201
+ );
202
+
187
203
  const baseStyles = cn(
188
204
  // Base appearance
189
205
  "relative z-50 overflow-hidden",
@@ -224,6 +240,7 @@ function SelectContent({
224
240
  >
225
241
  <SelectScrollUpButton />
226
242
  <SelectPrimitive.Viewport
243
+ ref={viewportRef}
227
244
  className={cn(
228
245
  "p-1",
229
246
  position === "popper" &&
@@ -10,9 +10,15 @@ import {
10
10
  import { cva } from "class-variance-authority";
11
11
  import { toast as sonnerToast, Toaster as SonnerToaster } from "sonner";
12
12
 
13
- import { Button } from "@brightlocal/ui-components/button";
13
+ import { Button, type ButtonVariant } from "@brightlocal/ui-components/button";
14
14
  import { cn } from "@brightlocal/ui-components/lib/utils";
15
15
 
16
+ /**
17
+ * Supported button variant values for toast action buttons.
18
+ * Derived from ButtonVariant to stay in sync with Button component.
19
+ */
20
+ export type SonnerButtonVariant = ButtonVariant;
21
+
16
22
  /**
17
23
  * Internal props for the Toast component.
18
24
  * Includes the `id` field which is managed internally by Sonner.
@@ -32,13 +38,7 @@ type ToastProps = {
32
38
  /** Click handler for the button */
33
39
  onClick?: () => void;
34
40
  /** Visual variant of the button */
35
- variant?:
36
- | "default"
37
- | "destructive"
38
- | "outline"
39
- | "secondary"
40
- | "ghost"
41
- | "warning";
41
+ variant?: SonnerButtonVariant;
42
42
  };
43
43
  /** Color theme for the toast */
44
44
  colorSchema?: SonnerColorSchema;
@@ -11,14 +11,14 @@ import { toggleVariants } from "./toggle";
11
11
  */
12
12
  type ToggleGroupContextValue = {
13
13
  /** Visual style variant inherited by child items */
14
- variant?: "default" | "outline";
14
+ variant?: "simple" | "outline";
15
15
  /** Size variant inherited by child items */
16
16
  size?: "default" | "sm" | "lg";
17
17
  };
18
18
 
19
19
  const ToggleGroupContext = React.createContext<ToggleGroupContextValue>({
20
20
  size: "default",
21
- variant: "default",
21
+ variant: "simple",
22
22
  });
23
23
 
24
24
  type ToggleGroupProps = {
@@ -30,9 +30,9 @@ type ToggleGroupProps = {
30
30
  trackingLabel?: string;
31
31
  /**
32
32
  * Visual style variant
33
- * @default "default"
33
+ * @default "simple"
34
34
  */
35
- variant?: "default" | "outline";
35
+ variant?: "simple" | "outline";
36
36
  /**
37
37
  * Size variant
38
38
  * @default "default"
@@ -91,9 +91,9 @@ type ToggleGroupItemProps = {
91
91
  ariaLabel?: string;
92
92
  /**
93
93
  * Visual style variant (inherited from ToggleGroup if not specified)
94
- * @default "default"
94
+ * @default "simple"
95
95
  */
96
- variant?: "default" | "outline";
96
+ variant?: "simple" | "outline";
97
97
  /**
98
98
  * Size variant (inherited from ToggleGroup if not specified)
99
99
  * @default "default"
@@ -11,7 +11,7 @@ const toggleVariants = cva(
11
11
  {
12
12
  variants: {
13
13
  variant: {
14
- default: "bg-transparent",
14
+ simple: "bg-transparent",
15
15
  outline:
16
16
  "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground",
17
17
  },
@@ -22,7 +22,7 @@ const toggleVariants = cva(
22
22
  },
23
23
  },
24
24
  defaultVariants: {
25
- variant: "default",
25
+ variant: "simple",
26
26
  size: "default",
27
27
  },
28
28
  }
@@ -40,9 +40,9 @@ export interface ToggleProps
40
40
  trackingLabel?: string;
41
41
  /**
42
42
  * Visual style variant
43
- * @default "default"
43
+ * @default "simple"
44
44
  */
45
- variant?: "default" | "outline";
45
+ variant?: "simple" | "outline";
46
46
  /**
47
47
  * Size variant
48
48
  * @default "default"
@@ -0,0 +1,53 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+
3
+ export interface UseDebounceResult<T> {
4
+ /** The debounced value — updates after `delay` ms of inactivity. */
5
+ debouncedValue: T;
6
+ /** Flush the pending value immediately, bypassing the delay. */
7
+ flush: () => void;
8
+ }
9
+
10
+ /**
11
+ * Debounces a value by the given delay.
12
+ * Returns the latest value only after `delay` ms of inactivity,
13
+ * plus a `flush` function to skip the wait and update immediately.
14
+ *
15
+ * @param value - The value to debounce.
16
+ * @param delay - Debounce delay in milliseconds (default 300).
17
+ */
18
+ export function useDebounce<T>(
19
+ value: T,
20
+ delay: number = 300
21
+ ): UseDebounceResult<T> {
22
+ const [debouncedValue, setDebouncedValue] = useState(value);
23
+ const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
24
+ const latestValue = useRef(value);
25
+
26
+ useEffect(() => {
27
+ latestValue.current = value;
28
+ }, [value]);
29
+
30
+ useEffect(() => {
31
+ timerRef.current = setTimeout(() => {
32
+ timerRef.current = null;
33
+ setDebouncedValue(value);
34
+ }, delay);
35
+
36
+ return () => {
37
+ if (timerRef.current) {
38
+ clearTimeout(timerRef.current);
39
+ timerRef.current = null;
40
+ }
41
+ };
42
+ }, [value, delay]);
43
+
44
+ const flush = useCallback(() => {
45
+ if (timerRef.current) {
46
+ clearTimeout(timerRef.current);
47
+ timerRef.current = null;
48
+ }
49
+ setDebouncedValue(latestValue.current);
50
+ }, []);
51
+
52
+ return { debouncedValue, flush };
53
+ }
@@ -1,6 +1,18 @@
1
1
  import * as React from "react";
2
2
 
3
- const MOBILE_BREAKPOINT = 768;
3
+ /** Fallback used when the CSS variable is not available (e.g. SSR) */
4
+ const MOBILE_BREAKPOINT_FALLBACK = 640;
5
+
6
+ function getMobileBreakpoint(): number {
7
+ if (typeof document === "undefined") return MOBILE_BREAKPOINT_FALLBACK;
8
+
9
+ const raw = getComputedStyle(document.documentElement)
10
+ .getPropertyValue("--ds-breakpoint-sm")
11
+ .trim();
12
+ const parsed = parseInt(raw, 10);
13
+
14
+ return Number.isNaN(parsed) ? MOBILE_BREAKPOINT_FALLBACK : parsed;
15
+ }
4
16
 
5
17
  export function useIsMobile() {
6
18
  const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
@@ -8,12 +20,13 @@ export function useIsMobile() {
8
20
  );
9
21
 
10
22
  React.useEffect(() => {
11
- const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
23
+ const breakpoint = getMobileBreakpoint();
24
+ const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
12
25
  const onChange = () => {
13
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
26
+ setIsMobile(window.innerWidth < breakpoint);
14
27
  };
15
28
  mql.addEventListener("change", onChange);
16
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
29
+ setIsMobile(window.innerWidth < breakpoint);
17
30
  return () => mql.removeEventListener("change", onChange);
18
31
  }, []);
19
32
 
package/src/index.ts CHANGED
@@ -68,6 +68,7 @@ export * from "./blocks/input-list";
68
68
  export * from "./blocks/sidebar";
69
69
 
70
70
  // Hooks
71
+ export * from "./hooks/use-debounce";
71
72
  export * from "./hooks/use-mobile";
72
73
  export * from "./hooks/use-prefers-reduced-motion";
73
74
 
@@ -0,0 +1,29 @@
1
+ import { type DependencyList, useEffect } from "react";
2
+
3
+ /**
4
+ * Dev-only guidance warning. In non-development builds this returns before
5
+ * registering any effect, so no warning is emitted and `check` is never called.
6
+ *
7
+ * @param check - Return `true` to trigger the warning (only called in dev)
8
+ * @param message - Warning text (prefix `[BrightLocal DS]` is added automatically)
9
+ * @param deps - Effect dependency list
10
+ */
11
+ export function useDevWarning(
12
+ check: () => boolean,
13
+ message: string,
14
+ deps: DependencyList
15
+ ): void {
16
+ if (process.env.NODE_ENV !== "development") return;
17
+
18
+ // eslint-disable-next-line react-hooks/rules-of-hooks -- safe: condition is a build-time constant
19
+ useEffect(() => {
20
+ // Defer one frame so child components have committed to the DOM
21
+ const raf = requestAnimationFrame(() => {
22
+ if (check()) {
23
+ console.warn(`[BrightLocal DS] ${message}`);
24
+ }
25
+ });
26
+ return () => cancelAnimationFrame(raf);
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, deps);
29
+ }