mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-09 20:37:47 +00:00
feat: Add Vue adapter (#416)
* chore: initial work at scaffolding Vue package * chore: initial work on adding in useField and useForm API * chore: fix build for Vue package * chore: migrate to slots for functional comps * chore: got initial fields rendering * chore: add component names for debuggability * chore: fix error regarding passdown props * chore: fix Promise constructor error in demo * chore: initial work at writing vue store implementation * feat: add initial useStore and Subscribe instances * fix: state is now passed as a dedicated reactive option * chore: temporarily remove Vue 2 typechecking * chore: make Provider and selector optional * chore: add createFormFactory * chore: attempt 1 of test - JSX * chore: attempt 2 of test - Vue JSX * chore: attempt 3 of test - H * chore: migrate to proper h function * chore: fix tests by bumping package * chore: fix JSX typings * chore: add another test for useForm * chore: listen for fieldAPIs to update * fix: fields should now update during mount * chore: add test for useField in Vue * test: add useField Vue tests * docs: add early docs for Vue package
This commit is contained in:
46
docs/framework/vue/quick-start.md
Normal file
46
docs/framework/vue/quick-start.md
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
id: quick-start
|
||||
title: Quick Start
|
||||
---
|
||||
|
||||
The bare minimum to get started with TanStack Form is to create a form and add a field. Keep in mind that this example does not include any validation or error handling... yet.
|
||||
|
||||
```vue
|
||||
<!-- App.vue -->
|
||||
<script setup>
|
||||
import { useForm } from '@tanstack/vue-form'
|
||||
|
||||
const form = useForm({
|
||||
// Memoize your default values to prevent re-renders
|
||||
defaultValues: {
|
||||
fullName: '',
|
||||
},
|
||||
onSubmit: async (values) => {
|
||||
// Do something with form data
|
||||
console.log(values)
|
||||
},
|
||||
})
|
||||
|
||||
form.provideFormContext()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<form.Field name="fullName">
|
||||
<template v-slot="field">
|
||||
<input
|
||||
:name="field.name"
|
||||
:value="field.state.value"
|
||||
:onBlur="field.handleBlur"
|
||||
:onChange="(e) => field.handleChange(e.target.value)"
|
||||
/>
|
||||
</template>
|
||||
</form.Field>
|
||||
</div>
|
||||
<button type="submit">Submit</button>
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
From here, you'll be ready to explore all of the other features of TanStack Form!
|
||||
6
docs/framework/vue/reference/Field.md
Normal file
6
docs/framework/vue/reference/Field.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: field
|
||||
title: Field
|
||||
---
|
||||
|
||||
Please see [/packages/vue-form/src/useField.tsx](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx)
|
||||
36
docs/framework/vue/reference/createFormFactory.md
Normal file
36
docs/framework/vue/reference/createFormFactory.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
id: createFormFactory
|
||||
title: createFormFactory
|
||||
---
|
||||
|
||||
### `createFormFactory`
|
||||
|
||||
```tsx
|
||||
export function createFormFactory<TFormData>(
|
||||
opts?: FormOptions<TFormData>,
|
||||
): FormFactory<TFormData>
|
||||
```
|
||||
|
||||
A function that creates a new `FormFactory<TFormData>` instance.
|
||||
|
||||
- `opts`
|
||||
- Optional form options and a `listen` function to be called with the form state.
|
||||
|
||||
### `FormFactory<TFormData>`
|
||||
|
||||
A type representing a form factory. Form factories provide a type-safe way to interact with the form API as opposed to using the globally exported form utilities.
|
||||
|
||||
```tsx
|
||||
export type FormFactory<TFormData> = {
|
||||
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>
|
||||
useField: UseField<TFormData>
|
||||
Field: FieldComponent<TFormData>
|
||||
}
|
||||
```
|
||||
|
||||
- `useForm`
|
||||
- A custom composition that creates and returns a new instance of the `FormApi<TFormData>` class.
|
||||
- `useField`
|
||||
- A custom composition that returns an instance of the `FieldApi<TFormData>` class.
|
||||
- `Field`
|
||||
- A form field component.
|
||||
6
docs/framework/vue/reference/fieldApi.md
Normal file
6
docs/framework/vue/reference/fieldApi.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: fieldApi
|
||||
title: Field API
|
||||
---
|
||||
|
||||
Please see [/packages/vue-form/src/useField.tsx](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx)
|
||||
6
docs/framework/vue/reference/formApi.md
Normal file
6
docs/framework/vue/reference/formApi.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: formApi
|
||||
title: Form API
|
||||
---
|
||||
|
||||
Please see [/packages/vue-form/src/useForm.tsx](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx)
|
||||
6
docs/framework/vue/reference/useField.md
Normal file
6
docs/framework/vue/reference/useField.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: useField
|
||||
title: useField
|
||||
---
|
||||
|
||||
Please see [/packages/vue-form/src/useField.tsx](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useField.tsx)
|
||||
6
docs/framework/vue/reference/useForm.md
Normal file
6
docs/framework/vue/reference/useForm.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
id: useForm
|
||||
title: useForm
|
||||
---
|
||||
|
||||
Please see [/packages/vue-form/src/useForm.tsx](https://github.com/TanStack/form/blob/main/packages/vue-form/src/useForm.tsx)
|
||||
Reference in New Issue
Block a user