@ssplib/react-components 0.0.76 → 0.0.78

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.
@@ -35,6 +35,7 @@ function getChildrenNames(children) {
35
35
  children.forEach((x) => {
36
36
  if (!x.props)
37
37
  return;
38
+ console.log('PROPS:', x.props);
38
39
  if (x.props.children) {
39
40
  const childrenArr = getChildrenNames(Array.isArray(x.props.children) ? x.props.children : [x.props.children]);
40
41
  arr = arr.concat(childrenArr);
@@ -1,10 +1,10 @@
1
1
  import { ReactElement } from 'react';
2
- export default function FileUpload({ name, required, title, customPlaceholder, defaultChecked, xs, sm, md, ...props }: {
2
+ export default function FileUpload({ name, required, title, defaultChecked, xs, unregisterNameList, sm, md, ...props }: {
3
3
  name: string;
4
- children?: ReactElement | ReactElement[];
4
+ children?: [ReactElement, ReactElement];
5
5
  title?: string;
6
+ unregisterNameList: string[];
6
7
  defaultChecked?: boolean;
7
- customPlaceholder?: string;
8
8
  required?: boolean;
9
9
  xs?: number;
10
10
  sm?: number;
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __rest = (this && this.__rest) || function (s, e) {
26
3
  var t = {};
27
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -39,44 +16,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
16
  Object.defineProperty(exports, "__esModule", { value: true });
40
17
  const material_1 = require("@mui/material");
41
18
  const InputLabel_1 = __importDefault(require("@mui/material/InputLabel"));
42
- const lodash_get_1 = __importDefault(require("lodash.get"));
43
- const react_1 = __importStar(require("react"));
44
- const form_1 = require("../../../context/form");
19
+ const react_1 = __importDefault(require("react"));
45
20
  const Switch_1 = __importDefault(require("../switch/Switch"));
46
- const MaskInput_1 = __importDefault(require("./MaskInput"));
21
+ const ToggleVisibility_1 = require("../switch/ToggleVisibility");
22
+ const Input_1 = require("./Input");
47
23
  function FileUpload(_a) {
48
- var _b;
49
- var { name, required = false, title, customPlaceholder, defaultChecked = false, xs = 12, sm, md } = _a, props = __rest(_a, ["name", "required", "title", "customPlaceholder", "defaultChecked", "xs", "sm", "md"]);
50
- const context = (0, react_1.useContext)(form_1.FormContext);
24
+ var { name, required = false, title, defaultChecked = false, xs = 12, unregisterNameList, sm, md } = _a, props = __rest(_a, ["name", "required", "title", "defaultChecked", "xs", "unregisterNameList", "sm", "md"]);
51
25
  const switchName = `${name}-switch`;
52
- let oldValue = (0, react_1.useRef)(null);
53
- (0, react_1.useEffect)(() => {
54
- const active = context === null || context === void 0 ? void 0 : context.formGetValues(switchName);
55
- if (oldValue.current === active)
56
- return;
57
- oldValue.current = active;
58
- const children = Array.isArray(props.children) ? props.children : [props.children];
59
- const keys = children.map((x) => x === null || x === void 0 ? void 0 : x.props.name);
60
- if (!active)
61
- context === null || context === void 0 ? void 0 : context.formUnregister(name);
62
- else
63
- context === null || context === void 0 ? void 0 : context.formUnregister(keys);
64
- }, [context]);
65
26
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
66
27
  title && (react_1.default.createElement(InputLabel_1.default, { required: required, sx: { textTransform: 'capitalize' } }, title)),
67
28
  react_1.default.createElement(material_1.Stack, { direction: 'row' },
68
29
  react_1.default.createElement(Switch_1.default, { name: switchName, defaultChecked: defaultChecked }),
69
- react_1.default.createElement(material_1.Box, { hidden: !(context === null || context === void 0 ? void 0 : context.formWatch(switchName)) },
70
- react_1.default.createElement(MaskInput_1.default, { formConfig: Object.assign(Object.assign({}, context === null || context === void 0 ? void 0 : context.formRegister(name, {
71
- validate: (v, f) => {
72
- if (context === null || context === void 0 ? void 0 : context.formWatch(switchName)) {
73
- if (v.length <= 0 && required)
74
- return 'Este campo é obrigatório';
75
- }
76
- },
77
- })), { placeholder: customPlaceholder ? customPlaceholder : '', size: 'small', error: (0, lodash_get_1.default)(context === null || context === void 0 ? void 0 : context.errors, name) ? true : false, helperText: (_b = (0, lodash_get_1.default)(context === null || context === void 0 ? void 0 : context.errors, name)) === null || _b === void 0 ? void 0 : _b.message, fullWidth: false }), maskProps: {
78
- mask: /^\d+$/,
79
- } })),
80
- react_1.default.createElement(material_1.Box, { hidden: context === null || context === void 0 ? void 0 : context.formWatch(switchName) }, props.children && props.children))));
30
+ react_1.default.createElement(ToggleVisibility_1.SwitchWatch, { switchId: switchName, unregisterNameList: unregisterNameList },
31
+ react_1.default.createElement(Input_1.Input, { name: 'ddd', type: 'input' })))));
81
32
  }
82
33
  exports.default = FileUpload;
@@ -64,6 +64,34 @@ const getKeys = (values, id) => {
64
64
  keys = [...keys, ...Object.keys(values.files).map((x) => `files.${x}`)];
65
65
  return keys;
66
66
  };
67
+ const _getKeys = (value) => {
68
+ const keys = Object.keys(value);
69
+ if (!value || keys.length <= 0)
70
+ return { objs: [], literals: [] };
71
+ console.log('ATUAL KEYS:', keys);
72
+ let literalValues = [];
73
+ let objectValues = [];
74
+ let result = keys;
75
+ keys.forEach((x) => {
76
+ console.log(x, ':', typeof value[x]);
77
+ if (typeof value[x] === 'object') {
78
+ objectValues.push(x);
79
+ const obj = _getKeys(value[x]);
80
+ objectValues = objectValues.concat(obj.objs);
81
+ }
82
+ else {
83
+ literalValues.push(x);
84
+ }
85
+ });
86
+ console.log({
87
+ objs: objectValues,
88
+ literals: literalValues,
89
+ });
90
+ return {
91
+ objs: objectValues,
92
+ literals: literalValues,
93
+ };
94
+ };
67
95
  function Stepper(_a) {
68
96
  var { debugLog = false } = _a, props = __rest(_a, ["debugLog"]);
69
97
  const length = Array.isArray(props.children) ? props.children.length : 1;
@@ -79,6 +107,8 @@ function Stepper(_a) {
79
107
  const handleNext = () => __awaiter(this, void 0, void 0, function* () {
80
108
  if (debugLog)
81
109
  console.log(context.formGetValues());
110
+ console.log('TRIGGER:', getKeys(context.formGetValues(), activeStep));
111
+ // _getKeys(context.formGetValues()[activeStep])
82
112
  const result = yield context.formTrigger(getKeys(context.formGetValues(), activeStep));
83
113
  if (!result) {
84
114
  setCanPass(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",