@rachelallyson/hero-hook-form 2.2.0 → 2.2.1
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 +8 -0
- package/dist/index.d.ts +249 -1
- package/dist/react/index.d.ts +249 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.2.1] - 2026-01-13
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Type Safety**: Improved type inference for `FormFieldHelpers.content()` to fix TypeScript "unsafe call" errors
|
|
10
|
+
- Changed return type from `ZodFormFieldConfig<T>` to `ContentFieldConfig<T>` for better type inference
|
|
11
|
+
- Fixes TypeScript compilation errors when using the content helper function
|
|
12
|
+
|
|
5
13
|
## [2.2.0] - 2026-01-13
|
|
6
14
|
|
|
7
15
|
### Added
|
package/dist/index.d.ts
CHANGED
|
@@ -466,10 +466,63 @@ type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends strin
|
|
|
466
466
|
};
|
|
467
467
|
declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
468
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Props for the InputField component.
|
|
471
|
+
*
|
|
472
|
+
* @template TFieldValues - The form data type
|
|
473
|
+
*/
|
|
469
474
|
type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
470
475
|
inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
471
476
|
transform?: (value: string) => string;
|
|
472
477
|
};
|
|
478
|
+
/**
|
|
479
|
+
* Input field component for text, email, password, tel, and number inputs.
|
|
480
|
+
*
|
|
481
|
+
* @description
|
|
482
|
+
* A memoized input field component that integrates with React Hook Form
|
|
483
|
+
* and HeroUI Input component. Supports all standard input types and
|
|
484
|
+
* includes automatic validation error display.
|
|
485
|
+
*
|
|
486
|
+
* @template TFieldValues - The form data type
|
|
487
|
+
*
|
|
488
|
+
* @param {InputFieldProps<TFieldValues>} props - Component props
|
|
489
|
+
* @param {Path<TFieldValues>} props.name - Field name path
|
|
490
|
+
* @param {string} [props.label] - Field label
|
|
491
|
+
* @param {string} [props.description] - Field description/help text
|
|
492
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
493
|
+
* @param {boolean} [props.isDisabled] - Whether field is disabled
|
|
494
|
+
* @param {RegisterOptions<TFieldValues>} [props.rules] - Validation rules
|
|
495
|
+
* @param {Partial<InputProps>} [props.inputProps] - Additional Input component props
|
|
496
|
+
* @param {(value: string) => string} [props.transform] - Value transformation function
|
|
497
|
+
*
|
|
498
|
+
* @returns {JSX.Element} The rendered input field
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```tsx
|
|
502
|
+
* import { InputField } from "@rachelallyson/hero-hook-form";
|
|
503
|
+
* import { useForm, Controller } from "react-hook-form";
|
|
504
|
+
*
|
|
505
|
+
* function MyForm() {
|
|
506
|
+
* const { control } = useForm();
|
|
507
|
+
*
|
|
508
|
+
* return (
|
|
509
|
+
* <InputField
|
|
510
|
+
* name="email"
|
|
511
|
+
* label="Email Address"
|
|
512
|
+
* description="Enter your email address"
|
|
513
|
+
* control={control}
|
|
514
|
+
* inputProps={{
|
|
515
|
+
* type: "email",
|
|
516
|
+
* placeholder: "you@example.com",
|
|
517
|
+
* }}
|
|
518
|
+
* />
|
|
519
|
+
* );
|
|
520
|
+
* }
|
|
521
|
+
* ```
|
|
522
|
+
*
|
|
523
|
+
* @see {@link FormFieldHelpers.input} for helper function to create input field config
|
|
524
|
+
* @category Fields
|
|
525
|
+
*/
|
|
473
526
|
declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
474
527
|
|
|
475
528
|
interface RadioOption<TValue extends string | number> {
|
|
@@ -1389,7 +1442,7 @@ declare const FormFieldHelpers: {
|
|
|
1389
1442
|
}) => React$1.ReactNode;
|
|
1390
1443
|
className?: string;
|
|
1391
1444
|
name?: Path<T>;
|
|
1392
|
-
}) =>
|
|
1445
|
+
}) => ContentFieldConfig<T>;
|
|
1393
1446
|
/**
|
|
1394
1447
|
* Create a date field
|
|
1395
1448
|
*/
|
|
@@ -2025,11 +2078,68 @@ declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
|
|
|
2025
2078
|
fields: ZodFormFieldConfig<T>[];
|
|
2026
2079
|
}, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
|
|
2027
2080
|
|
|
2081
|
+
/**
|
|
2082
|
+
* Props for the ConditionalField component.
|
|
2083
|
+
*
|
|
2084
|
+
* @template TFieldValues - The form data type
|
|
2085
|
+
*/
|
|
2028
2086
|
interface ConditionalFieldProps<TFieldValues extends FieldValues> {
|
|
2029
2087
|
config: ConditionalFieldConfig<TFieldValues>;
|
|
2030
2088
|
control: Control<TFieldValues>;
|
|
2031
2089
|
className?: string;
|
|
2032
2090
|
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Conditional field component that shows/hides fields based on form values.
|
|
2093
|
+
*
|
|
2094
|
+
* @description
|
|
2095
|
+
* Renders a field only when a condition function returns true based on
|
|
2096
|
+
* current form values. Useful for creating dynamic forms that adapt to
|
|
2097
|
+
* user input. The field is completely removed from the DOM when hidden.
|
|
2098
|
+
*
|
|
2099
|
+
* @template TFieldValues - The form data type
|
|
2100
|
+
*
|
|
2101
|
+
* @param {ConditionalFieldProps<TFieldValues>} props - Component props
|
|
2102
|
+
* @param {ConditionalFieldConfig<TFieldValues>} props.config - Conditional field configuration
|
|
2103
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
2104
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2105
|
+
*
|
|
2106
|
+
* @returns {JSX.Element|null} The rendered field or null if condition is not met
|
|
2107
|
+
*
|
|
2108
|
+
* @example
|
|
2109
|
+
* ```tsx
|
|
2110
|
+
* import { ConditionalField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2111
|
+
*
|
|
2112
|
+
* const fields = [
|
|
2113
|
+
* FormFieldHelpers.checkbox("hasPhone", "I have a phone number"),
|
|
2114
|
+
* ConditionalField({
|
|
2115
|
+
* config: {
|
|
2116
|
+
* name: "phone",
|
|
2117
|
+
* condition: (values) => values.hasPhone === true,
|
|
2118
|
+
* field: FormFieldHelpers.input("phone", "Phone Number", "tel"),
|
|
2119
|
+
* },
|
|
2120
|
+
* control: form.control,
|
|
2121
|
+
* }),
|
|
2122
|
+
* ];
|
|
2123
|
+
* ```
|
|
2124
|
+
*
|
|
2125
|
+
* @example
|
|
2126
|
+
* Multiple conditions:
|
|
2127
|
+
* ```tsx
|
|
2128
|
+
* ConditionalField({
|
|
2129
|
+
* config: {
|
|
2130
|
+
* name: "businessDetails",
|
|
2131
|
+
* condition: (values) =>
|
|
2132
|
+
* values.userType === "business" && values.isRegistered === true,
|
|
2133
|
+
* field: FormFieldHelpers.input("taxId", "Tax ID"),
|
|
2134
|
+
* },
|
|
2135
|
+
* control: form.control,
|
|
2136
|
+
* }),
|
|
2137
|
+
* ```
|
|
2138
|
+
*
|
|
2139
|
+
* @see {@link DynamicSectionField} for grouping multiple conditional fields
|
|
2140
|
+
* @see {@link FieldArrayField} for repeating fields
|
|
2141
|
+
* @category Fields
|
|
2142
|
+
*/
|
|
2033
2143
|
declare function ConditionalField<TFieldValues extends FieldValues>({ className, config, control, }: ConditionalFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2034
2144
|
|
|
2035
2145
|
interface ContentFieldProps<TFieldValues extends FieldValues> {
|
|
@@ -2039,17 +2149,155 @@ interface ContentFieldProps<TFieldValues extends FieldValues> {
|
|
|
2039
2149
|
}
|
|
2040
2150
|
declare function ContentField<TFieldValues extends FieldValues>({ config, form, submissionState, }: ContentFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
2041
2151
|
|
|
2152
|
+
/**
|
|
2153
|
+
* Props for the FieldArrayField component.
|
|
2154
|
+
*
|
|
2155
|
+
* @template TFieldValues - The form data type
|
|
2156
|
+
*/
|
|
2042
2157
|
interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
|
|
2043
2158
|
config: FieldArrayConfig<TFieldValues>;
|
|
2044
2159
|
className?: string;
|
|
2045
2160
|
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Field array component for dynamic repeating field groups.
|
|
2163
|
+
*
|
|
2164
|
+
* @description
|
|
2165
|
+
* Allows users to add and remove multiple instances of a field group.
|
|
2166
|
+
* Useful for forms with repeating data like addresses, items, or contacts.
|
|
2167
|
+
* Automatically manages field array state and provides add/remove buttons.
|
|
2168
|
+
*
|
|
2169
|
+
* @template TFieldValues - The form data type
|
|
2170
|
+
*
|
|
2171
|
+
* @param {FieldArrayFieldProps<TFieldValues>} props - Component props
|
|
2172
|
+
* @param {FieldArrayConfig<TFieldValues>} props.config - Field array configuration
|
|
2173
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2174
|
+
*
|
|
2175
|
+
* @returns {JSX.Element} The rendered field array with add/remove controls
|
|
2176
|
+
*
|
|
2177
|
+
* @example
|
|
2178
|
+
* ```tsx
|
|
2179
|
+
* import { FieldArrayField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2180
|
+
*
|
|
2181
|
+
* const fields = [
|
|
2182
|
+
* FormFieldHelpers.input("name", "Name"),
|
|
2183
|
+
* FieldArrayField({
|
|
2184
|
+
* config: {
|
|
2185
|
+
* name: "addresses",
|
|
2186
|
+
* label: "Address",
|
|
2187
|
+
* fields: [
|
|
2188
|
+
* FormFieldHelpers.input("street", "Street Address"),
|
|
2189
|
+
* FormFieldHelpers.input("city", "City"),
|
|
2190
|
+
* FormFieldHelpers.input("zipCode", "ZIP Code"),
|
|
2191
|
+
* ],
|
|
2192
|
+
* min: 1,
|
|
2193
|
+
* max: 5,
|
|
2194
|
+
* addButtonText: "Add Address",
|
|
2195
|
+
* removeButtonText: "Remove Address",
|
|
2196
|
+
* },
|
|
2197
|
+
* }),
|
|
2198
|
+
* ];
|
|
2199
|
+
* ```
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* With validation:
|
|
2203
|
+
* ```tsx
|
|
2204
|
+
* const schema = z.object({
|
|
2205
|
+
* addresses: z.array(z.object({
|
|
2206
|
+
* street: z.string().min(1, "Street is required"),
|
|
2207
|
+
* city: z.string().min(1, "City is required"),
|
|
2208
|
+
* })).min(1, "At least one address is required"),
|
|
2209
|
+
* });
|
|
2210
|
+
* ```
|
|
2211
|
+
*
|
|
2212
|
+
* @see {@link ConditionalField} for conditional single fields
|
|
2213
|
+
* @see {@link DynamicSectionField} for conditional field groups
|
|
2214
|
+
* @category Fields
|
|
2215
|
+
*/
|
|
2046
2216
|
declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2047
2217
|
|
|
2218
|
+
/**
|
|
2219
|
+
* Props for the DynamicSectionField component.
|
|
2220
|
+
*
|
|
2221
|
+
* @template TFieldValues - The form data type
|
|
2222
|
+
*/
|
|
2048
2223
|
interface DynamicSectionFieldProps<TFieldValues extends FieldValues> {
|
|
2049
2224
|
config: DynamicSectionConfig<TFieldValues>;
|
|
2050
2225
|
control: Control<TFieldValues>;
|
|
2051
2226
|
className?: string;
|
|
2052
2227
|
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Dynamic section component that shows/hides groups of fields based on form values.
|
|
2230
|
+
*
|
|
2231
|
+
* @description
|
|
2232
|
+
* Similar to ConditionalField but for groups of fields. Renders a section
|
|
2233
|
+
* with title, description, and multiple fields when a condition is met.
|
|
2234
|
+
* Useful for creating multi-step-like experiences or conditional form sections.
|
|
2235
|
+
*
|
|
2236
|
+
* @template TFieldValues - The form data type
|
|
2237
|
+
*
|
|
2238
|
+
* @param {DynamicSectionFieldProps<TFieldValues>} props - Component props
|
|
2239
|
+
* @param {DynamicSectionConfig<TFieldValues>} props.config - Dynamic section configuration
|
|
2240
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
2241
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2242
|
+
*
|
|
2243
|
+
* @returns {JSX.Element|null} The rendered section or null if condition is not met
|
|
2244
|
+
*
|
|
2245
|
+
* @example
|
|
2246
|
+
* ```tsx
|
|
2247
|
+
* import { DynamicSectionField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2248
|
+
*
|
|
2249
|
+
* const fields = [
|
|
2250
|
+
* FormFieldHelpers.checkbox("hasEmergencyContact", "Has Emergency Contact"),
|
|
2251
|
+
* DynamicSectionField({
|
|
2252
|
+
* config: {
|
|
2253
|
+
* name: "emergencyContact",
|
|
2254
|
+
* title: "Emergency Contact Information",
|
|
2255
|
+
* description: "Please provide emergency contact details",
|
|
2256
|
+
* condition: (values) => values.hasEmergencyContact === true,
|
|
2257
|
+
* fields: [
|
|
2258
|
+
* FormFieldHelpers.input("name", "Contact Name"),
|
|
2259
|
+
* FormFieldHelpers.input("relationship", "Relationship"),
|
|
2260
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel"),
|
|
2261
|
+
* FormFieldHelpers.input("email", "Email", "email"),
|
|
2262
|
+
* ],
|
|
2263
|
+
* },
|
|
2264
|
+
* control: form.control,
|
|
2265
|
+
* }),
|
|
2266
|
+
* ];
|
|
2267
|
+
* ```
|
|
2268
|
+
*
|
|
2269
|
+
* @example
|
|
2270
|
+
* Nested dynamic sections:
|
|
2271
|
+
* ```tsx
|
|
2272
|
+
* DynamicSectionField({
|
|
2273
|
+
* config: {
|
|
2274
|
+
* name: "businessInfo",
|
|
2275
|
+
* title: "Business Information",
|
|
2276
|
+
* condition: (values) => values.accountType === "business",
|
|
2277
|
+
* fields: [
|
|
2278
|
+
* FormFieldHelpers.input("businessName", "Business Name"),
|
|
2279
|
+
* DynamicSectionField({
|
|
2280
|
+
* config: {
|
|
2281
|
+
* name: "billingAddress",
|
|
2282
|
+
* title: "Billing Address",
|
|
2283
|
+
* condition: (values) => values.businessName && values.taxId,
|
|
2284
|
+
* fields: [
|
|
2285
|
+
* FormFieldHelpers.input("street", "Street Address"),
|
|
2286
|
+
* FormFieldHelpers.input("city", "City"),
|
|
2287
|
+
* ],
|
|
2288
|
+
* },
|
|
2289
|
+
* control: form.control,
|
|
2290
|
+
* }),
|
|
2291
|
+
* ],
|
|
2292
|
+
* },
|
|
2293
|
+
* control: form.control,
|
|
2294
|
+
* }),
|
|
2295
|
+
* ```
|
|
2296
|
+
*
|
|
2297
|
+
* @see {@link ConditionalField} for single conditional fields
|
|
2298
|
+
* @see {@link FieldArrayField} for repeating fields
|
|
2299
|
+
* @category Fields
|
|
2300
|
+
*/
|
|
2053
2301
|
declare function DynamicSectionField<TFieldValues extends FieldValues>({ className, config, control, }: DynamicSectionFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2054
2302
|
|
|
2055
2303
|
interface FormStatusProps<T extends Record<string, any>> {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -458,10 +458,63 @@ type FontPickerFieldProps<TFieldValues extends FieldValues, TValue extends strin
|
|
|
458
458
|
};
|
|
459
459
|
declare function FontPickerField<TFieldValues extends FieldValues, TValue extends string = string>(props: FontPickerFieldProps<TFieldValues, TValue>): React$1.JSX.Element;
|
|
460
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Props for the InputField component.
|
|
463
|
+
*
|
|
464
|
+
* @template TFieldValues - The form data type
|
|
465
|
+
*/
|
|
461
466
|
type InputFieldProps<TFieldValues extends FieldValues> = FieldBaseProps<TFieldValues, string> & WithControl<TFieldValues> & {
|
|
462
467
|
inputProps?: Omit<React$1.ComponentProps<typeof Input>, "value" | "onValueChange" | "label" | "isInvalid" | "errorMessage" | "isDisabled">;
|
|
463
468
|
transform?: (value: string) => string;
|
|
464
469
|
};
|
|
470
|
+
/**
|
|
471
|
+
* Input field component for text, email, password, tel, and number inputs.
|
|
472
|
+
*
|
|
473
|
+
* @description
|
|
474
|
+
* A memoized input field component that integrates with React Hook Form
|
|
475
|
+
* and HeroUI Input component. Supports all standard input types and
|
|
476
|
+
* includes automatic validation error display.
|
|
477
|
+
*
|
|
478
|
+
* @template TFieldValues - The form data type
|
|
479
|
+
*
|
|
480
|
+
* @param {InputFieldProps<TFieldValues>} props - Component props
|
|
481
|
+
* @param {Path<TFieldValues>} props.name - Field name path
|
|
482
|
+
* @param {string} [props.label] - Field label
|
|
483
|
+
* @param {string} [props.description] - Field description/help text
|
|
484
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
485
|
+
* @param {boolean} [props.isDisabled] - Whether field is disabled
|
|
486
|
+
* @param {RegisterOptions<TFieldValues>} [props.rules] - Validation rules
|
|
487
|
+
* @param {Partial<InputProps>} [props.inputProps] - Additional Input component props
|
|
488
|
+
* @param {(value: string) => string} [props.transform] - Value transformation function
|
|
489
|
+
*
|
|
490
|
+
* @returns {JSX.Element} The rendered input field
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```tsx
|
|
494
|
+
* import { InputField } from "@rachelallyson/hero-hook-form";
|
|
495
|
+
* import { useForm, Controller } from "react-hook-form";
|
|
496
|
+
*
|
|
497
|
+
* function MyForm() {
|
|
498
|
+
* const { control } = useForm();
|
|
499
|
+
*
|
|
500
|
+
* return (
|
|
501
|
+
* <InputField
|
|
502
|
+
* name="email"
|
|
503
|
+
* label="Email Address"
|
|
504
|
+
* description="Enter your email address"
|
|
505
|
+
* control={control}
|
|
506
|
+
* inputProps={{
|
|
507
|
+
* type: "email",
|
|
508
|
+
* placeholder: "you@example.com",
|
|
509
|
+
* }}
|
|
510
|
+
* />
|
|
511
|
+
* );
|
|
512
|
+
* }
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* @see {@link FormFieldHelpers.input} for helper function to create input field config
|
|
516
|
+
* @category Fields
|
|
517
|
+
*/
|
|
465
518
|
declare const InputField: <TFieldValues extends FieldValues>(props: InputFieldProps<TFieldValues>) => React$1.JSX.Element;
|
|
466
519
|
|
|
467
520
|
interface RadioOption<TValue extends string | number> {
|
|
@@ -1381,7 +1434,7 @@ declare const FormFieldHelpers: {
|
|
|
1381
1434
|
}) => React$1.ReactNode;
|
|
1382
1435
|
className?: string;
|
|
1383
1436
|
name?: Path<T>;
|
|
1384
|
-
}) =>
|
|
1437
|
+
}) => ContentFieldConfig<T>;
|
|
1385
1438
|
/**
|
|
1386
1439
|
* Create a date field
|
|
1387
1440
|
*/
|
|
@@ -2017,11 +2070,68 @@ declare function useTypeInferredForm<T extends FieldValues>(formConfig: {
|
|
|
2017
2070
|
fields: ZodFormFieldConfig<T>[];
|
|
2018
2071
|
}, options?: UseInferredFormOptions<T>): UseFormReturn<T>;
|
|
2019
2072
|
|
|
2073
|
+
/**
|
|
2074
|
+
* Props for the ConditionalField component.
|
|
2075
|
+
*
|
|
2076
|
+
* @template TFieldValues - The form data type
|
|
2077
|
+
*/
|
|
2020
2078
|
interface ConditionalFieldProps<TFieldValues extends FieldValues> {
|
|
2021
2079
|
config: ConditionalFieldConfig<TFieldValues>;
|
|
2022
2080
|
control: Control<TFieldValues>;
|
|
2023
2081
|
className?: string;
|
|
2024
2082
|
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Conditional field component that shows/hides fields based on form values.
|
|
2085
|
+
*
|
|
2086
|
+
* @description
|
|
2087
|
+
* Renders a field only when a condition function returns true based on
|
|
2088
|
+
* current form values. Useful for creating dynamic forms that adapt to
|
|
2089
|
+
* user input. The field is completely removed from the DOM when hidden.
|
|
2090
|
+
*
|
|
2091
|
+
* @template TFieldValues - The form data type
|
|
2092
|
+
*
|
|
2093
|
+
* @param {ConditionalFieldProps<TFieldValues>} props - Component props
|
|
2094
|
+
* @param {ConditionalFieldConfig<TFieldValues>} props.config - Conditional field configuration
|
|
2095
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
2096
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2097
|
+
*
|
|
2098
|
+
* @returns {JSX.Element|null} The rendered field or null if condition is not met
|
|
2099
|
+
*
|
|
2100
|
+
* @example
|
|
2101
|
+
* ```tsx
|
|
2102
|
+
* import { ConditionalField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2103
|
+
*
|
|
2104
|
+
* const fields = [
|
|
2105
|
+
* FormFieldHelpers.checkbox("hasPhone", "I have a phone number"),
|
|
2106
|
+
* ConditionalField({
|
|
2107
|
+
* config: {
|
|
2108
|
+
* name: "phone",
|
|
2109
|
+
* condition: (values) => values.hasPhone === true,
|
|
2110
|
+
* field: FormFieldHelpers.input("phone", "Phone Number", "tel"),
|
|
2111
|
+
* },
|
|
2112
|
+
* control: form.control,
|
|
2113
|
+
* }),
|
|
2114
|
+
* ];
|
|
2115
|
+
* ```
|
|
2116
|
+
*
|
|
2117
|
+
* @example
|
|
2118
|
+
* Multiple conditions:
|
|
2119
|
+
* ```tsx
|
|
2120
|
+
* ConditionalField({
|
|
2121
|
+
* config: {
|
|
2122
|
+
* name: "businessDetails",
|
|
2123
|
+
* condition: (values) =>
|
|
2124
|
+
* values.userType === "business" && values.isRegistered === true,
|
|
2125
|
+
* field: FormFieldHelpers.input("taxId", "Tax ID"),
|
|
2126
|
+
* },
|
|
2127
|
+
* control: form.control,
|
|
2128
|
+
* }),
|
|
2129
|
+
* ```
|
|
2130
|
+
*
|
|
2131
|
+
* @see {@link DynamicSectionField} for grouping multiple conditional fields
|
|
2132
|
+
* @see {@link FieldArrayField} for repeating fields
|
|
2133
|
+
* @category Fields
|
|
2134
|
+
*/
|
|
2025
2135
|
declare function ConditionalField<TFieldValues extends FieldValues>({ className, config, control, }: ConditionalFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2026
2136
|
|
|
2027
2137
|
interface ContentFieldProps<TFieldValues extends FieldValues> {
|
|
@@ -2031,17 +2141,155 @@ interface ContentFieldProps<TFieldValues extends FieldValues> {
|
|
|
2031
2141
|
}
|
|
2032
2142
|
declare function ContentField<TFieldValues extends FieldValues>({ config, form, submissionState, }: ContentFieldProps<TFieldValues>): React$1.JSX.Element;
|
|
2033
2143
|
|
|
2144
|
+
/**
|
|
2145
|
+
* Props for the FieldArrayField component.
|
|
2146
|
+
*
|
|
2147
|
+
* @template TFieldValues - The form data type
|
|
2148
|
+
*/
|
|
2034
2149
|
interface FieldArrayFieldProps<TFieldValues extends FieldValues> {
|
|
2035
2150
|
config: FieldArrayConfig<TFieldValues>;
|
|
2036
2151
|
className?: string;
|
|
2037
2152
|
}
|
|
2153
|
+
/**
|
|
2154
|
+
* Field array component for dynamic repeating field groups.
|
|
2155
|
+
*
|
|
2156
|
+
* @description
|
|
2157
|
+
* Allows users to add and remove multiple instances of a field group.
|
|
2158
|
+
* Useful for forms with repeating data like addresses, items, or contacts.
|
|
2159
|
+
* Automatically manages field array state and provides add/remove buttons.
|
|
2160
|
+
*
|
|
2161
|
+
* @template TFieldValues - The form data type
|
|
2162
|
+
*
|
|
2163
|
+
* @param {FieldArrayFieldProps<TFieldValues>} props - Component props
|
|
2164
|
+
* @param {FieldArrayConfig<TFieldValues>} props.config - Field array configuration
|
|
2165
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2166
|
+
*
|
|
2167
|
+
* @returns {JSX.Element} The rendered field array with add/remove controls
|
|
2168
|
+
*
|
|
2169
|
+
* @example
|
|
2170
|
+
* ```tsx
|
|
2171
|
+
* import { FieldArrayField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2172
|
+
*
|
|
2173
|
+
* const fields = [
|
|
2174
|
+
* FormFieldHelpers.input("name", "Name"),
|
|
2175
|
+
* FieldArrayField({
|
|
2176
|
+
* config: {
|
|
2177
|
+
* name: "addresses",
|
|
2178
|
+
* label: "Address",
|
|
2179
|
+
* fields: [
|
|
2180
|
+
* FormFieldHelpers.input("street", "Street Address"),
|
|
2181
|
+
* FormFieldHelpers.input("city", "City"),
|
|
2182
|
+
* FormFieldHelpers.input("zipCode", "ZIP Code"),
|
|
2183
|
+
* ],
|
|
2184
|
+
* min: 1,
|
|
2185
|
+
* max: 5,
|
|
2186
|
+
* addButtonText: "Add Address",
|
|
2187
|
+
* removeButtonText: "Remove Address",
|
|
2188
|
+
* },
|
|
2189
|
+
* }),
|
|
2190
|
+
* ];
|
|
2191
|
+
* ```
|
|
2192
|
+
*
|
|
2193
|
+
* @example
|
|
2194
|
+
* With validation:
|
|
2195
|
+
* ```tsx
|
|
2196
|
+
* const schema = z.object({
|
|
2197
|
+
* addresses: z.array(z.object({
|
|
2198
|
+
* street: z.string().min(1, "Street is required"),
|
|
2199
|
+
* city: z.string().min(1, "City is required"),
|
|
2200
|
+
* })).min(1, "At least one address is required"),
|
|
2201
|
+
* });
|
|
2202
|
+
* ```
|
|
2203
|
+
*
|
|
2204
|
+
* @see {@link ConditionalField} for conditional single fields
|
|
2205
|
+
* @see {@link DynamicSectionField} for conditional field groups
|
|
2206
|
+
* @category Fields
|
|
2207
|
+
*/
|
|
2038
2208
|
declare function FieldArrayField<TFieldValues extends FieldValues>({ className, config, }: FieldArrayFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2039
2209
|
|
|
2210
|
+
/**
|
|
2211
|
+
* Props for the DynamicSectionField component.
|
|
2212
|
+
*
|
|
2213
|
+
* @template TFieldValues - The form data type
|
|
2214
|
+
*/
|
|
2040
2215
|
interface DynamicSectionFieldProps<TFieldValues extends FieldValues> {
|
|
2041
2216
|
config: DynamicSectionConfig<TFieldValues>;
|
|
2042
2217
|
control: Control<TFieldValues>;
|
|
2043
2218
|
className?: string;
|
|
2044
2219
|
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Dynamic section component that shows/hides groups of fields based on form values.
|
|
2222
|
+
*
|
|
2223
|
+
* @description
|
|
2224
|
+
* Similar to ConditionalField but for groups of fields. Renders a section
|
|
2225
|
+
* with title, description, and multiple fields when a condition is met.
|
|
2226
|
+
* Useful for creating multi-step-like experiences or conditional form sections.
|
|
2227
|
+
*
|
|
2228
|
+
* @template TFieldValues - The form data type
|
|
2229
|
+
*
|
|
2230
|
+
* @param {DynamicSectionFieldProps<TFieldValues>} props - Component props
|
|
2231
|
+
* @param {DynamicSectionConfig<TFieldValues>} props.config - Dynamic section configuration
|
|
2232
|
+
* @param {Control<TFieldValues>} props.control - React Hook Form control
|
|
2233
|
+
* @param {string} [props.className] - Additional CSS class name
|
|
2234
|
+
*
|
|
2235
|
+
* @returns {JSX.Element|null} The rendered section or null if condition is not met
|
|
2236
|
+
*
|
|
2237
|
+
* @example
|
|
2238
|
+
* ```tsx
|
|
2239
|
+
* import { DynamicSectionField, FormFieldHelpers } from "@rachelallyson/hero-hook-form";
|
|
2240
|
+
*
|
|
2241
|
+
* const fields = [
|
|
2242
|
+
* FormFieldHelpers.checkbox("hasEmergencyContact", "Has Emergency Contact"),
|
|
2243
|
+
* DynamicSectionField({
|
|
2244
|
+
* config: {
|
|
2245
|
+
* name: "emergencyContact",
|
|
2246
|
+
* title: "Emergency Contact Information",
|
|
2247
|
+
* description: "Please provide emergency contact details",
|
|
2248
|
+
* condition: (values) => values.hasEmergencyContact === true,
|
|
2249
|
+
* fields: [
|
|
2250
|
+
* FormFieldHelpers.input("name", "Contact Name"),
|
|
2251
|
+
* FormFieldHelpers.input("relationship", "Relationship"),
|
|
2252
|
+
* FormFieldHelpers.input("phone", "Phone Number", "tel"),
|
|
2253
|
+
* FormFieldHelpers.input("email", "Email", "email"),
|
|
2254
|
+
* ],
|
|
2255
|
+
* },
|
|
2256
|
+
* control: form.control,
|
|
2257
|
+
* }),
|
|
2258
|
+
* ];
|
|
2259
|
+
* ```
|
|
2260
|
+
*
|
|
2261
|
+
* @example
|
|
2262
|
+
* Nested dynamic sections:
|
|
2263
|
+
* ```tsx
|
|
2264
|
+
* DynamicSectionField({
|
|
2265
|
+
* config: {
|
|
2266
|
+
* name: "businessInfo",
|
|
2267
|
+
* title: "Business Information",
|
|
2268
|
+
* condition: (values) => values.accountType === "business",
|
|
2269
|
+
* fields: [
|
|
2270
|
+
* FormFieldHelpers.input("businessName", "Business Name"),
|
|
2271
|
+
* DynamicSectionField({
|
|
2272
|
+
* config: {
|
|
2273
|
+
* name: "billingAddress",
|
|
2274
|
+
* title: "Billing Address",
|
|
2275
|
+
* condition: (values) => values.businessName && values.taxId,
|
|
2276
|
+
* fields: [
|
|
2277
|
+
* FormFieldHelpers.input("street", "Street Address"),
|
|
2278
|
+
* FormFieldHelpers.input("city", "City"),
|
|
2279
|
+
* ],
|
|
2280
|
+
* },
|
|
2281
|
+
* control: form.control,
|
|
2282
|
+
* }),
|
|
2283
|
+
* ],
|
|
2284
|
+
* },
|
|
2285
|
+
* control: form.control,
|
|
2286
|
+
* }),
|
|
2287
|
+
* ```
|
|
2288
|
+
*
|
|
2289
|
+
* @see {@link ConditionalField} for single conditional fields
|
|
2290
|
+
* @see {@link FieldArrayField} for repeating fields
|
|
2291
|
+
* @category Fields
|
|
2292
|
+
*/
|
|
2045
2293
|
declare function DynamicSectionField<TFieldValues extends FieldValues>({ className, config, control, }: DynamicSectionFieldProps<TFieldValues>): React$1.JSX.Element | null;
|
|
2046
2294
|
|
|
2047
2295
|
interface FormStatusProps<T extends Record<string, any>> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rachelallyson/hero-hook-form",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Typed form helpers that combine React Hook Form and HeroUI components.",
|
|
5
5
|
"author": "Rachel Higley",
|
|
6
6
|
"homepage": "https://rachelallyson.github.io/hero-hook-form/",
|