@omer-x/tailwind-ui-kit 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +247 -0
- package/README.md +460 -0
- package/dist/components/button/BaseButton.d.ts +39 -12
- 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 +7 -6
- package/dist/components/dialog/AnimatedPopup.js +8 -33
- package/dist/components/dialog/DialogBackdrop.d.ts +7 -6
- package/dist/components/dialog/DialogBackdrop.js +7 -24
- package/dist/components/dialog/DialogTitle.d.ts +7 -6
- package/dist/components/dialog/DialogTitle.js +7 -17
- package/dist/components/dialog/index.d.ts +4 -5
- package/dist/components/dialog/index.js +4 -8
- package/dist/components/elements/JustAnchor.d.ts +7 -0
- package/dist/components/elements/JustAnchor.js +10 -0
- package/dist/components/elements/JustButton.d.ts +7 -0
- package/dist/components/elements/JustButton.js +10 -0
- package/dist/components/elements/JustDiv.d.ts +7 -0
- package/dist/components/elements/JustDiv.js +10 -0
- package/dist/components/elements/JustInput.d.ts +7 -0
- package/dist/components/elements/JustInput.js +10 -0
- package/dist/components/elements/JustSpan.d.ts +7 -0
- package/dist/components/elements/JustSpan.js +10 -0
- package/dist/components/form/BaseForm.d.ts +13 -0
- package/dist/components/form/BaseForm.js +78 -0
- package/dist/components/form/BaseFormField.d.ts +24 -0
- package/dist/components/form/BaseFormField.js +32 -0
- package/dist/components/form/BaseInput.d.ts +7 -0
- package/dist/components/form/BaseInput.js +21 -0
- package/dist/components/form/BaseSwitch.d.ts +33 -0
- package/dist/components/form/BaseSwitch.js +20 -0
- package/dist/components/form/ClientSideError.d.ts +9 -0
- package/dist/components/form/ClientSideError.js +39 -0
- package/dist/components/form/FieldRoot.d.ts +8 -0
- package/dist/components/form/FieldRoot.js +21 -0
- package/dist/components/form/FormContext.d.ts +28 -0
- package/dist/components/form/FormContext.js +12 -0
- package/dist/components/form/ServerSideError.d.ts +8 -0
- package/dist/components/form/ServerSideError.js +15 -0
- package/dist/components/form/index.d.ts +7 -0
- package/dist/components/form/index.js +6 -0
- 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 -3
- package/dist/components/layout/index.js +1 -4
- package/dist/components/page/Pagination.d.ts +21 -0
- package/dist/components/page/Pagination.js +65 -0
- package/dist/components/page/index.d.ts +3 -0
- package/dist/components/page/index.js +3 -0
- package/dist/components/page/usePagination.d.ts +30 -0
- package/dist/components/page/usePagination.js +41 -0
- 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 -3
- package/dist/components/table/index.js +1 -4
- package/dist/hooks/useRipples.d.ts +2 -0
- package/dist/hooks/useRipples.js +49 -0
- 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 +7 -0
- package/dist/utils/dirty-form.js +40 -0
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +2 -3
- package/dist/utils/render.d.ts +31 -0
- package/dist/utils/render.js +24 -0
- package/package.json +38 -23
- package/dist/components/button/PulseButton.d.ts +0 -10
- package/dist/components/button/PulseButton.js +0 -24
- package/dist/styles/ripple.module.d.ts +0 -2
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRender } from "
|
|
3
|
-
|
|
4
|
-
const AnimatedPopup = ({ render, ...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
|
-
)
|
|
29
|
-
}, otherProps)
|
|
1
|
+
import { cn } from "cn";
|
|
2
|
+
import { mergeProps, useRender } from "../../utils/render.js";
|
|
3
|
+
// src/components/dialog/AnimatedPopup.tsx
|
|
4
|
+
const AnimatedPopup = ({ render, className, ...otherProps }) => useRender({
|
|
5
|
+
defaultTagName: "div",
|
|
6
|
+
render,
|
|
7
|
+
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
8
|
});
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
AnimatedPopup_default as default
|
|
34
|
-
};
|
|
9
|
+
export { AnimatedPopup as default };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type DialogBackdropProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
declare const DialogBackdrop: ({ render, ...otherProps }: DialogBackdropProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export { DialogBackdrop as default };
|
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRender } from "
|
|
3
|
-
|
|
1
|
+
import { cn } from "cn";
|
|
2
|
+
import { mergeProps, useRender } from "../../utils/render.js";
|
|
3
|
+
// src/components/dialog/DialogBackdrop.tsx
|
|
4
4
|
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)
|
|
5
|
+
defaultTagName: "div",
|
|
6
|
+
render,
|
|
7
|
+
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
8
|
});
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
DialogBackdrop_default as default
|
|
26
|
-
};
|
|
9
|
+
export { DialogBackdrop as default };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type DialogTitleProps = ComponentProps<"h2"> & {
|
|
4
|
+
render?: RenderProp<"h2">;
|
|
5
|
+
};
|
|
6
|
+
declare const DialogTitle: ({ render, ...otherProps }: DialogTitleProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export { DialogTitle as default };
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRender } from "
|
|
3
|
-
|
|
1
|
+
import { cn } from "cn";
|
|
2
|
+
import { mergeProps, useRender } from "../../utils/render.js";
|
|
3
|
+
// src/components/dialog/DialogTitle.tsx
|
|
4
4
|
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)
|
|
5
|
+
defaultTagName: "h2",
|
|
6
|
+
render,
|
|
7
|
+
props: mergeProps({ className: cn("-mt-1.5", "mb-1", "text-xl", "font-semibold") }, otherProps)
|
|
15
8
|
});
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
DialogTitle_default as default
|
|
19
|
-
};
|
|
9
|
+
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 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustAnchorProps = ComponentProps<"a"> & {
|
|
4
|
+
render?: RenderProp<"a">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustAnchor: ({ render, ...props }: JustAnchorProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export { JustAnchor as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustButtonProps = ComponentProps<"button"> & {
|
|
4
|
+
render?: RenderProp<"button">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustButton: ({ render, ...props }: JustButtonProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export { JustButton as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustDivProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustDiv: ({ render, ...props }: JustDivProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export { JustDiv as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustInputProps = ComponentProps<"input"> & {
|
|
4
|
+
render?: RenderProp<"input">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustInput: ({ render, ...props }: JustInputProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
export { JustInput as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustSpanProps = ComponentProps<"span"> & {
|
|
4
|
+
render?: RenderProp<"span">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustSpan: ({ render, ...props }: JustSpanProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
|
+
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,24 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ZodType } from "zod";
|
|
3
|
+
export type FieldState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
/** The control has lost focus at least once. */
|
|
6
|
+
touched: boolean;
|
|
7
|
+
/** The value differs from the initial one. */
|
|
8
|
+
dirty: boolean;
|
|
9
|
+
/** `null` until the field is validated. */
|
|
10
|
+
valid: boolean | null;
|
|
11
|
+
filled: boolean;
|
|
12
|
+
focused: boolean;
|
|
13
|
+
};
|
|
14
|
+
type BaseFormFieldProps = {
|
|
15
|
+
schema: ZodType;
|
|
16
|
+
name: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
control?: RenderProp<"input", FieldState>;
|
|
19
|
+
renderLabel?: RenderProp<"label", FieldState>;
|
|
20
|
+
renderErrors?: RenderProp<"div", FieldState>;
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
declare const BaseFormField: ({ schema, name, label, control, renderLabel, renderErrors, className }: BaseFormFieldProps) => import("react").JSX.Element;
|
|
24
|
+
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,33 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
export type SwitchState = {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
required: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseSwitchProps = Omit<ComponentProps<"span">, "onChange" | "defaultChecked" | "defaultValue"> & {
|
|
10
|
+
label: ReactNode;
|
|
11
|
+
render?: RenderProp<"span", SwitchState>;
|
|
12
|
+
renderThumb?: RenderProp<"span", SwitchState>;
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Submitted when checked. */
|
|
15
|
+
value?: string;
|
|
16
|
+
/** Submitted when unchecked. */
|
|
17
|
+
uncheckedValue?: string;
|
|
18
|
+
checked?: boolean;
|
|
19
|
+
defaultChecked?: boolean;
|
|
20
|
+
/** Called with the new state and the DOM event that changed it. */
|
|
21
|
+
onCheckedChange?: (checked: boolean, event: Event) => void;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
readOnly?: boolean;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
/** The `id` of a `<form>` to submit with, when the switch isn't inside it. */
|
|
26
|
+
form?: string;
|
|
27
|
+
/** A ref to the hidden `<input>` that holds the value. */
|
|
28
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
29
|
+
/** Set to `true` when `render` renders a `<button>`. */
|
|
30
|
+
nativeButton?: boolean;
|
|
31
|
+
};
|
|
32
|
+
declare const BaseSwitch: ({ label, renderThumb, onCheckedChange, value, uncheckedValue, className, ...otherProps }: BaseSwitchProps) => import("react").JSX.Element;
|
|
33
|
+
export { BaseSwitch as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
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, onCheckedChange, 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
|
+
onCheckedChange: onCheckedChange && ((checked, details) => onCheckedChange(checked, details.event)),
|
|
13
|
+
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),
|
|
14
|
+
children: /* @__PURE__ */ jsx(Switch.Thumb, {
|
|
15
|
+
className: cn("size-3.5", "transition-[translate,background-color]", "duration-150", "ease-[ease]", "data-checked:translate-x-4"),
|
|
16
|
+
render: renderThumb
|
|
17
|
+
})
|
|
18
|
+
}), label]
|
|
19
|
+
});
|
|
20
|
+
export { BaseSwitch as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FieldState } from "./BaseFormField.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ZodType } from "zod";
|
|
4
|
+
type ClientSideErrorProps = {
|
|
5
|
+
schema: ZodType;
|
|
6
|
+
render?: RenderProp<"div", FieldState>;
|
|
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 };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Field } from "@base-ui/react/field";
|
|
3
|
+
import { use, useEffect } from "react";
|
|
4
|
+
import { FormContext } from "./FormContext.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/components/form/FieldRoot.tsx
|
|
7
|
+
const FieldRoot = ({ name, className, children }) => {
|
|
8
|
+
const { registerField, unregisterField } = use(FormContext);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
registerField(name);
|
|
11
|
+
return () => {
|
|
12
|
+
unregisterField(name);
|
|
13
|
+
};
|
|
14
|
+
}, [name]);
|
|
15
|
+
return /* @__PURE__ */ jsx(Field.Root, {
|
|
16
|
+
name,
|
|
17
|
+
className,
|
|
18
|
+
children
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export { FieldRoot as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FieldError, FormMessage } from "@omer-x/next-form-actions";
|
|
2
|
+
/**
|
|
3
|
+
* Turns an error code (a server error code, a browser validity state or a form message text)
|
|
4
|
+
* and its params into display text.
|
|
5
|
+
*/
|
|
6
|
+
export type MessageFormatter = (code: string, params?: Record<string, unknown>) => string;
|
|
7
|
+
/**
|
|
8
|
+
* A form-level message of the latest result, already formatted.
|
|
9
|
+
*/
|
|
10
|
+
export type DisplayedFormMessage = {
|
|
11
|
+
/**
|
|
12
|
+
* Stable within one result, for use as a React key.
|
|
13
|
+
*/
|
|
14
|
+
key: string;
|
|
15
|
+
type: FormMessage["type"];
|
|
16
|
+
text: string;
|
|
17
|
+
};
|
|
18
|
+
interface FormContextInterface {
|
|
19
|
+
fieldErrors: Record<string, FieldError[]>;
|
|
20
|
+
messages: DisplayedFormMessage[];
|
|
21
|
+
submissionId: number;
|
|
22
|
+
formatMessage: MessageFormatter;
|
|
23
|
+
pending: boolean;
|
|
24
|
+
registerField: (fieldName: string) => void;
|
|
25
|
+
unregisterField: (fieldName: string) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare const FormContext: import("react").Context<FormContextInterface>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
// src/components/form/FormContext.ts
|
|
3
|
+
const FormContext = createContext({
|
|
4
|
+
fieldErrors: {},
|
|
5
|
+
messages: [],
|
|
6
|
+
submissionId: 0,
|
|
7
|
+
formatMessage: (code) => code,
|
|
8
|
+
pending: false,
|
|
9
|
+
registerField: () => null,
|
|
10
|
+
unregisterField: () => null
|
|
11
|
+
});
|
|
12
|
+
export { FormContext };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FieldState } from "./BaseFormField.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
type ServerSideErrorProps = {
|
|
4
|
+
name: string;
|
|
5
|
+
render?: RenderProp<"div", FieldState>;
|
|
6
|
+
};
|
|
7
|
+
declare const ServerSideError: ({ name, render }: ServerSideErrorProps) => import("react").JSX.Element[];
|
|
8
|
+
export { ServerSideError as default };
|