@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
@@ -14,45 +14,96 @@ import { MinusIcon } from "@brightlocal/icons";
14
14
  import { cn } from "@brightlocal/ui-components/lib/utils";
15
15
  import { Label } from "@brightlocal/ui-components/label";
16
16
 
17
- type InputOTPProps = React.ComponentProps<typeof OTPInput> & {
17
+ /* -------------------------------------------------------------------------------------------------
18
+ * InputOTP Context
19
+ * -----------------------------------------------------------------------------------------------*/
20
+
21
+ interface InputOTPContextValue {
22
+ error?: boolean;
23
+ disabled?: boolean;
24
+ }
25
+
26
+ const InputOTPContext = React.createContext<InputOTPContextValue | null>(null);
27
+
28
+ function useInputOTPContext() {
29
+ const context = React.useContext(InputOTPContext);
30
+ if (!context) {
31
+ throw new Error("InputOTP components must be used within an <InputOTP>");
32
+ }
33
+ return context;
34
+ }
35
+
36
+ /* -------------------------------------------------------------------------------------------------
37
+ * InputOTP Root
38
+ * -----------------------------------------------------------------------------------------------*/
39
+
40
+ interface InputOTPProps extends Omit<
41
+ React.ComponentProps<typeof OTPInput>,
42
+ "render"
43
+ > {
44
+ /** Custom class for the container element */
18
45
  containerClassName?: string;
19
- trackingEl?: string;
46
+ /** Data hook for automated testing (REQUIRED) */
20
47
  dataHook: string;
48
+ /** Tracking element identifier for analytics */
49
+ trackingEl?: string;
50
+ /** Tracking label for analytics context */
21
51
  trackingLabel?: string;
22
- };
52
+ /** Whether the input has an error state */
53
+ error?: boolean;
54
+ /** Children components */
55
+ children: React.ReactNode;
56
+ }
23
57
 
24
58
  const InputOTP = React.forwardRef<HTMLInputElement, InputOTPProps>(
25
59
  (
26
- { trackingEl, trackingLabel, dataHook, containerClassName, ...props },
60
+ {
61
+ dataHook,
62
+ trackingEl,
63
+ trackingLabel,
64
+ containerClassName,
65
+ error,
66
+ disabled,
67
+ children,
68
+ ...props
69
+ },
27
70
  ref
28
71
  ) => {
29
- // Ensure we always have an accessible label if none is provided
30
- const hasAccessibleLabel = props.id || props["aria-label"];
31
- const effectiveAriaLabel = !hasAccessibleLabel
32
- ? "One-time password"
33
- : props["aria-label"];
72
+ const contextValue = React.useMemo<InputOTPContextValue>(
73
+ () => ({ error, disabled }),
74
+ [error, disabled]
75
+ );
34
76
 
35
77
  return (
36
- <OTPInput
37
- ref={ref}
38
- aria-label={effectiveAriaLabel}
39
- className="disabled:cursor-not-allowed"
40
- containerClassName={cn(
41
- "group flex items-center gap-2 has-disabled:opacity-50 w-fit",
42
- containerClassName
43
- )}
44
- data-hook={dataHook}
45
- data-slot="input-otp"
46
- data-tracking-el={trackingEl}
47
- data-tracking-label={trackingLabel}
48
- {...props}
49
- />
78
+ <InputOTPContext.Provider value={contextValue}>
79
+ <OTPInput
80
+ ref={ref}
81
+ aria-invalid={error ? "true" : undefined}
82
+ className="disabled:cursor-not-allowed"
83
+ containerClassName={cn(
84
+ "group flex items-center gap-2 has-disabled:opacity-50 w-fit",
85
+ containerClassName
86
+ )}
87
+ data-hook={dataHook}
88
+ data-slot="input-otp"
89
+ data-tracking-el={trackingEl}
90
+ data-tracking-label={trackingLabel}
91
+ disabled={disabled}
92
+ {...props}
93
+ >
94
+ {children}
95
+ </OTPInput>
96
+ </InputOTPContext.Provider>
50
97
  );
51
98
  }
52
99
  );
53
100
 
54
101
  InputOTP.displayName = "InputOTP";
55
102
 
103
+ /* -------------------------------------------------------------------------------------------------
104
+ * InputOTP Group
105
+ * -----------------------------------------------------------------------------------------------*/
106
+
56
107
  type InputOTPGroupProps = React.ComponentProps<"div">;
57
108
 
58
109
  function InputOTPGroup({ className, ...props }: InputOTPGroupProps) {
@@ -65,11 +116,17 @@ function InputOTPGroup({ className, ...props }: InputOTPGroupProps) {
65
116
  );
66
117
  }
67
118
 
68
- type InputOTPSlotProps = React.ComponentProps<"div"> & {
119
+ /* -------------------------------------------------------------------------------------------------
120
+ * InputOTP Slot
121
+ * -----------------------------------------------------------------------------------------------*/
122
+
123
+ interface InputOTPSlotProps extends React.ComponentProps<"div"> {
124
+ /** The index of the slot in the OTP input */
69
125
  index: number;
70
- };
126
+ }
71
127
 
72
128
  function InputOTPSlot({ index, className, ...props }: InputOTPSlotProps) {
129
+ const { error } = useInputOTPContext();
73
130
  const inputOTPContext = React.useContext(
74
131
  OTPInputContext
75
132
  ) as RenderProps | null;
@@ -87,15 +144,14 @@ function InputOTPSlot({ index, className, ...props }: InputOTPSlotProps) {
87
144
  "data-[active=true]:border-ring data-[active=true]:z-10",
88
145
  "data-[active=true]:shadow-default",
89
146
  // Error state
90
- "group-has-[input[aria-invalid=true]]:border-destructive",
91
- "group-has-[input[aria-invalid=true]]:data-[active=true]:shadow-destructive",
92
- "group-has-[input[aria-invalid=true]]:data-[active=true]:border-destructive",
93
-
147
+ error && "border-destructive",
148
+ error && isActive && "shadow-destructive",
94
149
  // Dark mode
95
150
  "dark:bg-input/30",
96
151
  className
97
152
  )}
98
153
  data-active={isActive}
154
+ data-error={error}
99
155
  data-slot="input-otp-slot"
100
156
  {...props}
101
157
  >
@@ -109,7 +165,13 @@ function InputOTPSlot({ index, className, ...props }: InputOTPSlotProps) {
109
165
  );
110
166
  }
111
167
 
112
- function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
168
+ /* -------------------------------------------------------------------------------------------------
169
+ * InputOTP Separator
170
+ * -----------------------------------------------------------------------------------------------*/
171
+
172
+ type InputOTPSeparatorProps = React.ComponentProps<"div">;
173
+
174
+ function InputOTPSeparator({ ...props }: InputOTPSeparatorProps) {
113
175
  return (
114
176
  <div data-slot="input-otp-separator" role="separator" {...props}>
115
177
  <MinusIcon />
@@ -117,64 +179,67 @@ function InputOTPSeparator({ ...props }: React.ComponentProps<"div">) {
117
179
  );
118
180
  }
119
181
 
120
- interface InputOTPFieldProps {
121
- id?: string;
182
+ /* -------------------------------------------------------------------------------------------------
183
+ * InputOTP Label
184
+ * -----------------------------------------------------------------------------------------------*/
185
+
186
+ interface InputOTPLabelProps extends React.ComponentProps<typeof Label> {
187
+ /** Data hook for automated testing */
188
+ dataHook?: string;
189
+ }
190
+
191
+ function InputOTPLabel({ dataHook, className, ...props }: InputOTPLabelProps) {
192
+ return (
193
+ <Label
194
+ className={cn("mb-2", className)}
195
+ data-hook={dataHook}
196
+ data-slot="input-otp-label"
197
+ {...props}
198
+ />
199
+ );
200
+ }
201
+
202
+ /* -------------------------------------------------------------------------------------------------
203
+ * InputOTP Field (Convenience wrapper with label)
204
+ * -----------------------------------------------------------------------------------------------*/
205
+
206
+ interface InputOTPFieldProps extends Omit<InputOTPProps, "children"> {
207
+ /** Label text */
122
208
  label?: string;
123
- dataHook: string;
124
- trackingEl?: string;
125
- trackingLabel?: string;
126
- children?: React.ReactNode;
127
- maxLength: number;
128
- containerClassName?: string;
129
- inputMode?: "numeric" | "text" | "none" | "tel" | "url" | "email" | "decimal";
130
- pasteTransformer?: (p: string) => string;
131
- pattern?: string;
132
- disabled?: boolean;
133
- className?: string;
209
+ /** Custom ID for the input */
210
+ id?: string;
211
+ /** Accessible label when no visible label is provided */
134
212
  "aria-label"?: string;
213
+ /** Children components */
214
+ children: React.ReactNode;
135
215
  }
136
216
 
137
217
  const InputOTPField = React.forwardRef<HTMLInputElement, InputOTPFieldProps>(
138
218
  (
139
- {
140
- label,
141
- id,
142
- dataHook,
143
- trackingEl,
144
- trackingLabel,
145
- containerClassName,
146
- children,
147
- "aria-label": ariaLabel,
148
- ...props
149
- },
219
+ { label, id, dataHook, "aria-label": ariaLabel, children, ...props },
150
220
  ref
151
221
  ) => {
152
222
  const generatedId = React.useId();
153
223
  const inputId = id || generatedId;
154
224
 
155
- // Ensure we always have an accessible label
156
225
  const effectiveAriaLabel =
157
226
  ariaLabel || (!label ? "One-time password" : undefined);
158
227
 
159
228
  return (
160
- <div className="w-fit">
229
+ <div className="w-fit" data-slot="input-otp-field">
161
230
  {label && (
162
- <Label
163
- className="mb-2"
164
- data-hook={dataHook ? `${dataHook}-label` : undefined}
231
+ <InputOTPLabel
232
+ dataHook={dataHook ? `${dataHook}-label` : undefined}
165
233
  htmlFor={inputId}
166
234
  >
167
235
  {label}
168
- </Label>
236
+ </InputOTPLabel>
169
237
  )}
170
238
  <InputOTP
171
239
  ref={ref}
172
240
  aria-label={effectiveAriaLabel}
173
- containerClassName={containerClassName}
174
241
  dataHook={dataHook}
175
242
  id={label ? inputId : undefined}
176
- trackingEl={trackingEl}
177
- trackingLabel={trackingLabel}
178
243
  {...props}
179
244
  >
180
245
  {children}
@@ -186,24 +251,23 @@ const InputOTPField = React.forwardRef<HTMLInputElement, InputOTPFieldProps>(
186
251
 
187
252
  InputOTPField.displayName = "InputOTPField";
188
253
 
189
- interface VariantInputOTPProps extends Omit<
254
+ /* -------------------------------------------------------------------------------------------------
255
+ * Variant Components (Convenience wrappers)
256
+ * -----------------------------------------------------------------------------------------------*/
257
+
258
+ interface InputOTPVariantProps extends Omit<
190
259
  InputOTPFieldProps,
191
260
  "children" | "maxLength"
192
261
  > {
262
+ /** Number of OTP digits */
193
263
  maxLength?: number;
194
- dataHook: string;
195
- trackingEl?: string;
196
- trackingLabel?: string;
197
- disabled?: boolean;
198
- autoFocus?: boolean;
199
- pattern?: string;
200
- "aria-label"?: string;
201
264
  }
202
265
 
266
+ /** Digits only OTP input with single group */
203
267
  const InputOTPDigitsOnly = React.forwardRef<
204
268
  HTMLInputElement,
205
- VariantInputOTPProps
206
- >(({ maxLength = 6, pattern = REGEXP_ONLY_DIGITS, ...props }, ref) => {
269
+ InputOTPVariantProps
270
+ >(({ maxLength = 6, ...props }, ref) => {
207
271
  return (
208
272
  <InputOTPField
209
273
  ref={ref}
@@ -212,7 +276,7 @@ const InputOTPDigitsOnly = React.forwardRef<
212
276
  pasteTransformer={(p: string) =>
213
277
  p.replace(/\D+/g, "").slice(0, maxLength)
214
278
  }
215
- pattern={pattern}
279
+ pattern={REGEXP_ONLY_DIGITS}
216
280
  {...props}
217
281
  >
218
282
  <InputOTPGroup>
@@ -226,9 +290,10 @@ const InputOTPDigitsOnly = React.forwardRef<
226
290
 
227
291
  InputOTPDigitsOnly.displayName = "InputOTPDigitsOnly";
228
292
 
293
+ /** OTP input with spacing between slots */
229
294
  const InputOTPWithSpacing = React.forwardRef<
230
295
  HTMLInputElement,
231
- VariantInputOTPProps
296
+ InputOTPVariantProps
232
297
  >(({ maxLength = 4, ...props }, ref) => {
233
298
  return (
234
299
  <InputOTPField
@@ -250,7 +315,8 @@ const InputOTPWithSpacing = React.forwardRef<
250
315
 
251
316
  InputOTPWithSpacing.displayName = "InputOTPWithSpacing";
252
317
 
253
- const InputOTPSimple = React.forwardRef<HTMLInputElement, VariantInputOTPProps>(
318
+ /** OTP input with two groups and a separator */
319
+ const InputOTPSimple = React.forwardRef<HTMLInputElement, InputOTPVariantProps>(
254
320
  ({ maxLength = 6, ...props }, ref) => {
255
321
  const firstGroupLength = Math.ceil(maxLength / 2);
256
322
  const secondGroupLength = maxLength - firstGroupLength;
@@ -278,9 +344,10 @@ const InputOTPSimple = React.forwardRef<HTMLInputElement, VariantInputOTPProps>(
278
344
 
279
345
  InputOTPSimple.displayName = "InputOTPSimple";
280
346
 
347
+ /** OTP input with separators between each pair of digits */
281
348
  const InputOTPWithSeparator = React.forwardRef<
282
349
  HTMLInputElement,
283
- VariantInputOTPProps
350
+ InputOTPVariantProps
284
351
  >(({ maxLength = 6, ...props }, ref) => {
285
352
  const groupSize = 2;
286
353
  const groups = Math.ceil(maxLength / groupSize);
@@ -309,19 +376,35 @@ const InputOTPWithSeparator = React.forwardRef<
309
376
 
310
377
  InputOTPWithSeparator.displayName = "InputOTPWithSeparator";
311
378
 
379
+ /* -------------------------------------------------------------------------------------------------
380
+ * Exports
381
+ * -----------------------------------------------------------------------------------------------*/
382
+
312
383
  export {
384
+ // Primitives for custom composition
385
+ InputOTP,
386
+ InputOTPGroup,
387
+ InputOTPSlot,
388
+ InputOTPSeparator,
389
+ InputOTPLabel,
390
+ InputOTPField,
391
+ // Variant components
313
392
  InputOTPDigitsOnly,
314
393
  InputOTPWithSpacing,
315
394
  InputOTPSimple,
316
395
  InputOTPWithSeparator,
396
+ // Regex patterns
317
397
  REGEXP_ONLY_DIGITS,
318
398
  REGEXP_ONLY_CHARS,
319
399
  REGEXP_ONLY_DIGITS_AND_CHARS,
320
400
  };
321
401
 
322
402
  export type {
323
- VariantInputOTPProps,
324
403
  InputOTPProps,
325
404
  InputOTPGroupProps,
326
405
  InputOTPSlotProps,
406
+ InputOTPSeparatorProps,
407
+ InputOTPLabelProps,
408
+ InputOTPFieldProps,
409
+ InputOTPVariantProps,
327
410
  };