@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.
- package/README.md +2 -1
- 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.cjs +1 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +19 -19
- 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 +75 -59
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +244 -191
- 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 +428 -388
- 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.cjs +1 -1
- package/dist/input-group.d.ts +5 -0
- package/dist/input-group.d.ts.map +1 -1
- package/dist/input-group.js +47 -39
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.d.ts +45 -32
- package/dist/input-otp.d.ts.map +1 -1
- package/dist/input-otp.js +138 -114
- package/dist/input-password.cjs +1 -1
- package/dist/input-password.d.ts +151 -19
- package/dist/input-password.d.ts.map +1 -1
- package/dist/input-password.js +197 -91
- package/dist/input.cjs +1 -1
- package/dist/input.d.ts +4 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +26 -24
- package/dist/logo.cjs +1 -1
- package/dist/logo.js +13 -13
- 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/radio-group.cjs +1 -1
- package/dist/radio-group.d.ts +4 -0
- package/dist/radio-group.d.ts.map +1 -1
- package/dist/radio-group.js +49 -47
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts +3 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +57 -56
- 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.cjs +1 -1
- package/dist/textarea.d.ts +4 -0
- package/dist/textarea.d.ts.map +1 -1
- package/dist/textarea.js +19 -18
- package/dist/toggle.cjs +1 -1
- package/dist/toggle.d.ts.map +1 -1
- package/dist/toggle.js +17 -17
- package/package.json +1 -1
- 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 -3
- package/src/components/chip.tsx +249 -0
- package/src/components/combobox.tsx +490 -298
- 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 +17 -2
- package/src/components/input-otp.tsx +161 -78
- package/src/components/input-password.tsx +473 -128
- package/src/components/input.tsx +11 -3
- package/src/components/logo.tsx +1 -1
- package/src/components/progress.tsx +21 -2
- package/src/components/radio-group.tsx +11 -0
- package/src/components/select.tsx +5 -2
- package/src/components/slider.tsx +85 -15
- package/src/components/textarea.tsx +15 -5
- package/src/components/toggle.tsx +13 -15
- 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
|
-
|
|
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 */
|
|
53
|
+
error?: boolean;
|
|
54
|
+
/** Children components */
|
|
55
|
+
children: React.ReactNode;
|
|
56
|
+
}
|
|
23
57
|
|
|
24
58
|
const InputOTP = React.forwardRef<HTMLInputElement, InputOTPProps>(
|
|
25
59
|
(
|
|
26
|
-
{
|
|
60
|
+
{
|
|
61
|
+
dataHook,
|
|
62
|
+
trackingEl,
|
|
63
|
+
trackingLabel,
|
|
64
|
+
containerClassName,
|
|
65
|
+
error,
|
|
66
|
+
disabled,
|
|
67
|
+
children,
|
|
68
|
+
...props
|
|
69
|
+
},
|
|
27
70
|
ref
|
|
28
71
|
) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: props["aria-label"];
|
|
72
|
+
const contextValue = React.useMemo<InputOTPContextValue>(
|
|
73
|
+
() => ({ error, disabled }),
|
|
74
|
+
[error, disabled]
|
|
75
|
+
);
|
|
34
76
|
|
|
35
77
|
return (
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
91
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
<
|
|
163
|
-
|
|
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
|
-
</
|
|
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
|
-
|
|
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
|
-
|
|
206
|
-
>(({ maxLength = 6,
|
|
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={
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
};
|