import { Field, FieldDescription, FieldError, FormControl, RadioGroup, RadioGroupItem, } from "@repo/shadcn-ui/components"; import { cn } from "@repo/shadcn-ui/lib/utils"; import * as React from "react"; import { Controller, type FieldPath, type FieldValues, useFormContext } from "react-hook-form"; import { FormFieldLabel } from "./form-field-label.tsx"; export interface RadioGroupFieldItem { value: string; label: string; description?: string; disabled?: boolean; } type RadioGroupFieldProps = { name: FieldPath; items: RadioGroupFieldItem[]; label?: string; description?: string; disabled?: boolean; required?: boolean; readOnly?: boolean; orientation?: "vertical" | "horizontal" | "responsive"; className?: string; inputClassName?: string; itemClassName?: string; }; export const RadioGroupField = ({ name, items, label, description, disabled = false, required = false, readOnly = false, orientation = "vertical", className, inputClassName, itemClassName, }: RadioGroupFieldProps) => { const baseId = React.useId(); const { control, formState } = useFormContext(); const isDisabled = Boolean(disabled || readOnly || formState.isSubmitting); return ( ( {label ? ( {label} ) : null} {items.map((item, index) => { const itemId = `${baseId}-${index}-${item.value}`; const itemDisabled = Boolean(isDisabled || item.disabled); return (
{item.description ? (

{item.description}

) : null}
); })}
{description ? ( {description} ) : (