@cronocode/react-box 1.0.0 → 1.0.1
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/box.module.css.js +1 -1
- package/components/buttonCore.d.ts +1 -1
- package/components/formAsync.d.ts +6 -2
- package/components/formAsync.js +11 -28
- package/package.json +1 -1
- package/style.css +1 -1
- package/types.d.ts +36 -36
- package/utils/form/formUtils.d.ts +5 -0
- package/utils/utils.js +33 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Box from '../box';
|
|
2
|
-
declare type BoxProps = React.ComponentProps<typeof Box
|
|
2
|
+
declare type BoxProps = React.ComponentProps<typeof Box<'button'>>;
|
|
3
3
|
declare type BoxTagProps = Required<BoxProps>['props'];
|
|
4
4
|
declare type ButtonTagProps = Omit<BoxTagProps, 'type' | 'onClick' | 'disabled'>;
|
|
5
5
|
declare type ButtonType = Required<React.ComponentProps<'button'>>['type'];
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import Box from '../box';
|
|
2
|
+
declare type BoxProps = React.ComponentProps<typeof Box<'form'>>;
|
|
3
|
+
declare type BoxTagProps = Required<BoxProps>['props'];
|
|
4
|
+
declare type FormAsyncTagProps = Omit<BoxTagProps, 'onSubmit' | 'ref'>;
|
|
5
|
+
interface Props<T> extends Omit<BoxProps, 'props' | 'tag'> {
|
|
6
|
+
props?: FormAsyncTagProps;
|
|
3
7
|
onSubmit: (obj: T, e: React.FormEvent<HTMLFormElement>) => void;
|
|
4
8
|
}
|
|
5
9
|
export default function FormAsync<T>(props: Props<T>): JSX.Element;
|
package/components/formAsync.js
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
1
|
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as p, useCallback as
|
|
3
|
-
import
|
|
2
|
+
import { useRef as p, useCallback as u } from "react";
|
|
3
|
+
import a from "../box.js";
|
|
4
|
+
import { F as c } from "../utils/utils.js";
|
|
4
5
|
import "../box.module.css.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
}, {}
|
|
11
|
-
return
|
|
12
|
-
if (c.length === 1) {
|
|
13
|
-
const e = c[0];
|
|
14
|
-
r[o] = e.type === "checkbox" || e.type === "radio" ? e.checked : e.value;
|
|
15
|
-
} else
|
|
16
|
-
r[o] = [], c.forEach((e) => {
|
|
17
|
-
var t;
|
|
18
|
-
e.type === "checkbox" ? e.checked && r[o].push(e.value) : e.type === "radio" ? r[o] = (t = c.find((f) => f.checked)) == null ? void 0 : t.value : r[o].push(e.value);
|
|
19
|
-
});
|
|
20
|
-
return r;
|
|
21
|
-
}, {});
|
|
22
|
-
}
|
|
23
|
-
function v(u) {
|
|
24
|
-
const { children: n, onSubmit: r } = u, o = p(null), c = s((e) => {
|
|
25
|
-
e.preventDefault();
|
|
26
|
-
const t = d(o.current);
|
|
27
|
-
r(t, e);
|
|
28
|
-
}, []);
|
|
29
|
-
return /* @__PURE__ */ i(m, { tag: "form", props: { ref: o, onSubmit: c }, children: n });
|
|
6
|
+
function S(o) {
|
|
7
|
+
const { onSubmit: m, props: n } = o, r = p(null), s = u((t) => {
|
|
8
|
+
t.preventDefault();
|
|
9
|
+
const f = c.getFormEntries(r.current);
|
|
10
|
+
m(f, t);
|
|
11
|
+
}, []), e = { ...n, onSubmit: s, ref: r };
|
|
12
|
+
return /* @__PURE__ */ i(a, { tag: "form", ...o, props: e });
|
|
30
13
|
}
|
|
31
14
|
export {
|
|
32
|
-
|
|
15
|
+
S as default
|
|
33
16
|
};
|