public commit

This commit is contained in:
dswbx
2024-11-16 12:01:47 +01:00
commit 90f80c4280
582 changed files with 49291 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import { Select, type SelectProps } from "@mantine/core";
import { type FieldValues, type UseControllerProps, useController } from "react-hook-form";
export type MantineSelectProps<T extends FieldValues> = UseControllerProps<T> &
Omit<SelectProps, "value" | "defaultValue">;
// @todo: change is not triggered correctly
export function MantineSelect<T extends FieldValues>({
name,
control,
defaultValue,
rules,
shouldUnregister,
onChange,
...props
}: MantineSelectProps<T>) {
const {
field: { value, onChange: fieldOnChange, ...field },
fieldState
} = useController<T>({
name,
control,
defaultValue,
rules,
shouldUnregister
});
return (
<Select
value={value}
onChange={async (e) => {
//console.log("change1", name, field.name, e);
await fieldOnChange({
...new Event("change", { bubbles: true, cancelable: true }),
target: {
value: e,
name: field.name
}
});
// @ts-ignore
onChange?.(e);
}}
error={fieldState.error?.message}
{...field}
{...props}
/>
);
}