@brightlocal/ui-components 0.1.4 → 0.3.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 (105) hide show
  1. package/README.md +2 -1
  2. package/dist/alert.cjs +1 -1
  3. package/dist/alert.d.ts +10 -1
  4. package/dist/alert.d.ts.map +1 -1
  5. package/dist/alert.js +6 -2
  6. package/dist/card.cjs +1 -1
  7. package/dist/card.d.ts +6 -2
  8. package/dist/card.d.ts.map +1 -1
  9. package/dist/card.js +89 -73
  10. package/dist/centred-layout.cjs +1 -1
  11. package/dist/centred-layout.d.ts +49 -25
  12. package/dist/centred-layout.d.ts.map +1 -1
  13. package/dist/centred-layout.js +57 -32
  14. package/dist/checkbox.cjs +1 -1
  15. package/dist/checkbox.d.ts.map +1 -1
  16. package/dist/checkbox.js +19 -19
  17. package/dist/chip.cjs +1 -0
  18. package/dist/chip.d.ts +61 -0
  19. package/dist/chip.d.ts.map +1 -0
  20. package/dist/chip.js +165 -0
  21. package/dist/combobox.cjs +1 -1
  22. package/dist/combobox.d.ts +75 -59
  23. package/dist/combobox.d.ts.map +1 -1
  24. package/dist/combobox.js +244 -191
  25. package/dist/date-picker.cjs +1 -1
  26. package/dist/date-picker.d.ts +89 -52
  27. package/dist/date-picker.d.ts.map +1 -1
  28. package/dist/date-picker.js +228 -210
  29. package/dist/dropdown-menu.d.ts.map +1 -1
  30. package/dist/header.cjs +1 -0
  31. package/dist/header.d.ts +42 -0
  32. package/dist/header.d.ts.map +1 -0
  33. package/dist/header.js +22 -0
  34. package/dist/index.cjs +1 -1
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +428 -388
  38. package/dist/input-chip.cjs +1 -0
  39. package/dist/input-chip.d.ts +117 -0
  40. package/dist/input-chip.d.ts.map +1 -0
  41. package/dist/input-chip.js +284 -0
  42. package/dist/input-group.cjs +1 -1
  43. package/dist/input-group.d.ts +5 -0
  44. package/dist/input-group.d.ts.map +1 -1
  45. package/dist/input-group.js +47 -39
  46. package/dist/input-otp.cjs +1 -1
  47. package/dist/input-otp.d.ts +45 -32
  48. package/dist/input-otp.d.ts.map +1 -1
  49. package/dist/input-otp.js +138 -114
  50. package/dist/input-password.cjs +1 -1
  51. package/dist/input-password.d.ts +151 -19
  52. package/dist/input-password.d.ts.map +1 -1
  53. package/dist/input-password.js +197 -91
  54. package/dist/input.cjs +1 -1
  55. package/dist/input.d.ts +4 -0
  56. package/dist/input.d.ts.map +1 -1
  57. package/dist/input.js +26 -24
  58. package/dist/logo.cjs +1 -1
  59. package/dist/logo.js +13 -13
  60. package/dist/progress.cjs +1 -1
  61. package/dist/progress.d.ts +10 -0
  62. package/dist/progress.d.ts.map +1 -1
  63. package/dist/progress.js +45 -36
  64. package/dist/radio-group.cjs +1 -1
  65. package/dist/radio-group.d.ts +4 -0
  66. package/dist/radio-group.d.ts.map +1 -1
  67. package/dist/radio-group.js +49 -47
  68. package/dist/select.cjs +1 -1
  69. package/dist/select.d.ts +3 -1
  70. package/dist/select.d.ts.map +1 -1
  71. package/dist/select.js +57 -56
  72. package/dist/slider.cjs +1 -1
  73. package/dist/slider.d.ts +31 -3
  74. package/dist/slider.d.ts.map +1 -1
  75. package/dist/slider.js +53 -43
  76. package/dist/textarea.cjs +1 -1
  77. package/dist/textarea.d.ts +4 -0
  78. package/dist/textarea.d.ts.map +1 -1
  79. package/dist/textarea.js +19 -18
  80. package/dist/toggle.cjs +1 -1
  81. package/dist/toggle.d.ts.map +1 -1
  82. package/dist/toggle.js +17 -17
  83. package/package.json +1 -1
  84. package/src/components/alert.tsx +10 -1
  85. package/src/components/card.tsx +66 -38
  86. package/src/components/centred-layout.tsx +115 -38
  87. package/src/components/checkbox.tsx +2 -3
  88. package/src/components/chip.tsx +249 -0
  89. package/src/components/combobox.tsx +490 -298
  90. package/src/components/date-picker.tsx +410 -266
  91. package/src/components/dropdown-menu.tsx +6 -1
  92. package/src/components/header.tsx +69 -0
  93. package/src/components/input-chip.tsx +548 -0
  94. package/src/components/input-group.tsx +17 -2
  95. package/src/components/input-otp.tsx +161 -78
  96. package/src/components/input-password.tsx +473 -128
  97. package/src/components/input.tsx +11 -3
  98. package/src/components/logo.tsx +1 -1
  99. package/src/components/progress.tsx +21 -2
  100. package/src/components/radio-group.tsx +11 -0
  101. package/src/components/select.tsx +5 -2
  102. package/src/components/slider.tsx +85 -15
  103. package/src/components/textarea.tsx +15 -5
  104. package/src/components/toggle.tsx +13 -15
  105. package/src/index.ts +3 -0
@@ -8,7 +8,7 @@ import { cn } from "@brightlocal/ui-components/lib/utils";
8
8
  */
9
9
  export type LogoVariant = "logotype" | "mark";
10
10
 
11
- const logoVariants = cva("inline-flex [&_path]:fill-primary", {
11
+ const logoVariants = cva("inline-flex [&_path]:fill-brand-primary-foreground", {
12
12
  variants: {
13
13
  variant: {
14
14
  logotype: "h-6",
@@ -33,6 +33,16 @@ interface ProgressProps extends React.ComponentProps<
33
33
  * Optional visible label text displayed above the progress bar
34
34
  */
35
35
  label?: string;
36
+ /**
37
+ * Custom class name for the indicator (progress fill)
38
+ * Use this to customize the color, e.g., "bg-red-500"
39
+ */
40
+ indicatorClassName?: string;
41
+ /**
42
+ * Whether the progress is in a disabled state
43
+ * When disabled, the component renders with 50% opacity
44
+ */
45
+ disabled?: boolean;
36
46
  }
37
47
 
38
48
  /**
@@ -52,6 +62,8 @@ const Progress = React.forwardRef<
52
62
  trackingLabel,
53
63
  ariaLabel = "Progress",
54
64
  label,
65
+ indicatorClassName,
66
+ disabled,
55
67
  ...props
56
68
  },
57
69
  ref
@@ -67,6 +79,7 @@ const Progress = React.forwardRef<
67
79
  className={cn(
68
80
  "relative h-2 w-full overflow-hidden rounded-full",
69
81
  "bg-primary/20",
82
+ !hasVisibleLabel && disabled && "opacity-50",
70
83
  className
71
84
  )}
72
85
  data-hook={dataHook}
@@ -80,7 +93,10 @@ const Progress = React.forwardRef<
80
93
  animate={{
81
94
  transform: `translateX(-${100 - (value || 0)}%)`,
82
95
  }}
83
- className="h-full w-full flex-1 bg-green-400"
96
+ className={cn(
97
+ "h-full w-full flex-1 bg-green-400",
98
+ indicatorClassName
99
+ )}
84
100
  data-slot="progress-indicator"
85
101
  initial={false}
86
102
  transition={{
@@ -100,7 +116,10 @@ const Progress = React.forwardRef<
100
116
 
101
117
  return (
102
118
  <div
103
- className="flex w-full items-center gap-2"
119
+ className={cn(
120
+ "flex w-full items-center gap-2",
121
+ disabled && "opacity-50"
122
+ )}
104
123
  data-slot="progress-wrapper"
105
124
  >
106
125
  <span
@@ -154,6 +154,10 @@ interface RadioGroupProps
154
154
  * Tracking label for analytics context
155
155
  */
156
156
  trackingLabel?: string;
157
+ /**
158
+ * Whether the radio group has an error state
159
+ */
160
+ error?: boolean;
157
161
  }
158
162
 
159
163
  /**
@@ -196,16 +200,23 @@ const RadioGroup = React.forwardRef<
196
200
  dataHook,
197
201
  trackingEl,
198
202
  trackingLabel,
203
+ error,
199
204
  ...props
200
205
  },
201
206
  ref
202
207
  ) => {
203
208
  const contextVariant = variant || "default";
209
+ // Support both error prop and aria-invalid for backwards compatibility
210
+ const hasError =
211
+ error ||
212
+ props["aria-invalid"] === true ||
213
+ props["aria-invalid"] === "true";
204
214
 
205
215
  return (
206
216
  <RadioGroupContext.Provider value={{ variant: contextVariant }}>
207
217
  <RadioGroupPrimitive.Root
208
218
  ref={ref}
219
+ aria-invalid={hasError ? "true" : undefined}
209
220
  className={cn(radioGroupVariants({ variant }), className)}
210
221
  data-hook={dataHook}
211
222
  data-slot="radio-group"
@@ -184,6 +184,8 @@ interface SelectTriggerProps extends React.ComponentProps<
184
184
  placeholder?: string;
185
185
  /** Data hook for testing and automation */
186
186
  dataHook?: string;
187
+ /** Whether the select trigger has an error state */
188
+ error?: boolean;
187
189
  }
188
190
 
189
191
  // ============================================================================
@@ -198,11 +200,12 @@ function SelectTrigger({
198
200
  children,
199
201
  placeholder,
200
202
  dataHook,
203
+ error,
201
204
  ...props
202
205
  }: SelectTriggerProps) {
203
- // Parse aria attributes
206
+ // Support both error prop and aria-invalid for backwards compatibility
204
207
  const isError =
205
- props["aria-invalid"] === true || props["aria-invalid"] === "true";
208
+ error || props["aria-invalid"] === true || props["aria-invalid"] === "true";
206
209
  const isRequired =
207
210
  props["aria-required"] === true || props["aria-required"] === "true";
208
211
 
@@ -15,10 +15,18 @@ export interface SliderProps extends React.ComponentProps<
15
15
  * Data hook for automated testing (required)
16
16
  */
17
17
  dataHook: string;
18
+ /**
19
+ * Slider mode - single value or range (two thumbs).
20
+ * - "single": One thumb, selects a single value (default)
21
+ * - "range": Two thumbs, selects a min/max range
22
+ * @default "single"
23
+ */
24
+ mode?: "single" | "range";
18
25
  /**
19
26
  * Accessible labels for the slider thumb(s).
20
- * For range sliders with multiple thumbs, provide an array of labels.
21
- * @default ["Slider"]
27
+ * - For single mode: provide one label (e.g., ["Volume"])
28
+ * - For range mode: provide two labels (e.g., ["Minimum price", "Maximum price"])
29
+ * @default ["Slider"] for single, ["Minimum value", "Maximum value"] for range
22
30
  */
23
31
  thumbLabels?: string[];
24
32
  /**
@@ -31,10 +39,33 @@ export interface SliderProps extends React.ComponentProps<
31
39
  trackingLabel?: string;
32
40
  }
33
41
 
42
+ const DEFAULT_SINGLE_LABELS = ["Slider"];
43
+ const DEFAULT_RANGE_LABELS = ["Minimum value", "Maximum value"];
44
+
34
45
  /**
35
46
  * Slider component for selecting numeric values within a range.
36
- * Supports single value selection and range selection (two thumbs).
47
+ * Supports single value selection (default) and range selection (two thumbs).
37
48
  * Built on Radix UI Slider primitive with full keyboard accessibility.
49
+ *
50
+ * @example Single value slider (controlled)
51
+ * ```tsx
52
+ * <Slider
53
+ * dataHook="volume-slider"
54
+ * value={[50]}
55
+ * onValueChange={(value) => setValue(value)}
56
+ * thumbLabels={["Volume"]}
57
+ * />
58
+ * ```
59
+ *
60
+ * @example Range slider (uncontrolled)
61
+ * ```tsx
62
+ * <Slider
63
+ * dataHook="price-range"
64
+ * mode="range"
65
+ * defaultValue={[20, 80]}
66
+ * thumbLabels={["Minimum price", "Maximum price"]}
67
+ * />
68
+ * ```
38
69
  */
39
70
  const Slider = React.forwardRef<
40
71
  React.ComponentRef<typeof SliderPrimitive.Root>,
@@ -47,6 +78,7 @@ const Slider = React.forwardRef<
47
78
  defaultValue,
48
79
  max = 100,
49
80
  min = 0,
81
+ mode = "single",
50
82
  thumbLabels,
51
83
  trackingEl,
52
84
  trackingLabel,
@@ -55,15 +87,52 @@ const Slider = React.forwardRef<
55
87
  },
56
88
  ref
57
89
  ) => {
58
- const _values = React.useMemo(
59
- () =>
60
- Array.isArray(value)
61
- ? value
62
- : Array.isArray(defaultValue)
63
- ? defaultValue
64
- : [min, max],
65
- [value, defaultValue, min, max]
66
- );
90
+ // Determine thumb count based on mode and provided values
91
+ const thumbCount = React.useMemo(() => {
92
+ // If value or defaultValue is explicitly provided as array, use its length
93
+ if (Array.isArray(value)) return value.length;
94
+ if (Array.isArray(defaultValue)) return defaultValue.length;
95
+ // Otherwise, use mode to determine thumb count
96
+ return mode === "range" ? 2 : 1;
97
+ }, [value, defaultValue, mode]);
98
+
99
+ // Compute effective default value for Radix
100
+ const effectiveDefaultValue = React.useMemo(() => {
101
+ if (defaultValue !== undefined) return defaultValue;
102
+ if (value !== undefined) return undefined; // Controlled, no default needed
103
+ // Provide sensible defaults based on mode
104
+ return mode === "range" ? [min, max] : [min];
105
+ }, [defaultValue, value, mode, min, max]);
106
+
107
+ // Get appropriate labels with fallbacks
108
+ const getThumbLabel = (index: number): string => {
109
+ const customLabel = thumbLabels?.[index];
110
+ if (customLabel) return customLabel;
111
+ const defaultLabels =
112
+ thumbCount > 1 ? DEFAULT_RANGE_LABELS : DEFAULT_SINGLE_LABELS;
113
+ return defaultLabels[index] ?? `Slider thumb ${index + 1}`;
114
+ };
115
+
116
+ // Dev-only warnings
117
+ if (process.env.NODE_ENV === "development") {
118
+ // Warn if both controlled and uncontrolled props are provided
119
+ if (value !== undefined && defaultValue !== undefined) {
120
+ console.warn(
121
+ `[Slider] Component is being used with both "value" and "defaultValue" props. ` +
122
+ `This is likely a mistake. Use "value" with "onValueChange" for controlled mode, ` +
123
+ `or "defaultValue" for uncontrolled mode, but not both.`
124
+ );
125
+ }
126
+
127
+ // Warn if thumbLabels length doesn't match thumb count
128
+ if (thumbLabels && thumbLabels.length !== thumbCount) {
129
+ console.warn(
130
+ `[Slider] "thumbLabels" array length (${thumbLabels.length}) doesn't match ` +
131
+ `the number of thumbs (${thumbCount}). ` +
132
+ `For ${mode === "range" ? "range" : "single"} mode, provide ${thumbCount} label(s).`
133
+ );
134
+ }
135
+ }
67
136
 
68
137
  return (
69
138
  <SliderPrimitive.Root
@@ -73,10 +142,11 @@ const Slider = React.forwardRef<
73
142
  className
74
143
  )}
75
144
  data-hook={dataHook}
145
+ data-mode={mode}
76
146
  data-slot="slider"
77
147
  data-tracking-el={trackingEl}
78
148
  data-tracking-label={trackingLabel}
79
- defaultValue={defaultValue}
149
+ defaultValue={effectiveDefaultValue}
80
150
  max={max}
81
151
  min={min}
82
152
  value={value}
@@ -95,10 +165,10 @@ const Slider = React.forwardRef<
95
165
  data-slot="slider-range"
96
166
  />
97
167
  </SliderPrimitive.Track>
98
- {Array.from({ length: _values.length }, (_, index) => (
168
+ {Array.from({ length: thumbCount }, (_, index) => (
99
169
  <SliderPrimitive.Thumb
100
170
  key={index}
101
- aria-label={thumbLabels?.[index] ?? "Slider"}
171
+ aria-label={getThumbLabel(index)}
102
172
  className="border-primary bg-background ring-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
103
173
  data-slot="slider-thumb"
104
174
  />
@@ -35,6 +35,10 @@ interface TextareaProps extends Omit<
35
35
  * Optional id attribute for linking with label via htmlFor
36
36
  */
37
37
  id?: string;
38
+ /**
39
+ * Whether the textarea has an error state
40
+ */
41
+ error?: boolean;
38
42
  /**
39
43
  * Optional tracking prop for analytics tracking element identifier
40
44
  */
@@ -46,17 +50,23 @@ interface TextareaProps extends Omit<
46
50
  }
47
51
 
48
52
  const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
49
- ({ className, dataHook, trackingEl, trackingLabel, ...props }, ref) => {
50
- // Check for error state from aria-invalid attribute
51
- const hasErrorStyling =
52
- props["aria-invalid"] === true || props["aria-invalid"] === "true";
53
+ (
54
+ { className, dataHook, error, trackingEl, trackingLabel, ...props },
55
+ ref
56
+ ) => {
57
+ // Support both error prop and aria-invalid for backwards compatibility
58
+ const hasError =
59
+ error ||
60
+ props["aria-invalid"] === true ||
61
+ props["aria-invalid"] === "true";
53
62
 
54
63
  return (
55
64
  <textarea
56
65
  ref={ref}
66
+ aria-invalid={hasError ? "true" : undefined}
57
67
  className={cn(
58
68
  textareaVariants(),
59
- hasErrorStyling &&
69
+ hasError &&
60
70
  "border-destructive dark:border-destructive focus-visible:border-destructive focus-visible:shadow-destructive",
61
71
  className
62
72
  )}
@@ -7,7 +7,7 @@ import { cva, type VariantProps } from "class-variance-authority";
7
7
  import { cn } from "@brightlocal/ui-components/lib/utils";
8
8
 
9
9
  const toggleVariants = cva(
10
- "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:shadow-default outline-none transition-[color,box-shadow] duration-150 ease-in-out aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
10
+ "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:shadow-default outline-none transition-[color,box-shadow] duration-150 ease-in-out whitespace-nowrap",
11
11
  {
12
12
  variants: {
13
13
  variant: {
@@ -68,20 +68,18 @@ const Toggle = React.forwardRef<
68
68
  ...props
69
69
  },
70
70
  ref
71
- ) => {
72
- return (
73
- <TogglePrimitive.Root
74
- ref={ref}
75
- aria-label={ariaLabel}
76
- className={cn(toggleVariants({ variant, size, className }))}
77
- data-hook={dataHook}
78
- data-slot="toggle"
79
- data-tracking-el={trackingEl || `toggle-${variant}`}
80
- data-tracking-label={trackingLabel}
81
- {...props}
82
- />
83
- );
84
- }
71
+ ) => (
72
+ <TogglePrimitive.Root
73
+ ref={ref}
74
+ aria-label={ariaLabel}
75
+ className={cn(toggleVariants({ variant, size, className }))}
76
+ data-hook={dataHook}
77
+ data-slot="toggle"
78
+ data-tracking-el={trackingEl || `toggle-${variant}`}
79
+ data-tracking-label={trackingLabel}
80
+ {...props}
81
+ />
82
+ )
85
83
  );
86
84
 
87
85
  Toggle.displayName = "Toggle";
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./components/carousel";
13
13
  export * from "./components/chart";
14
14
  export * from "./components/centred-layout";
15
15
  export * from "./components/checkbox";
16
+ export * from "./components/chip";
16
17
  export * from "./components/collapsible";
17
18
  export * from "./components/combobox";
18
19
  export * from "./components/command";
@@ -24,8 +25,10 @@ export * from "./components/drawer";
24
25
  export * from "./components/dropdown-menu";
25
26
  export * from "./components/field";
26
27
  export * from "./components/global-layout";
28
+ export * from "./components/header";
27
29
  export * from "./components/hover-card";
28
30
  export * from "./components/input";
31
+ export * from "./components/input-chip";
29
32
  export * from "./components/input-group";
30
33
  export * from "./components/input-otp";
31
34
  export * from "./components/label";