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