@omer-x/tailwind-ui-kit 1.0.0-alpha.2 → 1.0.0-alpha.20

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.
Files changed (71) hide show
  1. package/MIGRATION.md +210 -0
  2. package/README.md +414 -0
  3. package/dist/components/button/BaseButton.d.ts +27 -11
  4. package/dist/components/button/BaseButton.js +57 -51
  5. package/dist/components/button/index.d.ts +2 -4
  6. package/dist/components/button/index.js +1 -4
  7. package/dist/components/dialog/AnimatedPopup.d.ts +3 -6
  8. package/dist/components/dialog/AnimatedPopup.js +7 -31
  9. package/dist/components/dialog/DialogBackdrop.d.ts +3 -6
  10. package/dist/components/dialog/DialogBackdrop.js +6 -22
  11. package/dist/components/dialog/DialogTitle.d.ts +3 -6
  12. package/dist/components/dialog/DialogTitle.js +6 -15
  13. package/dist/components/dialog/index.d.ts +4 -5
  14. package/dist/components/dialog/index.js +4 -8
  15. package/dist/components/elements/JustAnchor.d.ts +3 -0
  16. package/dist/components/elements/JustAnchor.js +10 -0
  17. package/dist/components/elements/JustButton.d.ts +3 -0
  18. package/dist/components/elements/JustButton.js +10 -0
  19. package/dist/components/elements/JustDiv.d.ts +3 -0
  20. package/dist/components/elements/JustDiv.js +10 -0
  21. package/dist/components/elements/JustInput.d.ts +3 -0
  22. package/dist/components/elements/JustInput.js +10 -0
  23. package/dist/components/elements/JustSpan.d.ts +3 -0
  24. package/dist/components/elements/JustSpan.js +10 -0
  25. package/dist/components/form/BaseForm.d.ts +13 -0
  26. package/dist/components/form/BaseForm.js +78 -0
  27. package/dist/components/form/BaseFormField.d.ts +14 -0
  28. package/dist/components/form/BaseFormField.js +32 -0
  29. package/dist/components/form/BaseInput.d.ts +7 -0
  30. package/dist/components/form/BaseInput.js +21 -0
  31. package/dist/components/form/BaseSwitch.d.ts +8 -0
  32. package/dist/components/form/BaseSwitch.js +19 -0
  33. package/dist/components/form/ClientSideError.d.ts +9 -0
  34. package/dist/components/form/ClientSideError.js +39 -0
  35. package/dist/components/form/FieldRoot.d.ts +8 -0
  36. package/dist/components/form/FieldRoot.js +21 -0
  37. package/dist/components/form/FormContext.d.ts +28 -0
  38. package/dist/components/form/FormContext.js +12 -0
  39. package/dist/components/form/ServerSideError.d.ts +8 -0
  40. package/dist/components/form/ServerSideError.js +15 -0
  41. package/dist/components/form/index.d.ts +7 -0
  42. package/dist/components/form/index.js +6 -0
  43. package/dist/components/form/useFormMessages.d.ts +10 -0
  44. package/dist/components/form/useFormMessages.js +16 -0
  45. package/dist/components/layout/Container.d.ts +5 -8
  46. package/dist/components/layout/Container.js +8 -10
  47. package/dist/components/layout/index.d.ts +2 -3
  48. package/dist/components/layout/index.js +1 -4
  49. package/dist/components/page/Pagination.d.ts +21 -0
  50. package/dist/components/page/Pagination.js +65 -0
  51. package/dist/components/page/index.d.ts +3 -0
  52. package/dist/components/page/index.js +3 -0
  53. package/dist/components/page/usePagination.d.ts +30 -0
  54. package/dist/components/page/usePagination.js +41 -0
  55. package/dist/components/table/Tdx.d.ts +5 -8
  56. package/dist/components/table/Tdx.js +13 -9
  57. package/dist/components/table/index.d.ts +2 -3
  58. package/dist/components/table/index.js +1 -4
  59. package/dist/hooks/useRipples.d.ts +2 -0
  60. package/dist/hooks/useRipples.js +49 -0
  61. package/dist/styles/ripple.module.css +1 -0
  62. package/dist/utils/cn.d.ts +6 -5
  63. package/dist/utils/cn.js +8 -6
  64. package/dist/utils/dirty-form.d.ts +7 -0
  65. package/dist/utils/dirty-form.js +40 -0
  66. package/dist/utils/index.d.ts +2 -2
  67. package/dist/utils/index.js +1 -4
  68. package/package.json +37 -23
  69. package/dist/components/button/PulseButton.d.ts +0 -10
  70. package/dist/components/button/PulseButton.js +0 -24
  71. package/dist/styles/ripple.module.d.ts +0 -2
@@ -1,52 +1,58 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { faSpinner } from "@fortawesome/free-solid-svg-icons/faSpinner";
3
- import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4
- import {} from "react";
5
- import { cn } from "../../utils/cn.js";
6
- import PulseButton from "./PulseButton.js";
7
- const BaseButton = ({
8
- size = "md",
9
- pending = false,
10
- disabled,
11
- focusableWhenDisabled,
12
- className,
13
- children,
14
- ...otherProps
15
- }) => /* @__PURE__ */ jsxs(
16
- PulseButton,
17
- {
18
- className: (state) => cn({
19
- // Size
20
- "h-12 px-5 text-base leading-7 gap-3": size === "lg",
21
- "h-10 px-4 text-sm leading-6 gap-3": size === "md",
22
- "h-9 px-3 text-sm leading-5 gap-2": size === "sm",
23
- "h-8 px-2.5 text-xs leading-4 gap-2": size === "xs"
24
- }, [
25
- // Base
26
- "relative",
27
- "flex items-center justify-center",
28
- "rounded-md",
29
- "font-medium",
30
- "select-none",
31
- "outline-0",
32
- "transition-colors",
33
- // Focus
34
- "focus-visible:outline-2",
35
- "focus-visible:outline-offset-2",
36
- // Cursor
37
- "cursor-pointer",
38
- "data-disabled:cursor-default"
39
- ], typeof className === "function" ? className(state) : className),
40
- disabled,
41
- focusableWhenDisabled: pending || focusableWhenDisabled,
42
- ...otherProps,
43
- children: [
44
- pending && /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faSpinner, size: "lg", className: "fa-spin-pulse" }),
45
- children
46
- ]
47
- }
48
- );
49
- var BaseButton_default = BaseButton;
50
- export {
51
- BaseButton_default as default
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,4 +1,2 @@
1
- export { default as BaseButton } from './BaseButton.js';
2
- import 'react/jsx-runtime';
3
- import 'react';
4
- import '@base-ui/react/button';
1
+ import BaseButton from "./BaseButton.js";
2
+ export { BaseButton };
@@ -1,4 +1 @@
1
- import { default as default2 } from "./BaseButton.js";
2
- export {
3
- default2 as BaseButton
4
- };
1
+ export { default as BaseButton } from "./BaseButton.js";
@@ -1,6 +1,3 @@
1
- import * as react from 'react';
2
- import { useRender } from '@base-ui/react/use-render';
3
-
4
- declare const AnimatedPopup: ({ render, ...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,34 +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 "../../utils/cn.js";
4
- const AnimatedPopup = ({ render, ...otherProps }) => useRender({
5
- defaultTagName: "div",
6
- render,
7
- props: mergeProps({
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
- )
29
- }, otherProps)
3
+ import { cn } from "cn";
4
+ // src/components/dialog/AnimatedPopup.tsx
5
+ const AnimatedPopup = ({ render, className, ...otherProps }) => useRender({
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)
30
9
  });
31
- var AnimatedPopup_default = AnimatedPopup;
32
- export {
33
- AnimatedPopup_default as default
34
- };
10
+ export { AnimatedPopup as default };
@@ -1,6 +1,3 @@
1
- import * as react from 'react';
2
- import { useRender } from '@base-ui/react/use-render';
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 "../../utils/cn.js";
3
+ import { cn } from "cn";
4
+ // src/components/dialog/DialogBackdrop.tsx
4
5
  const DialogBackdrop = ({ render, ...otherProps }) => useRender({
5
- defaultTagName: "div",
6
- render,
7
- props: mergeProps({
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
- var DialogBackdrop_default = DialogBackdrop;
24
- export {
25
- DialogBackdrop_default as default
26
- };
10
+ export { DialogBackdrop as default };
@@ -1,6 +1,3 @@
1
- import * as react from 'react';
2
- import { useRender } from '@base-ui/react/use-render';
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 "../../utils/cn.js";
3
+ import { cn } from "cn";
4
+ // src/components/dialog/DialogTitle.tsx
4
5
  const DialogTitle = ({ render, ...otherProps }) => useRender({
5
- defaultTagName: "h2",
6
- render,
7
- props: mergeProps({
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
- var DialogTitle_default = DialogTitle;
17
- export {
18
- DialogTitle_default as default
19
- };
10
+ export { DialogTitle as default };
@@ -1,5 +1,4 @@
1
- export { default as AnimatedPopup } from './AnimatedPopup.js';
2
- export { default as DialogBackdrop } from './DialogBackdrop.js';
3
- export { default as DialogTitle } from './DialogTitle.js';
4
- import 'react';
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 { default as default2 } from "./AnimatedPopup.js";
2
- import { default as default3 } from "./DialogBackdrop.js";
3
- import { default as default4 } from "./DialogTitle.js";
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 };
@@ -0,0 +1,3 @@
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 };
@@ -0,0 +1,10 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ // src/components/elements/JustAnchor.tsx
3
+ const JustAnchor = ({ render, ...props }) => {
4
+ return useRender({
5
+ defaultTagName: "a",
6
+ render,
7
+ props
8
+ });
9
+ };
10
+ export { JustAnchor as default };
@@ -0,0 +1,3 @@
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 };
@@ -0,0 +1,10 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ // src/components/elements/JustButton.tsx
3
+ const JustButton = ({ render, ...props }) => {
4
+ return useRender({
5
+ defaultTagName: "button",
6
+ render,
7
+ props
8
+ });
9
+ };
10
+ export { JustButton as default };
@@ -0,0 +1,3 @@
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 };
@@ -0,0 +1,10 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ // src/components/elements/JustDiv.tsx
3
+ const JustDiv = ({ render, ...props }) => {
4
+ return useRender({
5
+ defaultTagName: "div",
6
+ render,
7
+ props
8
+ });
9
+ };
10
+ export { JustDiv as default };
@@ -0,0 +1,3 @@
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 };
@@ -0,0 +1,10 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ // src/components/elements/JustInput.tsx
3
+ const JustInput = ({ render, ...props }) => {
4
+ return useRender({
5
+ defaultTagName: "input",
6
+ render,
7
+ props
8
+ });
9
+ };
10
+ export { JustInput as default };
@@ -0,0 +1,3 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ declare const JustSpan: ({ render, ...props }: useRender.ComponentProps<"span">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
3
+ export { JustSpan as default };
@@ -0,0 +1,10 @@
1
+ import { useRender } from "@base-ui/react/use-render";
2
+ // src/components/elements/JustSpan.tsx
3
+ const JustSpan = ({ render, ...props }) => {
4
+ return useRender({
5
+ defaultTagName: "span",
6
+ render,
7
+ props
8
+ });
9
+ };
10
+ export { JustSpan as default };
@@ -0,0 +1,13 @@
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;
11
+ };
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 };
@@ -0,0 +1,78 @@
1
+ "use client";
2
+ import { Form } from "@base-ui/react/form";
3
+ import { Fragment, startTransition, useActionState, useRef } from "react";
4
+ import { getDirtyFormData } from "../../utils/dirty-form.js";
5
+ import { FormContext } from "./FormContext.js";
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
12
+ };
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
+ });
77
+ };
78
+ export { BaseForm as default };
@@ -0,0 +1,14 @@
1
+ import { Field } from "@base-ui/react/field";
2
+ import { ComponentProps } from "react";
3
+ import { ZodType } from "zod";
4
+ type BaseFormFieldProps = {
5
+ schema: ZodType;
6
+ name: string;
7
+ label?: string;
8
+ control?: ComponentProps<typeof Field.Control>["render"];
9
+ renderLabel?: ComponentProps<typeof Field.Label>["render"];
10
+ renderErrors?: ComponentProps<typeof Field.Error>["render"];
11
+ className?: string;
12
+ };
13
+ declare const BaseFormField: ({ schema, name, label, control, renderLabel, renderErrors, className }: BaseFormFieldProps) => import("react").JSX.Element;
14
+ export { BaseFormField as default };
@@ -0,0 +1,32 @@
1
+ import { Field } from "@base-ui/react/field";
2
+ import { getFieldConstraints } from "@omer-x/zod-to-form-constraints";
3
+ import { cn } from "cn";
4
+ import ClientSideError from "./ClientSideError.js";
5
+ import FieldRoot from "./FieldRoot.js";
6
+ import ServerSideError from "./ServerSideError.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ // src/components/form/BaseFormField.tsx
9
+ const BaseFormField = ({ schema, name, label, control, renderLabel, renderErrors, className }) => /* @__PURE__ */ jsxs(FieldRoot, {
10
+ name,
11
+ className: cn("flex w-full flex-col items-start gap-1", className),
12
+ children: [
13
+ typeof label !== "undefined" && /* @__PURE__ */ jsx(Field.Label, {
14
+ render: renderLabel,
15
+ children: label
16
+ }),
17
+ /* @__PURE__ */ jsx(Field.Control, {
18
+ name,
19
+ render: control,
20
+ ...getFieldConstraints(schema)
21
+ }),
22
+ /* @__PURE__ */ jsx(ClientSideError, {
23
+ schema,
24
+ render: renderErrors
25
+ }),
26
+ /* @__PURE__ */ jsx(ServerSideError, {
27
+ name,
28
+ render: renderErrors
29
+ })
30
+ ]
31
+ });
32
+ export { BaseFormField as default };
@@ -0,0 +1,7 @@
1
+ import { ComponentProps } from "react";
2
+ import JustInput from "../elements/JustInput.js";
3
+ type BaseInputProps = Omit<ComponentProps<typeof JustInput>, "size"> & {
4
+ size?: "lg" | "md" | "sm" | "xs";
5
+ };
6
+ declare const BaseInput: ({ size, className, ...otherProps }: BaseInputProps) => import("react").JSX.Element;
7
+ export { BaseInput as default };
@@ -0,0 +1,21 @@
1
+ import { cn } from "cn";
2
+ import "react";
3
+ import JustInput from "../elements/JustInput.js";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/components/form/BaseInput.tsx
6
+ const BaseInput = ({ size = "md", className, ...otherProps }) => /* @__PURE__ */ jsx(JustInput, {
7
+ ...otherProps,
8
+ className: cn({
9
+ "h-12 px-5 text-base": size === "lg",
10
+ "h-9 px-3 text-sm": size === "md",
11
+ "h-8 px-2.5 text-sm": size === "sm",
12
+ "h-7 px-2 text-xs": size === "xs"
13
+ }, [
14
+ "rounded-md",
15
+ "outline-2",
16
+ "outline-offset-2",
17
+ "outline-transparent",
18
+ "transition-colors"
19
+ ], className)
20
+ });
21
+ export { BaseInput as default };
@@ -0,0 +1,8 @@
1
+ import { Switch } from "@base-ui/react/switch";
2
+ import { ComponentProps, ReactNode } from "react";
3
+ type BaseSwitchProps = ComponentProps<typeof Switch.Root> & {
4
+ label: ReactNode;
5
+ renderThumb?: ComponentProps<typeof Switch.Thumb>["render"];
6
+ };
7
+ declare const BaseSwitch: ({ label, renderThumb, value, uncheckedValue, className, ...otherProps }: BaseSwitchProps) => import("react").JSX.Element;
8
+ export { BaseSwitch as default };
@@ -0,0 +1,19 @@
1
+ import { Switch } from "@base-ui/react/switch";
2
+ import { cn } from "cn";
3
+ import "react";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ // src/components/form/BaseSwitch.tsx
6
+ const BaseSwitch = ({ label, renderThumb, value = "true", uncheckedValue = "false", className, ...otherProps }) => /* @__PURE__ */ jsxs("label", {
7
+ className: "flex items-center gap-2 text-sm font-normal",
8
+ children: [/* @__PURE__ */ jsx(Switch.Root, {
9
+ ...otherProps,
10
+ value,
11
+ uncheckedValue,
12
+ className: cn("flex", "h-5", "w-9", "shrink-0", "p-0.5", "transition-colors", "duration-150", "ease-[ease]", "focus-visible:outline-2", "focus-visible:outline-offset-2", className),
13
+ children: /* @__PURE__ */ jsx(Switch.Thumb, {
14
+ className: cn("size-3.5", "transition-[translate,background-color]", "duration-150", "ease-[ease]", "data-checked:translate-x-4"),
15
+ render: renderThumb
16
+ })
17
+ }), label]
18
+ });
19
+ export { BaseSwitch as default };
@@ -0,0 +1,9 @@
1
+ import { Field } from "@base-ui/react/field";
2
+ import { ComponentProps } from "react";
3
+ import { ZodType } from "zod";
4
+ type ClientSideErrorProps = {
5
+ schema: ZodType;
6
+ render?: ComponentProps<typeof Field.Error>["render"];
7
+ };
8
+ declare const ClientSideError: ({ schema, render }: ClientSideErrorProps) => import("react").JSX.Element[];
9
+ export { ClientSideError as default };
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ import { Field } from "@base-ui/react/field";
3
+ import { getErrorMessagePayload } from "@omer-x/zod-to-form-constraints";
4
+ import { use } from "react";
5
+ import { FormContext } from "./FormContext.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ // src/components/form/ClientSideError.tsx
8
+ const VALIDITY_STATES = [
9
+ "valueMissing",
10
+ "typeMismatch",
11
+ "patternMismatch",
12
+ "tooShort",
13
+ "tooLong",
14
+ "rangeUnderflow",
15
+ "rangeOverflow",
16
+ "stepMismatch",
17
+ "badInput"
18
+ ];
19
+ const PARAM_NAMES = {
20
+ tooShort: "minimum",
21
+ rangeUnderflow: "minimum",
22
+ tooLong: "maximum",
23
+ rangeOverflow: "maximum"
24
+ };
25
+ const FormattedError = ({ schema, state }) => {
26
+ const { formatMessage } = use(FormContext);
27
+ const paramName = PARAM_NAMES[state];
28
+ if (!paramName) return formatMessage(state);
29
+ return formatMessage(state, { [paramName]: getErrorMessagePayload(schema, state) });
30
+ };
31
+ const ClientSideError = ({ schema, render }) => VALIDITY_STATES.map((state) => /* @__PURE__ */ jsx(Field.Error, {
32
+ match: state,
33
+ render,
34
+ children: /* @__PURE__ */ jsx(FormattedError, {
35
+ schema,
36
+ state
37
+ })
38
+ }, state));
39
+ export { ClientSideError as default };
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from "react";
2
+ type FieldRootProps = {
3
+ name: string;
4
+ className?: string;
5
+ children: ReactNode;
6
+ };
7
+ declare const FieldRoot: ({ name, className, children }: FieldRootProps) => import("react").JSX.Element;
8
+ export { FieldRoot as default };