diff --git a/llms.txt b/llms.txt new file mode 100644 index 00000000..8e0b1f3f --- /dev/null +++ b/llms.txt @@ -0,0 +1,1009 @@ +# LambdaCurry Forms - Complete Implementation Guide for LLMs + +This comprehensive guide covers everything needed to implement forms using the `@lambdacurry/forms` remix-hook-form components. This documentation is specifically designed for LLMs to understand all features, patterns, and best practices. + +## Core Architecture Overview + +The library provides **form-aware wrapper components** in the `remix-hook-form` directory that automatically integrate with React Router forms and Remix Hook Form context. These components eliminate boilerplate while maintaining full customization capabilities. + +### Key Principle: Zero Boilerplate Form Integration +- Components automatically access form context via `useRemixFormContext()` +- No need to manually pass `control` props +- Automatic error handling and validation display +- Built-in accessibility features + +## Basic Form Setup Pattern + +### 1. Required Imports +```typescript +import { zodResolver } from '@hookform/resolvers/zod'; +import { RemixFormProvider, useRemixForm, getValidatedFormData } from 'remix-hook-form'; +import { z } from 'zod'; +import { useFetcher, type ActionFunctionArgs } from 'react-router'; + +// Import form components +import { TextField, Checkbox } from '@lambdacurry/forms'; +import { Button } from '@lambdacurry/forms/ui/button'; +``` + +### 2. Zod Schema Definition +```typescript +const formSchema = z.object({ + username: z.string().min(3, 'Username must be at least 3 characters'), + email: z.string().email('Invalid email address'), + terms: z.boolean().refine(val => val === true, 'You must accept the terms'), + age: z.coerce.number().min(18, 'Must be at least 18 years old'), +}); + +type FormData = z.infer; +``` + +### 3. Form Component Setup +```typescript +const MyFormComponent = () => { + const fetcher = useFetcher<{ message: string; errors?: Record }>(); + + const methods = useRemixForm({ + resolver: zodResolver(formSchema), + defaultValues: { + username: '', + email: '', + terms: false, + age: undefined, + }, + fetcher, + submitConfig: { + action: '/', + method: 'post', + }, + }); + + return ( + + + + + + + + + {fetcher.data?.message &&

{fetcher.data.message}

} +
+
+ ); +}; +``` + +### 4. Server Action Handler +```typescript +export const action = async ({ request }: ActionFunctionArgs) => { + const { data, errors } = await getValidatedFormData( + request, + zodResolver(formSchema) + ); + + if (errors) { + return { errors }; + } + + // Process the validated data + console.log('Form data:', data); + + return { message: 'Form submitted successfully!' }; +}; +``` + +## Available Form Components + +### TextField Component +```typescript + +``` + +### Textarea Component +```typescript +