@omer-x/tailwind-ui-kit 1.0.0-alpha.6 → 1.0.0-alpha.8
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/dist/components/button/PulseButton.d.ts +3 -5
- package/dist/components/button/PulseButton.js +18 -5
- package/dist/components/form/BaseFormField.d.ts +18 -0
- package/dist/components/form/BaseFormField.js +23 -0
- package/dist/components/form/FieldRoot.d.ts +11 -0
- package/dist/components/form/FieldRoot.js +23 -0
- package/dist/components/form/Form.d.ts +9 -0
- package/dist/components/form/Form.js +37 -0
- package/dist/components/form/FormContext.d.ts +10 -0
- package/dist/components/form/FormContext.js +9 -0
- package/dist/components/form/ServerSideError.d.ts +11 -0
- package/dist/components/form/ServerSideError.js +17 -0
- package/dist/components/form/index.d.ts +6 -2
- package/dist/components/form/index.js +6 -2
- package/package.json +6 -6
- package/dist/components/form/FormField.d.ts +0 -10
- package/dist/components/form/FormField.js +0 -19
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentProps
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
3
|
import { Button } from '@base-ui/react/button';
|
|
4
4
|
|
|
5
|
-
type PulseButtonProps = ComponentProps<typeof Button> & {
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
declare const PulseButton: ({ children, onClick, ...otherProps }: PulseButtonProps) => react.JSX.Element;
|
|
5
|
+
type PulseButtonProps = ComponentProps<typeof Button> & {};
|
|
6
|
+
declare const PulseButton: ({ type, onClick, children, ...otherProps }: PulseButtonProps) => react.JSX.Element;
|
|
9
7
|
|
|
10
8
|
export { PulseButton as default };
|
|
@@ -2,21 +2,34 @@
|
|
|
2
2
|
import { jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Button } from "@base-ui/react/button";
|
|
4
4
|
import {} from "react";
|
|
5
|
+
import { useFormStatus } from "react-dom";
|
|
5
6
|
import { useRipples } from "../../hooks/useRipples.js";
|
|
6
7
|
const PulseButton = ({
|
|
7
|
-
|
|
8
|
+
type,
|
|
8
9
|
onClick,
|
|
10
|
+
children,
|
|
9
11
|
...otherProps
|
|
10
12
|
}) => {
|
|
13
|
+
const { pending } = useFormStatus();
|
|
11
14
|
const [triggerRippleEffect, ripples] = useRipples();
|
|
15
|
+
const submitting = type === "submit" && pending;
|
|
12
16
|
const handleClick = (e) => {
|
|
13
17
|
triggerRippleEffect(e);
|
|
14
18
|
onClick?.(e);
|
|
15
19
|
};
|
|
16
|
-
return /* @__PURE__ */ jsxs(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
return /* @__PURE__ */ jsxs(
|
|
21
|
+
Button,
|
|
22
|
+
{
|
|
23
|
+
...otherProps,
|
|
24
|
+
type,
|
|
25
|
+
onClick: handleClick,
|
|
26
|
+
"data-submitting": submitting ? "" : void 0,
|
|
27
|
+
children: [
|
|
28
|
+
ripples,
|
|
29
|
+
children
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
);
|
|
20
33
|
};
|
|
21
34
|
var PulseButton_default = PulseButton;
|
|
22
35
|
export {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ComponentProps } from 'react';
|
|
3
|
+
import { Field } from '@base-ui/react/field';
|
|
4
|
+
import { getFieldConstraints } from '@omer-x/zod-to-form-constraints';
|
|
5
|
+
import { ZodType } from 'zod';
|
|
6
|
+
|
|
7
|
+
type BaseFormFieldProps = {
|
|
8
|
+
schema: ZodType;
|
|
9
|
+
name: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
renderInput: (props: ReturnType<typeof getFieldConstraints>) => ReactNode;
|
|
12
|
+
renderLabel?: ComponentProps<typeof Field.Label>["render"];
|
|
13
|
+
renderErrors?: ComponentProps<typeof Field.Error>["render"];
|
|
14
|
+
clientSideErrors?: Partial<Record<keyof ValidityState, string | ((payload: string | number | null) => string)>>;
|
|
15
|
+
};
|
|
16
|
+
declare const BaseFormField: ({ schema, name, label, renderInput, renderLabel, renderErrors, clientSideErrors, }: BaseFormFieldProps) => react.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { BaseFormField as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Field } from "@base-ui/react/field";
|
|
3
|
+
import { getErrorMessagePayload, getFieldConstraints } from "@omer-x/zod-to-form-constraints";
|
|
4
|
+
import FieldRoot from "./FieldRoot.js";
|
|
5
|
+
import ServerSideError from "./ServerSideError.js";
|
|
6
|
+
const BaseFormField = ({
|
|
7
|
+
schema,
|
|
8
|
+
name,
|
|
9
|
+
label,
|
|
10
|
+
renderInput,
|
|
11
|
+
renderLabel,
|
|
12
|
+
renderErrors,
|
|
13
|
+
clientSideErrors = {}
|
|
14
|
+
}) => /* @__PURE__ */ jsxs(FieldRoot, { name, className: "flex w-full flex-col items-start gap-1", children: [
|
|
15
|
+
typeof label !== "undefined" && /* @__PURE__ */ jsx(Field.Label, { render: renderLabel, children: label }),
|
|
16
|
+
renderInput(getFieldConstraints(schema)),
|
|
17
|
+
Object.entries(clientSideErrors).map(([stateName, message]) => /* @__PURE__ */ jsx(Field.Error, { match: stateName, render: renderErrors, children: typeof message === "string" ? message : message(getErrorMessagePayload(schema, stateName)) }, stateName)),
|
|
18
|
+
/* @__PURE__ */ jsx(ServerSideError, { name, render: renderErrors })
|
|
19
|
+
] });
|
|
20
|
+
var BaseFormField_default = BaseFormField;
|
|
21
|
+
export {
|
|
22
|
+
BaseFormField_default as default
|
|
23
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type FieldRootProps = {
|
|
5
|
+
name: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
declare const FieldRoot: ({ name, className, children, }: FieldRootProps) => react.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { FieldRoot as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Field } from "@base-ui/react/field";
|
|
4
|
+
import { use, useEffect } from "react";
|
|
5
|
+
import { FormContext } from "./FormContext.js";
|
|
6
|
+
const FieldRoot = ({
|
|
7
|
+
name,
|
|
8
|
+
className,
|
|
9
|
+
children
|
|
10
|
+
}) => {
|
|
11
|
+
const { registerField, unregisterField } = use(FormContext);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
registerField(name);
|
|
14
|
+
return () => {
|
|
15
|
+
unregisterField(name);
|
|
16
|
+
};
|
|
17
|
+
}, [name]);
|
|
18
|
+
return /* @__PURE__ */ jsx(Field.Root, { name, className, children });
|
|
19
|
+
};
|
|
20
|
+
var FieldRoot_default = FieldRoot;
|
|
21
|
+
export {
|
|
22
|
+
FieldRoot_default as default
|
|
23
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
type FormProps = Omit<ComponentProps<"form">, "action"> & {
|
|
5
|
+
action: (initialState: unknown, formData: FormData) => Promise<Record<string, string>>;
|
|
6
|
+
};
|
|
7
|
+
declare const Form: ({ action, className, children, }: FormProps) => react.JSX.Element;
|
|
8
|
+
|
|
9
|
+
export { Form as default };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Form as BaseForm } from "@base-ui/react/form";
|
|
4
|
+
import { useActionState, useRef } from "react";
|
|
5
|
+
import { FormContext } from "./FormContext.js";
|
|
6
|
+
const Form = ({
|
|
7
|
+
action,
|
|
8
|
+
className,
|
|
9
|
+
children
|
|
10
|
+
}) => {
|
|
11
|
+
const [state, formAction, _loading] = useActionState(action, {});
|
|
12
|
+
const fieldsRef = useRef(/* @__PURE__ */ new Set());
|
|
13
|
+
const getError = (fieldName) => {
|
|
14
|
+
if (fieldName in state) {
|
|
15
|
+
return state[fieldName];
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
const registerField = (fieldName) => {
|
|
20
|
+
fieldsRef.current.add(fieldName);
|
|
21
|
+
};
|
|
22
|
+
const unregisterField = (fieldName) => {
|
|
23
|
+
fieldsRef.current.delete(fieldName);
|
|
24
|
+
};
|
|
25
|
+
const globalErrors = Object.fromEntries(Object.entries(state).filter(([key]) => {
|
|
26
|
+
if (!fieldsRef.current.has(key)) return true;
|
|
27
|
+
return key.startsWith("[") && key.endsWith("]");
|
|
28
|
+
}));
|
|
29
|
+
return /* @__PURE__ */ jsxs(BaseForm, { action: formAction, className, errors: state, children: [
|
|
30
|
+
Object.entries(globalErrors).map(([key, value]) => /* @__PURE__ */ jsx("div", { className: "bg-red-500/50", children: value }, key)),
|
|
31
|
+
/* @__PURE__ */ jsx(FormContext, { value: { getError, registerField, unregisterField }, children })
|
|
32
|
+
] });
|
|
33
|
+
};
|
|
34
|
+
var Form_default = Form;
|
|
35
|
+
export {
|
|
36
|
+
Form_default as default
|
|
37
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
interface FormContextInterface {
|
|
4
|
+
getError: (fieldName: string) => string | null;
|
|
5
|
+
registerField: (fieldName: string) => void;
|
|
6
|
+
unregisterField: (fieldName: string) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const FormContext: react.Context<FormContextInterface>;
|
|
9
|
+
|
|
10
|
+
export { FormContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentProps } from 'react';
|
|
3
|
+
import { Field } from '@base-ui/react/field';
|
|
4
|
+
|
|
5
|
+
type ServerSideErrorProps = {
|
|
6
|
+
name: string;
|
|
7
|
+
render?: ComponentProps<typeof Field.Error>["render"];
|
|
8
|
+
};
|
|
9
|
+
declare const ServerSideError: ({ name, render, }: ServerSideErrorProps) => react.JSX.Element;
|
|
10
|
+
|
|
11
|
+
export { ServerSideError as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Field } from "@base-ui/react/field";
|
|
4
|
+
import { use } from "react";
|
|
5
|
+
import { FormContext } from "./FormContext.js";
|
|
6
|
+
const ServerSideError = ({
|
|
7
|
+
name,
|
|
8
|
+
render
|
|
9
|
+
}) => {
|
|
10
|
+
const { getError } = use(FormContext);
|
|
11
|
+
const error = getError(name);
|
|
12
|
+
return /* @__PURE__ */ jsx(Field.Error, { match: error !== null, render, children: error });
|
|
13
|
+
};
|
|
14
|
+
var ServerSideError_default = ServerSideError;
|
|
15
|
+
export {
|
|
16
|
+
ServerSideError_default as default
|
|
17
|
+
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as BaseInput } from './BaseInput.js';
|
|
2
|
+
export { default as Form } from './Form.js';
|
|
3
|
+
export { default as BaseFormField } from './BaseFormField.js';
|
|
2
4
|
import 'react';
|
|
3
|
-
import '@base-ui/react/
|
|
5
|
+
import '@base-ui/react/input';
|
|
6
|
+
import '@base-ui/react/field';
|
|
7
|
+
import '@omer-x/zod-to-form-constraints';
|
|
4
8
|
import 'zod';
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { default as default2 } from "./
|
|
1
|
+
import { default as default2 } from "./BaseInput.js";
|
|
2
|
+
import { default as default3 } from "./Form.js";
|
|
3
|
+
import { default as default4 } from "./BaseFormField.js";
|
|
2
4
|
export {
|
|
3
|
-
|
|
5
|
+
default4 as BaseFormField,
|
|
6
|
+
default2 as BaseInput,
|
|
7
|
+
default3 as Form
|
|
4
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omer-x/tailwind-ui-kit",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.8",
|
|
4
4
|
"description": "Tailwind CSS-based React component library for building user interfaces",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tailwind",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"build": "tsup"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@omer-x/zod-to-form-constraints": "^1.
|
|
70
|
+
"@omer-x/zod-to-form-constraints": "^1.1.2"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@base-ui/react": "^1",
|
|
@@ -82,11 +82,11 @@
|
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@omer-x/eslint-config": "^2.3.2",
|
|
85
|
-
"@tailwindcss/vite": "^4.3.
|
|
86
|
-
"@types/node": "^26.
|
|
85
|
+
"@tailwindcss/vite": "^4.3.2",
|
|
86
|
+
"@types/node": "^26.1.0",
|
|
87
87
|
"@types/react": "^19.2.17",
|
|
88
88
|
"@types/react-dom": "^19.2.3",
|
|
89
|
-
"@vitejs/plugin-react": "^6.0.
|
|
89
|
+
"@vitejs/plugin-react": "^6.0.3",
|
|
90
90
|
"@vitest/coverage-v8": "^4.1.9",
|
|
91
91
|
"esbuild-fix-imports-plugin": "^1.0.23",
|
|
92
92
|
"eslint": "^9.37.0",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"semantic-release": "^25.0.5",
|
|
96
96
|
"tsup": "^8.5.1",
|
|
97
97
|
"typescript": "^5",
|
|
98
|
-
"vite": "^8.
|
|
98
|
+
"vite": "^8.1.3",
|
|
99
99
|
"vitest": "^4.1.9"
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { ZodType } from 'zod';
|
|
4
|
-
|
|
5
|
-
interface FormFieldProps extends useRender.ComponentProps<"input"> {
|
|
6
|
-
schema: ZodType;
|
|
7
|
-
}
|
|
8
|
-
declare const FormField: ({ schema, render, ...otherProps }: FormFieldProps) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
9
|
-
|
|
10
|
-
export { FormField as default };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { getFieldConstraints } from "@omer-x/zod-to-form-constraints";
|
|
4
|
-
import {} from "zod";
|
|
5
|
-
const FormField = ({
|
|
6
|
-
schema,
|
|
7
|
-
render,
|
|
8
|
-
...otherProps
|
|
9
|
-
}) => {
|
|
10
|
-
return useRender({
|
|
11
|
-
defaultTagName: "input",
|
|
12
|
-
render,
|
|
13
|
-
props: mergeProps(getFieldConstraints(schema), otherProps)
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var FormField_default = FormField;
|
|
17
|
-
export {
|
|
18
|
-
FormField_default as default
|
|
19
|
-
};
|