@omer-x/tailwind-ui-kit 1.0.0-alpha.16 → 1.0.0-alpha.18
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentProps } from 'react';
|
|
2
|
+
import { ComponentPropsWithoutRef, ComponentProps } from 'react';
|
|
3
3
|
import JustDiv from '../elements/JustDiv.js';
|
|
4
4
|
import '@base-ui/react/use-render';
|
|
5
5
|
|
|
6
|
-
type BaseFormProps = Omit<
|
|
6
|
+
type BaseFormProps = Omit<ComponentPropsWithoutRef<"form">, "action"> & {
|
|
7
7
|
action: (initialState: unknown, formData: FormData) => Promise<Record<string, string>>;
|
|
8
8
|
defaultValues?: Record<string, unknown>;
|
|
9
9
|
onlyDirty?: boolean;
|
|
@@ -11,6 +11,6 @@ type BaseFormProps = Omit<ComponentProps<"form">, "action"> & {
|
|
|
11
11
|
renderMessages?: ComponentProps<typeof JustDiv>["render"];
|
|
12
12
|
onStateChange?: (state: Record<string, string>) => void;
|
|
13
13
|
};
|
|
14
|
-
declare const BaseForm: ({ action, defaultValues, onlyDirty, messages: messageTranslations, renderMessages, onStateChange,
|
|
14
|
+
declare const BaseForm: ({ action, defaultValues, onlyDirty, messages: messageTranslations, renderMessages, onStateChange, onSubmit, children, ...otherProps }: BaseFormProps) => react.JSX.Element;
|
|
15
15
|
|
|
16
16
|
export { BaseForm as default };
|
|
@@ -12,8 +12,9 @@ const BaseForm = ({
|
|
|
12
12
|
messages: messageTranslations = {},
|
|
13
13
|
renderMessages,
|
|
14
14
|
onStateChange,
|
|
15
|
-
|
|
16
|
-
children
|
|
15
|
+
onSubmit,
|
|
16
|
+
children,
|
|
17
|
+
...otherProps
|
|
17
18
|
}) => {
|
|
18
19
|
const [state, formAction, _loading] = useActionState(action, {});
|
|
19
20
|
const fieldsRef = useRef(/* @__PURE__ */ new Set());
|
|
@@ -48,18 +49,31 @@ const BaseForm = ({
|
|
|
48
49
|
if (!form) return formAction(fd);
|
|
49
50
|
return formAction(getDirtyFormData(form, defaultValues));
|
|
50
51
|
};
|
|
51
|
-
return /* @__PURE__ */ jsxs(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
return /* @__PURE__ */ jsxs(
|
|
53
|
+
Form,
|
|
54
|
+
{
|
|
55
|
+
...otherProps,
|
|
56
|
+
ref: formRef,
|
|
57
|
+
action: alteredAction,
|
|
58
|
+
errors: fieldMessages,
|
|
59
|
+
onSubmit: (e) => {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
onSubmit?.(e);
|
|
58
62
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
children: [
|
|
64
|
+
Object.entries(formMessages).map(([messageKey, message]) => /* @__PURE__ */ jsx(
|
|
65
|
+
JustDiv,
|
|
66
|
+
{
|
|
67
|
+
"data-message-type": messageKey.startsWith("[") ? messageKey.replace(/^\[|\]$/g, "") : "default",
|
|
68
|
+
render: renderMessages,
|
|
69
|
+
children: messageTranslations[message] || message
|
|
70
|
+
},
|
|
71
|
+
messageKey
|
|
72
|
+
)),
|
|
73
|
+
/* @__PURE__ */ jsx(FormContext, { value: { getFieldMessage, messageTranslations, registerField, unregisterField }, children })
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
);
|
|
63
77
|
};
|
|
64
78
|
var BaseForm_default = BaseForm;
|
|
65
79
|
export {
|