@connect-soft/form-generator 1.1.0-alpha6 → 1.1.0-alpha7

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/README.md CHANGED
@@ -120,10 +120,55 @@ registerFields({
120
120
 
121
121
  // Register the submit button component
122
122
  registerFormComponent('SubmitButton', Button);
123
+
124
+ // Optional: Register field wrappers for custom styling
125
+ registerFormComponent('FieldWrapper', ({ children, name, type, className }) => (
126
+ <div className={`field-wrapper field-${type}`} data-field={name}>
127
+ {children}
128
+ </div>
129
+ ));
130
+
131
+ registerFormComponent('FieldsWrapper', ({ children }) => (
132
+ <div className="form-fields">
133
+ {children}
134
+ </div>
135
+ ));
123
136
  ```
124
137
 
125
138
  ---
126
139
 
140
+ ## Field Wrappers
141
+
142
+ Customize how fields are wrapped without modifying individual field components:
143
+
144
+ ### FieldWrapper
145
+
146
+ Wraps each individual field. Receives the field's `name`, `type`, and `className`:
147
+
148
+ ```typescript
149
+ registerFormComponent('FieldWrapper', ({ children, name, type, className }) => (
150
+ <div className={`form-group ${className || ''}`} data-field-type={type}>
151
+ {children}
152
+ </div>
153
+ ));
154
+ ```
155
+
156
+ ### FieldsWrapper
157
+
158
+ Wraps all fields together (excludes the submit button). Useful for grid layouts:
159
+
160
+ ```typescript
161
+ registerFormComponent('FieldsWrapper', ({ children, className }) => (
162
+ <div className={`grid grid-cols-2 gap-4 ${className || ''}`}>
163
+ {children}
164
+ </div>
165
+ ));
166
+ ```
167
+
168
+ Both default to `React.Fragment`, adding zero DOM overhead when not customized.
169
+
170
+ ---
171
+
127
172
  ## Field Types
128
173
 
129
174
  Built-in HTML fallback types:
@@ -365,6 +410,8 @@ The render function receives:
365
410
  | `isValid` | `boolean` | Form validity state |
366
411
  | `isDirty` | `boolean` | Form dirty state |
367
412
  | `renderField` | `function` | Manual field renderer |
413
+ | `FieldWrapper` | `ComponentType` | Registered FieldWrapper component |
414
+ | `FieldsWrapper` | `ComponentType` | Registered FieldsWrapper component |
368
415
 
369
416
  ### Fields Object
370
417
 
package/dist/index.js CHANGED
@@ -2808,7 +2808,13 @@ const defaultFormComponents = {
2808
2808
  type: 'submit',
2809
2809
  className: className !== null && className !== void 0 ? className : 'form-submit',
2810
2810
  disabled: disabled || isSubmitting
2811
- }, isSubmitting ? 'Submitting...' : children)
2811
+ }, isSubmitting ? 'Submitting...' : children),
2812
+ FieldWrapper: ({
2813
+ children
2814
+ }) => /*#__PURE__*/React.createElement(React.Fragment, null, children),
2815
+ FieldsWrapper: ({
2816
+ children
2817
+ }) => /*#__PURE__*/React.createElement(React.Fragment, null, children)
2812
2818
  };
2813
2819
  const htmlInputTypes = {
2814
2820
  text: 'text',
@@ -3561,6 +3567,8 @@ function FormGeneratorImpl(props) {
3561
3567
  form: form
3562
3568
  }), [form, handleSubmit, mergedDefaultValues]);
3563
3569
  const SubmitButton = getFormComponent('SubmitButton');
3570
+ const FieldWrapper = getFormComponent('FieldWrapper');
3571
+ const FieldsWrapper = getFormComponent('FieldsWrapper');
3564
3572
  const {
3565
3573
  regularFields,
3566
3574
  arrayFields
@@ -3583,8 +3591,13 @@ function FormGeneratorImpl(props) {
3583
3591
  const entries = new Map();
3584
3592
  regularFields.forEach((field_0, index) => {
3585
3593
  if (!field_0.hidden) {
3586
- const element = jsxRuntime.jsx(FieldRenderer, {
3587
- field: field_0
3594
+ const element = jsxRuntime.jsx(FieldWrapper, {
3595
+ name: field_0.name,
3596
+ type: field_0.type,
3597
+ className: field_0.className,
3598
+ children: jsxRuntime.jsx(FieldRenderer, {
3599
+ field: field_0
3600
+ })
3588
3601
  }, field_0.name || `field-${index}`);
3589
3602
  entries.set(field_0.name, {
3590
3603
  field: field_0,
@@ -3594,7 +3607,7 @@ function FormGeneratorImpl(props) {
3594
3607
  }
3595
3608
  });
3596
3609
  return entries;
3597
- }, [regularFields]);
3610
+ }, [regularFields, FieldWrapper]);
3598
3611
  const templateFields = React.useMemo(() => createTemplateFields(fieldEntries), [fieldEntries]);
3599
3612
  const buttons = React.useMemo(() => {
3600
3613
  const result = {
@@ -3627,11 +3640,23 @@ function FormGeneratorImpl(props) {
3627
3640
  ref: formRef,
3628
3641
  onSubmit: handleSubmit,
3629
3642
  className: className,
3630
- children: [regularFields.map((field_2, index_0) => jsxRuntime.jsx(FieldRenderer, {
3631
- field: field_2
3632
- }, field_2.name || `field-${index_0}`)), arrayFields.map(arrayField => jsxRuntime.jsx(ArrayFieldRenderer, {
3633
- field: arrayField
3634
- }, arrayField.name)), jsxRuntime.jsx(SubmitButton, {
3643
+ children: [jsxRuntime.jsxs(FieldsWrapper, {
3644
+ children: [regularFields.map((field_2, index_0) => jsxRuntime.jsx(FieldWrapper, {
3645
+ name: field_2.name,
3646
+ type: field_2.type,
3647
+ className: field_2.className,
3648
+ children: jsxRuntime.jsx(FieldRenderer, {
3649
+ field: field_2
3650
+ })
3651
+ }, field_2.name || `field-${index_0}`)), arrayFields.map(arrayField => jsxRuntime.jsx(FieldWrapper, {
3652
+ name: arrayField.name,
3653
+ type: "array",
3654
+ className: arrayField.className,
3655
+ children: jsxRuntime.jsx(ArrayFieldRenderer, {
3656
+ field: arrayField
3657
+ })
3658
+ }, arrayField.name))]
3659
+ }), jsxRuntime.jsx(SubmitButton, {
3635
3660
  disabled: disabled || form.formState.isSubmitting,
3636
3661
  isSubmitting: form.formState.isSubmitting,
3637
3662
  children: submitText
@@ -3651,7 +3676,9 @@ function FormGeneratorImpl(props) {
3651
3676
  isSubmitting: form.formState.isSubmitting,
3652
3677
  isValid: form.formState.isValid,
3653
3678
  isDirty: form.formState.isDirty,
3654
- renderField
3679
+ renderField,
3680
+ FieldWrapper,
3681
+ FieldsWrapper
3655
3682
  };
3656
3683
  const renderFn = children;
3657
3684
  return jsxRuntime.jsx(FormProvider, {