@ttoss/forms 0.16.1 → 0.16.3
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 +36 -16
- package/dist/index.d.ts +2 -1
- package/dist/index.js +42 -22
- package/package.json +2 -2
- package/src/FormGroup.tsx +37 -13
package/dist/esm/index.js
CHANGED
|
@@ -363,9 +363,9 @@ var FormFieldTextarea = ({
|
|
|
363
363
|
};
|
|
364
364
|
|
|
365
365
|
// src/FormGroup.tsx
|
|
366
|
-
import
|
|
367
|
-
import
|
|
368
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
366
|
+
import * as React3 from "react";
|
|
367
|
+
import { Box as Box3, Flex as Flex6, Text } from "@ttoss/ui";
|
|
368
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
369
369
|
var FormGroupLevelsManagerContext = /*#__PURE__*/React3.createContext({
|
|
370
370
|
levelsLength: 1,
|
|
371
371
|
registerChild: () => {
|
|
@@ -402,10 +402,14 @@ var useFormGroup = () => {
|
|
|
402
402
|
levelsLength
|
|
403
403
|
};
|
|
404
404
|
};
|
|
405
|
-
var FormGroupWrapper =
|
|
405
|
+
var FormGroupWrapper = ({
|
|
406
|
+
title,
|
|
407
|
+
direction,
|
|
408
|
+
children,
|
|
409
|
+
...boxProps
|
|
410
|
+
}) => {
|
|
406
411
|
const {
|
|
407
|
-
level
|
|
408
|
-
levelsLength
|
|
412
|
+
level
|
|
409
413
|
} = useFormGroup();
|
|
410
414
|
const {
|
|
411
415
|
registerChild
|
|
@@ -415,18 +419,34 @@ var FormGroupWrapper = props => {
|
|
|
415
419
|
registerChild(level);
|
|
416
420
|
}
|
|
417
421
|
}, [level, registerChild]);
|
|
418
|
-
const
|
|
419
|
-
flexDirection:
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
paddingX: level ? "md" : "none",
|
|
423
|
-
...props.sx
|
|
422
|
+
const childrenContainerSx = {
|
|
423
|
+
flexDirection: direction || "column",
|
|
424
|
+
gap: "md",
|
|
425
|
+
width: "100%"
|
|
424
426
|
};
|
|
425
|
-
return /* @__PURE__ */
|
|
427
|
+
return /* @__PURE__ */jsxs6(Box3, {
|
|
426
428
|
"aria-level": level,
|
|
427
|
-
...
|
|
428
|
-
sx
|
|
429
|
-
|
|
429
|
+
...boxProps,
|
|
430
|
+
sx: {
|
|
431
|
+
marginTop: level === 0 ? "none" : "lg",
|
|
432
|
+
marginBottom: "lg",
|
|
433
|
+
...boxProps.sx
|
|
434
|
+
},
|
|
435
|
+
children: [title && /* @__PURE__ */jsx9(Box3, {
|
|
436
|
+
sx: {
|
|
437
|
+
marginBottom: "md"
|
|
438
|
+
},
|
|
439
|
+
children: /* @__PURE__ */jsx9(Text, {
|
|
440
|
+
sx: {
|
|
441
|
+
fontSize: "2xl",
|
|
442
|
+
fontWeight: "bold"
|
|
443
|
+
},
|
|
444
|
+
children: title
|
|
445
|
+
})
|
|
446
|
+
}), /* @__PURE__ */jsx9(Flex6, {
|
|
447
|
+
sx: childrenContainerSx,
|
|
448
|
+
children
|
|
449
|
+
})]
|
|
430
450
|
});
|
|
431
451
|
};
|
|
432
452
|
var FormGroup = props => {
|
package/dist/index.d.ts
CHANGED
|
@@ -69,8 +69,9 @@ declare const useFormGroup: () => {
|
|
|
69
69
|
levelsLength: number;
|
|
70
70
|
};
|
|
71
71
|
type FormGroupProps = {
|
|
72
|
+
title?: string;
|
|
72
73
|
direction?: 'column' | 'row';
|
|
73
|
-
} &
|
|
74
|
+
} & BoxProps;
|
|
74
75
|
declare const FormGroup: (props: FormGroupProps) => JSX.Element;
|
|
75
76
|
|
|
76
77
|
export { Form, FormField, FormFieldCheckbox, FormFieldInput, FormFieldRadio, FormFieldSelect, FormFieldTextarea, FormGroup, useFormGroup };
|
package/dist/index.js
CHANGED
|
@@ -414,10 +414,10 @@ var FormFieldTextarea = ({
|
|
|
414
414
|
};
|
|
415
415
|
|
|
416
416
|
// src/FormGroup.tsx
|
|
417
|
+
var React3 = __toESM(require("react"));
|
|
417
418
|
var import_ui9 = require("@ttoss/ui");
|
|
418
|
-
var import_react = __toESM(require("react"));
|
|
419
419
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
420
|
-
var FormGroupLevelsManagerContext =
|
|
420
|
+
var FormGroupLevelsManagerContext = React3.createContext({
|
|
421
421
|
levelsLength: 1,
|
|
422
422
|
registerChild: () => {
|
|
423
423
|
return null;
|
|
@@ -426,8 +426,8 @@ var FormGroupLevelsManagerContext = import_react.default.createContext({
|
|
|
426
426
|
var FormGroupLevelsManager = ({
|
|
427
427
|
children
|
|
428
428
|
}) => {
|
|
429
|
-
const [levelsLength, setLevelsLength] =
|
|
430
|
-
const registerChild =
|
|
429
|
+
const [levelsLength, setLevelsLength] = React3.useState(0);
|
|
430
|
+
const registerChild = React3.useCallback(level => {
|
|
431
431
|
if (level + 1 > levelsLength) {
|
|
432
432
|
setLevelsLength(level + 1);
|
|
433
433
|
}
|
|
@@ -440,44 +440,64 @@ var FormGroupLevelsManager = ({
|
|
|
440
440
|
children
|
|
441
441
|
});
|
|
442
442
|
};
|
|
443
|
-
var FormGroupContext =
|
|
443
|
+
var FormGroupContext = React3.createContext({});
|
|
444
444
|
var useFormGroup = () => {
|
|
445
445
|
const {
|
|
446
446
|
parentLevel
|
|
447
|
-
} =
|
|
447
|
+
} = React3.useContext(FormGroupContext);
|
|
448
448
|
const {
|
|
449
449
|
levelsLength
|
|
450
|
-
} =
|
|
450
|
+
} = React3.useContext(FormGroupLevelsManagerContext);
|
|
451
451
|
return {
|
|
452
452
|
level: parentLevel,
|
|
453
453
|
levelsLength
|
|
454
454
|
};
|
|
455
455
|
};
|
|
456
|
-
var FormGroupWrapper =
|
|
456
|
+
var FormGroupWrapper = ({
|
|
457
|
+
title,
|
|
458
|
+
direction,
|
|
459
|
+
children,
|
|
460
|
+
...boxProps
|
|
461
|
+
}) => {
|
|
457
462
|
const {
|
|
458
|
-
level
|
|
459
|
-
levelsLength
|
|
463
|
+
level
|
|
460
464
|
} = useFormGroup();
|
|
461
465
|
const {
|
|
462
466
|
registerChild
|
|
463
|
-
} =
|
|
464
|
-
|
|
467
|
+
} = React3.useContext(FormGroupLevelsManagerContext);
|
|
468
|
+
React3.useEffect(() => {
|
|
465
469
|
if (typeof level === "number") {
|
|
466
470
|
registerChild(level);
|
|
467
471
|
}
|
|
468
472
|
}, [level, registerChild]);
|
|
469
|
-
const
|
|
470
|
-
flexDirection:
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
paddingX: level ? "md" : "none",
|
|
474
|
-
...props.sx
|
|
473
|
+
const childrenContainerSx = {
|
|
474
|
+
flexDirection: direction || "column",
|
|
475
|
+
gap: "md",
|
|
476
|
+
width: "100%"
|
|
475
477
|
};
|
|
476
|
-
return /* @__PURE__ */(0, import_jsx_runtime9.
|
|
478
|
+
return /* @__PURE__ */(0, import_jsx_runtime9.jsxs)(import_ui9.Box, {
|
|
477
479
|
"aria-level": level,
|
|
478
|
-
...
|
|
479
|
-
sx
|
|
480
|
-
|
|
480
|
+
...boxProps,
|
|
481
|
+
sx: {
|
|
482
|
+
marginTop: level === 0 ? "none" : "lg",
|
|
483
|
+
marginBottom: "lg",
|
|
484
|
+
...boxProps.sx
|
|
485
|
+
},
|
|
486
|
+
children: [title && /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Box, {
|
|
487
|
+
sx: {
|
|
488
|
+
marginBottom: "md"
|
|
489
|
+
},
|
|
490
|
+
children: /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Text, {
|
|
491
|
+
sx: {
|
|
492
|
+
fontSize: "2xl",
|
|
493
|
+
fontWeight: "bold"
|
|
494
|
+
},
|
|
495
|
+
children: title
|
|
496
|
+
})
|
|
497
|
+
}), /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Flex, {
|
|
498
|
+
sx: childrenContainerSx,
|
|
499
|
+
children
|
|
500
|
+
})]
|
|
481
501
|
});
|
|
482
502
|
};
|
|
483
503
|
var FormGroup = props => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4db2b08b38e864b64c2652d20d1ea705768beb75"
|
|
48
48
|
}
|
package/src/FormGroup.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Box, BoxProps, Flex, FlexProps, Text } from '@ttoss/ui';
|
|
3
3
|
|
|
4
4
|
type FormGroupLevelsManagerContextType = {
|
|
5
5
|
levelsLength: number;
|
|
@@ -56,11 +56,17 @@ export const useFormGroup = () => {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
type FormGroupProps = {
|
|
59
|
+
title?: string;
|
|
59
60
|
direction?: 'column' | 'row';
|
|
60
|
-
} &
|
|
61
|
+
} & BoxProps;
|
|
61
62
|
|
|
62
|
-
const FormGroupWrapper = (
|
|
63
|
-
|
|
63
|
+
const FormGroupWrapper = ({
|
|
64
|
+
title,
|
|
65
|
+
direction,
|
|
66
|
+
children,
|
|
67
|
+
...boxProps
|
|
68
|
+
}: FormGroupProps) => {
|
|
69
|
+
const { level } = useFormGroup();
|
|
64
70
|
|
|
65
71
|
const { registerChild } = React.useContext(FormGroupLevelsManagerContext);
|
|
66
72
|
|
|
@@ -74,18 +80,36 @@ const FormGroupWrapper = (props: FormGroupProps) => {
|
|
|
74
80
|
}
|
|
75
81
|
}, [level, registerChild]);
|
|
76
82
|
|
|
77
|
-
const
|
|
78
|
-
flexDirection:
|
|
83
|
+
const childrenContainerSx: FlexProps['sx'] = {
|
|
84
|
+
flexDirection: direction || 'column',
|
|
85
|
+
gap: 'md',
|
|
79
86
|
width: '100%',
|
|
80
|
-
gap: 3 * (levelsLength - (level || 0)),
|
|
81
|
-
paddingX: level ? 'md' : 'none',
|
|
82
|
-
...props.sx,
|
|
83
87
|
};
|
|
84
88
|
|
|
85
89
|
return (
|
|
86
|
-
<
|
|
87
|
-
{
|
|
88
|
-
|
|
90
|
+
<Box
|
|
91
|
+
aria-level={level}
|
|
92
|
+
{...boxProps}
|
|
93
|
+
sx={{
|
|
94
|
+
marginTop: level === 0 ? 'none' : 'lg',
|
|
95
|
+
marginBottom: 'lg',
|
|
96
|
+
...boxProps.sx,
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{title && (
|
|
100
|
+
<Box sx={{ marginBottom: 'md' }}>
|
|
101
|
+
<Text
|
|
102
|
+
sx={{
|
|
103
|
+
fontSize: '2xl',
|
|
104
|
+
fontWeight: 'bold',
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
{title}
|
|
108
|
+
</Text>
|
|
109
|
+
</Box>
|
|
110
|
+
)}
|
|
111
|
+
<Flex sx={childrenContainerSx}>{children}</Flex>
|
|
112
|
+
</Box>
|
|
89
113
|
);
|
|
90
114
|
};
|
|
91
115
|
|