Skip to content

[Solid.js] feat: add withForm and createAppForm APIs #1453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/solid-form/src/createField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ interface FieldComponentBoundProps<
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
TParentSubmitMeta,
ExtendedApi = {},
> extends CreateFieldOptionsBound<
TParentData,
TName,
Expand All @@ -373,7 +374,7 @@ interface FieldComponentBoundProps<
TOnSubmitAsync
> {
children: (
fieldApi: () => FieldApi<
fieldApi: (() => FieldApi<
TParentData,
TName,
TData,
Expand All @@ -393,7 +394,8 @@ interface FieldComponentBoundProps<
TFormOnSubmitAsync,
TFormOnServer,
TParentSubmitMeta
>,
>) &
ExtendedApi,
) => JSXElement
}

Expand All @@ -408,6 +410,7 @@ export type FieldComponent<
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
TParentSubmitMeta,
ExtendedApi = {},
> = <
TName extends DeepKeys<TParentData>,
TData extends DeepValue<TParentData, TName>,
Expand Down Expand Up @@ -446,7 +449,8 @@ export type FieldComponent<
TFormOnSubmit,
TFormOnSubmitAsync,
TFormOnServer,
TParentSubmitMeta
TParentSubmitMeta,
ExtendedApi
>) => JSXElement

interface FieldComponentProps<
Expand Down
39 changes: 39 additions & 0 deletions packages/solid-form/src/createForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,45 @@ export interface SolidFormApi<
}) => JSXElement
}

/**
* An extended version of the `FormApi` class that includes Solid-specific functionalities from `SolidFormApi`
*/
export type SolidFormExtendedApi<
TFormData,
TOnMount extends undefined | FormValidateOrFn<TFormData>,
TOnChange extends undefined | FormValidateOrFn<TFormData>,
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
TSubmitMeta,
> = FormApi<
TFormData,
TOnMount,
TOnChange,
TOnChangeAsync,
TOnBlur,
TOnBlurAsync,
TOnSubmit,
TOnSubmitAsync,
TOnServer,
TSubmitMeta
> &
SolidFormApi<
TFormData,
TOnMount,
TOnChange,
TOnChangeAsync,
TOnBlur,
TOnBlurAsync,
TOnSubmit,
TOnSubmitAsync,
TOnServer,
TSubmitMeta
>

export function createForm<
TParentData,
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
Expand Down
1 change: 1 addition & 0 deletions packages/solid-form/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { createForm, type SolidFormApi } from './createForm'

export type { CreateField, FieldComponent } from './createField'
export { createField, Field } from './createField'
export { makeFormCreate, makeFormCreateContexts } from './makeFormCreate'
Loading