'use client' import React, { forwardRef, createContext, useContext, useMemo, useId } from 'react' /** * FormControl context for sharing state with child components */ interface FormControlContextValue { id?: string required?: boolean disabled?: boolean error?: boolean filled?: boolean focused?: boolean } const FormControlContext = createContext({}) /** * Hook to access FormControl context from child components */ export const useFormControl = () => useContext(FormControlContext) /** * Props for FormControl component */ export interface FormControlProps extends React.HTMLAttributes { children?: React.ReactNode /** Whether the field is required */ required?: boolean /** Whether the field is disabled */ disabled?: boolean /** Whether the field has an error */ error?: boolean /** Full width form control */ fullWidth?: boolean /** Margin size */ margin?: 'none' | 'dense' | 'normal' /** Size of the form control */ size?: 'small' | 'medium' /** Visual variant */ variant?: 'standard' | 'outlined' | 'filled' /** Whether the input has value (filled state) */ filled?: boolean /** Whether the input is focused */ focused?: boolean /** MUI sx prop for styling compatibility */ sx?: Record } /** * FormControl - Provides context to form input components for consistent state * * @example * ```tsx * * Email * * Required field * * ``` */ export const FormControl = forwardRef( ( { children, required = false, disabled = false, error = false, fullWidth = false, margin = 'none', size = 'medium', variant = 'outlined', filled = false, focused = false, className = '', sx, ...props }, ref ) => { const id = useId() const contextValue = useMemo( () => ({ id, required, disabled, error, filled, focused }), [id, required, disabled, error, filled, focused] ) return (
{children}
) } ) FormControl.displayName = 'FormControl'