@brightlocal/ui-components 0.2.0 → 0.3.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.
- package/dist/alert.cjs +1 -1
- package/dist/alert.d.ts +10 -1
- package/dist/alert.d.ts.map +1 -1
- package/dist/alert.js +6 -2
- package/dist/card.cjs +1 -1
- package/dist/card.d.ts +6 -2
- package/dist/card.d.ts.map +1 -1
- package/dist/card.js +89 -73
- package/dist/centred-layout.cjs +1 -1
- package/dist/centred-layout.d.ts +49 -25
- package/dist/centred-layout.d.ts.map +1 -1
- package/dist/centred-layout.js +57 -32
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/chip.cjs +1 -0
- package/dist/chip.d.ts +61 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +165 -0
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +5 -2
- package/dist/date-picker.cjs +1 -1
- package/dist/date-picker.d.ts +89 -52
- package/dist/date-picker.d.ts.map +1 -1
- package/dist/date-picker.js +228 -210
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/header.cjs +1 -0
- package/dist/header.d.ts +42 -0
- package/dist/header.d.ts.map +1 -0
- package/dist/header.js +22 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +426 -396
- package/dist/input-chip.cjs +1 -0
- package/dist/input-chip.d.ts +117 -0
- package/dist/input-chip.d.ts.map +1 -0
- package/dist/input-chip.js +284 -0
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.d.ts +43 -36
- package/dist/input-otp.d.ts.map +1 -1
- package/dist/input-otp.js +140 -119
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +147 -19
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +197 -92
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +10 -0
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +45 -36
- package/dist/select.d.ts.map +1 -1
- package/dist/slider.cjs +1 -1
- package/dist/slider.d.ts +31 -3
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +53 -43
- package/dist/textarea.d.ts.map +1 -1
- package/package.json +23 -24
- package/src/components/alert.tsx +10 -1
- package/src/components/card.tsx +66 -38
- package/src/components/centred-layout.tsx +115 -38
- package/src/components/checkbox.tsx +2 -2
- package/src/components/chip.tsx +249 -0
- package/src/components/combobox.tsx +17 -13
- package/src/components/date-picker.tsx +410 -266
- package/src/components/dropdown-menu.tsx +6 -1
- package/src/components/header.tsx +69 -0
- package/src/components/input-chip.tsx +548 -0
- package/src/components/input-group.tsx +4 -1
- package/src/components/input-otp.tsx +159 -91
- package/src/components/input-password.tsx +469 -129
- package/src/components/input.tsx +1 -1
- package/src/components/progress.tsx +21 -2
- package/src/components/select.tsx +1 -3
- package/src/components/slider.tsx +85 -15
- package/src/components/textarea.tsx +4 -1
- 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
|
-
|
|
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
|
-
|
|
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
|
-
{
|
|
60
|
+
{
|
|
61
|
+
dataHook,
|
|
62
|
+
trackingEl,
|
|
63
|
+
trackingLabel,
|
|
64
|
+
containerClassName,
|
|
65
|
+
error,
|
|
66
|
+
disabled,
|
|
67
|
+
children,
|
|
68
|
+
...props
|
|
69
|
+
},
|
|
29
70
|
ref
|
|
30
71
|
) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
100
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
/**
|
|
145
|
-
|
|
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
|
-
<
|
|
175
|
-
|
|
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
|
-
</
|
|
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
|
-
|
|
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
|
-
|
|
221
|
-
>(({ maxLength = 6,
|
|
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={
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
};
|