Files
pterodactyl-panel/resources/scripts/components/form/index.ts
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

58 lines
1.6 KiB
TypeScript

import { createFormHook, type AppFieldExtendedReactFormApi } from '@tanstack/react-form';
import type { FormAsyncValidateOrFn, FormValidateOrFn } from '@tanstack/form-core';
import { fieldContext, formContext } from './context';
import {
TextField,
TextAreaField,
NumberField,
SelectField,
MultiSelectField,
SwitchField,
CheckboxField,
} from './fields';
import { SubmitButton } from './SubmitButton';
const fieldComponents = {
TextField,
TextAreaField,
NumberField,
SelectField,
MultiSelectField,
SwitchField,
CheckboxField,
};
const formComponents = { SubmitButton };
export const { useAppForm } = createFormHook({
fieldContext,
formContext,
fieldComponents,
formComponents,
});
export { default as Form } from './Form';
export { useFormContext, useFieldContext } from './context';
export type { SelectOption } from './fields';
type SyncValidator<TFormData> = FormValidateOrFn<TFormData> | undefined;
type AsyncValidator<TFormData> = FormAsyncValidateOrFn<TFormData> | undefined;
/** Types a `form` prop for a sub-component that renders `<form.AppField>` of its parent's form. */
export type AppForm<TFormData> = AppFieldExtendedReactFormApi<
TFormData,
SyncValidator<TFormData>,
SyncValidator<TFormData>,
AsyncValidator<TFormData>,
SyncValidator<TFormData>,
AsyncValidator<TFormData>,
SyncValidator<TFormData>,
AsyncValidator<TFormData>,
SyncValidator<TFormData>,
AsyncValidator<TFormData>,
AsyncValidator<TFormData>,
unknown,
typeof fieldComponents,
typeof formComponents
>;