|
| 1 | +# Medusa Forms Registry |
| 2 | + |
| 3 | +This package provides a custom shadcn/ui registry that allows developers to install medusa-forms components using the native shadcn CLI. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +You can install components from this registry using the shadcn CLI: |
| 8 | + |
| 9 | +```bash |
| 10 | +npx shadcn@latest add --registry https://raw.githubusercontent.com/lambda-curry/medusa-forms/main/packages/medusa-forms/registry.json input |
| 11 | +``` |
| 12 | + |
| 13 | +## Available Components |
| 14 | + |
| 15 | +### Base UI Components |
| 16 | + |
| 17 | +- `field-wrapper` - Core wrapper component with error handling and labels |
| 18 | +- `field-error` - Error display component |
| 19 | +- `label` - Label component with tooltip support |
| 20 | +- `input` - Base input component |
| 21 | +- `select` - Base select component |
| 22 | +- `field-checkbox` - Base checkbox component |
| 23 | +- `textarea` - Base textarea component |
| 24 | +- `datepicker` - Base datepicker component |
| 25 | +- `currency-input` - Base currency input component |
| 26 | + |
| 27 | +### Controlled Components (React Hook Form) |
| 28 | + |
| 29 | +- `controlled-input` - Input with react-hook-form integration |
| 30 | +- `controlled-select` - Select with react-hook-form integration |
| 31 | +- `controlled-checkbox` - Checkbox with react-hook-form integration |
| 32 | +- `controlled-textarea` - Textarea with react-hook-form integration |
| 33 | +- `controlled-datepicker` - DatePicker with react-hook-form integration |
| 34 | +- `controlled-currency-input` - CurrencyInput with react-hook-form integration |
| 35 | + |
| 36 | +## Usage Examples |
| 37 | + |
| 38 | +### Installing a single component |
| 39 | + |
| 40 | +```bash |
| 41 | +npx shadcn@latest add --registry https://raw.githubusercontent.com/lambda-curry/medusa-forms/main/packages/medusa-forms/registry.json controlled-input |
| 42 | +``` |
| 43 | + |
| 44 | +### Installing multiple components |
| 45 | + |
| 46 | +```bash |
| 47 | +npx shadcn@latest add --registry https://raw.githubusercontent.com/lambda-curry/medusa-forms/main/packages/medusa-forms/registry.json controlled-input controlled-select controlled-checkbox |
| 48 | +``` |
| 49 | + |
| 50 | +### Using the components |
| 51 | + |
| 52 | +```tsx |
| 53 | +import { ControlledInput } from '@/components/ui/controlled-input' |
| 54 | +import { ControlledSelect } from '@/components/ui/controlled-select' |
| 55 | +import { useForm, FormProvider } from 'react-hook-form' |
| 56 | + |
| 57 | +function MyForm() { |
| 58 | + const methods = useForm() |
| 59 | + |
| 60 | + return ( |
| 61 | + <FormProvider {...methods}> |
| 62 | + <form> |
| 63 | + <ControlledInput |
| 64 | + name="email" |
| 65 | + label="Email" |
| 66 | + placeholder="Enter your email" |
| 67 | + /> |
| 68 | + |
| 69 | + <ControlledSelect |
| 70 | + name="country" |
| 71 | + label="Country" |
| 72 | + options={[ |
| 73 | + { label: 'United States', value: 'us' }, |
| 74 | + { label: 'Canada', value: 'ca' }, |
| 75 | + ]} |
| 76 | + /> |
| 77 | + </form> |
| 78 | + </FormProvider> |
| 79 | + ) |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +## Component Dependencies |
| 84 | + |
| 85 | +The registry properly handles component dependencies: |
| 86 | + |
| 87 | +- Controlled components depend on their base UI components |
| 88 | +- UI components depend on `field-wrapper` when needed |
| 89 | +- `field-wrapper` depends on `field-error` and `label` |
| 90 | +- All components use `@medusajs/ui` for base styling |
| 91 | + |
| 92 | +## Architecture |
| 93 | + |
| 94 | +### Field Wrapper Pattern |
| 95 | + |
| 96 | +All form components use a consistent wrapper pattern: |
| 97 | + |
| 98 | +- `FieldWrapper` provides consistent layout and error handling |
| 99 | +- `Label` component handles labels and tooltips |
| 100 | +- `FieldError` handles error message display |
| 101 | +- UI components wrap `@medusajs/ui` components |
| 102 | + |
| 103 | +### Controlled Component Pattern |
| 104 | + |
| 105 | +Controlled components use react-hook-form: |
| 106 | + |
| 107 | +- Uses `Controller` from react-hook-form |
| 108 | +- Integrates with form context |
| 109 | +- Handles form validation and errors |
| 110 | +- Preserves component props and types |
| 111 | + |
| 112 | +## Types and Interfaces |
| 113 | + |
| 114 | +- `BasicFieldProps` - Common field properties |
| 115 | +- `FieldWrapperProps` - Wrapper component props |
| 116 | +- Component-specific props (`InputProps`, `SelectProps`, etc.) |
| 117 | +- React Hook Form integration types |
| 118 | + |
0 commit comments