@brightlocal/ui-components 0.5.0 → 1.0.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.d.ts +2 -2
- package/dist/blocks/sidebar.d.ts +6 -6
- package/dist/button.d.ts +2 -2
- package/dist/carousel.d.ts +1 -1
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +11 -7
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +144 -133
- package/dist/date-picker.d.ts +2 -2
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +11 -4
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +113 -80
- package/dist/index.cjs +1 -1
- package/dist/index.js +253 -255
- package/dist/input-group.d.ts +1 -1
- package/dist/input-otp.cjs +1 -1
- package/dist/input-otp.d.ts +3 -20
- package/dist/input-otp.d.ts.map +1 -1
- package/dist/input-otp.js +91 -132
- package/dist/input-password.d.ts +1 -1
- package/dist/label.d.ts +2 -3
- package/dist/label.d.ts.map +1 -1
- package/dist/radio-group.cjs +1 -1
- package/dist/radio-group.d.ts +3 -19
- package/dist/radio-group.d.ts.map +1 -1
- package/dist/radio-group.js +92 -120
- package/dist/resizable.d.ts +1 -1
- package/dist/select.cjs +1 -1
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +19 -19
- package/dist/switch.cjs +1 -1
- package/dist/switch.d.ts +1 -21
- package/dist/switch.d.ts.map +1 -1
- package/dist/switch.js +31 -100
- package/package.json +2 -2
- package/src/components/combobox.tsx +22 -2
- package/src/components/field.tsx +47 -7
- package/src/components/input-otp.tsx +9 -89
- package/src/components/label.tsx +2 -2
- package/src/components/radio-group.tsx +65 -129
- package/src/components/select.tsx +3 -2
- package/src/components/switch.tsx +29 -140
- package/dist/link.figma.d.ts +0 -2
- package/dist/link.figma.d.ts.map +0 -1
- package/dist/switch.figma.d.ts +0 -2
- package/dist/switch.figma.d.ts.map +0 -1
- package/dist/toggle.figma.d.ts +0 -2
- package/dist/toggle.figma.d.ts.map +0 -1
- package/src/components/link.figma.tsx +0 -71
- package/src/components/switch.figma.tsx +0 -111
- package/src/components/toggle.figma.tsx +0 -75
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { ChevronsUpDown, Check } from "@brightlocal/icons";
|
|
5
5
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
6
|
+
import { defaultFilter } from "cmdk";
|
|
6
7
|
|
|
7
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
8
9
|
import {
|
|
@@ -34,6 +35,8 @@ interface ComboboxContextValue {
|
|
|
34
35
|
/** Map of value -> label for displaying selected value */
|
|
35
36
|
itemLabels: Map<string, string>;
|
|
36
37
|
registerItem: (value: string, label: string) => void;
|
|
38
|
+
/** Maps item value to a searchable string for filtering */
|
|
39
|
+
itemToStringValue?: (value: string) => string;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
const ComboboxContext = React.createContext<ComboboxContextValue | null>(null);
|
|
@@ -63,6 +66,8 @@ export interface ComboboxProps {
|
|
|
63
66
|
shouldFilter?: boolean;
|
|
64
67
|
/** Disabled state */
|
|
65
68
|
disabled?: boolean;
|
|
69
|
+
/** Maps item value to a searchable string. When provided, filtering uses this string instead of the raw value. */
|
|
70
|
+
itemToStringValue?: (value: string) => string;
|
|
66
71
|
/** Children */
|
|
67
72
|
children: React.ReactNode;
|
|
68
73
|
}
|
|
@@ -74,6 +79,7 @@ function Combobox({
|
|
|
74
79
|
onOpenChange: controlledOnOpenChange,
|
|
75
80
|
shouldFilter = true,
|
|
76
81
|
disabled = false,
|
|
82
|
+
itemToStringValue,
|
|
77
83
|
children,
|
|
78
84
|
}: ComboboxProps) {
|
|
79
85
|
const [uncontrolledValue, setUncontrolledValue] = React.useState("");
|
|
@@ -127,6 +133,7 @@ function Combobox({
|
|
|
127
133
|
disabled,
|
|
128
134
|
itemLabels,
|
|
129
135
|
registerItem,
|
|
136
|
+
itemToStringValue,
|
|
130
137
|
}),
|
|
131
138
|
[
|
|
132
139
|
open,
|
|
@@ -137,6 +144,7 @@ function Combobox({
|
|
|
137
144
|
disabled,
|
|
138
145
|
itemLabels,
|
|
139
146
|
registerItem,
|
|
147
|
+
itemToStringValue,
|
|
140
148
|
]
|
|
141
149
|
);
|
|
142
150
|
|
|
@@ -324,11 +332,18 @@ function ComboboxContent({
|
|
|
324
332
|
align = "start",
|
|
325
333
|
hideList = false,
|
|
326
334
|
}: ComboboxContentProps) {
|
|
327
|
-
const { shouldFilter } = useComboboxContext();
|
|
335
|
+
const { shouldFilter, itemToStringValue } = useComboboxContext();
|
|
336
|
+
|
|
337
|
+
const filter = React.useMemo(() => {
|
|
338
|
+
if (!itemToStringValue) return undefined;
|
|
339
|
+
return (value: string, search: string, keywords?: string[]) =>
|
|
340
|
+
defaultFilter(itemToStringValue(value), search, keywords);
|
|
341
|
+
}, [itemToStringValue]);
|
|
328
342
|
|
|
329
343
|
return (
|
|
330
344
|
<PopoverContent
|
|
331
345
|
align={align}
|
|
346
|
+
aria-label="Options"
|
|
332
347
|
className={cn("w-[var(--radix-popover-trigger-width)] p-0", className)}
|
|
333
348
|
data-slot="combobox-popover"
|
|
334
349
|
side="bottom"
|
|
@@ -340,6 +355,7 @@ function ComboboxContent({
|
|
|
340
355
|
)}
|
|
341
356
|
data-slot="combobox-command"
|
|
342
357
|
dataHook={dataHook || "combobox-command"}
|
|
358
|
+
filter={filter}
|
|
343
359
|
shouldFilter={shouldFilter}
|
|
344
360
|
>
|
|
345
361
|
{children}
|
|
@@ -454,7 +470,7 @@ export interface ComboboxItemProps extends Omit<
|
|
|
454
470
|
> {
|
|
455
471
|
/** The value of the item (required) */
|
|
456
472
|
value: string;
|
|
457
|
-
/** Display label - if not provided,
|
|
473
|
+
/** Display label - if not provided, inferred from children text content. Required when children are React elements (not plain text) to enable label-based search and trigger display. */
|
|
458
474
|
label?: string;
|
|
459
475
|
/** Data hook for automated testing */
|
|
460
476
|
dataHook?: string;
|
|
@@ -462,6 +478,8 @@ export interface ComboboxItemProps extends Omit<
|
|
|
462
478
|
highlight?: string;
|
|
463
479
|
/** Class name for highlighted text */
|
|
464
480
|
highlightClassName?: string;
|
|
481
|
+
/** Additional keywords to match against when filtering. The item label is always included automatically. */
|
|
482
|
+
keywords?: string[];
|
|
465
483
|
}
|
|
466
484
|
|
|
467
485
|
const ComboboxItem = React.forwardRef<
|
|
@@ -477,6 +495,7 @@ const ComboboxItem = React.forwardRef<
|
|
|
477
495
|
className,
|
|
478
496
|
highlight,
|
|
479
497
|
highlightClassName,
|
|
498
|
+
keywords,
|
|
480
499
|
...props
|
|
481
500
|
},
|
|
482
501
|
ref
|
|
@@ -528,6 +547,7 @@ const ComboboxItem = React.forwardRef<
|
|
|
528
547
|
className={cn("justify-between", className)}
|
|
529
548
|
data-slot="combobox-item"
|
|
530
549
|
dataHook={dataHook}
|
|
550
|
+
keywords={keywords ? [childText, ...keywords] : [childText]}
|
|
531
551
|
value={itemValue}
|
|
532
552
|
onSelect={handleSelect}
|
|
533
553
|
{...props}
|
package/src/components/field.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
3
3
|
import { AlertCircle, type LucideProps } from "@brightlocal/icons";
|
|
4
4
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
5
5
|
import { Description } from "./description";
|
|
6
|
-
import { Label } from "@brightlocal/ui-components/label";
|
|
6
|
+
import { Label, type LabelProps } from "@brightlocal/ui-components/label";
|
|
7
7
|
|
|
8
8
|
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
|
9
9
|
return (
|
|
@@ -67,6 +67,8 @@ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
67
67
|
const fieldVariants = cva(
|
|
68
68
|
[
|
|
69
69
|
"group/field flex w-full gap-2",
|
|
70
|
+
// RadioGroup context: positioned ancestor for RadioGroupItem click overlay + pointer cursor
|
|
71
|
+
"[[data-slot=radio-group]_&]:relative [[data-slot=radio-group]_&]:cursor-pointer [[data-slot=radio-group]_&]:gap-3 [[data-slot=radio-group]_&]:has-[[data-disabled]]:cursor-not-allowed",
|
|
70
72
|
// Label leading overrides: use leading-normal for wrap-capable labels (checkbox)
|
|
71
73
|
"has-[>[role=checkbox]]:[&_[data-slot=field-label]]:leading-normal",
|
|
72
74
|
],
|
|
@@ -77,17 +79,35 @@ const fieldVariants = cva(
|
|
|
77
79
|
horizontal: [
|
|
78
80
|
"grid grid-cols-[auto_1fr] items-center gap-x-2",
|
|
79
81
|
"[&>[data-slot=field-description]]:col-start-2 [&>[data-slot=field-error]]:col-start-2",
|
|
80
|
-
"has-[>[data-slot=field-content]]:items-start
|
|
82
|
+
"has-[>[data-slot=field-content]]:items-start",
|
|
81
83
|
],
|
|
82
84
|
responsive: [
|
|
83
85
|
"flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:grid @md/field-group:grid-cols-[auto_1fr] @md/field-group:items-center @md/field-group:[&>*]:w-auto",
|
|
84
86
|
"@md/field-group:[&>[data-slot=field-description]]:col-start-2 @md/field-group:[&>[data-slot=field-error]]:col-start-2",
|
|
85
|
-
"@md/field-group:has-[>[data-slot=field-content]]:items-start
|
|
87
|
+
"@md/field-group:has-[>[data-slot=field-content]]:items-start",
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
variant: {
|
|
91
|
+
default: [],
|
|
92
|
+
box: [
|
|
93
|
+
"relative cursor-pointer",
|
|
94
|
+
"rounded-lg border border-border bg-background p-3",
|
|
95
|
+
"transition-colors",
|
|
96
|
+
"[&_[data-slot=field-label]]:after:absolute [&_[data-slot=field-label]]:after:inset-0 [&_[data-slot=field-label]]:after:cursor-pointer",
|
|
97
|
+
// Focus ring when a child control receives focus
|
|
98
|
+
"has-[:focus-visible]:shadow-default has-[:focus-visible]:border-ring",
|
|
99
|
+
// Checked-state for radio/checkbox (not switch)
|
|
100
|
+
"has-[[data-state=checked]:not([role=switch])]:border-primary has-[[data-state=checked]:not([role=switch])]:bg-primary/10",
|
|
101
|
+
"dark:has-[[data-state=checked]:not([role=switch])]:bg-alpha-10",
|
|
102
|
+
// Error-state when inside an invalid container (e.g. RadioGroup with error)
|
|
103
|
+
"[[aria-invalid=true]_&]:border-red-600/40 dark:[[aria-invalid=true]_&]:border-red-400/60",
|
|
104
|
+
"[[aria-invalid=true]_&]:has-[:focus-visible]:border-destructive [[aria-invalid=true]_&]:has-[:focus-visible]:shadow-destructive",
|
|
86
105
|
],
|
|
87
106
|
},
|
|
88
107
|
},
|
|
89
108
|
defaultVariants: {
|
|
90
109
|
orientation: "vertical",
|
|
110
|
+
variant: "default",
|
|
91
111
|
},
|
|
92
112
|
}
|
|
93
113
|
);
|
|
@@ -96,14 +116,32 @@ const fieldVariants = cva(
|
|
|
96
116
|
* Props for the Field component
|
|
97
117
|
*/
|
|
98
118
|
interface FieldProps
|
|
99
|
-
extends React.ComponentProps<"div">, VariantProps<typeof fieldVariants> {
|
|
119
|
+
extends React.ComponentProps<"div">, VariantProps<typeof fieldVariants> {
|
|
120
|
+
/**
|
|
121
|
+
* Controls the grid column sizing for horizontal orientation.
|
|
122
|
+
* - `"start"` (default): `auto 1fr` — control left, content right
|
|
123
|
+
* - `"end"`: `1fr auto` — content left, control right
|
|
124
|
+
*/
|
|
125
|
+
align?: "start" | "end";
|
|
126
|
+
}
|
|
100
127
|
|
|
101
|
-
function Field({
|
|
128
|
+
function Field({
|
|
129
|
+
className,
|
|
130
|
+
orientation = "vertical",
|
|
131
|
+
variant = "default",
|
|
132
|
+
align = "start",
|
|
133
|
+
...props
|
|
134
|
+
}: FieldProps) {
|
|
102
135
|
return (
|
|
103
136
|
<div
|
|
104
|
-
className={cn(
|
|
137
|
+
className={cn(
|
|
138
|
+
fieldVariants({ orientation, variant }),
|
|
139
|
+
align === "end" && orientation === "horizontal" && "grid-cols-[1fr_auto]",
|
|
140
|
+
className
|
|
141
|
+
)}
|
|
105
142
|
data-orientation={orientation}
|
|
106
143
|
data-slot="field"
|
|
144
|
+
data-variant={variant}
|
|
107
145
|
role="group"
|
|
108
146
|
{...props}
|
|
109
147
|
/>
|
|
@@ -115,6 +153,8 @@ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
115
153
|
<div
|
|
116
154
|
className={cn(
|
|
117
155
|
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
|
156
|
+
// Center text for boxIconVertical RadioGroup
|
|
157
|
+
"[[data-variant=boxIconVertical]_&]:items-center [[data-variant=boxIconVertical]_&]:text-center",
|
|
118
158
|
className
|
|
119
159
|
)}
|
|
120
160
|
data-slot="field-content"
|
|
@@ -123,7 +163,7 @@ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
123
163
|
);
|
|
124
164
|
}
|
|
125
165
|
|
|
126
|
-
interface FieldLabelProps extends
|
|
166
|
+
interface FieldLabelProps extends LabelProps {
|
|
127
167
|
/**
|
|
128
168
|
* Required htmlFor attribute for linking label with input
|
|
129
169
|
*/
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
import { Minus } from "@brightlocal/icons";
|
|
13
13
|
|
|
14
14
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
15
|
-
import { Label } from "@brightlocal/ui-components/label";
|
|
16
15
|
|
|
17
16
|
/* -------------------------------------------------------------------------------------------------
|
|
18
17
|
* InputOTP Context
|
|
@@ -179,86 +178,11 @@ function InputOTPSeparator({ ...props }: InputOTPSeparatorProps) {
|
|
|
179
178
|
);
|
|
180
179
|
}
|
|
181
180
|
|
|
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 */
|
|
208
|
-
label?: string;
|
|
209
|
-
/** Custom ID for the input */
|
|
210
|
-
id?: string;
|
|
211
|
-
/** Accessible label when no visible label is provided */
|
|
212
|
-
"aria-label"?: string;
|
|
213
|
-
/** Children components */
|
|
214
|
-
children: React.ReactNode;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const InputOTPField = React.forwardRef<HTMLInputElement, InputOTPFieldProps>(
|
|
218
|
-
(
|
|
219
|
-
{ label, id, dataHook, "aria-label": ariaLabel, children, ...props },
|
|
220
|
-
ref
|
|
221
|
-
) => {
|
|
222
|
-
const generatedId = React.useId();
|
|
223
|
-
const inputId = id || generatedId;
|
|
224
|
-
|
|
225
|
-
const effectiveAriaLabel =
|
|
226
|
-
ariaLabel || (!label ? "One-time password" : undefined);
|
|
227
|
-
|
|
228
|
-
return (
|
|
229
|
-
<div className="w-fit" data-slot="input-otp-field">
|
|
230
|
-
{label && (
|
|
231
|
-
<InputOTPLabel
|
|
232
|
-
dataHook={dataHook ? `${dataHook}-label` : undefined}
|
|
233
|
-
htmlFor={inputId}
|
|
234
|
-
>
|
|
235
|
-
{label}
|
|
236
|
-
</InputOTPLabel>
|
|
237
|
-
)}
|
|
238
|
-
<InputOTP
|
|
239
|
-
ref={ref}
|
|
240
|
-
aria-label={effectiveAriaLabel}
|
|
241
|
-
dataHook={dataHook}
|
|
242
|
-
id={label ? inputId : undefined}
|
|
243
|
-
{...props}
|
|
244
|
-
>
|
|
245
|
-
{children}
|
|
246
|
-
</InputOTP>
|
|
247
|
-
</div>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
InputOTPField.displayName = "InputOTPField";
|
|
253
|
-
|
|
254
181
|
/* -------------------------------------------------------------------------------------------------
|
|
255
182
|
* Variant Components (Convenience wrappers)
|
|
256
183
|
* -----------------------------------------------------------------------------------------------*/
|
|
257
184
|
|
|
258
|
-
interface InputOTPVariantProps extends Omit<
|
|
259
|
-
InputOTPFieldProps,
|
|
260
|
-
"children" | "maxLength"
|
|
261
|
-
> {
|
|
185
|
+
interface InputOTPVariantProps extends Omit<InputOTPProps, "children" | "maxLength"> {
|
|
262
186
|
/** Number of OTP digits */
|
|
263
187
|
maxLength?: number;
|
|
264
188
|
}
|
|
@@ -269,7 +193,7 @@ const InputOTPDigitsOnly = React.forwardRef<
|
|
|
269
193
|
InputOTPVariantProps
|
|
270
194
|
>(({ maxLength = 6, ...props }, ref) => {
|
|
271
195
|
return (
|
|
272
|
-
<
|
|
196
|
+
<InputOTP
|
|
273
197
|
ref={ref}
|
|
274
198
|
inputMode="numeric"
|
|
275
199
|
maxLength={maxLength}
|
|
@@ -284,7 +208,7 @@ const InputOTPDigitsOnly = React.forwardRef<
|
|
|
284
208
|
<InputOTPSlot key={i} index={i} />
|
|
285
209
|
))}
|
|
286
210
|
</InputOTPGroup>
|
|
287
|
-
</
|
|
211
|
+
</InputOTP>
|
|
288
212
|
);
|
|
289
213
|
});
|
|
290
214
|
|
|
@@ -296,7 +220,7 @@ const InputOTPWithSpacing = React.forwardRef<
|
|
|
296
220
|
InputOTPVariantProps
|
|
297
221
|
>(({ maxLength = 4, ...props }, ref) => {
|
|
298
222
|
return (
|
|
299
|
-
<
|
|
223
|
+
<InputOTP
|
|
300
224
|
ref={ref}
|
|
301
225
|
containerClassName="gap-2"
|
|
302
226
|
maxLength={maxLength}
|
|
@@ -309,7 +233,7 @@ const InputOTPWithSpacing = React.forwardRef<
|
|
|
309
233
|
index={i}
|
|
310
234
|
/>
|
|
311
235
|
))}
|
|
312
|
-
</
|
|
236
|
+
</InputOTP>
|
|
313
237
|
);
|
|
314
238
|
});
|
|
315
239
|
|
|
@@ -322,7 +246,7 @@ const InputOTPSimple = React.forwardRef<HTMLInputElement, InputOTPVariantProps>(
|
|
|
322
246
|
const secondGroupLength = maxLength - firstGroupLength;
|
|
323
247
|
|
|
324
248
|
return (
|
|
325
|
-
<
|
|
249
|
+
<InputOTP ref={ref} maxLength={maxLength} {...props}>
|
|
326
250
|
<InputOTPGroup>
|
|
327
251
|
{Array.from({ length: firstGroupLength }, (_, i) => (
|
|
328
252
|
<InputOTPSlot key={i} index={i} />
|
|
@@ -337,7 +261,7 @@ const InputOTPSimple = React.forwardRef<HTMLInputElement, InputOTPVariantProps>(
|
|
|
337
261
|
/>
|
|
338
262
|
))}
|
|
339
263
|
</InputOTPGroup>
|
|
340
|
-
</
|
|
264
|
+
</InputOTP>
|
|
341
265
|
);
|
|
342
266
|
}
|
|
343
267
|
);
|
|
@@ -353,7 +277,7 @@ const InputOTPWithSeparator = React.forwardRef<
|
|
|
353
277
|
const groups = Math.ceil(maxLength / groupSize);
|
|
354
278
|
|
|
355
279
|
return (
|
|
356
|
-
<
|
|
280
|
+
<InputOTP ref={ref} maxLength={maxLength} {...props}>
|
|
357
281
|
{Array.from({ length: groups }, (_, groupIndex) => {
|
|
358
282
|
const startIndex = groupIndex * groupSize;
|
|
359
283
|
const endIndex = Math.min(startIndex + groupSize, maxLength);
|
|
@@ -370,7 +294,7 @@ const InputOTPWithSeparator = React.forwardRef<
|
|
|
370
294
|
</React.Fragment>
|
|
371
295
|
);
|
|
372
296
|
})}
|
|
373
|
-
</
|
|
297
|
+
</InputOTP>
|
|
374
298
|
);
|
|
375
299
|
});
|
|
376
300
|
|
|
@@ -386,8 +310,6 @@ export {
|
|
|
386
310
|
InputOTPGroup,
|
|
387
311
|
InputOTPSlot,
|
|
388
312
|
InputOTPSeparator,
|
|
389
|
-
InputOTPLabel,
|
|
390
|
-
InputOTPField,
|
|
391
313
|
// Variant components
|
|
392
314
|
InputOTPDigitsOnly,
|
|
393
315
|
InputOTPWithSpacing,
|
|
@@ -404,7 +326,5 @@ export type {
|
|
|
404
326
|
InputOTPGroupProps,
|
|
405
327
|
InputOTPSlotProps,
|
|
406
328
|
InputOTPSeparatorProps,
|
|
407
|
-
InputOTPLabelProps,
|
|
408
|
-
InputOTPFieldProps,
|
|
409
329
|
InputOTPVariantProps,
|
|
410
330
|
};
|
package/src/components/label.tsx
CHANGED
|
@@ -17,7 +17,7 @@ const labelVariants = cva(
|
|
|
17
17
|
}
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
interface LabelProps extends React.
|
|
20
|
+
interface LabelProps extends React.ComponentPropsWithoutRef<"label"> {
|
|
21
21
|
/**
|
|
22
22
|
* Data hook for automated testing
|
|
23
23
|
* Used to identify component in tests and E2E automation
|
|
@@ -41,7 +41,7 @@ interface LabelProps extends React.ComponentProps<typeof LabelPrimitive.Root> {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const Label = React.forwardRef<
|
|
44
|
-
|
|
44
|
+
HTMLLabelElement,
|
|
45
45
|
LabelProps
|
|
46
46
|
>(
|
|
47
47
|
(
|
|
@@ -6,7 +6,6 @@ import { Circle } from "@brightlocal/icons";
|
|
|
6
6
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
7
7
|
|
|
8
8
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
9
|
-
import { Label } from "@brightlocal/ui-components/label";
|
|
10
9
|
|
|
11
10
|
/* ---------------------------------- Styles -------------------------------- */
|
|
12
11
|
|
|
@@ -14,9 +13,9 @@ const radioGroupVariants = cva("grid", {
|
|
|
14
13
|
variants: {
|
|
15
14
|
variant: {
|
|
16
15
|
default: ["gap-3"],
|
|
17
|
-
box: ["gap-
|
|
16
|
+
box: ["gap-3"],
|
|
18
17
|
boxIconVertical: ["grid-flow-col auto-cols-fr gap-3"],
|
|
19
|
-
boxIconHorizontal: ["gap-
|
|
18
|
+
boxIconHorizontal: ["gap-3"],
|
|
20
19
|
},
|
|
21
20
|
},
|
|
22
21
|
defaultVariants: {
|
|
@@ -25,32 +24,14 @@ const radioGroupVariants = cva("grid", {
|
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
const radioGroupItemVariants = cva(
|
|
28
|
-
"group relative flex cursor-pointer outline-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
27
|
+
"group relative flex cursor-pointer outline-none disabled:cursor-not-allowed disabled:opacity-50 after:absolute after:inset-0",
|
|
29
28
|
{
|
|
30
29
|
variants: {
|
|
31
30
|
variant: {
|
|
32
|
-
default: ["items-
|
|
33
|
-
box: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"data-[state=checked]:border-primary data-[state=checked]:bg-primary/10",
|
|
37
|
-
"dark:data-[state=checked]:bg-alpha-10",
|
|
38
|
-
"focus-visible:outline-none",
|
|
39
|
-
],
|
|
40
|
-
boxIconVertical: [
|
|
41
|
-
"flex-col items-center gap-3 rounded-lg border border-border bg-background p-3",
|
|
42
|
-
"transition-colors",
|
|
43
|
-
"data-[state=checked]:border-primary data-[state=checked]:bg-primary/10",
|
|
44
|
-
"dark:data-[state=checked]:bg-alpha-10",
|
|
45
|
-
"focus-visible:outline-none focus-visible:shadow-default",
|
|
46
|
-
],
|
|
47
|
-
boxIconHorizontal: [
|
|
48
|
-
"flex-row items-start gap-3 rounded-lg border border-border bg-background p-3",
|
|
49
|
-
"transition-colors",
|
|
50
|
-
"data-[state=checked]:border-primary data-[state=checked]:bg-primary/10",
|
|
51
|
-
"dark:data-[state=checked]:bg-alpha-10",
|
|
52
|
-
"focus-visible:outline-none focus-visible:shadow-default",
|
|
53
|
-
],
|
|
31
|
+
default: ["items-center"],
|
|
32
|
+
box: ["items-center"],
|
|
33
|
+
boxIconVertical: ["items-center justify-center"],
|
|
34
|
+
boxIconHorizontal: ["items-center justify-center"],
|
|
54
35
|
},
|
|
55
36
|
},
|
|
56
37
|
defaultVariants: {
|
|
@@ -99,23 +80,6 @@ const radioCircleVariants = cva(
|
|
|
99
80
|
}
|
|
100
81
|
);
|
|
101
82
|
|
|
102
|
-
const radioContentVariants = cva(
|
|
103
|
-
"text-foreground flex flex-col gap-1.5 leading-none",
|
|
104
|
-
{
|
|
105
|
-
variants: {
|
|
106
|
-
variant: {
|
|
107
|
-
default: [],
|
|
108
|
-
box: ["text-left"],
|
|
109
|
-
boxIconVertical: ["items-center"],
|
|
110
|
-
boxIconHorizontal: ["text-left justify-center"],
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
defaultVariants: {
|
|
114
|
-
variant: "default",
|
|
115
|
-
},
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
|
|
119
83
|
/* ---------------------------------- Types --------------------------------- */
|
|
120
84
|
|
|
121
85
|
/**
|
|
@@ -133,6 +97,7 @@ type RadioGroupVariant =
|
|
|
133
97
|
|
|
134
98
|
interface RadioGroupContextValue {
|
|
135
99
|
variant?: RadioGroupVariant;
|
|
100
|
+
error?: boolean;
|
|
136
101
|
}
|
|
137
102
|
|
|
138
103
|
/**
|
|
@@ -163,23 +128,9 @@ interface RadioGroupProps
|
|
|
163
128
|
/**
|
|
164
129
|
* Props for the RadioGroupItem component.
|
|
165
130
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
VariantProps<typeof radioGroupItemVariants> {
|
|
170
|
-
/**
|
|
171
|
-
* Label text displayed next to the radio button
|
|
172
|
-
*/
|
|
173
|
-
label?: React.ReactNode;
|
|
174
|
-
/**
|
|
175
|
-
* Description text displayed below the label
|
|
176
|
-
*/
|
|
177
|
-
description?: React.ReactNode;
|
|
178
|
-
/**
|
|
179
|
-
* Icon displayed for box icon variants
|
|
180
|
-
*/
|
|
181
|
-
icon?: React.ReactNode;
|
|
182
|
-
}
|
|
131
|
+
type RadioGroupItemProps = React.ComponentPropsWithoutRef<
|
|
132
|
+
typeof RadioGroupPrimitive.Item
|
|
133
|
+
>;
|
|
183
134
|
|
|
184
135
|
/* --------------------------------- Context -------------------------------- */
|
|
185
136
|
|
|
@@ -201,6 +152,7 @@ const RadioGroup = React.forwardRef<
|
|
|
201
152
|
trackingEl,
|
|
202
153
|
trackingLabel,
|
|
203
154
|
error,
|
|
155
|
+
orientation,
|
|
204
156
|
...props
|
|
205
157
|
},
|
|
206
158
|
ref
|
|
@@ -212,8 +164,14 @@ const RadioGroup = React.forwardRef<
|
|
|
212
164
|
props["aria-invalid"] === true ||
|
|
213
165
|
props["aria-invalid"] === "true";
|
|
214
166
|
|
|
167
|
+
// Auto-set horizontal orientation for boxIconVertical (items laid out in columns)
|
|
168
|
+
const effectiveOrientation =
|
|
169
|
+
variant === "boxIconVertical" ? "horizontal" : orientation;
|
|
170
|
+
|
|
215
171
|
return (
|
|
216
|
-
<RadioGroupContext.Provider
|
|
172
|
+
<RadioGroupContext.Provider
|
|
173
|
+
value={{ variant: contextVariant, error: hasError }}
|
|
174
|
+
>
|
|
217
175
|
<RadioGroupPrimitive.Root
|
|
218
176
|
ref={ref}
|
|
219
177
|
aria-invalid={hasError ? "true" : undefined}
|
|
@@ -222,6 +180,8 @@ const RadioGroup = React.forwardRef<
|
|
|
222
180
|
data-slot="radio-group"
|
|
223
181
|
data-tracking-el={trackingEl}
|
|
224
182
|
data-tracking-label={trackingLabel}
|
|
183
|
+
data-variant={variant}
|
|
184
|
+
orientation={effectiveOrientation}
|
|
225
185
|
{...props}
|
|
226
186
|
/>
|
|
227
187
|
</RadioGroupContext.Provider>
|
|
@@ -235,74 +195,50 @@ RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
|
|
|
235
195
|
const RadioGroupItem = React.forwardRef<
|
|
236
196
|
React.ElementRef<typeof RadioGroupPrimitive.Item>,
|
|
237
197
|
RadioGroupItemProps
|
|
238
|
-
>(
|
|
239
|
-
(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
: "fill-background text-background"
|
|
283
|
-
)}
|
|
284
|
-
size={8}
|
|
285
|
-
/>
|
|
286
|
-
</RadioGroupPrimitive.Indicator>
|
|
287
|
-
</div>
|
|
288
|
-
)}
|
|
289
|
-
|
|
290
|
-
{/* Label and description */}
|
|
291
|
-
{(label || description || children) && (
|
|
292
|
-
<div className={radioContentVariants({ variant })}>
|
|
293
|
-
{label && (
|
|
294
|
-
<Label className="my-[1px] cursor-pointer">{label}</Label>
|
|
295
|
-
)}
|
|
296
|
-
{description && (
|
|
297
|
-
<p className="text-muted-foreground text-sm">{description}</p>
|
|
298
|
-
)}
|
|
299
|
-
{children}
|
|
300
|
-
</div>
|
|
301
|
-
)}
|
|
302
|
-
</RadioGroupPrimitive.Item>
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
);
|
|
198
|
+
>(({ className, children, ...props }, ref) => {
|
|
199
|
+
const { variant: ctxVariant, error } = React.useContext(RadioGroupContext);
|
|
200
|
+
const variant = ctxVariant ?? "default";
|
|
201
|
+
|
|
202
|
+
const isBoxIcon =
|
|
203
|
+
variant === "boxIconVertical" || variant === "boxIconHorizontal";
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<RadioGroupPrimitive.Item
|
|
207
|
+
ref={ref}
|
|
208
|
+
className={cn(radioGroupItemVariants({ variant }), className)}
|
|
209
|
+
data-slot="radio-group-item"
|
|
210
|
+
{...props}
|
|
211
|
+
>
|
|
212
|
+
{/* Radio button circle for default and box variants */}
|
|
213
|
+
{!isBoxIcon && (
|
|
214
|
+
<div
|
|
215
|
+
className={cn(
|
|
216
|
+
radioCircleVariants({ variant }),
|
|
217
|
+
error && [
|
|
218
|
+
"border-red-600/40 dark:border-red-400/60",
|
|
219
|
+
"group-focus-visible:border-destructive group-focus-visible:shadow-destructive",
|
|
220
|
+
]
|
|
221
|
+
)}
|
|
222
|
+
>
|
|
223
|
+
<RadioGroupPrimitive.Indicator
|
|
224
|
+
className="absolute inset-0 flex items-center justify-center"
|
|
225
|
+
data-slot="radio-group-indicator"
|
|
226
|
+
>
|
|
227
|
+
<Circle
|
|
228
|
+
className={cn(
|
|
229
|
+
variant === "default"
|
|
230
|
+
? "fill-primary text-primary"
|
|
231
|
+
: "fill-background text-background"
|
|
232
|
+
)}
|
|
233
|
+
size={8}
|
|
234
|
+
/>
|
|
235
|
+
</RadioGroupPrimitive.Indicator>
|
|
236
|
+
</div>
|
|
237
|
+
)}
|
|
238
|
+
{children}
|
|
239
|
+
</RadioGroupPrimitive.Item>
|
|
240
|
+
);
|
|
241
|
+
});
|
|
306
242
|
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
|
|
307
243
|
|
|
308
244
|
/* --------------------------------- Exports -------------------------------- */
|