// packages/rdx-ui/src/components/form/switch-field.tsx import { Field, FieldContent, FieldDescription, FieldError, Switch, } 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"; type SwitchFieldProps = { name: FieldPath; label?: string | React.ReactNode; description?: string; reserveDescriptionSpace?: boolean; onCheckedChange?: (checked: boolean) => void; disabled?: boolean; required?: boolean; readOnly?: boolean; orientation?: "vertical" | "horizontal" | "responsive"; className?: string; inputClassName?: string; }; export const SwitchField = ({ name, label, description, reserveDescriptionSpace = false, onCheckedChange, disabled = false, required = false, readOnly = false, orientation = "horizontal", className, inputClassName, }: SwitchFieldProps) => { const { control, formState } = useFormContext(); const inputId = React.useId(); const descriptionId = description ? `${inputId}-description` : undefined; const isDisabled = disabled || readOnly || formState.isSubmitting; return ( { const hasError = Boolean(fieldState.error); return ( {label} {description ? ( {description} ) : reserveDescriptionSpace ? (