@ttoss/forms 0.41.0 → 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-PBTKK77I.js → chunk-HN7QPZLJ.js} +17 -40
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +53 -2
- package/package.json +7 -7
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
|
|
@@ -203,7 +203,6 @@ var FormFieldCurrencyInput = /* @__PURE__ */__name(({
|
|
|
203
203
|
// src/FormFieldDatePicker.tsx
|
|
204
204
|
import { DatePicker } from "@ttoss/components/DatePicker";
|
|
205
205
|
var FormFieldDatePicker = /* @__PURE__ */__name(({
|
|
206
|
-
disabled,
|
|
207
206
|
...props
|
|
208
207
|
}) => {
|
|
209
208
|
const {
|
|
@@ -217,6 +216,7 @@ var FormFieldDatePicker = /* @__PURE__ */__name(({
|
|
|
217
216
|
id,
|
|
218
217
|
defaultValue,
|
|
219
218
|
presets,
|
|
219
|
+
disabled,
|
|
220
220
|
...datePickerProps
|
|
221
221
|
} = props;
|
|
222
222
|
return /* @__PURE__ */React.createElement(FormField, {
|
|
@@ -235,6 +235,7 @@ var FormFieldDatePicker = /* @__PURE__ */__name(({
|
|
|
235
235
|
}) => {
|
|
236
236
|
return /* @__PURE__ */React.createElement(DatePicker, {
|
|
237
237
|
...datePickerProps,
|
|
238
|
+
disabled,
|
|
238
239
|
value: field.value,
|
|
239
240
|
onChange: /* @__PURE__ */__name(range => {
|
|
240
241
|
field.onChange(range);
|
|
@@ -847,43 +848,23 @@ var FormFieldTextarea = /* @__PURE__ */__name(({
|
|
|
847
848
|
// src/FormGroup.tsx
|
|
848
849
|
import { Box as Box4, Flex as Flex4, Text as Text3 } from "@ttoss/ui";
|
|
849
850
|
import * as React4 from "react";
|
|
850
|
-
var FormGroupLevelsManagerContext = /* @__PURE__ */React4.createContext({
|
|
851
|
-
levelsLength: 1,
|
|
852
|
-
registerChild: /* @__PURE__ */__name(() => {
|
|
853
|
-
return null;
|
|
854
|
-
}, "registerChild")
|
|
855
|
-
});
|
|
856
|
-
var FormGroupLevelsManager = /* @__PURE__ */__name(({
|
|
857
|
-
children
|
|
858
|
-
}) => {
|
|
859
|
-
const [levelsLength, setLevelsLength] = React4.useState(0);
|
|
860
|
-
const registerChild = React4.useCallback(level => {
|
|
861
|
-
if (level + 1 > levelsLength) {
|
|
862
|
-
setLevelsLength(level + 1);
|
|
863
|
-
}
|
|
864
|
-
}, [levelsLength]);
|
|
865
|
-
return /* @__PURE__ */React4.createElement(FormGroupLevelsManagerContext.Provider, {
|
|
866
|
-
value: {
|
|
867
|
-
levelsLength,
|
|
868
|
-
registerChild
|
|
869
|
-
}
|
|
870
|
-
}, children);
|
|
871
|
-
}, "FormGroupLevelsManager");
|
|
872
851
|
var FormGroupContext = /* @__PURE__ */React4.createContext({});
|
|
873
852
|
var useFormGroup = /* @__PURE__ */__name(() => {
|
|
874
853
|
const {
|
|
875
854
|
parentLevel
|
|
876
855
|
} = React4.useContext(FormGroupContext);
|
|
877
|
-
const {
|
|
878
|
-
levelsLength
|
|
879
|
-
} = React4.useContext(FormGroupLevelsManagerContext);
|
|
880
856
|
return {
|
|
881
857
|
level: parentLevel,
|
|
882
|
-
|
|
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
|
|
883
863
|
};
|
|
884
864
|
}, "useFormGroup");
|
|
885
865
|
var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
886
866
|
title,
|
|
867
|
+
description,
|
|
887
868
|
direction,
|
|
888
869
|
children,
|
|
889
870
|
name,
|
|
@@ -892,37 +873,33 @@ var FormGroupWrapper = /* @__PURE__ */__name(({
|
|
|
892
873
|
const {
|
|
893
874
|
level
|
|
894
875
|
} = useFormGroup();
|
|
895
|
-
const {
|
|
896
|
-
registerChild
|
|
897
|
-
} = React4.useContext(FormGroupLevelsManagerContext);
|
|
898
|
-
React4.useEffect(() => {
|
|
899
|
-
if (typeof level === "number") {
|
|
900
|
-
registerChild(level);
|
|
901
|
-
}
|
|
902
|
-
}, [level, registerChild]);
|
|
903
876
|
const childrenContainerSx = {
|
|
904
877
|
flexDirection: direction || "column",
|
|
905
878
|
gap: "1",
|
|
906
879
|
width: "100%"
|
|
907
880
|
};
|
|
908
881
|
return /* @__PURE__ */React4.createElement(Box4, {
|
|
909
|
-
"
|
|
882
|
+
"data-level": level,
|
|
910
883
|
...boxProps,
|
|
911
884
|
sx: {
|
|
912
885
|
marginTop: level === 0 ? "none" : "4",
|
|
913
886
|
marginBottom: "4",
|
|
914
887
|
...boxProps.sx
|
|
915
888
|
}
|
|
916
|
-
}, title && /* @__PURE__ */React4.createElement(Box4, {
|
|
889
|
+
}, (title || description) && /* @__PURE__ */React4.createElement(Box4, {
|
|
917
890
|
sx: {
|
|
918
891
|
marginBottom: "2"
|
|
919
892
|
}
|
|
920
|
-
}, /* @__PURE__ */React4.createElement(Text3, {
|
|
893
|
+
}, title && /* @__PURE__ */React4.createElement(Text3, {
|
|
921
894
|
sx: {
|
|
922
895
|
fontSize: "2xl",
|
|
923
896
|
fontWeight: "bold"
|
|
924
897
|
}
|
|
925
|
-
}, title)
|
|
898
|
+
}, title), description && /* @__PURE__ */React4.createElement(Text3, {
|
|
899
|
+
sx: {
|
|
900
|
+
color: "text.secondary"
|
|
901
|
+
}
|
|
902
|
+
}, description)), /* @__PURE__ */React4.createElement(Flex4, {
|
|
926
903
|
sx: childrenContainerSx
|
|
927
904
|
}, children), name && /* @__PURE__ */React4.createElement(FormErrorMessage, {
|
|
928
905
|
name
|
|
@@ -937,7 +914,7 @@ var FormGroup = /* @__PURE__ */__name(props => {
|
|
|
937
914
|
value: {
|
|
938
915
|
parentLevel: currentLevel
|
|
939
916
|
}
|
|
940
|
-
},
|
|
917
|
+
}, /* @__PURE__ */React4.createElement(FormGroupWrapper, props));
|
|
941
918
|
}, "FormGroup");
|
|
942
919
|
|
|
943
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
|
@@ -50,7 +50,7 @@ interface DateRangePreset {
|
|
|
50
50
|
type FormFieldDatePickerProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & {
|
|
51
51
|
presets?: DateRangePreset[];
|
|
52
52
|
};
|
|
53
|
-
declare const FormFieldDatePicker: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({
|
|
53
|
+
declare const FormFieldDatePicker: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: FormFieldDatePickerProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
54
54
|
|
|
55
55
|
type FormFieldInputProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<InputProps, 'name'>;
|
|
56
56
|
declare const FormFieldInput: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ defaultValue, disabled, ...props }: FormFieldInputProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
|
|
@@ -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/
|
|
44
|
-
"@ttoss/
|
|
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/components": "^2.13.
|
|
56
|
-
"@ttoss/react-icons": "^0.6.0",
|
|
55
|
+
"@ttoss/components": "^2.13.1",
|
|
57
56
|
"@ttoss/i18n-cli": "^0.7.39",
|
|
58
|
-
"@ttoss/react-
|
|
57
|
+
"@ttoss/react-icons": "^0.6.0",
|
|
59
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",
|