@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
@@ -12,179 +12,524 @@ import {
12
12
  InputGroupButton,
13
13
  } from "@brightlocal/ui-components/input-group";
14
14
 
15
- type PasswordStrength = "meter" | "weak" | "ok" | "good" | "great";
15
+ // ============================================================================
16
+ // Types
17
+ // ============================================================================
16
18
 
17
- interface PasswordStrengthConfig {
19
+ /**
20
+ * Default password strength levels (industry standard)
21
+ */
22
+ type DefaultPasswordStrength = "meter" | "weak" | "ok" | "good" | "great";
23
+
24
+ /**
25
+ * Configuration for a single strength level
26
+ */
27
+ interface StrengthLevelConfig {
18
28
  label: string;
19
29
  value: number;
20
30
  color: string;
21
31
  }
22
32
 
23
- const PASSWORD_STRENGTH: Record<PasswordStrength, PasswordStrengthConfig> = {
24
- meter: { label: "Meter", value: 0, color: "bg-muted" },
25
- weak: { label: "Weak", value: 25, color: "bg-red-500" },
26
- ok: { label: "Ok", value: 50, color: "bg-orange-500" },
33
+ /**
34
+ * Default strength levels configuration
35
+ */
36
+ const DEFAULT_STRENGTH_LEVELS: Record<
37
+ DefaultPasswordStrength,
38
+ StrengthLevelConfig
39
+ > = {
40
+ meter: { label: "Meter", value: 0, color: "bg-green-500" },
41
+ weak: { label: "Weak", value: 25, color: "bg-green-500" },
42
+ ok: { label: "Ok", value: 50, color: "bg-green-500" },
27
43
  good: { label: "Good", value: 75, color: "bg-green-500" },
28
- great: { label: "Great", value: 100, color: "bg-green-600" },
44
+ great: { label: "Great", value: 100, color: "bg-green-500" },
29
45
  };
30
46
 
31
- interface InputPasswordProps extends Omit<
32
- React.ComponentProps<"input">,
33
- "type"
47
+ /**
48
+ * Calculate password strength based on various criteria (default implementation)
49
+ * - Minimum 12 characters required for "ok" or better
50
+ */
51
+ function calculatePasswordStrength(password: string): DefaultPasswordStrength {
52
+ if (!password || password.length === 0) {
53
+ return "meter";
54
+ }
55
+
56
+ // Minimum 12 characters required for "ok" or better
57
+ if (password.length < 12) {
58
+ return "weak";
59
+ }
60
+
61
+ let score = 0;
62
+
63
+ // Length bonuses
64
+ if (password.length >= 16) score += 1;
65
+
66
+ // Character variety checks
67
+ if (/[a-z]/.test(password)) score += 1; // lowercase
68
+ if (/[A-Z]/.test(password)) score += 1; // uppercase
69
+ if (/[0-9]/.test(password)) score += 1; // numbers
70
+ if (/[^a-zA-Z0-9]/.test(password)) score += 1; // special characters
71
+
72
+ // Determine strength based on score
73
+ if (score <= 1) return "ok";
74
+ if (score <= 3) return "good";
75
+ return "great";
76
+ }
77
+
78
+ // ============================================================================
79
+ // Context
80
+ // ============================================================================
81
+
82
+ interface InputPasswordContextValue {
83
+ // Visibility state
84
+ showPassword: boolean;
85
+ setShowPassword: (show: boolean) => void;
86
+ toggleVisibility: () => void;
87
+
88
+ // Password value and strength
89
+ password: string;
90
+ setPassword: (password: string) => void;
91
+ strength: string;
92
+ strengthLevels: Record<string, StrengthLevelConfig>;
93
+
94
+ // Disabled state
95
+ disabled?: boolean;
96
+
97
+ // Data attributes
98
+ dataHook: string;
99
+ trackingEl?: string;
100
+ trackingLabel?: string;
101
+
102
+ // Input ID for label association
103
+ inputId: string;
104
+
105
+ // Error state
106
+ error?: boolean;
107
+ }
108
+
109
+ const InputPasswordContext =
110
+ React.createContext<InputPasswordContextValue | null>(null);
111
+
112
+ function useInputPasswordContext() {
113
+ const context = React.useContext(InputPasswordContext);
114
+ if (!context) {
115
+ throw new Error(
116
+ "InputPassword compound components must be used within InputPasswordRoot"
117
+ );
118
+ }
119
+ return context;
120
+ }
121
+
122
+ // ============================================================================
123
+ // InputPasswordRoot
124
+ // ============================================================================
125
+
126
+ export interface InputPasswordRootProps<
127
+ T extends string = DefaultPasswordStrength,
34
128
  > {
35
129
  /**
36
- * Show password strength indicator below the input
130
+ * Data hook for automated testing (REQUIRED)
37
131
  */
38
- showStrength?: boolean;
132
+ dataHook: string;
39
133
  /**
40
- * Callback when password strength changes
134
+ * Tracking element identifier for analytics
41
135
  */
42
- onStrengthChange?: (strength: PasswordStrength) => void;
136
+ trackingEl?: string;
43
137
  /**
44
- * Required data-hook attribute for testing
138
+ * Tracking label for analytics context
45
139
  */
46
- dataHook: string;
140
+ trackingLabel?: string;
47
141
  /**
48
- * Optional tracking element identifier
142
+ * Disabled state
49
143
  */
50
- trackingEl?: string;
144
+ disabled?: boolean;
51
145
  /**
52
- * Optional tracking label
146
+ * Controlled password value
53
147
  */
54
- trackingLabel?: string;
148
+ value?: string;
149
+ /**
150
+ * Callback fired when password changes
151
+ */
152
+ onChange?: (value: string) => void;
153
+ /**
154
+ * Callback fired when password strength changes
155
+ */
156
+ onStrengthChange?: (strength: T) => void;
157
+ /**
158
+ * Custom strength levels configuration.
159
+ * Define your own levels with custom keys, labels, values, and colors.
160
+ * @example
161
+ * strengthLevels={{
162
+ * empty: { label: "Enter password", value: 0, color: "bg-muted" },
163
+ * slow: { label: "Slow", value: 33, color: "bg-red-500" },
164
+ * medium: { label: "Medium", value: 66, color: "bg-yellow-500" },
165
+ * fast: { label: "Fast", value: 100, color: "bg-green-500" },
166
+ * }}
167
+ */
168
+ strengthLevels?: Record<T, StrengthLevelConfig>;
169
+ /**
170
+ * Custom function to calculate password strength.
171
+ * Must return a key from strengthLevels (or default levels if not provided).
172
+ * @default calculatePasswordStrength (built-in)
173
+ */
174
+ calculateStrength?: (password: string) => T;
175
+ /**
176
+ * Whether the input has an error state
177
+ */
178
+ error?: boolean;
179
+ /**
180
+ * ID for the input element (for label association)
181
+ */
182
+ id?: string;
183
+ /**
184
+ * Children components
185
+ */
186
+ children: React.ReactNode;
187
+ /**
188
+ * Additional class name for the root container
189
+ */
190
+ className?: string;
55
191
  }
56
192
 
57
193
  /**
58
- * Calculate password strength based on various criteria
194
+ * InputPasswordRoot - Root component that provides context for all InputPassword parts
195
+ *
196
+ * Generic type parameter T allows custom strength levels:
197
+ * @example
198
+ * // Using default levels
199
+ * <InputPasswordRoot dataHook="password">...</InputPasswordRoot>
200
+ *
201
+ * // Using custom levels
202
+ * type MyStrength = "empty" | "slow" | "medium" | "fast";
203
+ * <InputPasswordRoot<MyStrength>
204
+ * dataHook="password"
205
+ * strengthLevels={{
206
+ * empty: { label: "Enter password", value: 0, color: "bg-muted" },
207
+ * slow: { label: "Slow", value: 33, color: "bg-red-500" },
208
+ * medium: { label: "Medium", value: 66, color: "bg-yellow-500" },
209
+ * fast: { label: "Fast", value: 100, color: "bg-green-500" },
210
+ * }}
211
+ * calculateStrength={(password) => {
212
+ * if (!password) return "empty";
213
+ * if (password.length < 8) return "slow";
214
+ * if (password.length < 12) return "medium";
215
+ * return "fast";
216
+ * }}
217
+ * >
218
+ * ...
219
+ * </InputPasswordRoot>
59
220
  */
60
- function calculatePasswordStrength(password: string): PasswordStrength {
61
- if (!password || password.length === 0) {
62
- return "meter";
63
- }
221
+ function InputPasswordRoot<T extends string = DefaultPasswordStrength>({
222
+ children,
223
+ dataHook,
224
+ trackingEl,
225
+ trackingLabel,
226
+ disabled,
227
+ value,
228
+ onChange,
229
+ onStrengthChange,
230
+ strengthLevels,
231
+ calculateStrength,
232
+ error,
233
+ id,
234
+ className,
235
+ }: InputPasswordRootProps<T>) {
236
+ const [showPassword, setShowPassword] = React.useState(false);
237
+ const [internalPassword, setInternalPassword] = React.useState("");
238
+ const [strength, setStrength] = React.useState<string>("meter");
64
239
 
65
- let score = 0;
240
+ const generatedId = React.useId();
241
+ const inputId = id || generatedId;
66
242
 
67
- // Length check
68
- if (password.length >= 8) score += 1;
69
- if (password.length >= 12) score += 1;
243
+ const password = value !== undefined ? value : internalPassword;
70
244
 
71
- // Character variety checks
72
- if (/[a-z]/.test(password)) score += 1; // lowercase
73
- if (/[A-Z]/.test(password)) score += 1; // uppercase
74
- if (/[0-9]/.test(password)) score += 1; // numbers
75
- if (/[^a-zA-Z0-9]/.test(password)) score += 1; // special characters
245
+ // Use provided levels or defaults
246
+ const levels = (strengthLevels ?? DEFAULT_STRENGTH_LEVELS) as Record<
247
+ string,
248
+ StrengthLevelConfig
249
+ >;
76
250
 
77
- // Determine strength based on score
78
- if (score <= 2) return "weak";
79
- if (score <= 3) return "ok";
80
- if (score <= 4) return "good";
81
- return "great";
251
+ // Use provided calculator or default
252
+ const calculator =
253
+ calculateStrength ?? (calculatePasswordStrength as (password: string) => T);
254
+
255
+ const handleSetPassword = React.useCallback(
256
+ (newPassword: string) => {
257
+ if (value === undefined) {
258
+ setInternalPassword(newPassword);
259
+ }
260
+ onChange?.(newPassword);
261
+ },
262
+ [value, onChange]
263
+ );
264
+
265
+ const toggleVisibility = React.useCallback(() => {
266
+ setShowPassword((prev) => !prev);
267
+ }, []);
268
+
269
+ // Calculate password strength with debounce
270
+ React.useEffect(() => {
271
+ const timeoutId = setTimeout(() => {
272
+ const newStrength = calculator(password);
273
+ setStrength(newStrength);
274
+ onStrengthChange?.(newStrength);
275
+ }, 180);
276
+
277
+ return () => clearTimeout(timeoutId);
278
+ }, [password, calculator, onStrengthChange]);
279
+
280
+ const contextValue = React.useMemo<InputPasswordContextValue>(
281
+ () => ({
282
+ showPassword,
283
+ setShowPassword,
284
+ toggleVisibility,
285
+ password,
286
+ setPassword: handleSetPassword,
287
+ strength,
288
+ strengthLevels: levels,
289
+ disabled,
290
+ dataHook,
291
+ trackingEl,
292
+ trackingLabel,
293
+ inputId,
294
+ error,
295
+ }),
296
+ [
297
+ showPassword,
298
+ toggleVisibility,
299
+ password,
300
+ handleSetPassword,
301
+ strength,
302
+ levels,
303
+ disabled,
304
+ dataHook,
305
+ trackingEl,
306
+ trackingLabel,
307
+ inputId,
308
+ error,
309
+ ]
310
+ );
311
+
312
+ return (
313
+ <InputPasswordContext.Provider value={contextValue}>
314
+ <div className={cn("w-full", className)}>{children}</div>
315
+ </InputPasswordContext.Provider>
316
+ );
82
317
  }
83
318
 
84
- const InputPassword = React.forwardRef<HTMLInputElement, InputPasswordProps>(
319
+ InputPasswordRoot.displayName = "InputPasswordRoot";
320
+
321
+ // ============================================================================
322
+ // InputPasswordField
323
+ // ============================================================================
324
+
325
+ export interface InputPasswordFieldProps extends Omit<
326
+ React.ComponentProps<typeof InputGroupInput>,
327
+ "type"
328
+ > {
329
+ /**
330
+ * Additional class name for the InputGroup wrapper
331
+ */
332
+ groupClassName?: string;
333
+ }
334
+
335
+ /**
336
+ * InputPasswordField - The password input field with toggle button
337
+ * Wraps InputGroup with InputGroupInput and InputGroupAddon for the toggle
338
+ */
339
+ const InputPasswordField = React.forwardRef<
340
+ HTMLInputElement,
341
+ InputPasswordFieldProps
342
+ >(({ className, groupClassName, onChange, ...props }, ref) => {
343
+ const {
344
+ showPassword,
345
+ toggleVisibility,
346
+ password,
347
+ setPassword,
348
+ disabled,
349
+ dataHook,
350
+ trackingEl,
351
+ trackingLabel,
352
+ inputId,
353
+ error,
354
+ } = useInputPasswordContext();
355
+
356
+ const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
357
+ setPassword(e.target.value);
358
+ onChange?.(e);
359
+ };
360
+
361
+ return (
362
+ <InputGroup className={groupClassName} dataHook={dataHook} error={error}>
363
+ <InputGroupInput
364
+ ref={ref}
365
+ className={className}
366
+ disabled={disabled}
367
+ id={inputId}
368
+ trackingEl={trackingEl}
369
+ trackingLabel={trackingLabel}
370
+ type={showPassword ? "text" : "password"}
371
+ value={password}
372
+ onChange={handleChange}
373
+ {...props}
374
+ />
375
+ <InputGroupAddon align="inline-end">
376
+ <InputGroupButton
377
+ aria-label={showPassword ? "Hide password" : "Show password"}
378
+ data-hook={`${dataHook}-toggle`}
379
+ disabled={disabled}
380
+ size="icon"
381
+ variant="ghost"
382
+ onClick={toggleVisibility}
383
+ >
384
+ {showPassword ? (
385
+ <EyeOff className="h-4 w-4" />
386
+ ) : (
387
+ <Eye className="h-4 w-4" />
388
+ )}
389
+ </InputGroupButton>
390
+ </InputGroupAddon>
391
+ </InputGroup>
392
+ );
393
+ });
394
+
395
+ InputPasswordField.displayName = "InputPasswordField";
396
+
397
+ // ============================================================================
398
+ // InputPasswordToggle
399
+ // ============================================================================
400
+
401
+ export interface InputPasswordToggleProps extends Omit<
402
+ React.ComponentProps<typeof InputGroupButton>,
403
+ "onClick" | "aria-label"
404
+ > {
405
+ /**
406
+ * Custom aria-label for show state
407
+ * @default "Show password"
408
+ */
409
+ showLabel?: string;
410
+ /**
411
+ * Custom aria-label for hide state
412
+ * @default "Hide password"
413
+ */
414
+ hideLabel?: string;
415
+ }
416
+
417
+ /**
418
+ * InputPasswordToggle - Standalone toggle button for password visibility
419
+ * Use this when you need custom placement of the toggle button
420
+ */
421
+ const InputPasswordToggle = React.forwardRef<
422
+ HTMLButtonElement,
423
+ InputPasswordToggleProps
424
+ >(
85
425
  (
86
426
  {
87
427
  className,
88
- showStrength = true,
89
- onStrengthChange,
90
- dataHook,
91
- trackingEl,
92
- trackingLabel,
93
- onChange,
94
- value,
95
- id,
428
+ showLabel = "Show password",
429
+ hideLabel = "Hide password",
430
+ size = "icon",
431
+ variant = "ghost",
96
432
  ...props
97
433
  },
98
434
  ref
99
435
  ) => {
100
- const [showPassword, setShowPassword] = React.useState(false);
101
- const [strength, setStrength] = React.useState<PasswordStrength>("meter");
102
- const [internalValue, setInternalValue] = React.useState("");
436
+ const { showPassword, toggleVisibility, disabled, dataHook } =
437
+ useInputPasswordContext();
103
438
 
104
- const generatedId = React.useId();
105
- const inputId = id || generatedId;
106
- const currentValue = value !== undefined ? String(value) : internalValue;
439
+ return (
440
+ <InputGroupButton
441
+ ref={ref}
442
+ aria-label={showPassword ? hideLabel : showLabel}
443
+ className={className}
444
+ data-hook={`${dataHook}-toggle`}
445
+ disabled={disabled}
446
+ size={size}
447
+ variant={variant}
448
+ onClick={toggleVisibility}
449
+ {...props}
450
+ >
451
+ {showPassword ? (
452
+ <EyeOff className="h-4 w-4" />
453
+ ) : (
454
+ <Eye className="h-4 w-4" />
455
+ )}
456
+ </InputGroupButton>
457
+ );
458
+ }
459
+ );
107
460
 
108
- // Calculate password strength with debounce
109
- React.useEffect(() => {
110
- const timeoutId = setTimeout(() => {
111
- const newStrength = calculatePasswordStrength(currentValue);
112
- setStrength(newStrength);
113
- onStrengthChange?.(newStrength);
114
- }, 180);
461
+ InputPasswordToggle.displayName = "InputPasswordToggle";
115
462
 
116
- return () => clearTimeout(timeoutId);
117
- }, [currentValue, onStrengthChange]);
463
+ // ============================================================================
464
+ // InputPasswordStrength
465
+ // ============================================================================
118
466
 
119
- const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
120
- setInternalValue(e.target.value);
121
- onChange?.(e);
122
- };
467
+ export interface InputPasswordStrengthProps {
468
+ /**
469
+ * Additional class name
470
+ */
471
+ className?: string;
472
+ /**
473
+ * Whether to show the label next to the progress bar
474
+ * @default true
475
+ */
476
+ showLabel?: boolean;
477
+ }
123
478
 
124
- const togglePasswordVisibility = () => {
125
- setShowPassword((prev) => !prev);
126
- };
479
+ /**
480
+ * InputPasswordStrength - Password strength indicator
481
+ * Displays a progress bar and optional label showing password strength.
482
+ * Automatically uses the strength levels configured on InputPasswordRoot.
483
+ */
484
+ function InputPasswordStrength({
485
+ className,
486
+ showLabel = true,
487
+ }: InputPasswordStrengthProps) {
488
+ const { strength, strengthLevels, dataHook, disabled } =
489
+ useInputPasswordContext();
127
490
 
128
- const strengthConfig = PASSWORD_STRENGTH[strength];
491
+ // Get config for current strength level
492
+ const config = strengthLevels[strength] ?? {
493
+ label: strength,
494
+ value: 0,
495
+ color: "bg-muted",
496
+ };
129
497
 
130
- return (
131
- <div className="w-full">
132
- <InputGroup className={className} dataHook={dataHook}>
133
- <InputGroupInput
134
- ref={ref}
135
- id={inputId}
136
- trackingEl={trackingEl}
137
- trackingLabel={trackingLabel}
138
- type={showPassword ? "text" : "password"}
139
- value={value}
140
- onChange={handleChange}
141
- {...props}
142
- />
143
- <InputGroupAddon align="inline-end">
144
- <InputGroupButton
145
- aria-label={showPassword ? "Hide password" : "Show password"}
146
- data-hook={dataHook ? `${dataHook}-toggle` : undefined}
147
- disabled={props.disabled}
148
- size="icon"
149
- variant="ghost"
150
- onClick={togglePasswordVisibility}
151
- >
152
- {showPassword ? (
153
- <EyeOff className="h-4 w-4" />
154
- ) : (
155
- <Eye className="h-4 w-4" />
156
- )}
157
- </InputGroupButton>
158
- </InputGroupAddon>
159
- </InputGroup>
160
-
161
- {showStrength && (
162
- <div className="mt-1 space-y-2">
163
- <div className="flex items-center gap-2">
164
- <Progress
165
- className={cn("h-2 flex-1")}
166
- dataHook={
167
- dataHook
168
- ? `${dataHook}-strength-progress`
169
- : "password-strength-progress"
170
- }
171
- value={strengthConfig.value}
172
- />
173
- <span
174
- className="text-foreground w-10 shrink-0 text-right text-sm font-medium whitespace-nowrap"
175
- data-hook={dataHook ? `${dataHook}-strength-label` : undefined}
176
- >
177
- {strengthConfig.label}
178
- </span>
179
- </div>
180
- </div>
498
+ return (
499
+ <div className={cn("mt-1 space-y-2", className)}>
500
+ <div className={cn("flex items-center gap-2", disabled && "opacity-50")}>
501
+ <Progress
502
+ className="h-2 flex-1"
503
+ dataHook={`${dataHook}-strength-progress`}
504
+ indicatorClassName={config.color}
505
+ value={config.value}
506
+ />
507
+ {showLabel && (
508
+ <span
509
+ className="text-foreground w-10 shrink-0 text-right text-sm font-medium whitespace-nowrap"
510
+ data-hook={`${dataHook}-strength-label`}
511
+ >
512
+ {config.label}
513
+ </span>
181
514
  )}
182
515
  </div>
183
- );
184
- }
185
- );
516
+ </div>
517
+ );
518
+ }
519
+
520
+ InputPasswordStrength.displayName = "InputPasswordStrength";
186
521
 
187
- InputPassword.displayName = "InputPassword";
522
+ // ============================================================================
523
+ // Exports
524
+ // ============================================================================
525
+
526
+ export {
527
+ InputPasswordRoot,
528
+ InputPasswordField,
529
+ InputPasswordToggle,
530
+ InputPasswordStrength,
531
+ calculatePasswordStrength,
532
+ DEFAULT_STRENGTH_LEVELS,
533
+ };
188
534
 
189
- export { InputPassword, calculatePasswordStrength, PASSWORD_STRENGTH };
190
- export type { InputPasswordProps, PasswordStrength };
535
+ export type { DefaultPasswordStrength, StrengthLevelConfig };
@@ -78,6 +78,10 @@ export interface InputProps
78
78
  * Required data-hook attribute for automated testing
79
79
  */
80
80
  dataHook: string;
81
+ /**
82
+ * Whether the input has an error state
83
+ */
84
+ error?: boolean;
81
85
  /**
82
86
  * Optional tracking element identifier for analytics
83
87
  */
@@ -95,23 +99,27 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
95
99
  hasIcon = false,
96
100
  hasSecondaryIcon = false,
97
101
  dataHook,
102
+ error,
98
103
  trackingEl,
99
104
  trackingLabel,
100
105
  ...props
101
106
  },
102
107
  ref
103
108
  ) => {
104
- // Check for error state from aria-invalid attribute
109
+ // Support both error prop and aria-invalid for backwards compatibility
105
110
  const hasError =
106
- props["aria-invalid"] === true || props["aria-invalid"] === "true";
111
+ error ||
112
+ props["aria-invalid"] === true ||
113
+ props["aria-invalid"] === "true";
107
114
 
108
115
  return (
109
116
  <input
110
117
  ref={ref}
118
+ aria-invalid={hasError ? "true" : undefined}
111
119
  className={cn(
112
120
  inputVariants({ hasIcon, hasSecondaryIcon }),
113
121
  hasError &&
114
- "border-destructive dark:border-destructive focus-visible:border-destructive focus-visible:shadow-destructive",
122
+ "focus-visible:border-destructive focus-visible:shadow-destructive border-red-600/40 dark:border-red-400/60",
115
123
  className
116
124
  )}
117
125
  data-hook={dataHook}