-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mount method on FormApi * fix solid-form test case * fix: added form.mount() to tests * feat: valibot-form-adapter * chore: add missing config items * docs: add Valibot React example * docs: add Solid Valibot example * docs: add valibot Vue example * fix: valibot async adapter now works * docs: add docs for valibot adapter --------- Co-authored-by: Corbin Crutchley <[email protected]>
- Loading branch information
1 parent
1a37fab
commit 31f6261
Showing
57 changed files
with
2,150 additions
and
1,495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @ts-check | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
const config = { | ||
extends: ["plugin:react/recommended", "plugin:react-hooks/recommended"], | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: "./tsconfig.json", | ||
}, | ||
rules: { | ||
"react/no-children-prop": "off", | ||
}, | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
pnpm-lock.yaml | ||
yarn.lock | ||
package-lock.json | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Example | ||
|
||
To run this example: | ||
|
||
- `npm install` | ||
- `npm run dev` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/emblem-light.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
|
||
<title>TanStack Form React Valibot Example App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@tanstack/form-example-react-valibot", | ||
"version": "0.0.1", | ||
"main": "src/index.jsx", | ||
"scripts": { | ||
"dev": "vite --port=3001", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-form": "0.7.2", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0", | ||
"valibot": "^0.20.1", | ||
"@tanstack/valibot-form-adapter": "0.7.2", | ||
"@tanstack/form-core": "0.7.2", | ||
"@tanstack/zod-form-adapter": "0.7.2", | ||
"@tanstack/vue-form": "0.7.2", | ||
"@tanstack/yup-form-adapter": "0.7.2", | ||
"@tanstack/solid-form": "0.7.2" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-react": "^4.0.4", | ||
"vite": "^4.4.9" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"nx": { | ||
"implicitDependencies": [ | ||
"@tanstack/form-core", | ||
"@tanstack/react-form", | ||
"@tanstack/zod-form-adapter" | ||
], | ||
"targets": { | ||
"test:types": { | ||
"dependsOn": [ | ||
"build" | ||
] | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import * as React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import { useForm } from "@tanstack/react-form"; | ||
import { valibotValidator } from "@tanstack/valibot-form-adapter"; | ||
import { string, minLength, stringAsync, PipeResult } from "valibot"; | ||
import type { FieldApi } from "@tanstack/react-form"; | ||
|
||
function FieldInfo({ field }: { field: FieldApi<any, any, unknown, unknown> }) { | ||
return ( | ||
<> | ||
{field.state.meta.touchedErrors ? ( | ||
<em>{field.state.meta.touchedErrors}</em> | ||
) : null} | ||
{field.state.meta.isValidating ? "Validating..." : null} | ||
</> | ||
); | ||
} | ||
|
||
export default function App() { | ||
const form = useForm({ | ||
defaultValues: { | ||
firstName: "", | ||
lastName: "", | ||
}, | ||
onSubmit: async (values) => { | ||
// Do something with form data | ||
console.log(values); | ||
}, | ||
// Add a validator to support Valibot usage in Form and Field | ||
validator: valibotValidator, | ||
}); | ||
|
||
return ( | ||
<div> | ||
<h1>Valibot Form Example</h1> | ||
<form.Provider> | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
void form.handleSubmit(); | ||
}} | ||
> | ||
<div> | ||
{/* A type-safe field component*/} | ||
<form.Field | ||
name="firstName" | ||
onChange={string([ | ||
minLength(3, "First name must be at least 3 characters"), | ||
])} | ||
onChangeAsyncDebounceMs={500} | ||
onChangeAsync={stringAsync([ | ||
async (value) => { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return ( | ||
value.includes("error") | ||
? { | ||
issues: [ | ||
{ | ||
input: value, | ||
validation: "firstName", | ||
message: "No 'error' allowed in first name", | ||
}, | ||
], | ||
} | ||
: { output: value } | ||
) as PipeResult<string>; | ||
}, | ||
])} | ||
children={(field) => { | ||
// Avoid hasty abstractions. Render props are great! | ||
return ( | ||
<> | ||
<label htmlFor={field.name}>First Name:</label> | ||
<input | ||
name={field.name} | ||
value={field.state.value} | ||
onBlur={field.handleBlur} | ||
onChange={(e) => field.handleChange(e.target.value)} | ||
/> | ||
<FieldInfo field={field} /> | ||
</> | ||
); | ||
}} | ||
/> | ||
</div> | ||
<div> | ||
<form.Field | ||
name="lastName" | ||
children={(field) => ( | ||
<> | ||
<label htmlFor={field.name}>Last Name:</label> | ||
<input | ||
name={field.name} | ||
value={field.state.value} | ||
onBlur={field.handleBlur} | ||
onChange={(e) => field.handleChange(e.target.value)} | ||
/> | ||
<FieldInfo field={field} /> | ||
</> | ||
)} | ||
/> | ||
</div> | ||
<form.Subscribe | ||
selector={(state) => [state.canSubmit, state.isSubmitting]} | ||
children={([canSubmit, isSubmitting]) => ( | ||
<button type="submit" disabled={!canSubmit}> | ||
{isSubmitting ? "..." : "Submit"} | ||
</button> | ||
)} | ||
/> | ||
</form> | ||
</form.Provider> | ||
</div> | ||
); | ||
} | ||
|
||
const rootElement = document.getElementById("root")!; | ||
|
||
createRoot(rootElement).render(<App />); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react", | ||
"noEmit": true, | ||
"lib": ["DOM", "DOM.Iterable", "ES2020"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
Oops, something went wrong.