@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 CHANGED
@@ -363,9 +363,9 @@ var FormFieldTextarea = ({
363
363
  };
364
364
 
365
365
  // src/FormGroup.tsx
366
- import { Flex as Flex6 } from "@ttoss/ui";
367
- import React3 from "react";
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 = props => {
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 sx = {
419
- flexDirection: props.direction || "column",
420
- width: "100%",
421
- gap: 3 * (levelsLength - (level || 0)),
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__ */jsx9(Flex6, {
427
+ return /* @__PURE__ */jsxs6(Box3, {
426
428
  "aria-level": level,
427
- ...props,
428
- sx,
429
- children: props.children
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
- } & FlexProps;
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 = import_react.default.createContext({
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] = import_react.default.useState(0);
430
- const registerChild = import_react.default.useCallback(level => {
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 = import_react.default.createContext({});
443
+ var FormGroupContext = React3.createContext({});
444
444
  var useFormGroup = () => {
445
445
  const {
446
446
  parentLevel
447
- } = import_react.default.useContext(FormGroupContext);
447
+ } = React3.useContext(FormGroupContext);
448
448
  const {
449
449
  levelsLength
450
- } = import_react.default.useContext(FormGroupLevelsManagerContext);
450
+ } = React3.useContext(FormGroupLevelsManagerContext);
451
451
  return {
452
452
  level: parentLevel,
453
453
  levelsLength
454
454
  };
455
455
  };
456
- var FormGroupWrapper = props => {
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
- } = import_react.default.useContext(FormGroupLevelsManagerContext);
464
- import_react.default.useEffect(() => {
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 sx = {
470
- flexDirection: props.direction || "column",
471
- width: "100%",
472
- gap: 3 * (levelsLength - (level || 0)),
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.jsx)(import_ui9.Flex, {
478
+ return /* @__PURE__ */(0, import_jsx_runtime9.jsxs)(import_ui9.Box, {
477
479
  "aria-level": level,
478
- ...props,
479
- sx,
480
- children: props.children
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.1",
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": "b865ab2a3ba818f221370f6c95a7d580e59a5642"
47
+ "gitHead": "4db2b08b38e864b64c2652d20d1ea705768beb75"
48
48
  }
package/src/FormGroup.tsx CHANGED
@@ -1,5 +1,5 @@
1
- import { Flex, FlexProps } from '@ttoss/ui';
2
- import React from 'react';
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
- } & FlexProps;
61
+ } & BoxProps;
61
62
 
62
- const FormGroupWrapper = (props: FormGroupProps) => {
63
- const { level, levelsLength } = useFormGroup();
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 sx: FlexProps['sx'] = {
78
- flexDirection: props.direction || 'column',
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
- <Flex aria-level={level} {...props} sx={sx}>
87
- {props.children}
88
- </Flex>
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