Replace entire codebase with homarr-labs/homarr
This commit is contained in:
4
packages/form/eslint.config.js
Normal file
4
packages/form/eslint.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import baseConfig from "@homarr/eslint-config/base";
|
||||
|
||||
/** @type {import('typescript-eslint').Config} */
|
||||
export default [...baseConfig];
|
||||
2
packages/form/index.ts
Normal file
2
packages/form/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./src";
|
||||
export * from "@mantine/form";
|
||||
40
packages/form/package.json
Normal file
40
packages/form/package.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "@homarr/form",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./index.ts",
|
||||
"./types": "./src/types.ts"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf .turbo node_modules",
|
||||
"format": "prettier --check . --ignore-path ../../.gitignore",
|
||||
"lint": "eslint",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"prettier": "@homarr/prettier-config",
|
||||
"dependencies": {
|
||||
"@homarr/common": "workspace:^0.1.0",
|
||||
"@homarr/translation": "workspace:^0.1.0",
|
||||
"@homarr/validation": "workspace:^0.1.0",
|
||||
"@mantine/form": "^8.3.10",
|
||||
"mantine-form-zod-resolver": "^1.3.0",
|
||||
"zod": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@homarr/eslint-config": "workspace:^0.2.0",
|
||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||
"eslint": "^9.39.2",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
39
packages/form/src/index.ts
Normal file
39
packages/form/src/index.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { useForm } from "@mantine/form";
|
||||
import { zod4Resolver } from "mantine-form-zod-resolver";
|
||||
import type { ZodDiscriminatedUnion, ZodIntersection, ZodObject, ZodPipe } from "zod/v4";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { zodErrorMap } from "@homarr/validation/form/i18n";
|
||||
|
||||
type inferPossibleSchema<
|
||||
TSchema extends
|
||||
| ZodObject
|
||||
| ZodPipe<ZodObject>
|
||||
| ZodIntersection<ZodObject | ZodDiscriminatedUnion<ZodObject[]>, ZodObject>,
|
||||
> = z.infer<TSchema> extends Record<string, unknown> ? z.infer<TSchema> : never;
|
||||
|
||||
export const useZodForm = <
|
||||
TSchema extends
|
||||
| ZodObject
|
||||
| ZodPipe<ZodObject>
|
||||
| ZodIntersection<ZodObject | ZodDiscriminatedUnion<ZodObject[]>, ZodObject>,
|
||||
>(
|
||||
schema: TSchema,
|
||||
options: Omit<
|
||||
Exclude<Parameters<typeof useForm<inferPossibleSchema<TSchema>>>[0], undefined>,
|
||||
"validate" | "validateInputOnBlur" | "validateInputOnChange"
|
||||
>,
|
||||
) => {
|
||||
const t = useI18n();
|
||||
|
||||
z.config({
|
||||
customError: zodErrorMap(t),
|
||||
});
|
||||
return useForm<inferPossibleSchema<TSchema>>({
|
||||
...options,
|
||||
validateInputOnBlur: true,
|
||||
validateInputOnChange: true,
|
||||
validate: zod4Resolver(schema),
|
||||
});
|
||||
};
|
||||
23
packages/form/src/types.ts
Normal file
23
packages/form/src/types.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { ChangeEvent, FocusEvent } from "react";
|
||||
|
||||
export interface InputPropsFor<T, TOnChangeArg, TComponent extends HTMLElement = HTMLInputElement> extends BasePropsFor<
|
||||
TOnChangeArg,
|
||||
TComponent
|
||||
> {
|
||||
value?: T;
|
||||
defaultValue?: T;
|
||||
}
|
||||
|
||||
interface BasePropsFor<TOnChangeArg, TComponent extends HTMLElement> {
|
||||
onChange: (value: TOnChangeArg) => void;
|
||||
error?: string;
|
||||
onBlur?: (event: FocusEvent<TComponent>) => void;
|
||||
onFocus?: (event: FocusEvent<TComponent>) => void;
|
||||
}
|
||||
|
||||
export interface CheckboxProps<
|
||||
TOnChangeArg = ChangeEvent<HTMLInputElement>,
|
||||
TComponent extends HTMLElement = HTMLInputElement,
|
||||
> extends BasePropsFor<TOnChangeArg, TComponent> {
|
||||
checked?: boolean;
|
||||
}
|
||||
8
packages/form/tsconfig.json
Normal file
8
packages/form/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@homarr/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||
},
|
||||
"include": ["*.ts", "src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user