@rachelallyson/hero-hook-form 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -42
- package/README.md +131 -178
- package/dist/index.d.ts +73 -4
- package/dist/index.js +225 -80
- package/dist/react/index.d.ts +73 -4
- package/dist/react/index.js +225 -80
- package/package.json +41 -32
package/CHANGELOG.md
CHANGED
|
@@ -2,49 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
## [1.0.2] - 2025-01-27
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
### Enhanced
|
|
8
|
+
|
|
9
|
+
- **Font Picker Refactored**: Now uses native [HeroUI Autocomplete component](https://www.heroui.com/docs/components/autocomplete)
|
|
10
|
+
- **Better Integration**: Perfect HeroUI design system integration with Autocomplete
|
|
11
|
+
- **Enhanced Features**: Built-in search, filtering, keyboard navigation, and accessibility
|
|
12
|
+
- **Sections Support**: Organized font categories with `AutocompleteSection`
|
|
13
|
+
- **Improved Performance**: Leverages HeroUI's optimized Autocomplete implementation
|
|
14
|
+
- **Better UX**: Native HeroUI animations, transitions, and responsive design
|
|
9
15
|
|
|
10
16
|
### Added
|
|
11
17
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
###
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
- **Google Fonts Integration**: Access to 1000+ Google Fonts with API key
|
|
19
|
+
- **Automatic Font Loading**: Selected fonts are automatically loaded from Google Fonts
|
|
20
|
+
- **Fallback Support**: Graceful fallback to local fonts if Google Fonts unavailable
|
|
21
|
+
- **Font Previews**: Live font previews in the picker
|
|
22
|
+
- **Accessibility Features**: Full ARIA support and keyboard navigation
|
|
23
|
+
|
|
24
|
+
## [1.0.1] - 2024-12-19
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **`createZodFormConfig` function**: Missing utility function for creating Zod form configurations
|
|
29
|
+
- **Font picker field**: Optional font picker field with `react-fontpicker-ts` integration
|
|
30
|
+
- **Comprehensive documentation**: Complete guides for radio buttons, nested fields, and font picker
|
|
31
|
+
- **Working examples**: Practical examples demonstrating proper usage
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- **Default values handling**: Fixed type casting issues in `createZodFormConfig`
|
|
36
|
+
- **Radio button configuration**: Clarified proper usage with `radioOptions` instead of `inputProps.options`
|
|
37
|
+
- **Nested field names**: Documented proper schema structure for nested fields like "fonts.scale"
|
|
38
|
+
- **Type safety**: Updated `ZodFormConfig` interface to make `schema` required
|
|
39
|
+
|
|
40
|
+
### Documentation
|
|
41
|
+
|
|
42
|
+
- [Quick Start Guide](./docs/quick-start.md) - Get started quickly with examples
|
|
43
|
+
- [Radio Buttons Guide](./docs/radio-buttons-guide.md) - Complete guide for radio button configuration
|
|
44
|
+
- [Nested Fields Guide](./docs/nested-fields-guide.md) - Working with nested field names
|
|
45
|
+
- [Input Types Guide](./docs/input-types-guide.md) - Complete reference for all input types
|
|
46
|
+
- [Font Picker Guide](./docs/font-picker-guide.md) - Optional font picker field
|
|
47
|
+
- [Font Picker Styling](./docs/font-picker-styling.md) - HeroUI integration and styling
|
|
48
|
+
- [Fixes Summary](./docs/fixes-summary.md) - Summary of all fixes implemented
|
|
49
|
+
|
|
50
|
+
### Examples
|
|
51
|
+
|
|
52
|
+
- `example-settings-form.tsx` - Complete settings form with nested fields and radio buttons
|
|
53
|
+
- `example-nested-fields.tsx` - Demonstration of nested field names
|
|
54
|
+
|
|
55
|
+
## [1.0.0] - 2024-12-18
|
|
56
|
+
|
|
57
|
+
### Initial Release
|
|
58
|
+
|
|
59
|
+
- Basic form components with HeroUI integration
|
|
60
|
+
- Zod integration support
|
|
61
|
+
- TypeScript support
|
|
62
|
+
- Form validation and error handling
|
package/README.md
CHANGED
|
@@ -6,22 +6,24 @@
|
|
|
6
6
|
[](https://reactjs.org/)
|
|
7
7
|
[](https://heroui.com/)
|
|
8
8
|
|
|
9
|
-
> **
|
|
9
|
+
> **Type-safe form components that combine React Hook Form with HeroUI's design system.**
|
|
10
10
|
|
|
11
|
-
Build beautiful, accessible forms with full TypeScript support, validation, and HeroUI's design system.
|
|
11
|
+
Build beautiful, accessible forms with full TypeScript support, comprehensive validation, and HeroUI's modern design system. Perfect for React applications that need robust form handling with excellent developer experience.
|
|
12
12
|
|
|
13
13
|
## ✨ Features
|
|
14
14
|
|
|
15
|
-
- 🎯 **Strongly-typed** field components
|
|
16
|
-
- 🏗️ **
|
|
17
|
-
- Default entrypoint for individual HeroUI packages
|
|
18
|
-
- `/react` entrypoint for the aggregate `@heroui/react`
|
|
19
|
-
- 📦 **Optional
|
|
20
|
-
- 🔧 **Global configuration** system for consistent styling
|
|
21
|
-
- ✅ **Zod integration** for schema-based validation
|
|
22
|
-
- 🎨 **Multiple layouts** (vertical, horizontal, grid)
|
|
23
|
-
- ♿ **Accessibility-first** with HeroUI's built-in
|
|
15
|
+
- 🎯 **Strongly-typed** field components with automatic TypeScript inference
|
|
16
|
+
- 🏗️ **Dual entrypoints** for maximum flexibility:
|
|
17
|
+
- Default entrypoint for individual HeroUI packages (better tree-shaking)
|
|
18
|
+
- `/react` entrypoint for the aggregate `@heroui/react` (convenient single dependency)
|
|
19
|
+
- 📦 **Optional dependencies** - install only what you need
|
|
20
|
+
- 🔧 **Global configuration** system for consistent styling across your app
|
|
21
|
+
- ✅ **Zod integration** for schema-based validation with type safety
|
|
22
|
+
- 🎨 **Multiple layouts** (vertical, horizontal, grid) with responsive design
|
|
23
|
+
- ♿ **Accessibility-first** with HeroUI's built-in ARIA support
|
|
24
24
|
- 🌳 **Tree-shakeable** for optimal bundle sizes
|
|
25
|
+
- 🚀 **Rapid prototyping** with ConfigurableForm component
|
|
26
|
+
- 🎨 **Optional font picker** with Google Fonts integration
|
|
25
27
|
|
|
26
28
|
## 🚀 Quick Start
|
|
27
29
|
|
|
@@ -38,6 +40,16 @@ npm install @rachelallyson/hero-hook-form react-hook-form zod
|
|
|
38
40
|
npm install @heroui/button @heroui/input @heroui/select # Only what you need
|
|
39
41
|
```
|
|
40
42
|
|
|
43
|
+
### Option 3: With Optional Font Picker
|
|
44
|
+
|
|
45
|
+
For advanced font selection with Google Fonts integration:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @rachelallyson/hero-hook-form @rachelallyson/heroui-font-picker
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The `FontPickerField` will automatically use the font picker package if available, with a helpful fallback message if not installed.
|
|
52
|
+
|
|
41
53
|
### Basic Usage
|
|
42
54
|
|
|
43
55
|
```tsx
|
|
@@ -77,39 +89,39 @@ export function ContactForm() {
|
|
|
77
89
|
|
|
78
90
|
## Requirements
|
|
79
91
|
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
- HeroUI
|
|
92
|
+
- **React**: >=18.2 <20
|
|
93
|
+
- **React DOM**: >=18.2 <20
|
|
94
|
+
- **React Hook Form**: >=7 <8
|
|
95
|
+
- **HeroUI**: >=2 <3 (either individual packages or `@heroui/react`)
|
|
84
96
|
|
|
85
|
-
## Installation
|
|
97
|
+
## Installation Options
|
|
86
98
|
|
|
87
|
-
### Option A:
|
|
99
|
+
### Option A: Individual HeroUI Packages (Recommended for Production)
|
|
88
100
|
|
|
89
|
-
Install
|
|
101
|
+
Install only the HeroUI components you actually use for optimal bundle size:
|
|
90
102
|
|
|
91
103
|
```bash
|
|
92
|
-
#
|
|
104
|
+
# Minimal set that covers all included fields
|
|
93
105
|
npm i @rachelallyson/hero-hook-form react-hook-form \
|
|
94
106
|
@heroui/input @heroui/checkbox @heroui/radio @heroui/select \
|
|
95
107
|
@heroui/switch @heroui/button @heroui/spinner
|
|
96
108
|
```
|
|
97
109
|
|
|
98
|
-
|
|
110
|
+
Import from the package root:
|
|
99
111
|
|
|
100
112
|
```tsx
|
|
101
113
|
import { InputField, SelectField, CheckboxField, RadioGroupField, SwitchField, TextareaField, SubmitButton } from "@rachelallyson/hero-hook-form";
|
|
102
114
|
```
|
|
103
115
|
|
|
104
|
-
### Option B:
|
|
116
|
+
### Option B: Aggregate HeroUI Package (Recommended for Development)
|
|
105
117
|
|
|
106
|
-
Install the
|
|
118
|
+
Install the all-in-one HeroUI package for convenience:
|
|
107
119
|
|
|
108
120
|
```bash
|
|
109
121
|
npm i @rachelallyson/hero-hook-form react-hook-form @heroui/react
|
|
110
122
|
```
|
|
111
123
|
|
|
112
|
-
|
|
124
|
+
Import from the `/react` subpath:
|
|
113
125
|
|
|
114
126
|
```tsx
|
|
115
127
|
import { InputField, SelectField, CheckboxField, RadioGroupField, SwitchField, TextareaField, SubmitButton } from "@rachelallyson/hero-hook-form/react";
|
|
@@ -229,185 +241,126 @@ const config = createZodFormConfig(contactSchema, [
|
|
|
229
241
|
/>
|
|
230
242
|
```
|
|
231
243
|
|
|
232
|
-
###
|
|
233
|
-
|
|
234
|
-
- **Type Safety**: Full TypeScript support with automatic type inference
|
|
235
|
-
- **Runtime Validation**: Comprehensive validation with custom error messages
|
|
236
|
-
- **Schema Reusability**: Define schemas once and reuse across your app
|
|
237
|
-
- **Complex Validation**: Support for enums, numbers, custom refinements, and more
|
|
238
|
-
- **Optional Integration**: Only install Zod if you need it
|
|
239
|
-
|
|
240
|
-
### Zod vs Standard Validation
|
|
241
|
-
|
|
242
|
-
| Feature | Standard Form | Zod Form |
|
|
243
|
-
|---------|---------------|----------|
|
|
244
|
-
| Validation Rules | In field config | In schema |
|
|
245
|
-
| Type Safety | Manual types | Automatic inference |
|
|
246
|
-
| Error Messages | Inline | In schema |
|
|
247
|
-
| Reusability | Per field | Schema-wide |
|
|
248
|
-
| Runtime Safety | Basic | Comprehensive |
|
|
249
|
-
|
|
250
|
-
## Quick start
|
|
244
|
+
### Nested Fields and Radio Buttons
|
|
251
245
|
|
|
252
|
-
|
|
246
|
+
For nested field names and radio buttons:
|
|
253
247
|
|
|
254
248
|
```tsx
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export function ExampleForm() {
|
|
269
|
-
const methods = useForm<Values>({
|
|
270
|
-
defaultValues: {
|
|
271
|
-
name: "",
|
|
272
|
-
email: "",
|
|
273
|
-
bio: "",
|
|
274
|
-
plan: "free",
|
|
275
|
-
agree: false,
|
|
276
|
-
enabled: false,
|
|
277
|
-
},
|
|
278
|
-
mode: "onBlur",
|
|
279
|
-
});
|
|
249
|
+
const settingsSchema = z.object({
|
|
250
|
+
fonts: z.object({
|
|
251
|
+
scale: z.enum(["small", "medium", "large"]).default("medium"),
|
|
252
|
+
}),
|
|
253
|
+
layout: z.object({
|
|
254
|
+
sidebarPosition: z.enum(["left", "right", "hidden"]).default("left"),
|
|
255
|
+
}),
|
|
256
|
+
style: z.object({
|
|
257
|
+
theme: z.enum(["light", "dark", "auto"]).default("auto"),
|
|
258
|
+
}),
|
|
259
|
+
});
|
|
280
260
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
<SwitchField control={methods.control} label="Enable feature" name="enabled" />
|
|
320
|
-
|
|
321
|
-
<div className="flex justify-end">
|
|
322
|
-
<SubmitButton buttonProps={{ color: "primary" }}>Submit</SubmitButton>
|
|
323
|
-
</div>
|
|
324
|
-
</Form>
|
|
325
|
-
);
|
|
326
|
-
}
|
|
261
|
+
const config = createZodFormConfig(settingsSchema, [
|
|
262
|
+
{
|
|
263
|
+
name: "fonts.scale",
|
|
264
|
+
type: "radio",
|
|
265
|
+
label: "Font Scale",
|
|
266
|
+
radioOptions: [
|
|
267
|
+
{ label: "Small", value: "small" },
|
|
268
|
+
{ label: "Medium", value: "medium" },
|
|
269
|
+
{ label: "Large", value: "large" },
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "layout.sidebarPosition",
|
|
274
|
+
type: "radio",
|
|
275
|
+
label: "Sidebar Position",
|
|
276
|
+
radioOptions: [
|
|
277
|
+
{ label: "Left", value: "left" },
|
|
278
|
+
{ label: "Right", value: "right" },
|
|
279
|
+
{ label: "Hidden", value: "hidden" },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "style.theme",
|
|
284
|
+
type: "radio",
|
|
285
|
+
label: "Theme",
|
|
286
|
+
radioOptions: [
|
|
287
|
+
{ label: "Light", value: "light" },
|
|
288
|
+
{ label: "Dark", value: "dark" },
|
|
289
|
+
{ label: "Auto", value: "auto" },
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
], {
|
|
293
|
+
defaultValues: {
|
|
294
|
+
fonts: { scale: "large" },
|
|
295
|
+
layout: { sidebarPosition: "right" },
|
|
296
|
+
style: { theme: "auto" },
|
|
297
|
+
},
|
|
298
|
+
});
|
|
327
299
|
```
|
|
328
300
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
### Field components
|
|
332
|
-
|
|
333
|
-
All field components are strongly typed over your form values and expose a `...Props` prop for passing through component props in a type-safe way. We derive prop types via `React.ComponentProps<typeof Component>` to avoid tight coupling to HeroUI’s internal type names.
|
|
334
|
-
|
|
335
|
-
- `InputField<TFieldValues>`
|
|
336
|
-
- `inputProps?: Omit<ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">`
|
|
337
|
-
- `transform?: (value: string) => string` – modify the value before writing to the form state
|
|
338
|
-
- `TextareaField<TFieldValues>`
|
|
339
|
-
- `textareaProps?: Omit<ComponentProps<typeof Textarea>, ...>`
|
|
340
|
-
- `SelectField<TFieldValues, TValue extends string | number = string>`
|
|
341
|
-
- `options: readonly { label: string; value: TValue; description?: string; disabled?: boolean }[]`
|
|
342
|
-
- `selectProps?: Omit<ComponentProps<typeof Select>, "selectedKeys" | "onSelectionChange" | ...>`
|
|
343
|
-
- `RadioGroupField<TFieldValues, TValue extends string | number = string>`
|
|
344
|
-
- `options: readonly { label: string; value: TValue; description?: string; disabled?: boolean }[]`
|
|
345
|
-
- `radioGroupProps?: Omit<ComponentProps<typeof RadioGroup>, "value" | "onValueChange" | "label">`
|
|
346
|
-
- `CheckboxField<TFieldValues>`
|
|
347
|
-
- `checkboxProps?: Omit<ComponentProps<typeof Checkbox>, ...>`
|
|
348
|
-
- `SwitchField<TFieldValues>`
|
|
349
|
-
- `switchProps?: Omit<ComponentProps<typeof Switch>, ...>`
|
|
350
|
-
- `SubmitButton`
|
|
351
|
-
- `isLoading?: boolean` – if omitted, reflects RHF’s `formState.isSubmitting`
|
|
352
|
-
- `buttonProps?: Omit<ComponentProps<typeof Button>, "type" | "isLoading">`
|
|
353
|
-
|
|
354
|
-
### Form provider
|
|
301
|
+
### Zod Features
|
|
355
302
|
|
|
356
|
-
-
|
|
303
|
+
- **Type Safety**: Full TypeScript support with automatic type inference
|
|
304
|
+
- **Nested Fields**: Support for nested field names like "fonts.scale"
|
|
305
|
+
- **Default Values**: Proper handling of default values with nested structure
|
|
306
|
+
- **Radio Buttons**: Easy configuration with `radioOptions`
|
|
357
307
|
|
|
358
|
-
|
|
359
|
-
import { Form } from "@rachelallyson/hero-hook-form"; // or "/react"
|
|
308
|
+
## 🎯 Examples
|
|
360
309
|
|
|
361
|
-
|
|
362
|
-
{/* fields */}
|
|
363
|
-
</Form>
|
|
364
|
-
```
|
|
310
|
+
Check out our [comprehensive demo](../example/app/comprehensive-demo/page.tsx) to see Hero Hook Form in action with all field types and layouts!
|
|
365
311
|
|
|
366
|
-
|
|
312
|
+
## 📚 Documentation
|
|
367
313
|
|
|
368
|
-
|
|
314
|
+
For comprehensive guides and examples, visit our [documentation](./docs/README.md):
|
|
369
315
|
|
|
370
|
-
|
|
371
|
-
|
|
316
|
+
- [🚀 Getting Started](./docs/getting-started.md) - Installation, setup, and first form
|
|
317
|
+
- [🧩 Components](./docs/components.md) - All available field components
|
|
318
|
+
- [⚙️ Configuration](./docs/configuration.md) - Global configuration and providers
|
|
319
|
+
- [📝 Form Builder](./docs/form-builder.md) - ConfigurableForm component
|
|
320
|
+
- [✅ Validation](./docs/validation.md) - Form validation patterns
|
|
321
|
+
- [🔮 Zod Integration](./docs/zod-integration.md) - Schema-based validation with Zod
|
|
322
|
+
- [🎨 Layouts](./docs/layouts.md) - Form layout options
|
|
323
|
+
- [📖 API Reference](./docs/api-reference.md) - Complete API documentation
|
|
372
324
|
|
|
373
|
-
|
|
374
|
-
await api.save(values);
|
|
375
|
-
} catch (e) {
|
|
376
|
-
applyServerErrors(methods, e.errors);
|
|
377
|
-
}
|
|
378
|
-
```
|
|
325
|
+
## 🔧 API Overview
|
|
379
326
|
|
|
380
|
-
|
|
327
|
+
### Field Components
|
|
381
328
|
|
|
382
|
-
|
|
383
|
-
- Use `/react` if your app installs the aggregate `@heroui/react` and you prefer a single HeroUI dep.
|
|
329
|
+
All field components are strongly typed and expose component-specific props:
|
|
384
330
|
|
|
385
|
-
|
|
331
|
+
- **`InputField`** - Text inputs with validation
|
|
332
|
+
- **`TextareaField`** - Multi-line text inputs
|
|
333
|
+
- **`SelectField`** - Dropdown selections
|
|
334
|
+
- **`RadioGroupField`** - Radio button groups
|
|
335
|
+
- **`CheckboxField`** - Single checkboxes
|
|
336
|
+
- **`SwitchField`** - Toggle switches
|
|
337
|
+
- **`SliderField`** - Range slider inputs
|
|
338
|
+
- **`DateField`** - Date picker inputs
|
|
339
|
+
- **`FileField`** - File upload inputs
|
|
340
|
+
- **`FontPickerField`** - Optional font selection (requires `@rachelallyson/heroui-font-picker`)
|
|
386
341
|
|
|
387
|
-
|
|
342
|
+
### Form Components
|
|
388
343
|
|
|
389
|
-
-
|
|
390
|
-
-
|
|
391
|
-
-
|
|
344
|
+
- **`Form`** - Light wrapper around React Hook Form's FormProvider
|
|
345
|
+
- **`FormField`** - Generic field wrapper component
|
|
346
|
+
- **`ZodForm`** - Schema-based forms with Zod validation
|
|
347
|
+
- **`ConfigurableForm`** - Rapid form development with declarative config
|
|
392
348
|
|
|
393
|
-
|
|
349
|
+
### Utilities & Hooks
|
|
394
350
|
|
|
395
|
-
|
|
351
|
+
- **`applyServerErrors`** - Map API validation errors to form fields
|
|
352
|
+
- **`HeroHookFormProvider`** - Global configuration for consistent styling
|
|
353
|
+
- **`useHeroForm`** - Enhanced form hook with additional utilities
|
|
354
|
+
- **`useFormHelper`** - Form helper utilities
|
|
396
355
|
|
|
397
|
-
|
|
356
|
+
For complete API documentation, see [API Reference](./docs/api-reference.md).
|
|
398
357
|
|
|
399
|
-
|
|
400
|
-
- [🧩 Components](./docs/components.md) - All available field components
|
|
401
|
-
- [🏗️ Form Builder](./docs/form-builder.md) - ConfigurableForm component guide
|
|
402
|
-
- [⚙️ Configuration](./docs/configuration.md) - Global configuration and providers
|
|
403
|
-
- [✅ Validation](./docs/validation.md) - Form validation patterns
|
|
404
|
-
- [🔒 Zod Integration](./docs/zod-integration.md) - Schema-based validation with Zod
|
|
405
|
-
- [🎨 Layouts](./docs/layouts.md) - Form layout options
|
|
406
|
-
- [📖 API Reference](./docs/api-reference.md) - Complete API documentation
|
|
358
|
+
## 🎯 Entrypoint Selection
|
|
407
359
|
|
|
408
|
-
|
|
360
|
+
- **Default entrypoint**: For apps using individual HeroUI packages (better tree-shaking)
|
|
361
|
+
- **`/react` entrypoint**: For apps using `@heroui/react` (convenient single dependency)
|
|
409
362
|
|
|
410
|
-
|
|
363
|
+
Both entrypoints are fully tree-shakeable and support all features.
|
|
411
364
|
|
|
412
365
|
## ❓ FAQ
|
|
413
366
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import React$1, { ComponentProps } from 'react';
|
|
|
2
2
|
import { Button } from '@heroui/react';
|
|
3
3
|
import * as react_hook_form from 'react-hook-form';
|
|
4
4
|
import { FieldValues, Path, RegisterOptions, Control, UseFormReturn, FieldErrors, UseFormProps, SubmitHandler, UseFormSetError } from 'react-hook-form';
|
|
5
|
+
export { UseFormReturn, useFormContext } from 'react-hook-form';
|
|
5
6
|
import * as zod from 'zod';
|
|
6
7
|
import { z } from 'zod';
|
|
7
8
|
import * as _internationalized_date from '@internationalized/date';
|
|
@@ -87,6 +88,11 @@ interface FileFieldConfig<TFieldValues extends FieldValues> extends BaseFormFiel
|
|
|
87
88
|
multiple?: boolean;
|
|
88
89
|
accept?: string;
|
|
89
90
|
}
|
|
91
|
+
interface FontPickerFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
92
|
+
type: "fontPicker";
|
|
93
|
+
defaultValue?: string;
|
|
94
|
+
fontPickerProps?: Record<string, string | number | boolean>;
|
|
95
|
+
}
|
|
90
96
|
interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFieldConfig<TFieldValues> {
|
|
91
97
|
type: "custom";
|
|
92
98
|
render: (field: {
|
|
@@ -97,7 +103,7 @@ interface CustomFieldConfig<TFieldValues extends FieldValues> extends BaseFormFi
|
|
|
97
103
|
isSubmitting: boolean;
|
|
98
104
|
}) => React.ReactNode;
|
|
99
105
|
}
|
|
100
|
-
type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues>;
|
|
106
|
+
type FormFieldConfig<TFieldValues extends FieldValues> = StringFieldConfig<TFieldValues> | BooleanFieldConfig<TFieldValues> | RadioFieldConfig<TFieldValues> | SliderFieldConfig<TFieldValues> | DateFieldConfig<TFieldValues> | FileFieldConfig<TFieldValues> | FontPickerFieldConfig<TFieldValues> | CustomFieldConfig<TFieldValues>;
|
|
101
107
|
interface FormConfig<TFieldValues extends FieldValues> {
|
|
102
108
|
fields: FormFieldConfig<TFieldValues>[];
|
|
103
109
|
layout?: "vertical" | "horizontal" | "grid" | "custom";
|
|
@@ -111,9 +117,9 @@ interface FormConfig<TFieldValues extends FieldValues> {
|
|
|
111
117
|
className?: string;
|
|
112
118
|
defaultValues?: Partial<TFieldValues>;
|
|
113
119
|
}
|
|
114
|
-
type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules">;
|
|
120
|
+
type ZodFormFieldConfig<TFieldValues extends FieldValues> = Omit<StringFieldConfig<TFieldValues>, "rules"> | Omit<BooleanFieldConfig<TFieldValues>, "rules"> | Omit<RadioFieldConfig<TFieldValues>, "rules"> | Omit<SliderFieldConfig<TFieldValues>, "rules"> | Omit<DateFieldConfig<TFieldValues>, "rules"> | Omit<FileFieldConfig<TFieldValues>, "rules"> | Omit<FontPickerFieldConfig<TFieldValues>, "rules"> | Omit<CustomFieldConfig<TFieldValues>, "rules">;
|
|
115
121
|
interface ZodFormConfig<TFieldValues extends FieldValues> extends UseFormProps<TFieldValues> {
|
|
116
|
-
schema
|
|
122
|
+
schema: zod.ZodSchema<TFieldValues>;
|
|
117
123
|
fields: ZodFormFieldConfig<TFieldValues>[];
|
|
118
124
|
onError?: (errors: FieldErrors<TFieldValues>) => void;
|
|
119
125
|
errorDisplay?: "inline" | "toast" | "modal" | "none";
|
|
@@ -235,6 +241,17 @@ type FileFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldVal
|
|
|
235
241
|
};
|
|
236
242
|
declare function FileField<TFieldValues extends FieldValues>(props: FileFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
237
243
|
|
|
244
|
+
interface FontPickerProps {
|
|
245
|
+
showFontPreview?: boolean;
|
|
246
|
+
loadAllVariants?: boolean;
|
|
247
|
+
onFontsLoaded?: (loaded: boolean) => void;
|
|
248
|
+
fontsLoadedTimeout?: number;
|
|
249
|
+
}
|
|
250
|
+
type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends string = string> = FieldBaseProps<TFieldValues, TValue> & WithControl<TFieldValues> & {
|
|
251
|
+
fontPickerProps?: FontPickerProps;
|
|
252
|
+
};
|
|
253
|
+
declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
254
|
+
|
|
238
255
|
type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
239
256
|
inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
240
257
|
transform?: (value: string) => string;
|
|
@@ -300,6 +317,54 @@ declare function useFormHelper<T extends FieldValues>({ defaultValues, methods,
|
|
|
300
317
|
submissionState: FormSubmissionState;
|
|
301
318
|
};
|
|
302
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Enhanced hook that provides both form methods and styling defaults
|
|
322
|
+
*
|
|
323
|
+
* This hook combines React Hook Form's useFormContext with Hero Hook Form's
|
|
324
|
+
* styling defaults, giving you access to both form functionality and
|
|
325
|
+
* component styling in one convenient hook.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```tsx
|
|
329
|
+
* import { useHeroForm } from "@rachelallyson/hero-hook-form";
|
|
330
|
+
*
|
|
331
|
+
* function MyComponent() {
|
|
332
|
+
* const { formState, getValues, setValue, defaults } = useHeroForm();
|
|
333
|
+
*
|
|
334
|
+
* // Access form state
|
|
335
|
+
* const isSubmitting = formState.isSubmitting;
|
|
336
|
+
* const errors = formState.errors;
|
|
337
|
+
*
|
|
338
|
+
* // Access form methods
|
|
339
|
+
* const values = getValues();
|
|
340
|
+
* const handleReset = () => setValue('fieldName', '');
|
|
341
|
+
*
|
|
342
|
+
* // Access styling defaults
|
|
343
|
+
* const inputDefaults = defaults.input;
|
|
344
|
+
* const buttonDefaults = defaults.submitButton;
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
declare function useHeroForm<TFieldValues extends FieldValues>(): {
|
|
349
|
+
defaults: Required<Pick<HeroHookFormDefaultsConfig, "input" | "textarea" | "select" | "switch" | "radioGroup" | "checkbox" | "slider" | "dateInput" | "submitButton">>;
|
|
350
|
+
watch: react_hook_form.UseFormWatch<TFieldValues>;
|
|
351
|
+
getValues: react_hook_form.UseFormGetValues<TFieldValues>;
|
|
352
|
+
getFieldState: react_hook_form.UseFormGetFieldState<TFieldValues>;
|
|
353
|
+
setError: react_hook_form.UseFormSetError<TFieldValues>;
|
|
354
|
+
clearErrors: react_hook_form.UseFormClearErrors<TFieldValues>;
|
|
355
|
+
setValue: react_hook_form.UseFormSetValue<TFieldValues>;
|
|
356
|
+
trigger: react_hook_form.UseFormTrigger<TFieldValues>;
|
|
357
|
+
formState: react_hook_form.FormState<TFieldValues>;
|
|
358
|
+
resetField: react_hook_form.UseFormResetField<TFieldValues>;
|
|
359
|
+
reset: react_hook_form.UseFormReset<TFieldValues>;
|
|
360
|
+
handleSubmit: react_hook_form.UseFormHandleSubmit<TFieldValues, TFieldValues>;
|
|
361
|
+
unregister: react_hook_form.UseFormUnregister<TFieldValues>;
|
|
362
|
+
control: react_hook_form.Control<TFieldValues, any, TFieldValues>;
|
|
363
|
+
register: react_hook_form.UseFormRegister<TFieldValues>;
|
|
364
|
+
setFocus: react_hook_form.UseFormSetFocus<TFieldValues>;
|
|
365
|
+
subscribe: react_hook_form.UseFormSubscribe<TFieldValues>;
|
|
366
|
+
};
|
|
367
|
+
|
|
303
368
|
type InputProps = React$1.ComponentProps<typeof Input>;
|
|
304
369
|
type TextareaProps = React$1.ComponentProps<typeof Textarea>;
|
|
305
370
|
type SelectProps = React$1.ComponentProps<typeof Select>;
|
|
@@ -532,5 +597,9 @@ declare function ZodForm<T extends FieldValues>({ className, columns, config, er
|
|
|
532
597
|
* Hook for using Zod validation with React Hook Form
|
|
533
598
|
*/
|
|
534
599
|
declare function useZodForm<TFieldValues extends FieldValues>(config: ZodFormConfig<TFieldValues>): react_hook_form.UseFormReturn<TFieldValues, any, TFieldValues>;
|
|
600
|
+
/**
|
|
601
|
+
* Helper function to create Zod form configurations
|
|
602
|
+
*/
|
|
603
|
+
declare function createZodFormConfig<TFieldValues extends FieldValues>(schema: z.ZodSchema<TFieldValues>, fields: ZodFormFieldConfig<TFieldValues>[], defaultValues?: Partial<TFieldValues>): ZodFormConfig<TFieldValues>;
|
|
535
604
|
|
|
536
|
-
export { type BaseFormFieldConfig, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, type ConditionalValidation, ConfigurableForm, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, type FormConfig, FormField, type FormFieldConfig, type FormProps, FormProvider, type FormStep, type FormSubmissionState, type FormTestUtils, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, commonValidations, createConditionalSchema, createConfirmPasswordSchema, createDateSchema, createEmailSchema, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNumberRangeSchema, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createUrlSchema, getFieldError, getFormErrors, hasFieldError, hasFormErrors, simulateFieldInput, simulateFormSubmission, useFormHelper, useHeroHookFormDefaults, useZodForm, waitForFormState };
|
|
605
|
+
export { type BaseFormFieldConfig, type BooleanFieldConfig, type ButtonDefaults, type CheckboxDefaults, CheckboxField, type CheckboxFieldProps, type CommonFieldDefaults, type ConditionalValidation, ConfigurableForm, type CustomFieldConfig, DateField, type DateFieldConfig, type DateFieldProps, type DateInputDefaults, type FieldBaseProps, type FieldGroup, FileField, type FileFieldConfig, type FileFieldProps, FontPickerField, type FontPickerFieldConfig, type FontPickerFieldProps, type FormConfig, FormField, type FormFieldConfig, type FormProps, FormProvider, type FormStep, type FormSubmissionState, type FormTestUtils, type FormValidationError, type HeroHookFormDefaultsConfig, HeroHookFormProvider, type HeroHookFormProviderProps, type InputDefaults, InputField, type InputFieldProps, type RadioFieldConfig, type RadioGroupDefaults, RadioGroupField, type RadioGroupFieldProps, type SelectDefaults, SelectField, type SelectFieldProps, type ServerFieldError, type ServerFormError, type SliderDefaults, SliderField, type SliderFieldConfig, type SliderFieldProps, type StringFieldConfig, SubmitButton, type SubmitButtonProps, type SwitchDefaults, SwitchField, type SwitchFieldProps, type TextareaDefaults, TextareaField, type TextareaFieldProps, type ValidationUtils, type WithControl, type WizardFormConfig, ZodForm, type ZodFormConfig, type ZodFormFieldConfig, applyServerErrors, commonValidations, createConditionalSchema, createConfirmPasswordSchema, createDateSchema, createEmailSchema, createFileSchema, createFormTestUtils, createFutureDateSchema, createMaxLengthSchema, createMinLengthSchema, createMockFormData, createMockFormErrors, createNumberRangeSchema, createPasswordSchema, createPastDateSchema, createPhoneSchema, createRequiredCheckboxSchema, createRequiredSchema, createUrlSchema, createZodFormConfig, getFieldError, getFormErrors, hasFieldError, hasFormErrors, simulateFieldInput, simulateFormSubmission, useFormHelper, useHeroForm, useHeroHookFormDefaults, useZodForm, waitForFormState };
|