Skip to content

Commit 79da6a7

Browse files
committed
Merge branch 'react'
2 parents 2213942 + 2d5747e commit 79da6a7

582 files changed

Lines changed: 21023 additions & 374 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ node_modules
44
/pt-br
55
/fr
66
/pirate
7+
.pnpm-store/
78
.node_modules_tmp

1.getting-started/2.installation.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ description: Get up and running with FormKit in your project.
77

88
## Prerequisites
99

10-
- Vue 3+ or Nuxt 3+.
10+
- :FrameworkText{vue="Vue 3+ or Nuxt 3+." react="React 18+ or Astro with React integration."}
1111
- Vite (strongly recommended for automatic optimizations)
1212
- Node.js: `14.18.0`, `16.12.0`, or higher.
1313
- Terminal: To run `npm`/`yarn`/`pnpm` commands.
1414

15+
::NpxSkillCta
16+
::
17+
18+
If you'd rather install FormKit by hand, use the wizard below.
1519

1620
## Installation instruction wizard
1721

1822
::InstallWizard
1923
::
20-

1.getting-started/3.your-first-form.md

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ navigation:
99

1010
## Introduction
1111

12-
Let's start by creating our first FormKit form! We'll learn some of FormKit's key features and how they benefit you. We'll also pick up some nice tips along the way — like how to manage form state without using `v-model`.
12+
Let's start by creating our first FormKit form! We'll learn some of FormKit's key features and how they benefit you. We'll also pick up some nice tips along the way — like how to manage form state without relying on :FrameworkText{vue="<code>v-model</code>" react="<code>modelValue</code> and <code>onUpdateModelValue</code>"}.
1313

1414
::Callout
1515
---
1616
type: "info"
17-
label: "Composition API"
17+
label: "Prerequisites"
1818
---
19-
This guide assumes you are are familiar with the <a href="https://vuejs.org/guide/introduction.html#api-styles">Vue Composition API</a>.
19+
This guide assumes you are familiar with your framework’s component model, props, and event handlers.
2020
::
2121

22+
::FrameworkOnly{framework="vue"}
2223
::VideoCard
2324
---
2425
title: "Robust Vue.js Forms - Vue School Course"
@@ -27,6 +28,7 @@ watch-time: "1 hr, 49 mins"
2728
external-vid: "https://vueschool.io/courses/robust-vue-js-forms-with-formkit?friend=formkit"
2829
---
2930
::
31+
:::
3032

3133
## Our first input
3234

@@ -44,6 +46,7 @@ By default, the `<FormKit />` component will use `type="text"` if no `type` is s
4446
---
4547
name: "First input"
4648
file: "_examples/guides/your-first-form/first-input/example.vue"
49+
react-file: "_examples/guides/your-first-form/first-input/example.react.jsx"
4750
---
4851
::
4952

@@ -58,6 +61,7 @@ file: [
5861
"_examples/guides/your-first-form/input-name-id/example.vue",
5962
"_examples/_no-tailwind/formkit.config.ts"
6063
]
64+
react-file: "_examples/guides/your-first-form/input-name-id/example.react.jsx"
6165
render: "html"
6266
---
6367
::
@@ -70,6 +74,7 @@ Our input is still missing some key accessibility functionality like a `label`,
7074
---
7175
name: "Adding label and help texts"
7276
file: "_examples/guides/your-first-form/input-accessible-text/example.vue"
77+
react-file: "_examples/guides/your-first-form/input-accessible-text/example.react.jsx"
7378
---
7479
::
7580

@@ -83,6 +88,7 @@ Let's start building an example that we can add to for this guide. Imagining we
8388
---
8489
name: "Adding label and help texts"
8590
file: "_examples/guides/your-first-form/input-vitality-bar/example.vue"
91+
react-file: "_examples/guides/your-first-form/input-vitality-bar/example.react.jsx"
8692
---
8793
::
8894

@@ -94,6 +100,7 @@ Validation is one of the main features of FormKit. It helps the user know if the
94100
---
95101
name: "Adding validation to name"
96102
file: "_examples/guides/your-first-form/input-validation/example.vue"
103+
react-file: "_examples/guides/your-first-form/input-validation/example.react.jsx"
97104
---
98105
::
99106

@@ -108,6 +115,7 @@ Suppose our "backend" requires that data like `strength` be [cast to a number](h
108115
---
109116
name: "Adding plugin to cast to number"
110117
file: "_examples/guides/your-first-form/input-cast-number/example.vue"
118+
react-file: "_examples/guides/your-first-form/input-cast-number/example.react.jsx"
111119
---
112120
::
113121

@@ -129,40 +137,57 @@ The <code>form</code> type will actively collect all the values from child input
129137
---
130138
name: "Character creation form"
131139
file: "_examples/guides/your-first-form/character-basic-form/example.vue"
140+
react-file: "_examples/guides/your-first-form/character-basic-form/example.react.jsx"
132141
---
133142
::
134143

135144
### Adding the submit handler
136145

137-
The first feature of a form that we'll explore is that we have a `@submit` event ready to make our life easier when the time comes to submit our form. The `@submit` event gives us as the first argument all the descendant fields the form gathered from the inputs. There is no need to use numerous `v-model`s to collect the form data. Let's add our `createCharacter()` submit handler:
146+
The first feature of a form that we'll explore is that we have a ready-made submit handler hook in :FrameworkText{vue="<code>@submit</code>" react="<code>onSubmit</code>"}. This handler receives, as its first argument, all the descendant field values the form gathered from its inputs. There is no need to wire numerous :FrameworkText{vue="<code>v-model</code>s" react="controlled fields"} just to collect the form data. Let's add our `createCharacter()` submit handler:
138147

139148
::Example
140149
---
141150
name: "Adding form submit"
142151
file: "_examples/guides/your-first-form/character-form-submit/example.vue"
152+
react-file: "_examples/guides/your-first-form/character-form-submit/example.react.jsx"
143153
---
144154
::
145155

146156
### Changing the submit button
147157

148-
As a convenience when using `type="form"`, the `form` outputs a submit button automatically. For our case, a "Submit" text does not show the intent of the form correctly. To fix that, we can use the `submit-label` prop, which is a `form`-specific feature, by adding `submit-label="Create Character"` to show the intent of the form:
158+
As a convenience when using `type="form"`, the `form` outputs a submit button automatically. For our case, a "Submit" text does not show the intent of the form correctly. To fix that, we can use the `submitLabel` / `submit-label` prop, which is a `form`-specific feature:
149159

160+
::FrameworkOnly{framework="vue"}
150161
```html
151162
<FormKit type="form" @submit="createCharacter" submit-label="Create Character">
152163
<!-- Rest of our creation form -->
153164
</FormKit>
154165
```
166+
::
167+
168+
::FrameworkOnly{framework="react"}
169+
```jsx
170+
<FormKit
171+
type="form"
172+
onSubmit={createCharacter}
173+
submitLabel="Create Character"
174+
>
175+
{/* Rest of our creation form */}
176+
</FormKit>
177+
```
178+
::
155179

156180
### Grouping related inputs
157181

158182
While the form works right now, we can see that some related inputs are separated (i.e., the form data is a flat structure where all form data are siblings). Suppose our backend needs all attributes inside an `attributes` property. We can use the `group` type to group related inputs together by a common `name`.
159183

160-
Just like the `form` type, you can wrap all yours fields inside a `<FormKit type="group" name: "attributes">`. Don't forget to add the name property:
184+
Just like the `form` type, you can wrap all your fields inside a `<FormKit type="group" name="attributes">`. Don't forget to add the `name` prop:
161185

162186
::Example
163187
---
164188
name: "Grouping inputs"
165189
file: "_examples/guides/your-first-form/character-group-attributes/example.vue"
190+
react-file: "_examples/guides/your-first-form/character-group-attributes/example.react.jsx"
166191
---
167192
::
168193

@@ -184,6 +209,7 @@ With those features combined, we can get an input's core `node`, listen for and
184209
---
185210
name: "Updating attributes based on the character class"
186211
file: "_examples/guides/your-first-form/character-attributes-update/example.vue"
212+
react-file: "_examples/guides/your-first-form/character-attributes-update/example.react.jsx"
187213
---
188214
::
189215

@@ -206,6 +232,10 @@ file: [
206232
"_examples/guides/your-first-form/character-plugin/example.vue",
207233
"_examples/guides/your-first-form/character-plugin/plugins.js",
208234
]
235+
react-file: [
236+
"_examples/guides/your-first-form/character-plugin/example.react.jsx",
237+
"_examples/guides/your-first-form/character-plugin/plugins.js"
238+
]
209239
init-file-tab: "example.vue"
210240
---
211241
::
@@ -230,6 +260,11 @@ file: [
230260
"_examples/guides/your-first-form/character-group-rule/plugins.js",
231261
"_examples/guides/your-first-form/character-group-rule/rules.js",
232262
]
263+
react-file: [
264+
"_examples/guides/your-first-form/character-group-rule/example.react.jsx",
265+
"_examples/guides/your-first-form/character-group-rule/plugins.js",
266+
"_examples/guides/your-first-form/character-group-rule/rules.js"
267+
]
233268
init-file-tab: "example.vue"
234269
---
235270
::
@@ -238,18 +273,18 @@ init-file-tab: "example.vue"
238273

239274
Sometimes forms need to show or hide fields depending on the value of another input. We can do this by learning 2 new concepts:
240275

241-
- [Context object](/essentials/configuration) — We can access an input's value (along with other data) inside our form because all `FormKit` components receive their [context object](https://formkit.com/essentials/configuration) in the `#default` [slot prop](https://vuejs.org/guide/components/slots.html#scoped-slots).
276+
- [Context object](/essentials/configuration) — We can access an input's value (along with other data) inside our form because all `FormKit` components expose their [context object](https://formkit.com/essentials/configuration) to :FrameworkText{vue="the <code>#default</code> slot prop" react="the render-prop child function"}.
242277
- The value of a `group` - The value of a [group](/inputs/group) (and `form`) input is an object with the values of its children, keyed by the children's `name`s.
243278

244279
::Callout
245280
---
246281
type: "info"
247-
label: "Vue's key property"
282+
label: "Stable keys"
248283
---
249-
When using conditional rendering, note that Vue needs hints to know that a DOM element needs a re-render, instead of trying to reuse it. We can add a unique <code>key</code> property to the element to help Vue.
284+
When using conditional rendering, it can be helpful to give the toggled subtree a unique <code>key</code> so the framework remounts it instead of trying to reuse stale DOM or state.
250285
::
251286

252-
So, let's grab the context object of the `group` input and extract the `value`: `#default="{ value }"`. We want to add a small easter egg for our users if they decide to change all attributes to 1:
287+
So, let's grab the context object of the `group` input and extract the `value` from :FrameworkText{vue="<code>#default=&quot;{ value }&quot;</code>" react="the render-prop child function"}. We want to add a small easter egg for our users if they decide to change all attributes to 1:
253288

254289
::Example
255290
---
@@ -259,6 +294,11 @@ file: [
259294
"_examples/guides/your-first-form/character-easter-egg/plugins.js",
260295
"_examples/guides/your-first-form/character-easter-egg/rules.js",
261296
]
297+
react-file: [
298+
"_examples/guides/your-first-form/character-easter-egg/example.react.jsx",
299+
"_examples/guides/your-first-form/character-easter-egg/plugins.js",
300+
"_examples/guides/your-first-form/character-easter-egg/rules.js"
301+
]
262302
init-file-tab: "example.vue"
263303
---
264304
::

0 commit comments

Comments
 (0)