import { ReactNode, FormHTMLAttributes } from 'react'; import { Form as RemixForm } from '@remix-run/react'; import { defaultLayoutConfig, type LayoutConfig } from '~/lib/layout-utils'; import { Button } from './Button'; import { Text } from './Text'; interface FormProps extends Omit, 'className'> { children: ReactNode; className?: string; config?: Partial; title?: string; description?: string; loading?: boolean; error?: string; success?: string; actions?: ReactNode; spacing?: 'sm' | 'md' | 'lg'; } export function Form({ children, className = '', config = {}, title, description, loading = false, error, success, actions, spacing = 'md', ...props }: FormProps) { const layoutConfig = { ...defaultLayoutConfig, ...config }; const spacingClasses = { sm: 'space-y-4', md: 'space-y-6', lg: 'space-y-8', }; return (
{/* Form Header */} {(title || description) && (
{title && ( {title} )} {description && ( {description} )}
)} {/* Success Message */} {success && (
{success}
)} {/* Error Message */} {error && (
{error}
)} {/* Form Content */} {children} {/* Form Actions */} {actions && (
{actions}
)}
{/* Loading Overlay */} {loading && (
جاري المعالجة...
)}
); } // Form Actions Component interface FormActionsProps { children: ReactNode; className?: string; config?: Partial; justify?: 'start' | 'center' | 'end' | 'between'; spacing?: 'sm' | 'md' | 'lg'; } export function FormActions({ children, className = '', config = {}, justify = 'end', spacing = 'md', }: FormActionsProps) { const layoutConfig = { ...defaultLayoutConfig, ...config }; const justifyClasses = { start: 'justify-start', center: 'justify-center', end: 'justify-end', between: 'justify-between', }; const spacingClasses = { sm: 'space-x-2 space-x-reverse', md: 'space-x-4 space-x-reverse', lg: 'space-x-6 space-x-reverse', }; return (
{children}
); } // Form Section Component interface FormSectionProps { children: ReactNode; title?: string; description?: string; className?: string; config?: Partial; } export function FormSection({ children, title, description, className = '', config = {}, }: FormSectionProps) { const layoutConfig = { ...defaultLayoutConfig, ...config }; return (
{(title || description) && (
{title && ( {title} )} {description && ( {description} )}
)}
{children}
); } // Form Grid Component interface FormGridProps { children: ReactNode; columns?: 1 | 2 | 3 | 4; className?: string; config?: Partial; gap?: 'sm' | 'md' | 'lg'; } export function FormGrid({ children, columns = 2, className = '', config = {}, gap = 'md', }: FormGridProps) { const layoutConfig = { ...defaultLayoutConfig, ...config }; const columnClasses = { 1: 'grid-cols-1', 2: 'grid-cols-1 md:grid-cols-2', 3: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3', 4: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4', }; const gapClasses = { sm: 'gap-4', md: 'gap-6', lg: 'gap-8', }; return (
{children}
); }