--- name: form-components description: StepLeague reusable form components with accessibility features. Use when creating any form, input field, select dropdown, checkbox, or file upload in the application. Keywords: form, input, select, checkbox, textarea, file upload, accessibility, FormInput, FormSelect. compatibility: Antigravity, Claude Code, Cursor metadata: version: "1.1" project: "stepleague" --- # Form Components Skill ## Core Rule **ALWAYS use form components from `@/components/ui/form-fields`.** These components: - Auto-generate `id`/`name` attributes - Include accessibility features (aria-describedby, aria-invalid) - Consistent styling across the app - Proper label association --- ## Available Components | Component | Purpose | |-----------|---------| | `FormInput` | Text, email, password, number inputs | | `FormSelect` | Dropdown select | | `FormCheckbox` | Checkbox with label | | `FormTextarea` | Multi-line text input | | `FormFileInput` | File upload | --- ## Usage Examples ### FormInput ```tsx import { FormInput } from "@/components/ui/form-fields"; setSteps(e.target.value)} /> ``` ### FormSelect ```tsx import { FormSelect } from "@/components/ui/form-fields"; setSelectedLeague(e.target.value)} required > {leagues.map((league) => ( ))} ``` ### FormCheckbox ```tsx import { FormCheckbox } from "@/components/ui/form-fields"; setAcceptedTerms(e.target.checked)} required /> ``` ### FormTextarea ```tsx import { FormTextarea } from "@/components/ui/form-fields"; setFeedback(e.target.value)} /> ``` ### FormFileInput ```tsx import { FormFileInput } from "@/components/ui/form-fields"; ``` --- ## Props Reference ### Common Props (All Components) | Prop | Type | Required | Description | |------|------|----------|-------------| | `fieldName` | `string` | ✅ | Unique identifier (becomes id/name) | | `label` | `string` | ✅ | Label text | | `error` | `string` | ❌ | Error message to display | | `description` | `string` | ❌ | Help text below field | | `required` | `boolean` | ❌ | Adds required indicator | | `disabled` | `boolean` | ❌ | Disables the field | | `className` | `string` | ❌ | Additional CSS classes | ### FormInput Additional Props | Prop | Type | Description | |------|------|-------------| | `type` | `string` | Input type (text, email, password, number, etc.) | | `placeholder` | `string` | Placeholder text | | `min`, `max` | `number` | For number inputs | | `pattern` | `string` | Validation pattern | ### FormSelect Additional Props | Prop | Type | Description | |------|------|-------------| | `children` | `ReactNode` | Option elements | | `placeholder` | `string` | First disabled option text | --- ## Accessibility Features The form components automatically provide: ### 1. Label Association ```html ``` ### 2. Error Announcements ```html ``` ### 3. Description Association ```html

We'll never share your email

``` --- ## Form Patterns ### Basic Form ```tsx import { FormInput, FormSelect, FormCheckbox } from "@/components/ui/form-fields"; function MyForm() { const [formData, setFormData] = useState({ email: '', role: '', newsletter: false, }); const [errors, setErrors] = useState({}); return (
setFormData(prev => ({ ...prev, email: e.target.value }))} error={errors.email} required /> setFormData(prev => ({ ...prev, role: e.target.value }))} required > setFormData(prev => ({ ...prev, newsletter: e.target.checked }))} /> ); } ``` ### With Loading State ```tsx ``` --- ## Anti-Patterns ### ❌ Don't Use Raw HTML Elements ```tsx // ❌ WRONG // ✅ CORRECT ``` ### ❌ Don't Forget fieldName ```tsx // ❌ WRONG - no fieldName // ✅ CORRECT ``` ### ❌ Don't Duplicate IDs ```tsx // ❌ WRONG - duplicate fieldNames // ✅ CORRECT - unique fieldNames ``` --- ## Reference Files | File | Purpose | |------|---------| | `src/components/ui/form-fields.tsx` | Component implementations | | `docs/FORM_SYSTEM.md` | Full documentation | --- ## Related Skills - `design-system` - Form styling and theming - `architecture-philosophy` - Use existing components