@omer-x/tailwind-ui-kit 1.0.0-alpha.18 → 1.0.0-alpha.19
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/MIGRATION.md +164 -0
- package/README.md +390 -0
- package/dist/components/button/BaseButton.d.ts +27 -11
- package/dist/components/button/BaseButton.js +57 -51
- package/dist/components/button/index.d.ts +2 -4
- package/dist/components/button/index.js +1 -4
- package/dist/components/dialog/AnimatedPopup.d.ts +3 -6
- package/dist/components/dialog/AnimatedPopup.js +6 -31
- package/dist/components/dialog/DialogBackdrop.d.ts +3 -6
- package/dist/components/dialog/DialogBackdrop.js +6 -22
- package/dist/components/dialog/DialogTitle.d.ts +3 -6
- package/dist/components/dialog/DialogTitle.js +6 -15
- package/dist/components/dialog/index.d.ts +4 -5
- package/dist/components/dialog/index.js +4 -8
- package/dist/components/elements/JustAnchor.d.ts +3 -6
- package/dist/components/elements/JustAnchor.js +8 -13
- package/dist/components/elements/JustButton.d.ts +3 -6
- package/dist/components/elements/JustButton.js +8 -13
- package/dist/components/elements/JustDiv.d.ts +3 -6
- package/dist/components/elements/JustDiv.js +8 -13
- package/dist/components/elements/JustInput.d.ts +3 -6
- package/dist/components/elements/JustInput.js +8 -13
- package/dist/components/form/BaseForm.d.ts +12 -15
- package/dist/components/form/BaseForm.js +72 -75
- package/dist/components/form/BaseFormField.d.ts +12 -19
- package/dist/components/form/BaseFormField.js +29 -24
- package/dist/components/form/BaseInput.d.ts +5 -9
- package/dist/components/form/BaseInput.js +20 -31
- package/dist/components/form/BaseSwitch.d.ts +6 -9
- package/dist/components/form/BaseSwitch.js +18 -51
- package/dist/components/form/ClientSideError.d.ts +9 -0
- package/dist/components/form/ClientSideError.js +39 -0
- package/dist/components/form/FieldRoot.d.ts +6 -9
- package/dist/components/form/FieldRoot.js +16 -18
- package/dist/components/form/FormContext.d.ts +26 -9
- package/dist/components/form/FormContext.js +9 -7
- package/dist/components/form/ServerSideError.d.ts +6 -10
- package/dist/components/form/ServerSideError.js +10 -14
- package/dist/components/form/index.d.ts +7 -11
- package/dist/components/form/index.js +6 -10
- package/dist/components/form/useFormMessages.d.ts +10 -0
- package/dist/components/form/useFormMessages.js +16 -0
- package/dist/components/layout/Container.d.ts +5 -8
- package/dist/components/layout/Container.js +8 -10
- package/dist/components/layout/index.d.ts +2 -2
- package/dist/components/layout/index.js +1 -4
- package/dist/components/page/Pagination.d.ts +11 -15
- package/dist/components/page/Pagination.js +60 -48
- package/dist/components/page/index.d.ts +2 -5
- package/dist/components/page/index.js +1 -4
- package/dist/components/table/Tdx.d.ts +5 -8
- package/dist/components/table/Tdx.js +13 -9
- package/dist/components/table/index.d.ts +2 -2
- package/dist/components/table/index.js +1 -4
- package/dist/hooks/useRipples.d.ts +2 -5
- package/dist/hooks/useRipples.js +46 -33
- package/dist/styles/ripple.module.css +1 -0
- package/dist/utils/cn.d.ts +6 -5
- package/dist/utils/cn.js +8 -6
- package/dist/utils/dirty-form.d.ts +1 -3
- package/dist/utils/dirty-form.js +24 -39
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +1 -4
- package/package.json +27 -24
- package/dist/components/button/PulseButton.d.ts +0 -8
- package/dist/components/button/PulseButton.js +0 -41
- package/dist/styles/ripple.module.d.ts +0 -2
|
@@ -1,52 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {} from "react";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import { Button } from "@base-ui/react/button";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { use } from "react";
|
|
5
|
+
import { useFormStatus } from "react-dom";
|
|
6
|
+
import { useRipples } from "../../hooks/useRipples.js";
|
|
7
|
+
import { FormContext } from "../form/FormContext.js";
|
|
8
|
+
import { jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/components/button/BaseButton.tsx
|
|
10
|
+
const BaseButton = ({ size = "md", pending: pendingProp = false, spinner, iconOnly = false, type, disabled = false, focusableWhenDisabled = false, onClick, className, children, ...otherProps }) => {
|
|
11
|
+
const { pending: nativeFormPending } = useFormStatus();
|
|
12
|
+
const { pending: baseFormPending } = use(FormContext);
|
|
13
|
+
const pending = pendingProp || type === "submit" && (nativeFormPending || baseFormPending);
|
|
14
|
+
const [triggerRippleEffect, ripples] = useRipples();
|
|
15
|
+
const handleClick = (e) => {
|
|
16
|
+
onClick?.(e);
|
|
17
|
+
if (!e.defaultPrevented) triggerRippleEffect(e);
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
20
|
+
...otherProps,
|
|
21
|
+
type,
|
|
22
|
+
disabled: pending || disabled,
|
|
23
|
+
focusableWhenDisabled: pending || focusableWhenDisabled,
|
|
24
|
+
onClick: handleClick,
|
|
25
|
+
"aria-busy": pending || void 0,
|
|
26
|
+
"data-pending": pending ? "" : void 0,
|
|
27
|
+
"data-icon-only": iconOnly ? "" : void 0,
|
|
28
|
+
className: cn({
|
|
29
|
+
"h-12 text-base leading-7 gap-3": size === "lg",
|
|
30
|
+
"h-10 text-sm leading-6 gap-3": size === "md",
|
|
31
|
+
"h-9 text-sm leading-5 gap-2": size === "sm",
|
|
32
|
+
"h-8 text-xs leading-4 gap-2": size === "xs",
|
|
33
|
+
"px-5": size === "lg" && !iconOnly,
|
|
34
|
+
"px-4": size === "md" && !iconOnly,
|
|
35
|
+
"px-3": size === "sm" && !iconOnly,
|
|
36
|
+
"px-2.5": size === "xs" && !iconOnly,
|
|
37
|
+
"aspect-square px-0": iconOnly
|
|
38
|
+
}, [
|
|
39
|
+
"relative",
|
|
40
|
+
"flex items-center justify-center",
|
|
41
|
+
"rounded-md",
|
|
42
|
+
"font-medium",
|
|
43
|
+
"select-none",
|
|
44
|
+
"outline-0",
|
|
45
|
+
"transition-colors",
|
|
46
|
+
"focus-visible:outline-2",
|
|
47
|
+
"focus-visible:outline-offset-2",
|
|
48
|
+
"cursor-pointer",
|
|
49
|
+
"data-disabled:cursor-default"
|
|
50
|
+
], className),
|
|
51
|
+
children: [
|
|
52
|
+
ripples,
|
|
53
|
+
pending && spinner,
|
|
54
|
+
!(pending && iconOnly && spinner) && children
|
|
55
|
+
]
|
|
56
|
+
});
|
|
52
57
|
};
|
|
58
|
+
export { BaseButton as default };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const AnimatedPopup: ({ render, className, ...otherProps }: useRender.ComponentProps<"div">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { AnimatedPopup as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const AnimatedPopup: ({ render, className, ...otherProps }: useRender.ComponentProps<"div">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { AnimatedPopup as default };
|
|
@@ -1,35 +1,10 @@
|
|
|
1
1
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
2
|
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { cn } from "
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
// src/components/dialog/AnimatedPopup.tsx
|
|
4
5
|
const AnimatedPopup = ({ render, className, ...otherProps }) => useRender({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
className: cn(
|
|
9
|
-
"fixed",
|
|
10
|
-
"top-[calc(50%+1.25rem*var(--nested-dialogs))]",
|
|
11
|
-
"left-1/2",
|
|
12
|
-
"-mt-8",
|
|
13
|
-
"w-96",
|
|
14
|
-
"max-w-[calc(100vw-3rem)]",
|
|
15
|
-
"-translate-x-1/2",
|
|
16
|
-
"-translate-y-1/2",
|
|
17
|
-
"scale-[calc(1-0.1*var(--nested-dialogs))]",
|
|
18
|
-
"transition-all",
|
|
19
|
-
"duration-150",
|
|
20
|
-
"data-[ending-style]:scale-90",
|
|
21
|
-
"data-[ending-style]:opacity-0",
|
|
22
|
-
"data-[nested-dialog-open]:after:absolute",
|
|
23
|
-
"data-[nested-dialog-open]:after:inset-0",
|
|
24
|
-
"data-[nested-dialog-open]:after:rounded-[inherit]",
|
|
25
|
-
"data-[nested-dialog-open]:after:bg-black/5",
|
|
26
|
-
"data-[starting-style]:scale-90",
|
|
27
|
-
"data-[starting-style]:opacity-0",
|
|
28
|
-
className
|
|
29
|
-
)
|
|
30
|
-
}, otherProps)
|
|
6
|
+
defaultTagName: "div",
|
|
7
|
+
render,
|
|
8
|
+
props: mergeProps({ className: cn("fixed", "top-[calc(50%+1.25rem*var(--nested-dialogs))]", "left-1/2", "-mt-8", "w-96", "max-w-[calc(100vw-3rem)]", "-translate-x-1/2", "-translate-y-1/2", "scale-[calc(1-0.1*var(--nested-dialogs))]", "transition-all", "duration-150", "data-[ending-style]:scale-90", "data-[ending-style]:opacity-0", "data-[nested-dialog-open]:after:absolute", "data-[nested-dialog-open]:after:inset-0", "data-[nested-dialog-open]:after:rounded-[inherit]", "data-[nested-dialog-open]:after:bg-black/5", "data-[starting-style]:scale-90", "data-[starting-style]:opacity-0", className) }, otherProps)
|
|
31
9
|
});
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
AnimatedPopup_default as default
|
|
35
|
-
};
|
|
10
|
+
export { AnimatedPopup as default };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const DialogBackdrop: ({ render, ...otherProps }: useRender.ComponentProps<"div">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { DialogBackdrop as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const DialogBackdrop: ({ render, ...otherProps }: useRender.ComponentProps<"div">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { DialogBackdrop as default };
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
2
|
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { cn } from "
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
// src/components/dialog/DialogBackdrop.tsx
|
|
4
5
|
const DialogBackdrop = ({ render, ...otherProps }) => useRender({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
className: cn(
|
|
9
|
-
"fixed",
|
|
10
|
-
"inset-0",
|
|
11
|
-
"min-h-dvh",
|
|
12
|
-
"bg-black",
|
|
13
|
-
"opacity-20",
|
|
14
|
-
"transition-all",
|
|
15
|
-
"duration-150",
|
|
16
|
-
"data-[ending-style]:opacity-0",
|
|
17
|
-
"data-[starting-style]:opacity-0",
|
|
18
|
-
"dark:opacity-70",
|
|
19
|
-
"supports-[-webkit-touch-callout:none]:absolute"
|
|
20
|
-
)
|
|
21
|
-
}, otherProps)
|
|
6
|
+
defaultTagName: "div",
|
|
7
|
+
render,
|
|
8
|
+
props: mergeProps({ className: cn("fixed", "inset-0", "min-h-dvh", "bg-black", "opacity-20", "transition-all", "duration-150", "data-[ending-style]:opacity-0", "data-[starting-style]:opacity-0", "dark:opacity-70", "supports-[-webkit-touch-callout:none]:absolute") }, otherProps)
|
|
22
9
|
});
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
DialogBackdrop_default as default
|
|
26
|
-
};
|
|
10
|
+
export { DialogBackdrop as default };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const DialogTitle: ({ render, ...otherProps }: useRender.ComponentProps<"h2">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { DialogTitle as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const DialogTitle: ({ render, ...otherProps }: useRender.ComponentProps<"h2">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { DialogTitle as default };
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
2
|
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { cn } from "
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
// src/components/dialog/DialogTitle.tsx
|
|
4
5
|
const DialogTitle = ({ render, ...otherProps }) => useRender({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
className: cn(
|
|
9
|
-
"-mt-1.5",
|
|
10
|
-
"mb-1",
|
|
11
|
-
"text-xl",
|
|
12
|
-
"font-semibold"
|
|
13
|
-
)
|
|
14
|
-
}, otherProps)
|
|
6
|
+
defaultTagName: "h2",
|
|
7
|
+
render,
|
|
8
|
+
props: mergeProps({ className: cn("-mt-1.5", "mb-1", "text-xl", "font-semibold") }, otherProps)
|
|
15
9
|
});
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
DialogTitle_default as default
|
|
19
|
-
};
|
|
10
|
+
export { DialogTitle as default };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import '@base-ui/react/use-render';
|
|
1
|
+
import AnimatedPopup from "./AnimatedPopup.js";
|
|
2
|
+
import DialogBackdrop from "./DialogBackdrop.js";
|
|
3
|
+
import DialogTitle from "./DialogTitle.js";
|
|
4
|
+
export { AnimatedPopup, DialogBackdrop, DialogTitle };
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export {
|
|
5
|
-
default2 as AnimatedPopup,
|
|
6
|
-
default3 as DialogBackdrop,
|
|
7
|
-
default4 as DialogTitle
|
|
8
|
-
};
|
|
1
|
+
import AnimatedPopup from "./AnimatedPopup.js";
|
|
2
|
+
import DialogBackdrop from "./DialogBackdrop.js";
|
|
3
|
+
import DialogTitle from "./DialogTitle.js";
|
|
4
|
+
export { AnimatedPopup, DialogBackdrop, DialogTitle };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const JustAnchor: ({ render, ...props }: useRender.ComponentProps<"a">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { JustAnchor as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const JustAnchor: ({ render, ...props }: useRender.ComponentProps<"a">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { JustAnchor as default };
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
props
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var JustAnchor_default = JustAnchor;
|
|
13
|
-
export {
|
|
14
|
-
JustAnchor_default as default
|
|
2
|
+
// src/components/elements/JustAnchor.tsx
|
|
3
|
+
const JustAnchor = ({ render, ...props }) => {
|
|
4
|
+
return useRender({
|
|
5
|
+
defaultTagName: "a",
|
|
6
|
+
render,
|
|
7
|
+
props
|
|
8
|
+
});
|
|
15
9
|
};
|
|
10
|
+
export { JustAnchor as default };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const JustButton: ({ render, ...props }: useRender.ComponentProps<"button">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { JustButton as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const JustButton: ({ render, ...props }: useRender.ComponentProps<"button">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { JustButton as default };
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
props
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var JustButton_default = JustButton;
|
|
13
|
-
export {
|
|
14
|
-
JustButton_default as default
|
|
2
|
+
// src/components/elements/JustButton.tsx
|
|
3
|
+
const JustButton = ({ render, ...props }) => {
|
|
4
|
+
return useRender({
|
|
5
|
+
defaultTagName: "button",
|
|
6
|
+
render,
|
|
7
|
+
props
|
|
8
|
+
});
|
|
15
9
|
};
|
|
10
|
+
export { JustButton as default };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const JustDiv: ({ render, ...props }: useRender.ComponentProps<"div">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { JustDiv as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const JustDiv: ({ render, ...props }: useRender.ComponentProps<"div">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { JustDiv as default };
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
props
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var JustDiv_default = JustDiv;
|
|
13
|
-
export {
|
|
14
|
-
JustDiv_default as default
|
|
2
|
+
// src/components/elements/JustDiv.tsx
|
|
3
|
+
const JustDiv = ({ render, ...props }) => {
|
|
4
|
+
return useRender({
|
|
5
|
+
defaultTagName: "div",
|
|
6
|
+
render,
|
|
7
|
+
props
|
|
8
|
+
});
|
|
15
9
|
};
|
|
10
|
+
export { JustDiv as default };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const JustInput: ({ render, ...props }: useRender.ComponentProps<"input">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
5
|
-
|
|
6
|
-
export { JustInput as default };
|
|
1
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
+
declare const JustInput: ({ render, ...props }: useRender.ComponentProps<"input">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
+
export { JustInput as default };
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
props
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var JustInput_default = JustInput;
|
|
13
|
-
export {
|
|
14
|
-
JustInput_default as default
|
|
2
|
+
// src/components/elements/JustInput.tsx
|
|
3
|
+
const JustInput = ({ render, ...props }) => {
|
|
4
|
+
return useRender({
|
|
5
|
+
defaultTagName: "input",
|
|
6
|
+
render,
|
|
7
|
+
props
|
|
8
|
+
});
|
|
15
9
|
};
|
|
10
|
+
export { JustInput as default };
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
renderMessages?: ComponentProps<typeof JustDiv>["render"];
|
|
12
|
-
onStateChange?: (state: Record<string, string>) => void;
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
import { MessageFormatter } from "./FormContext.js";
|
|
3
|
+
import { FormAction, FormActionState } from "@omer-x/next-form-actions";
|
|
4
|
+
type BaseFormProps<Data> = Omit<ComponentPropsWithoutRef<"form">, "action"> & {
|
|
5
|
+
action: FormAction<Data>;
|
|
6
|
+
formatMessage?: MessageFormatter;
|
|
7
|
+
defaultValues?: Record<string, unknown>;
|
|
8
|
+
onlyDirty?: boolean;
|
|
9
|
+
resetOnSuccess?: boolean;
|
|
10
|
+
onResult?: (result: FormActionState<Data>) => void;
|
|
13
11
|
};
|
|
14
|
-
declare const BaseForm: ({ action, defaultValues, onlyDirty,
|
|
15
|
-
|
|
16
|
-
export { BaseForm as default };
|
|
12
|
+
declare const BaseForm: <Data>({ action, formatMessage, defaultValues, onlyDirty, resetOnSuccess, onResult, onSubmit, children, ...otherProps }: BaseFormProps<Data>) => import("react").JSX.Element;
|
|
13
|
+
export { BaseForm as default };
|
|
@@ -1,81 +1,78 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
2
|
import { Form } from "@base-ui/react/form";
|
|
4
|
-
import {
|
|
3
|
+
import { Fragment, startTransition, useActionState, useRef } from "react";
|
|
5
4
|
import { getDirtyFormData } from "../../utils/dirty-form.js";
|
|
6
|
-
import JustDiv from "../elements/JustDiv.js";
|
|
7
5
|
import { FormContext } from "./FormContext.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
onStateChange,
|
|
15
|
-
onSubmit,
|
|
16
|
-
children,
|
|
17
|
-
...otherProps
|
|
18
|
-
}) => {
|
|
19
|
-
const [state, formAction, _loading] = useActionState(action, {});
|
|
20
|
-
const fieldsRef = useRef(/* @__PURE__ */ new Set());
|
|
21
|
-
const formRef = useRef(null);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
onStateChange?.(state);
|
|
24
|
-
}, [state]);
|
|
25
|
-
const getFieldMessage = (fieldName) => {
|
|
26
|
-
if (fieldName in state) {
|
|
27
|
-
return state[fieldName];
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
};
|
|
31
|
-
const registerField = (fieldName) => {
|
|
32
|
-
fieldsRef.current.add(fieldName);
|
|
33
|
-
};
|
|
34
|
-
const unregisterField = (fieldName) => {
|
|
35
|
-
fieldsRef.current.delete(fieldName);
|
|
36
|
-
};
|
|
37
|
-
const { formMessages, fieldMessages } = Object.keys(state).reduce((bundle, key) => {
|
|
38
|
-
if (fieldsRef.current.has(key)) {
|
|
39
|
-
return { ...bundle, fieldMessages: { ...bundle.fieldMessages, [key]: state[key] } };
|
|
40
|
-
}
|
|
41
|
-
return { ...bundle, formMessages: { ...bundle.formMessages, [key]: state[key] } };
|
|
42
|
-
}, {
|
|
43
|
-
formMessages: {},
|
|
44
|
-
fieldMessages: {}
|
|
45
|
-
});
|
|
46
|
-
const alteredAction = async (fd) => {
|
|
47
|
-
if (!onlyDirty) return formAction(fd);
|
|
48
|
-
const form = formRef.current;
|
|
49
|
-
if (!form) return formAction(fd);
|
|
50
|
-
return formAction(getDirtyFormData(form, defaultValues));
|
|
51
|
-
};
|
|
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);
|
|
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
|
-
);
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/form/BaseForm.tsx
|
|
8
|
+
const INITIAL_STATE = {
|
|
9
|
+
result: { status: "idle" },
|
|
10
|
+
submissionId: 0,
|
|
11
|
+
resetCount: 0
|
|
77
12
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
13
|
+
const NO_FIELD_ERRORS = {};
|
|
14
|
+
const formatAsIs = (code) => code;
|
|
15
|
+
const BaseForm = ({ action, formatMessage = formatAsIs, defaultValues = {}, onlyDirty = false, resetOnSuccess = false, onResult, onSubmit, children, ...otherProps }) => {
|
|
16
|
+
const submit = async (previous, formData) => {
|
|
17
|
+
const result = await action(previous.result, formData);
|
|
18
|
+
onResult?.(result);
|
|
19
|
+
return {
|
|
20
|
+
result,
|
|
21
|
+
submissionId: previous.submissionId + 1,
|
|
22
|
+
resetCount: resetOnSuccess && result.status === "success" ? previous.resetCount + 1 : previous.resetCount
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const [{ result: state, submissionId, resetCount }, formAction, pending] = useActionState(submit, INITIAL_STATE);
|
|
26
|
+
const fieldsRef = useRef(/* @__PURE__ */ new Set());
|
|
27
|
+
const registerField = (fieldName) => {
|
|
28
|
+
fieldsRef.current.add(fieldName);
|
|
29
|
+
};
|
|
30
|
+
const unregisterField = (fieldName) => {
|
|
31
|
+
fieldsRef.current.delete(fieldName);
|
|
32
|
+
};
|
|
33
|
+
const fieldErrors = state.status === "failure" ? state.fieldErrors : NO_FIELD_ERRORS;
|
|
34
|
+
const mountedFieldErrors = {};
|
|
35
|
+
const messages = [];
|
|
36
|
+
if (state.status === "failure" && state.message) messages.push({
|
|
37
|
+
key: "message",
|
|
38
|
+
type: state.message.type,
|
|
39
|
+
text: formatMessage(state.message.text)
|
|
40
|
+
});
|
|
41
|
+
for (const [fieldName, errors] of Object.entries(fieldErrors)) {
|
|
42
|
+
const texts = errors.map((error) => formatMessage(error.code, error.params));
|
|
43
|
+
if (fieldsRef.current.has(fieldName)) mountedFieldErrors[fieldName] = texts;
|
|
44
|
+
else texts.forEach((text, index) => {
|
|
45
|
+
messages.push({
|
|
46
|
+
key: `field:${fieldName}:${index}`,
|
|
47
|
+
type: "error",
|
|
48
|
+
text
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsx(Form, {
|
|
53
|
+
...otherProps,
|
|
54
|
+
errors: mountedFieldErrors,
|
|
55
|
+
onSubmit: (e) => {
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
onSubmit?.(e);
|
|
58
|
+
if (e.defaultPrevented) return;
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
const form = e.currentTarget;
|
|
61
|
+
const formData = onlyDirty ? getDirtyFormData(form, defaultValues) : new FormData(form, e.nativeEvent.submitter);
|
|
62
|
+
startTransition(() => formAction(formData));
|
|
63
|
+
},
|
|
64
|
+
children: /* @__PURE__ */ jsx(FormContext, {
|
|
65
|
+
value: {
|
|
66
|
+
fieldErrors,
|
|
67
|
+
messages,
|
|
68
|
+
submissionId,
|
|
69
|
+
formatMessage,
|
|
70
|
+
pending,
|
|
71
|
+
registerField,
|
|
72
|
+
unregisterField
|
|
73
|
+
},
|
|
74
|
+
children: /* @__PURE__ */ jsx(Fragment, { children }, resetCount)
|
|
75
|
+
})
|
|
76
|
+
});
|
|
81
77
|
};
|
|
78
|
+
export { BaseForm as default };
|