'use client'; import type { BaseFormInputProps, WithHelperTextProps } from '@/components/blocks/asset-form/asset-form-types'; import { getAriaAttributes } from '@/components/blocks/asset-form/asset-form-types'; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; import { Switch } from '@/components/ui/switch'; import { cn } from '@/lib/utils'; import type { ComponentPropsWithoutRef } from 'react'; import type { FieldValues } from 'react-hook-form'; type SwitchProps = ComponentPropsWithoutRef; type AssetFormSwitchProps = Omit> & BaseFormInputProps & WithHelperTextProps; /** * A form switch component that wraps shadcn's Switch component with form field functionality. * Provides a toggle switch with optional helper text and full form integration. * * @example * ```tsx * * ``` */ export function AssetFormSwitch({ label, description, helperText, rules, className, ...props }: AssetFormSwitchProps) { return ( { const ariaAttrs = getAriaAttributes(field.name, !!fieldState.error, props.disabled); return ( {label && ( {label} {props.required && *} )}
{helperText && ( {helperText} )}
{description && {description}}
); }} /> ); }