@ttoss/forms 0.41.1 → 0.41.2
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 +31 -6
- package/dist/esm/MultistepForm/index.js +1 -1
- package/dist/esm/{chunk-6UQV3E5X.js → chunk-HN7QPZLJ.js} +15 -39
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +52 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -619,25 +619,50 @@ Brazilian phone number input with formatting.
|
|
|
619
619
|
|
|
620
620
|
## FormGroup
|
|
621
621
|
|
|
622
|
-
Groups related fields with optional
|
|
622
|
+
Groups related fields with an optional title, description, and layout direction.
|
|
623
623
|
|
|
624
624
|
```tsx
|
|
625
|
-
<FormGroup
|
|
625
|
+
<FormGroup title="Personal Information" direction="row">
|
|
626
626
|
<FormFieldInput name="firstName" label="First Name" />
|
|
627
627
|
<FormFieldInput name="lastName" label="Last Name" />
|
|
628
628
|
</FormGroup>
|
|
629
629
|
|
|
630
|
-
<FormGroup
|
|
630
|
+
<FormGroup title="Address" description="Where we'll send your order">
|
|
631
631
|
<FormFieldInput name="street" label="Street" />
|
|
632
632
|
<FormFieldInput name="city" label="City" />
|
|
633
633
|
</FormGroup>
|
|
634
634
|
```
|
|
635
635
|
|
|
636
|
+
Nest `FormGroup` components to create hierarchical sections:
|
|
637
|
+
|
|
638
|
+
```tsx
|
|
639
|
+
<FormGroup title="Personal details">
|
|
640
|
+
<FormFieldInput name="firstName" label="First name" />
|
|
641
|
+
<FormFieldInput name="lastName" label="Last name" />
|
|
642
|
+
|
|
643
|
+
<FormGroup title="Address" direction="row">
|
|
644
|
+
<FormFieldInput name="city" label="City" />
|
|
645
|
+
<FormFieldInput name="zip" label="ZIP" />
|
|
646
|
+
</FormGroup>
|
|
647
|
+
</FormGroup>
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
To display a group-level validation error (e.g. for an array field), pass the `name` prop:
|
|
651
|
+
|
|
652
|
+
```tsx
|
|
653
|
+
<FormGroup name="items" title="Items">
|
|
654
|
+
{fields.map((field, i) => (
|
|
655
|
+
<FormFieldInput key={field.id} name={`items[${i}].value`} label="Value" />
|
|
656
|
+
))}
|
|
657
|
+
</FormGroup>
|
|
658
|
+
```
|
|
659
|
+
|
|
636
660
|
**Props:**
|
|
637
661
|
|
|
638
|
-
- `
|
|
639
|
-
- `
|
|
640
|
-
- `
|
|
662
|
+
- `title`: Optional heading displayed above the group's children
|
|
663
|
+
- `description`: Optional description displayed below the title
|
|
664
|
+
- `direction`: Layout direction (`'row'` | `'column'`, default: `'column'`)
|
|
665
|
+
- `name`: Field name used to display a group-level validation error message
|
|
641
666
|
|
|
642
667
|
## Multistep Forms
|
|
643
668
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { Form, useForm, yupResolver } from "../chunk-
|
|
3
|
+
import { Form, useForm, yupResolver } from "../chunk-HN7QPZLJ.js";
|
|
4
4
|
import { __name } from "../chunk-BL55OAIO.js";
|
|
5
5
|
|
|
6
6
|
// src/MultistepForm/MultistepForm.tsx
|
|
@@ -848,43 +848,23 @@ var FormFieldTextarea = /* @__PURE__ */__name(({
|
|
|
848
848
|
// src/FormGroup.tsx
|
|
849
849
|
import { Box as Box4, Flex as Flex4, Text as Text3 } from "@ttoss/ui";
|
|
850
850
|
import * as React4 from "react";
|
|
851
|
-
var FormGroupLevelsManagerContext = /* @__PURE__ */React4.createContext({
|
|
852
|
-
levelsLength: 1,
|
|
853
|
-
registerChild: /* @__PURE__ */__name(() => {
|
|
854
|
-
return null;
|
|
855
|
-
}, "registerChild")
|
|
856
|
-
});
|
|
857
|
-
var FormGroupLevelsManager = /* @__PURE__ */__name(({
|
|
858
|
-
children
|
|
859
|
-
}) => {
|
|
860
|
-
const [levelsLength, setLevelsLength] = React4.useState(0);
|
|
861
|
-
const registerChild = React4.useCallback(level => {
|
|
862
|
-
if (level + 1 > levelsLength) {
|
|
863
|
-
setLevelsLength(level + 1);
|
|
864
|
-
}
|
|
865
|
-
}, [levelsLength]);
|
|
866
|
-
return /* @__PURE__ */React4.createElement(FormGroupLevelsManagerContext.Provider, {
|
|
867
|
-
value: {
|
|
868
|
-
levelsLength,
|
|
869
|
-
registerChild
|
|
870
|
-
}
|
|
871
|
-
}, children);
|
|
872
|
-
}, "FormGroupLevelsManager");
|
|
873
851
|
var FormGroupContext = /* @__PURE__ */React4.createContext({});
|
|
874
852
|
var useFormGroup = /* @__PURE__ */__name(() => {
|
|
875
853
|
const {
|
|
876
854
|
parentLevel
|
|
877
855
|
} = React4.useContext(FormGroupContext);
|
|
878
|
-
const {
|
|
879
|
-
levelsLength
|
|
880
|
-
} = React4.useContext(FormGroupLevelsManagerContext);
|
|
881
856
|
return {
|
|
882
857
|
level: parentLevel,
|
|
883
|
-
|
|
858
|
+
/**
|
|
859
|
+
* @deprecated `levelsLength` has been removed from `FormGroup` internals.
|
|
860
|
+
* This field always returns `undefined`. Use `level` to determine nesting depth.
|
|
861
|
+
*/
|
|
862
|
+
levelsLength: void 0
|
|
884
863
|
};
|
|
885
864
|
}, "useFormGroup");
|
|
886
865
|
var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
887
866
|
title,
|
|
867
|
+
description,
|
|
888
868
|
direction,
|
|
889
869
|
children,
|
|
890
870
|
name,
|
|
@@ -893,37 +873,33 @@ var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
|
893
873
|
const {
|
|
894
874
|
level
|
|
895
875
|
} = useFormGroup();
|
|
896
|
-
const {
|
|
897
|
-
registerChild
|
|
898
|
-
} = React4.useContext(FormGroupLevelsManagerContext);
|
|
899
|
-
React4.useEffect(() => {
|
|
900
|
-
if (typeof level === "number") {
|
|
901
|
-
registerChild(level);
|
|
902
|
-
}
|
|
903
|
-
}, [level, registerChild]);
|
|
904
876
|
const childrenContainerSx = {
|
|
905
877
|
flexDirection: direction || "column",
|
|
906
878
|
gap: "1",
|
|
907
879
|
width: "100%"
|
|
908
880
|
};
|
|
909
881
|
return /* @__PURE__ */React4.createElement(Box4, {
|
|
910
|
-
"
|
|
882
|
+
"data-level": level,
|
|
911
883
|
...boxProps,
|
|
912
884
|
sx: {
|
|
913
885
|
marginTop: level === 0 ? "none" : "4",
|
|
914
886
|
marginBottom: "4",
|
|
915
887
|
...boxProps.sx
|
|
916
888
|
}
|
|
917
|
-
}, title && /* @__PURE__ */React4.createElement(Box4, {
|
|
889
|
+
}, (title || description) && /* @__PURE__ */React4.createElement(Box4, {
|
|
918
890
|
sx: {
|
|
919
891
|
marginBottom: "2"
|
|
920
892
|
}
|
|
921
|
-
}, /* @__PURE__ */React4.createElement(Text3, {
|
|
893
|
+
}, title && /* @__PURE__ */React4.createElement(Text3, {
|
|
922
894
|
sx: {
|
|
923
895
|
fontSize: "2xl",
|
|
924
896
|
fontWeight: "bold"
|
|
925
897
|
}
|
|
926
|
-
}, title)
|
|
898
|
+
}, title), description && /* @__PURE__ */React4.createElement(Text3, {
|
|
899
|
+
sx: {
|
|
900
|
+
color: "text.secondary"
|
|
901
|
+
}
|
|
902
|
+
}, description)), /* @__PURE__ */React4.createElement(Flex4, {
|
|
927
903
|
sx: childrenContainerSx
|
|
928
904
|
}, children), name && /* @__PURE__ */React4.createElement(FormErrorMessage, {
|
|
929
905
|
name
|
|
@@ -938,7 +914,7 @@ var FormGroup = /* @__PURE__ */__name(props => {
|
|
|
938
914
|
value: {
|
|
939
915
|
parentLevel: currentLevel
|
|
940
916
|
}
|
|
941
|
-
},
|
|
917
|
+
}, /* @__PURE__ */React4.createElement(FormGroupWrapper, props));
|
|
942
918
|
}, "FormGroup");
|
|
943
919
|
|
|
944
920
|
// src/yup/i18n.ts
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver } from "./chunk-
|
|
2
|
+
import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver } from "./chunk-HN7QPZLJ.js";
|
|
3
3
|
import { FormErrorMessage, FormField, FormFieldPatternFormat } from "./chunk-BL55OAIO.js";
|
|
4
4
|
export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver };
|
package/dist/index.d.ts
CHANGED
|
@@ -114,13 +114,64 @@ declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues
|
|
|
114
114
|
|
|
115
115
|
declare const useFormGroup: () => {
|
|
116
116
|
level: number | undefined;
|
|
117
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @deprecated `levelsLength` has been removed from `FormGroup` internals.
|
|
119
|
+
* This field always returns `undefined`. Use `level` to determine nesting depth.
|
|
120
|
+
*/
|
|
121
|
+
levelsLength: number | undefined;
|
|
118
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Props for the FormGroup component.
|
|
125
|
+
*/
|
|
119
126
|
type FormGroupProps = {
|
|
127
|
+
/**
|
|
128
|
+
* The field name used to display a validation error message below the group.
|
|
129
|
+
* Useful when the group maps to an array or object field in the form schema.
|
|
130
|
+
*/
|
|
120
131
|
name?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Optional heading displayed above the group's children.
|
|
134
|
+
*/
|
|
121
135
|
title?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Optional description displayed below the title.
|
|
138
|
+
*/
|
|
139
|
+
description?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Layout direction for the group's children.
|
|
142
|
+
* @default 'column'
|
|
143
|
+
*/
|
|
122
144
|
direction?: 'column' | 'row';
|
|
123
145
|
} & BoxProps;
|
|
146
|
+
/**
|
|
147
|
+
* FormGroup is a layout container that organises form fields into labelled,
|
|
148
|
+
* optionally nested sections. Each nested `FormGroup` increments an internal
|
|
149
|
+
* `level` counter exposed via `useFormGroup`, which drives a `data-level`
|
|
150
|
+
* attribute and top-margin spacing so deeper groups are visually indented.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* <FormGroup title="Personal details">
|
|
155
|
+
* <FormFieldInput name="firstName" label="First name" />
|
|
156
|
+
* <FormFieldInput name="lastName" label="Last name" />
|
|
157
|
+
*
|
|
158
|
+
* <FormGroup title="Address" direction="row">
|
|
159
|
+
* <FormFieldInput name="city" label="City" />
|
|
160
|
+
* <FormFieldInput name="zip" label="ZIP" />
|
|
161
|
+
* </FormGroup>
|
|
162
|
+
* </FormGroup>
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Show a group-level validation error (e.g. for an array field)
|
|
167
|
+
* ```tsx
|
|
168
|
+
* <FormGroup name="items" title="Items">
|
|
169
|
+
* {fields.map((field, i) => (
|
|
170
|
+
* <FormFieldInput key={field.id} name={`items[${i}].value`} label="Value" />
|
|
171
|
+
* ))}
|
|
172
|
+
* </FormGroup>
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
124
175
|
declare const FormGroup: (props: FormGroupProps) => react_jsx_runtime.JSX.Element;
|
|
125
176
|
|
|
126
177
|
export { type DateRangePreset, Form, FormErrorMessage, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldProps, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, type FormRadioOption, useFormGroup };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": ">=16.8.0",
|
|
43
|
-
"@ttoss/components": "^2.13.1",
|
|
44
43
|
"@ttoss/ui": "^6.7.0",
|
|
44
|
+
"@ttoss/components": "^2.13.1",
|
|
45
45
|
"@ttoss/react-i18n": "^2.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"react-error-boundary": "^6.1.0",
|
|
53
53
|
"tsup": "^8.5.1",
|
|
54
54
|
"yup": "^1.7.1",
|
|
55
|
-
"@ttoss/config": "^1.36.0",
|
|
56
|
-
"@ttoss/i18n-cli": "^0.7.39",
|
|
57
55
|
"@ttoss/components": "^2.13.1",
|
|
56
|
+
"@ttoss/i18n-cli": "^0.7.39",
|
|
58
57
|
"@ttoss/react-icons": "^0.6.0",
|
|
59
|
-
"@ttoss/
|
|
58
|
+
"@ttoss/config": "^1.36.0",
|
|
59
|
+
"@ttoss/ui": "^6.7.0",
|
|
60
60
|
"@ttoss/test-utils": "^4.1.0",
|
|
61
|
-
"@ttoss/
|
|
61
|
+
"@ttoss/react-i18n": "^2.1.0"
|
|
62
62
|
},
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public",
|