@ttoss/forms 0.16.1 → 0.16.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/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: () => {
@@ -404,8 +404,7 @@ var useFormGroup = () => {
404
404
  };
405
405
  var FormGroupWrapper = props => {
406
406
  const {
407
- level,
408
- levelsLength
407
+ level
409
408
  } = useFormGroup();
410
409
  const {
411
410
  registerChild
@@ -417,16 +416,32 @@ var FormGroupWrapper = props => {
417
416
  }, [level, registerChild]);
418
417
  const sx = {
419
418
  flexDirection: props.direction || "column",
419
+ gap: "md",
420
420
  width: "100%",
421
- gap: 3 * (levelsLength - (level || 0)),
422
- paddingX: level ? "md" : "none",
423
421
  ...props.sx
424
422
  };
425
- return /* @__PURE__ */jsx9(Flex6, {
423
+ return /* @__PURE__ */jsxs6(Box3, {
426
424
  "aria-level": level,
427
- ...props,
428
- sx,
429
- children: props.children
425
+ sx: {
426
+ marginBottom: "2xl",
427
+ marginX: level === 0 ? "none" : "md"
428
+ },
429
+ children: [props.title && /* @__PURE__ */jsx9(Box3, {
430
+ sx: {
431
+ marginBottom: "md"
432
+ },
433
+ children: /* @__PURE__ */jsx9(Text, {
434
+ sx: {
435
+ fontSize: "2xl",
436
+ fontWeight: "bold"
437
+ },
438
+ children: props.title
439
+ })
440
+ }), /* @__PURE__ */jsx9(Flex6, {
441
+ ...props,
442
+ sx,
443
+ children: props.children
444
+ })]
430
445
  });
431
446
  };
432
447
  var FormGroup = props => {
package/dist/index.d.ts CHANGED
@@ -69,6 +69,7 @@ declare const useFormGroup: () => {
69
69
  levelsLength: number;
70
70
  };
71
71
  type FormGroupProps = {
72
+ title?: string;
72
73
  direction?: 'column' | 'row';
73
74
  } & FlexProps;
74
75
  declare const FormGroup: (props: FormGroupProps) => JSX.Element;
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,14 +440,14 @@ 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
@@ -455,29 +455,44 @@ var useFormGroup = () => {
455
455
  };
456
456
  var FormGroupWrapper = props => {
457
457
  const {
458
- level,
459
- levelsLength
458
+ level
460
459
  } = useFormGroup();
461
460
  const {
462
461
  registerChild
463
- } = import_react.default.useContext(FormGroupLevelsManagerContext);
464
- import_react.default.useEffect(() => {
462
+ } = React3.useContext(FormGroupLevelsManagerContext);
463
+ React3.useEffect(() => {
465
464
  if (typeof level === "number") {
466
465
  registerChild(level);
467
466
  }
468
467
  }, [level, registerChild]);
469
468
  const sx = {
470
469
  flexDirection: props.direction || "column",
470
+ gap: "md",
471
471
  width: "100%",
472
- gap: 3 * (levelsLength - (level || 0)),
473
- paddingX: level ? "md" : "none",
474
472
  ...props.sx
475
473
  };
476
- return /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Flex, {
474
+ return /* @__PURE__ */(0, import_jsx_runtime9.jsxs)(import_ui9.Box, {
477
475
  "aria-level": level,
478
- ...props,
479
- sx,
480
- children: props.children
476
+ sx: {
477
+ marginBottom: "2xl",
478
+ marginX: level === 0 ? "none" : "md"
479
+ },
480
+ children: [props.title && /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Box, {
481
+ sx: {
482
+ marginBottom: "md"
483
+ },
484
+ children: /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Text, {
485
+ sx: {
486
+ fontSize: "2xl",
487
+ fontWeight: "bold"
488
+ },
489
+ children: props.title
490
+ })
491
+ }), /* @__PURE__ */(0, import_jsx_runtime9.jsx)(import_ui9.Flex, {
492
+ ...props,
493
+ sx,
494
+ children: props.children
495
+ })]
481
496
  });
482
497
  };
483
498
  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.2",
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": "3b5fa98e8b9445d00d44fcc0788f65c7ff22d6ca"
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, Flex, FlexProps, Text } from '@ttoss/ui';
3
3
 
4
4
  type FormGroupLevelsManagerContextType = {
5
5
  levelsLength: number;
@@ -56,11 +56,12 @@ export const useFormGroup = () => {
56
56
  };
57
57
 
58
58
  type FormGroupProps = {
59
+ title?: string;
59
60
  direction?: 'column' | 'row';
60
61
  } & FlexProps;
61
62
 
62
63
  const FormGroupWrapper = (props: FormGroupProps) => {
63
- const { level, levelsLength } = useFormGroup();
64
+ const { level } = useFormGroup();
64
65
 
65
66
  const { registerChild } = React.useContext(FormGroupLevelsManagerContext);
66
67
 
@@ -76,16 +77,35 @@ const FormGroupWrapper = (props: FormGroupProps) => {
76
77
 
77
78
  const sx: FlexProps['sx'] = {
78
79
  flexDirection: props.direction || 'column',
80
+ gap: 'md',
79
81
  width: '100%',
80
- gap: 3 * (levelsLength - (level || 0)),
81
- paddingX: level ? 'md' : 'none',
82
82
  ...props.sx,
83
83
  };
84
84
 
85
85
  return (
86
- <Flex aria-level={level} {...props} sx={sx}>
87
- {props.children}
88
- </Flex>
86
+ <Box
87
+ aria-level={level}
88
+ sx={{
89
+ marginBottom: '2xl',
90
+ marginX: level === 0 ? 'none' : 'md',
91
+ }}
92
+ >
93
+ {props.title && (
94
+ <Box sx={{ marginBottom: 'md' }}>
95
+ <Text
96
+ sx={{
97
+ fontSize: '2xl',
98
+ fontWeight: 'bold',
99
+ }}
100
+ >
101
+ {props.title}
102
+ </Text>
103
+ </Box>
104
+ )}
105
+ <Flex {...props} sx={sx}>
106
+ {props.children}
107
+ </Flex>
108
+ </Box>
89
109
  );
90
110
  };
91
111