@brightlocal/ui-components 0.5.0 → 1.0.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/dist/alert.d.ts +2 -2
- package/dist/blocks/sidebar.d.ts +2 -2
- package/dist/button.d.ts +2 -2
- package/dist/combobox.cjs +1 -1
- package/dist/combobox.d.ts +6 -2
- package/dist/combobox.d.ts.map +1 -1
- package/dist/combobox.js +144 -133
- package/dist/field.cjs +1 -1
- package/dist/field.d.ts +8 -1
- 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/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/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 +45 -5
- package/src/components/input-otp.tsx +9 -89
- package/src/components/radio-group.tsx +65 -129
- 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
package/src/components/field.tsx
CHANGED
|
@@ -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"
|
|
@@ -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
|
};
|
|
@@ -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 -------------------------------- */
|