@gustavo-valsechi/client 1.4.6 → 1.4.7
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.
|
@@ -44,6 +44,7 @@ var Types = __toESM(require("./types"));
|
|
|
44
44
|
__reExport(form_exports, require("./types"), module.exports);
|
|
45
45
|
function Form(props) {
|
|
46
46
|
const formRef = props.formRef || (0, import_react.useRef)({});
|
|
47
|
+
const [submitting, setSubmitting] = (0, import_react.useState)(false);
|
|
47
48
|
const setSchema = () => {
|
|
48
49
|
const schema2 = {};
|
|
49
50
|
import_lodash.default.forEach(props.inputs, (data) => {
|
|
@@ -92,14 +93,27 @@ function Form(props) {
|
|
|
92
93
|
}
|
|
93
94
|
);
|
|
94
95
|
};
|
|
95
|
-
|
|
96
|
+
const onSubmit = async (data) => {
|
|
97
|
+
if (!props.onSubmit) return;
|
|
98
|
+
setSubmitting(true);
|
|
99
|
+
await props.onSubmit(data);
|
|
100
|
+
setSubmitting(false);
|
|
101
|
+
};
|
|
102
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_styles.Container, { ref: formRef, onSubmit: handleSubmit(onSubmit), children: [
|
|
96
103
|
import_lodash.default.map(
|
|
97
104
|
props.inputs,
|
|
98
105
|
(data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.default.Fragment, { children: component(data) }, index)
|
|
99
106
|
),
|
|
100
107
|
import_lodash.default.isArray(props.buttons) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "form-buttons", children: import_lodash.default.map(
|
|
101
108
|
props.buttons,
|
|
102
|
-
(data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
109
|
+
(data, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
110
|
+
Types.Button,
|
|
111
|
+
{
|
|
112
|
+
...data,
|
|
113
|
+
loading: data.type === "submit" ? submitting || !!data.loading : !!data.loading
|
|
114
|
+
},
|
|
115
|
+
index
|
|
116
|
+
)
|
|
103
117
|
) })
|
|
104
118
|
] });
|
|
105
119
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useEffect, useRef } from "react";
|
|
3
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { Container } from "./styles";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { useForm } from "react-hook-form";
|
|
@@ -10,6 +10,7 @@ import * as Types from "./types";
|
|
|
10
10
|
export * from "./types";
|
|
11
11
|
function Form(props) {
|
|
12
12
|
const formRef = props.formRef || useRef({});
|
|
13
|
+
const [submitting, setSubmitting] = useState(false);
|
|
13
14
|
const setSchema = () => {
|
|
14
15
|
const schema2 = {};
|
|
15
16
|
_.forEach(props.inputs, (data) => {
|
|
@@ -58,14 +59,27 @@ function Form(props) {
|
|
|
58
59
|
}
|
|
59
60
|
);
|
|
60
61
|
};
|
|
61
|
-
|
|
62
|
+
const onSubmit = async (data) => {
|
|
63
|
+
if (!props.onSubmit) return;
|
|
64
|
+
setSubmitting(true);
|
|
65
|
+
await props.onSubmit(data);
|
|
66
|
+
setSubmitting(false);
|
|
67
|
+
};
|
|
68
|
+
return /* @__PURE__ */ jsxs(Container, { ref: formRef, onSubmit: handleSubmit(onSubmit), children: [
|
|
62
69
|
_.map(
|
|
63
70
|
props.inputs,
|
|
64
71
|
(data, index) => /* @__PURE__ */ jsx(React.Fragment, { children: component(data) }, index)
|
|
65
72
|
),
|
|
66
73
|
_.isArray(props.buttons) && /* @__PURE__ */ jsx("div", { className: "form-buttons", children: _.map(
|
|
67
74
|
props.buttons,
|
|
68
|
-
(data, index) => /* @__PURE__ */ jsx(
|
|
75
|
+
(data, index) => /* @__PURE__ */ jsx(
|
|
76
|
+
Types.Button,
|
|
77
|
+
{
|
|
78
|
+
...data,
|
|
79
|
+
loading: data.type === "submit" ? submitting || !!data.loading : !!data.loading
|
|
80
|
+
},
|
|
81
|
+
index
|
|
82
|
+
)
|
|
69
83
|
) })
|
|
70
84
|
] });
|
|
71
85
|
}
|
|
@@ -40,11 +40,10 @@ var import_lodash = __toESM(require("lodash"));
|
|
|
40
40
|
function Button(props) {
|
|
41
41
|
const [loading, setLoading] = (0, import_react.useState)(false);
|
|
42
42
|
const onClick = async (e) => {
|
|
43
|
-
var _a, _b
|
|
43
|
+
var _a, _b;
|
|
44
44
|
if (!props.onClick) return;
|
|
45
45
|
setLoading(true);
|
|
46
|
-
|
|
47
|
-
if (((_d = (_c = props.onClick) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name) === "AsyncFunction") {
|
|
46
|
+
if (((_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "AsyncFunction") {
|
|
48
47
|
await props.onClick(e);
|
|
49
48
|
} else {
|
|
50
49
|
props.onClick(e);
|
|
@@ -60,7 +59,7 @@ function Button(props) {
|
|
|
60
59
|
onClick: async (e) => await onClick(e),
|
|
61
60
|
...import_lodash.default.omit(props, ["loading", "type", "onClick"]),
|
|
62
61
|
children: [
|
|
63
|
-
!!props.loading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loading.Loading, {}),
|
|
62
|
+
(loading || !!props.loading) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loading.Loading, {}),
|
|
64
63
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: props.label })
|
|
65
64
|
]
|
|
66
65
|
}
|
|
@@ -7,11 +7,10 @@ import _ from "lodash";
|
|
|
7
7
|
function Button(props) {
|
|
8
8
|
const [loading, setLoading] = useState(false);
|
|
9
9
|
const onClick = async (e) => {
|
|
10
|
-
var _a, _b
|
|
10
|
+
var _a, _b;
|
|
11
11
|
if (!props.onClick) return;
|
|
12
12
|
setLoading(true);
|
|
13
|
-
|
|
14
|
-
if (((_d = (_c = props.onClick) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name) === "AsyncFunction") {
|
|
13
|
+
if (((_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "AsyncFunction") {
|
|
15
14
|
await props.onClick(e);
|
|
16
15
|
} else {
|
|
17
16
|
props.onClick(e);
|
|
@@ -27,7 +26,7 @@ function Button(props) {
|
|
|
27
26
|
onClick: async (e) => await onClick(e),
|
|
28
27
|
..._.omit(props, ["loading", "type", "onClick"]),
|
|
29
28
|
children: [
|
|
30
|
-
!!props.loading && /* @__PURE__ */ jsx(Loading, {}),
|
|
29
|
+
(loading || !!props.loading) && /* @__PURE__ */ jsx(Loading, {}),
|
|
31
30
|
/* @__PURE__ */ jsx("span", { children: props.label })
|
|
32
31
|
]
|
|
33
32
|
}
|