@gustavo-valsechi/client 1.4.358 → 1.4.360
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/src/components/types/form/index.js +20 -4
- package/dist/src/components/types/form/index.mjs +21 -5
- package/dist/src/components/types/form/styles.d.ts +1 -0
- package/dist/src/components/types/form/styles.js +7 -6
- package/dist/src/components/types/form/styles.mjs +5 -5
- package/dist/src/interfaces/components/form/index.d.ts +2 -1
- package/dist/src/interfaces/components/form/select/index.d.ts +0 -1
- package/dist/src/interfaces/components/form/text/index.d.ts +0 -1
- package/dist/src/interfaces/components/form/textarea/index.d.ts +0 -1
- package/package.json +1 -1
|
@@ -93,7 +93,10 @@ function Form(props) {
|
|
|
93
93
|
const values = getValues();
|
|
94
94
|
if (!Object.keys(defaultValues).length) {
|
|
95
95
|
const modalContainer = document.getElementById("modal-context-container");
|
|
96
|
-
import_lodash.default.forEach(props.inputs, (data) =>
|
|
96
|
+
import_lodash.default.forEach(props.inputs, (data) => {
|
|
97
|
+
if (import_lodash.default.isArray(data)) return import_lodash.default.forEach(data, (input) => defaultValues[input.name] = "");
|
|
98
|
+
defaultValues[data.name] = "";
|
|
99
|
+
});
|
|
97
100
|
setTimeout(() => reset({ ...defaultValues, ...values }, { keepErrors: false }), ((_a = modalContainer == null ? void 0 : modalContainer.contains) == null ? void 0 : _a.call(modalContainer, formRef.current)) ? 300 : 0);
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
@@ -115,7 +118,7 @@ function Form(props) {
|
|
|
115
118
|
reset(defaultValues, { keepErrors: false });
|
|
116
119
|
}, [props.defaultValues, props.inputs, props.clearWhen]);
|
|
117
120
|
const component = (data) => {
|
|
118
|
-
var _a;
|
|
121
|
+
var _a, _b, _c, _d, _e;
|
|
119
122
|
let inputType = "";
|
|
120
123
|
inputType = import_lodash.default.upperFirst(import_lodash.default.camelCase(data.type));
|
|
121
124
|
inputType = import_lodash.default.includes(inputType, "Input") ? inputType : `Input${inputType}`;
|
|
@@ -132,7 +135,8 @@ function Form(props) {
|
|
|
132
135
|
setValue,
|
|
133
136
|
getValues,
|
|
134
137
|
setError,
|
|
135
|
-
watch
|
|
138
|
+
watch,
|
|
139
|
+
optional: (_e = (_d = (_c = (_b = data.validation) == null ? void 0 : _b.safeParse) == null ? void 0 : _c.call(_b, void 0)) == null ? void 0 : _d.success) != null ? _e : true
|
|
136
140
|
}
|
|
137
141
|
);
|
|
138
142
|
};
|
|
@@ -142,12 +146,24 @@ function Form(props) {
|
|
|
142
146
|
await props.onSubmit(data);
|
|
143
147
|
setSubmitting(false);
|
|
144
148
|
};
|
|
149
|
+
const setFlexWidth = (inputs, input) => {
|
|
150
|
+
if (import_lodash.default.some(inputs, (data) => !data.maxLength)) return 1;
|
|
151
|
+
const minLength = import_lodash.default.min(import_lodash.default.map(inputs, (data) => data.maxLength));
|
|
152
|
+
return input.maxLength / minLength;
|
|
153
|
+
};
|
|
145
154
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_styles.Container, { ref: formRef, onSubmit: handleSubmit(onSubmit), children: [
|
|
146
155
|
import_lodash.default.map(
|
|
147
156
|
props.inputs,
|
|
148
157
|
(data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Fragment, { children: import_lodash.default.isArray(data) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "form-content", children: import_lodash.default.map(
|
|
149
158
|
data,
|
|
150
|
-
(input, index2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
159
|
+
(input, index2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
160
|
+
import_styles.FormInput,
|
|
161
|
+
{
|
|
162
|
+
flex: setFlexWidth(data, input),
|
|
163
|
+
children: component(input)
|
|
164
|
+
},
|
|
165
|
+
index2
|
|
166
|
+
)
|
|
151
167
|
) }) : component(data) }, index)
|
|
152
168
|
),
|
|
153
169
|
import_lodash.default.isArray(props.buttons) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "form-buttons", children: import_lodash.default.map(
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import React, { useEffect, useRef, useState } from "react";
|
|
5
|
-
import { Container } from "./styles";
|
|
5
|
+
import { Container, FormInput } from "./styles";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { useForm } from "react-hook-form";
|
|
8
8
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
@@ -59,7 +59,10 @@ function Form(props) {
|
|
|
59
59
|
const values = getValues();
|
|
60
60
|
if (!Object.keys(defaultValues).length) {
|
|
61
61
|
const modalContainer = document.getElementById("modal-context-container");
|
|
62
|
-
_.forEach(props.inputs, (data) =>
|
|
62
|
+
_.forEach(props.inputs, (data) => {
|
|
63
|
+
if (_.isArray(data)) return _.forEach(data, (input) => defaultValues[input.name] = "");
|
|
64
|
+
defaultValues[data.name] = "";
|
|
65
|
+
});
|
|
63
66
|
setTimeout(() => reset({ ...defaultValues, ...values }, { keepErrors: false }), ((_a = modalContainer == null ? void 0 : modalContainer.contains) == null ? void 0 : _a.call(modalContainer, formRef.current)) ? 300 : 0);
|
|
64
67
|
return;
|
|
65
68
|
}
|
|
@@ -81,7 +84,7 @@ function Form(props) {
|
|
|
81
84
|
reset(defaultValues, { keepErrors: false });
|
|
82
85
|
}, [props.defaultValues, props.inputs, props.clearWhen]);
|
|
83
86
|
const component = (data) => {
|
|
84
|
-
var _a;
|
|
87
|
+
var _a, _b, _c, _d, _e;
|
|
85
88
|
let inputType = "";
|
|
86
89
|
inputType = _.upperFirst(_.camelCase(data.type));
|
|
87
90
|
inputType = _.includes(inputType, "Input") ? inputType : `Input${inputType}`;
|
|
@@ -98,7 +101,8 @@ function Form(props) {
|
|
|
98
101
|
setValue,
|
|
99
102
|
getValues,
|
|
100
103
|
setError,
|
|
101
|
-
watch
|
|
104
|
+
watch,
|
|
105
|
+
optional: (_e = (_d = (_c = (_b = data.validation) == null ? void 0 : _b.safeParse) == null ? void 0 : _c.call(_b, void 0)) == null ? void 0 : _d.success) != null ? _e : true
|
|
102
106
|
}
|
|
103
107
|
);
|
|
104
108
|
};
|
|
@@ -108,12 +112,24 @@ function Form(props) {
|
|
|
108
112
|
await props.onSubmit(data);
|
|
109
113
|
setSubmitting(false);
|
|
110
114
|
};
|
|
115
|
+
const setFlexWidth = (inputs, input) => {
|
|
116
|
+
if (_.some(inputs, (data) => !data.maxLength)) return 1;
|
|
117
|
+
const minLength = _.min(_.map(inputs, (data) => data.maxLength));
|
|
118
|
+
return input.maxLength / minLength;
|
|
119
|
+
};
|
|
111
120
|
return /* @__PURE__ */ jsxs(Container, { ref: formRef, onSubmit: handleSubmit(onSubmit), children: [
|
|
112
121
|
_.map(
|
|
113
122
|
props.inputs,
|
|
114
123
|
(data, index) => /* @__PURE__ */ jsx(React.Fragment, { children: _.isArray(data) ? /* @__PURE__ */ jsx("div", { className: "form-content", children: _.map(
|
|
115
124
|
data,
|
|
116
|
-
(input, index2) => /* @__PURE__ */ jsx(
|
|
125
|
+
(input, index2) => /* @__PURE__ */ jsx(
|
|
126
|
+
FormInput,
|
|
127
|
+
{
|
|
128
|
+
flex: setFlexWidth(data, input),
|
|
129
|
+
children: component(input)
|
|
130
|
+
},
|
|
131
|
+
index2
|
|
132
|
+
)
|
|
117
133
|
) }) : component(data) }, index)
|
|
118
134
|
),
|
|
119
135
|
_.isArray(props.buttons) && /* @__PURE__ */ jsx("div", { className: "form-buttons", children: _.map(
|
|
@@ -30,7 +30,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
31
|
var styles_exports = {};
|
|
32
32
|
__export(styles_exports, {
|
|
33
|
-
Container: () => Container
|
|
33
|
+
Container: () => Container,
|
|
34
|
+
FormInput: () => FormInput
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(styles_exports);
|
|
36
37
|
var import_styled_components = __toESM(require("styled-components"));
|
|
@@ -45,10 +46,6 @@ const Container = import_styled_components.default.form`
|
|
|
45
46
|
display: flex;
|
|
46
47
|
gap: .5rem;
|
|
47
48
|
flex-wrap: wrap;
|
|
48
|
-
|
|
49
|
-
.form-input {
|
|
50
|
-
flex: 1 1 10rem;
|
|
51
|
-
}
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
.form-buttons {
|
|
@@ -61,7 +58,11 @@ const Container = import_styled_components.default.form`
|
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
`;
|
|
61
|
+
const FormInput = import_styled_components.default.div`
|
|
62
|
+
flex: ${({ flex }) => flex} 1 8rem;
|
|
63
|
+
`;
|
|
64
64
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
65
|
0 && (module.exports = {
|
|
66
|
-
Container
|
|
66
|
+
Container,
|
|
67
|
+
FormInput
|
|
67
68
|
});
|
|
@@ -12,10 +12,6 @@ const Container = styled.form`
|
|
|
12
12
|
display: flex;
|
|
13
13
|
gap: .5rem;
|
|
14
14
|
flex-wrap: wrap;
|
|
15
|
-
|
|
16
|
-
.form-input {
|
|
17
|
-
flex: 1 1 10rem;
|
|
18
|
-
}
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
.form-buttons {
|
|
@@ -28,6 +24,10 @@ const Container = styled.form`
|
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
26
|
`;
|
|
27
|
+
const FormInput = styled.div`
|
|
28
|
+
flex: ${({ flex }) => flex} 1 8rem;
|
|
29
|
+
`;
|
|
31
30
|
export {
|
|
32
|
-
Container
|
|
31
|
+
Container,
|
|
32
|
+
FormInput
|
|
33
33
|
};
|
|
@@ -17,7 +17,7 @@ export interface IForm {
|
|
|
17
17
|
formRef?: any;
|
|
18
18
|
onSubmit: (values: any, actions?: any) => void;
|
|
19
19
|
clearWhen?: boolean;
|
|
20
|
-
inputs: Array<IFormInput
|
|
20
|
+
inputs: Array<IFormInput | Array<IFormInput>>;
|
|
21
21
|
buttons?: Array<IButton>;
|
|
22
22
|
}
|
|
23
23
|
export interface IInputBase {
|
|
@@ -29,6 +29,7 @@ export interface IInputBase {
|
|
|
29
29
|
error?: string;
|
|
30
30
|
disabled?: boolean;
|
|
31
31
|
optional?: boolean;
|
|
32
|
+
maxLength?: number;
|
|
32
33
|
register?: UseFormRegister<any>;
|
|
33
34
|
validation?: z.ZodTypeAny;
|
|
34
35
|
watch?: (...args: any[]) => string;
|