Replace entire codebase with homarr-labs/homarr

This commit is contained in:
Thomas Camlong
2026-01-15 21:54:44 +01:00
parent c5bc3b1559
commit 4fdd1fe351
4666 changed files with 409577 additions and 147434 deletions

View 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),
});
};

View 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;
}