@ttoss/forms 0.14.32 → 0.15.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/dist/esm/index.js +14 -25
- package/dist/index.d.ts +5 -6
- package/dist/index.js +14 -25
- package/package.json +3 -3
- package/src/FormGroup.tsx +17 -25
package/dist/esm/index.js
CHANGED
|
@@ -311,6 +311,7 @@ import { Flex as Flex2 } from "@ttoss/ui";
|
|
|
311
311
|
import React3 from "react";
|
|
312
312
|
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
313
313
|
var FormGroupLevelsManagerContext = /*#__PURE__*/React3.createContext({
|
|
314
|
+
levelsLength: 1,
|
|
314
315
|
registerChild: () => {
|
|
315
316
|
return null;
|
|
316
317
|
}
|
|
@@ -345,9 +346,7 @@ var useFormGroup = () => {
|
|
|
345
346
|
levelsLength
|
|
346
347
|
};
|
|
347
348
|
};
|
|
348
|
-
var FormGroupWrapper =
|
|
349
|
-
children
|
|
350
|
-
}) => {
|
|
349
|
+
var FormGroupWrapper = props => {
|
|
351
350
|
const {
|
|
352
351
|
level,
|
|
353
352
|
levelsLength
|
|
@@ -360,31 +359,21 @@ var FormGroupWrapper = ({
|
|
|
360
359
|
registerChild(level);
|
|
361
360
|
}
|
|
362
361
|
}, [level, registerChild]);
|
|
363
|
-
const sx =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}) => {
|
|
371
|
-
if (!level || !levelsLength) {
|
|
372
|
-
return 0;
|
|
373
|
-
}
|
|
374
|
-
const value = levelsLength / level;
|
|
375
|
-
return `calc(${space["lg"]} / ${value})`;
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
}, [level, levelsLength]);
|
|
362
|
+
const sx = {
|
|
363
|
+
flexDirection: props.direction || "column",
|
|
364
|
+
width: "100%",
|
|
365
|
+
gap: 3 * (levelsLength - (level || 0)),
|
|
366
|
+
paddingX: level ? "md" : "none",
|
|
367
|
+
...props.sx
|
|
368
|
+
};
|
|
379
369
|
return /* @__PURE__ */jsx9(Flex2, {
|
|
380
370
|
"aria-level": level,
|
|
371
|
+
...props,
|
|
381
372
|
sx,
|
|
382
|
-
children
|
|
373
|
+
children: props.children
|
|
383
374
|
});
|
|
384
375
|
};
|
|
385
|
-
var FormGroup =
|
|
386
|
-
children
|
|
387
|
-
}) => {
|
|
376
|
+
var FormGroup = props => {
|
|
388
377
|
const {
|
|
389
378
|
level
|
|
390
379
|
} = useFormGroup();
|
|
@@ -395,10 +384,10 @@ var FormGroup = ({
|
|
|
395
384
|
},
|
|
396
385
|
children: currentLevel === 0 ? /* @__PURE__ */jsx9(FormGroupLevelsManager, {
|
|
397
386
|
children: /* @__PURE__ */jsx9(FormGroupWrapper, {
|
|
398
|
-
|
|
387
|
+
...props
|
|
399
388
|
})
|
|
400
389
|
}) : /* @__PURE__ */jsx9(FormGroupWrapper, {
|
|
401
|
-
|
|
390
|
+
...props
|
|
402
391
|
})
|
|
403
392
|
});
|
|
404
393
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,8 @@ export * from 'react-hook-form';
|
|
|
5
5
|
import * as yup from 'yup';
|
|
6
6
|
export { yup };
|
|
7
7
|
import * as React from 'react';
|
|
8
|
-
import React__default from 'react';
|
|
9
8
|
import * as _ttoss_ui from '@ttoss/ui';
|
|
10
|
-
import { BoxProps, CheckboxProps, LabelProps, RadioProps } from '@ttoss/ui';
|
|
9
|
+
import { BoxProps, CheckboxProps, LabelProps, RadioProps, FlexProps } from '@ttoss/ui';
|
|
11
10
|
import * as theme_ui from 'theme-ui';
|
|
12
11
|
|
|
13
12
|
declare const Form: <TFieldValues extends FieldValues = FieldValues>({ children, onSubmit, sx, ...formMethods }: {
|
|
@@ -68,11 +67,11 @@ declare const FormFieldTextarea: <TFieldValues extends FieldValues = FieldValues
|
|
|
68
67
|
|
|
69
68
|
declare const useFormGroup: () => {
|
|
70
69
|
level: number | undefined;
|
|
71
|
-
levelsLength: number
|
|
70
|
+
levelsLength: number;
|
|
72
71
|
};
|
|
73
72
|
type FormGroupProps = {
|
|
74
|
-
|
|
75
|
-
};
|
|
76
|
-
declare const FormGroup: (
|
|
73
|
+
direction?: 'column' | 'row';
|
|
74
|
+
} & FlexProps;
|
|
75
|
+
declare const FormGroup: (props: FormGroupProps) => JSX.Element;
|
|
77
76
|
|
|
78
77
|
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/dist/index.js
CHANGED
|
@@ -362,6 +362,7 @@ var import_ui9 = require("@ttoss/ui");
|
|
|
362
362
|
var import_react = __toESM(require("react"));
|
|
363
363
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
364
364
|
var FormGroupLevelsManagerContext = import_react.default.createContext({
|
|
365
|
+
levelsLength: 1,
|
|
365
366
|
registerChild: () => {
|
|
366
367
|
return null;
|
|
367
368
|
}
|
|
@@ -396,9 +397,7 @@ var useFormGroup = () => {
|
|
|
396
397
|
levelsLength
|
|
397
398
|
};
|
|
398
399
|
};
|
|
399
|
-
var FormGroupWrapper =
|
|
400
|
-
children
|
|
401
|
-
}) => {
|
|
400
|
+
var FormGroupWrapper = props => {
|
|
402
401
|
const {
|
|
403
402
|
level,
|
|
404
403
|
levelsLength
|
|
@@ -411,31 +410,21 @@ var FormGroupWrapper = ({
|
|
|
411
410
|
registerChild(level);
|
|
412
411
|
}
|
|
413
412
|
}, [level, registerChild]);
|
|
414
|
-
const sx =
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}) => {
|
|
422
|
-
if (!level || !levelsLength) {
|
|
423
|
-
return 0;
|
|
424
|
-
}
|
|
425
|
-
const value = levelsLength / level;
|
|
426
|
-
return `calc(${space["lg"]} / ${value})`;
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
}, [level, levelsLength]);
|
|
413
|
+
const sx = {
|
|
414
|
+
flexDirection: props.direction || "column",
|
|
415
|
+
width: "100%",
|
|
416
|
+
gap: 3 * (levelsLength - (level || 0)),
|
|
417
|
+
paddingX: level ? "md" : "none",
|
|
418
|
+
...props.sx
|
|
419
|
+
};
|
|
430
420
|
return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Flex, {
|
|
431
421
|
"aria-level": level,
|
|
422
|
+
...props,
|
|
432
423
|
sx,
|
|
433
|
-
children
|
|
424
|
+
children: props.children
|
|
434
425
|
});
|
|
435
426
|
};
|
|
436
|
-
var FormGroup =
|
|
437
|
-
children
|
|
438
|
-
}) => {
|
|
427
|
+
var FormGroup = props => {
|
|
439
428
|
const {
|
|
440
429
|
level
|
|
441
430
|
} = useFormGroup();
|
|
@@ -446,10 +435,10 @@ var FormGroup = ({
|
|
|
446
435
|
},
|
|
447
436
|
children: currentLevel === 0 ? /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormGroupLevelsManager, {
|
|
448
437
|
children: /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormGroupWrapper, {
|
|
449
|
-
|
|
438
|
+
...props
|
|
450
439
|
})
|
|
451
440
|
}) : /* @__PURE__ */(0, import_jsx_runtime9.jsx)(FormGroupWrapper, {
|
|
452
|
-
|
|
441
|
+
...props
|
|
453
442
|
})
|
|
454
443
|
});
|
|
455
444
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ttoss/config": "^1.29.3",
|
|
33
33
|
"@ttoss/test-utils": "^1.21.2",
|
|
34
|
-
"@ttoss/ui": "^1.
|
|
34
|
+
"@ttoss/ui": "^1.32.0",
|
|
35
35
|
"@types/jest": "^29.5.0",
|
|
36
36
|
"jest": "^29.5.0",
|
|
37
37
|
"react": "^18.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "d8d388f73b22a40e68b59c3276bb2d3b2f486225"
|
|
45
45
|
}
|
package/src/FormGroup.tsx
CHANGED
|
@@ -2,12 +2,13 @@ import { Flex, FlexProps } from '@ttoss/ui';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
|
|
4
4
|
type FormGroupLevelsManagerContextType = {
|
|
5
|
-
levelsLength
|
|
5
|
+
levelsLength: number;
|
|
6
6
|
registerChild: (level: number) => void;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const FormGroupLevelsManagerContext =
|
|
10
10
|
React.createContext<FormGroupLevelsManagerContextType>({
|
|
11
|
+
levelsLength: 1,
|
|
11
12
|
registerChild: () => {
|
|
12
13
|
return null;
|
|
13
14
|
},
|
|
@@ -55,10 +56,10 @@ export const useFormGroup = () => {
|
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
type FormGroupProps = {
|
|
58
|
-
|
|
59
|
-
};
|
|
59
|
+
direction?: 'column' | 'row';
|
|
60
|
+
} & FlexProps;
|
|
60
61
|
|
|
61
|
-
const FormGroupWrapper = (
|
|
62
|
+
const FormGroupWrapper = (props: FormGroupProps) => {
|
|
62
63
|
const { level, levelsLength } = useFormGroup();
|
|
63
64
|
|
|
64
65
|
const { registerChild } = React.useContext(FormGroupLevelsManagerContext);
|
|
@@ -73,31 +74,22 @@ const FormGroupWrapper = ({ children }: { children: React.ReactNode }) => {
|
|
|
73
74
|
}
|
|
74
75
|
}, [level, registerChild]);
|
|
75
76
|
|
|
76
|
-
const sx: FlexProps['sx'] =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const value = levelsLength / level;
|
|
87
|
-
|
|
88
|
-
return `calc(${space['lg']} / ${value})`;
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}, [level, levelsLength]);
|
|
77
|
+
const sx: FlexProps['sx'] = {
|
|
78
|
+
flexDirection: props.direction || 'column',
|
|
79
|
+
width: '100%',
|
|
80
|
+
gap: 3 * (levelsLength - (level || 0)),
|
|
81
|
+
paddingX: level ? 'md' : 'none',
|
|
82
|
+
...props.sx,
|
|
83
|
+
};
|
|
92
84
|
|
|
93
85
|
return (
|
|
94
|
-
<Flex aria-level={level} sx={sx}>
|
|
95
|
-
{children}
|
|
86
|
+
<Flex aria-level={level} {...props} sx={sx}>
|
|
87
|
+
{props.children}
|
|
96
88
|
</Flex>
|
|
97
89
|
);
|
|
98
90
|
};
|
|
99
91
|
|
|
100
|
-
export const FormGroup = (
|
|
92
|
+
export const FormGroup = (props: FormGroupProps) => {
|
|
101
93
|
const { level } = useFormGroup();
|
|
102
94
|
|
|
103
95
|
const currentLevel = level === undefined ? 0 : level + 1;
|
|
@@ -106,10 +98,10 @@ export const FormGroup = ({ children }: FormGroupProps) => {
|
|
|
106
98
|
<FormGroupContext.Provider value={{ parentLevel: currentLevel }}>
|
|
107
99
|
{currentLevel === 0 ? (
|
|
108
100
|
<FormGroupLevelsManager>
|
|
109
|
-
<FormGroupWrapper
|
|
101
|
+
<FormGroupWrapper {...props} />
|
|
110
102
|
</FormGroupLevelsManager>
|
|
111
103
|
) : (
|
|
112
|
-
<FormGroupWrapper
|
|
104
|
+
<FormGroupWrapper {...props} />
|
|
113
105
|
)}
|
|
114
106
|
</FormGroupContext.Provider>
|
|
115
107
|
);
|