|
| 1 | +# Medusa Forms shadcn/ui Registry |
| 2 | + |
| 3 | +This repository provides a custom shadcn/ui registry for medusa-forms components, allowing developers to install them using the native shadcn CLI. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +You can install individual medusa-forms components using the shadcn CLI: |
| 8 | + |
| 9 | +```bash |
| 10 | +# Install individual components |
| 11 | +npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-input.json |
| 12 | +npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-select.json |
| 13 | +npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-checkbox.json |
| 14 | +npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-textarea.json |
| 15 | +npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-datepicker.json |
| 16 | +npx shadcn@latest add https://raw.githubusercontent.com/lambda-curry/forms/main/registry/controlled-currency-input.json |
| 17 | +``` |
| 18 | + |
| 19 | +## Available Components |
| 20 | + |
| 21 | +### ControlledInput |
| 22 | +A controlled input component with react-hook-form integration. |
| 23 | + |
| 24 | +```tsx |
| 25 | +import { ControlledInput } from '@/components/ui/controlled-input' |
| 26 | + |
| 27 | +<ControlledInput |
| 28 | + name="email" |
| 29 | + label="Email" |
| 30 | + placeholder="Enter your email" |
| 31 | + rules={{ required: 'Email is required' }} |
| 32 | +/> |
| 33 | +``` |
| 34 | + |
| 35 | +### ControlledSelect |
| 36 | +A controlled select component with react-hook-form integration. |
| 37 | + |
| 38 | +```tsx |
| 39 | +import { ControlledSelect } from '@/components/ui/controlled-select' |
| 40 | + |
| 41 | +const options = [ |
| 42 | + { label: 'Option 1', value: 'option1' }, |
| 43 | + { label: 'Option 2', value: 'option2' }, |
| 44 | +] |
| 45 | + |
| 46 | +<ControlledSelect |
| 47 | + name="category" |
| 48 | + label="Category" |
| 49 | + placeholder="Select a category" |
| 50 | + options={options} |
| 51 | + rules={{ required: 'Category is required' }} |
| 52 | +/> |
| 53 | +``` |
| 54 | + |
| 55 | +### ControlledCheckbox |
| 56 | +A controlled checkbox component with react-hook-form integration. |
| 57 | + |
| 58 | +```tsx |
| 59 | +import { ControlledCheckbox } from '@/components/ui/controlled-checkbox' |
| 60 | + |
| 61 | +<ControlledCheckbox |
| 62 | + name="terms" |
| 63 | + label="I agree to the terms and conditions" |
| 64 | + rules={{ required: 'You must agree to the terms' }} |
| 65 | +/> |
| 66 | +``` |
| 67 | + |
| 68 | +### ControlledTextarea |
| 69 | +A controlled textarea component with react-hook-form integration. |
| 70 | + |
| 71 | +```tsx |
| 72 | +import { ControlledTextarea } from '@/components/ui/controlled-textarea' |
| 73 | + |
| 74 | +<ControlledTextarea |
| 75 | + name="description" |
| 76 | + label="Description" |
| 77 | + placeholder="Enter a description" |
| 78 | + rows={4} |
| 79 | + rules={{ required: 'Description is required' }} |
| 80 | +/> |
| 81 | +``` |
| 82 | + |
| 83 | +### ControlledDatePicker |
| 84 | +A controlled date picker component with react-hook-form integration. |
| 85 | + |
| 86 | +```tsx |
| 87 | +import { ControlledDatePicker } from '@/components/ui/controlled-datepicker' |
| 88 | + |
| 89 | +<ControlledDatePicker |
| 90 | + name="birthDate" |
| 91 | + label="Birth Date" |
| 92 | + placeholder="Select your birth date" |
| 93 | + rules={{ required: 'Birth date is required' }} |
| 94 | +/> |
| 95 | +``` |
| 96 | + |
| 97 | +### ControlledCurrencyInput |
| 98 | +A controlled currency input component with react-hook-form integration. |
| 99 | + |
| 100 | +```tsx |
| 101 | +import { ControlledCurrencyInput } from '@/components/ui/controlled-currency-input' |
| 102 | + |
| 103 | +<ControlledCurrencyInput |
| 104 | + name="price" |
| 105 | + label="Price" |
| 106 | + placeholder="Enter price" |
| 107 | + currency="USD" |
| 108 | + rules={{ required: 'Price is required' }} |
| 109 | +/> |
| 110 | +``` |
| 111 | + |
| 112 | +## Prerequisites |
| 113 | + |
| 114 | +Before using these components, make sure you have: |
| 115 | + |
| 116 | +1. **shadcn/ui initialized** in your project: |
| 117 | + ```bash |
| 118 | + npx shadcn@latest init |
| 119 | + ``` |
| 120 | + |
| 121 | +2. **Required dependencies** installed: |
| 122 | + ```bash |
| 123 | + npm install @medusajs/ui react-hook-form @hookform/error-message |
| 124 | + ``` |
| 125 | + |
| 126 | +3. **FormProvider setup** in your application: |
| 127 | + ```tsx |
| 128 | + import { useForm, FormProvider } from 'react-hook-form' |
| 129 | + |
| 130 | + function MyForm() { |
| 131 | + const methods = useForm() |
| 132 | + |
| 133 | + return ( |
| 134 | + <FormProvider {...methods}> |
| 135 | + <form onSubmit={methods.handleSubmit(onSubmit)}> |
| 136 | + {/* Your controlled components here */} |
| 137 | + </form> |
| 138 | + </FormProvider> |
| 139 | + ) |
| 140 | + } |
| 141 | + ``` |
| 142 | + |
| 143 | +## Benefits |
| 144 | + |
| 145 | +✅ **No Custom CLI**: Leverage existing shadcn infrastructure |
| 146 | +✅ **Familiar UX**: Developers already know `npx shadcn@latest add` |
| 147 | +✅ **Auto Dependencies**: shadcn handles npm package installation |
| 148 | +✅ **TypeScript Support**: Built-in TypeScript compatibility |
| 149 | +✅ **Zero Maintenance**: No CLI package to maintain |
| 150 | +✅ **Instant Adoption**: Works with existing shadcn projects |
| 151 | +✅ **v0 Compatible**: Components work with v0.dev |
| 152 | + |
| 153 | +## Registry Structure |
| 154 | + |
| 155 | +``` |
| 156 | +lambda-curry/forms/ |
| 157 | +├── registry.json # Main registry configuration |
| 158 | +├── registry/ # Component registry files |
| 159 | +│ ├── controlled-input.json |
| 160 | +│ ├── controlled-select.json |
| 161 | +│ ├── controlled-checkbox.json |
| 162 | +│ ├── controlled-textarea.json |
| 163 | +│ ├── controlled-datepicker.json |
| 164 | +│ └── controlled-currency-input.json |
| 165 | +└── src/registry/ # Component source files |
| 166 | + ├── controlled-input.tsx |
| 167 | + ├── controlled-select.tsx |
| 168 | + ├── controlled-checkbox.tsx |
| 169 | + ├── controlled-textarea.tsx |
| 170 | + ├── controlled-datepicker.tsx |
| 171 | + └── controlled-currency-input.tsx |
| 172 | +``` |
| 173 | + |
| 174 | +## Contributing |
| 175 | + |
| 176 | +To add new components to the registry: |
| 177 | + |
| 178 | +1. Create the component in `src/registry/` |
| 179 | +2. Add it to the main `registry.json` |
| 180 | +3. Generate the individual JSON file in `registry/` |
| 181 | +4. Update this documentation |
| 182 | + |
| 183 | +## License |
| 184 | + |
| 185 | +This project is licensed under the same license as the main forms repository. |
| 186 | + |
0 commit comments