@tanstack/cta-engine 0.10.0-alpha.21 → 0.10.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add-ons.js +91 -5
- package/dist/add.js +125 -0
- package/dist/cli.js +132 -0
- package/dist/config-file.js +9 -14
- package/dist/constants.js +2 -0
- package/dist/create-app.js +451 -142
- package/dist/custom-add-on.js +254 -0
- package/dist/environment.js +32 -64
- package/dist/file-helper.js +18 -0
- package/dist/index.js +1 -17
- package/dist/mcp.js +229 -0
- package/dist/options.js +333 -9
- package/dist/package-manager.js +6 -51
- package/dist/templates.js +6 -0
- package/dist/toolchain.js +6 -0
- package/dist/types/add-ons.d.ts +8 -3
- package/dist/types/add.d.ts +3 -0
- package/dist/types/cli.d.ts +7 -0
- package/dist/types/config-file.d.ts +4 -6
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/create-app.d.ts +7 -1
- package/dist/types/custom-add-on.d.ts +3 -0
- package/dist/types/environment.d.ts +1 -2
- package/dist/types/file-helper.d.ts +2 -0
- package/dist/types/index.d.ts +1 -20
- package/dist/types/mcp.d.ts +7 -0
- package/dist/types/options.d.ts +6 -2
- package/dist/types/package-manager.d.ts +1 -18
- package/dist/types/templates.d.ts +1 -0
- package/dist/types/toolchain.d.ts +3 -0
- package/dist/types/types.d.ts +85 -788
- package/dist/types/utils.d.ts +0 -5
- package/dist/types.js +1 -65
- package/dist/utils.js +0 -9
- package/package.json +12 -9
- package/src/add-ons.ts +123 -7
- package/src/add.ts +186 -0
- package/src/cli.ts +210 -0
- package/src/config-file.ts +17 -26
- package/src/constants.ts +5 -0
- package/src/create-app.ts +730 -180
- package/src/custom-add-on.ts +325 -0
- package/src/environment.ts +33 -77
- package/src/file-helper.ts +20 -0
- package/src/index.ts +1 -77
- package/src/mcp.ts +302 -0
- package/src/options.ts +409 -8
- package/src/package-manager.ts +9 -80
- package/src/templates.ts +7 -0
- package/src/toolchain.ts +7 -0
- package/src/types.ts +87 -175
- package/src/utils.ts +0 -17
- package/templates/react/add-on/clerk/README.md +3 -0
- package/templates/react/add-on/clerk/assets/_dot_env.local.append +2 -0
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/header-user.tsx +19 -0
- package/templates/react/add-on/clerk/assets/src/integrations/clerk/provider.tsx +18 -0
- package/templates/react/add-on/clerk/assets/src/routes/demo.clerk.tsx +20 -0
- package/templates/react/add-on/clerk/info.json +13 -0
- package/templates/react/add-on/clerk/package.json +5 -0
- package/templates/react/add-on/convex/README.md +4 -0
- package/templates/react/add-on/convex/assets/_dot_cursorrules.append +93 -0
- package/templates/react/add-on/convex/assets/_dot_env.local.append +3 -0
- package/templates/react/add-on/convex/assets/convex/products.ts +8 -0
- package/templates/react/add-on/convex/assets/convex/schema.ts +10 -0
- package/templates/react/add-on/convex/assets/src/integrations/convex/provider.tsx +20 -0
- package/templates/react/add-on/convex/assets/src/routes/demo.convex.tsx +33 -0
- package/templates/react/add-on/convex/info.json +13 -0
- package/templates/react/add-on/convex/package.json +6 -0
- package/templates/react/add-on/form/assets/src/components/demo.FormComponents.tsx.ejs +300 -0
- package/templates/react/add-on/form/assets/src/hooks/demo.form-context.ts +4 -0
- package/templates/react/add-on/form/assets/src/hooks/demo.form.ts +22 -0
- package/templates/react/add-on/form/assets/src/routes/demo.form.address.tsx.ejs +213 -0
- package/templates/react/add-on/form/assets/src/routes/demo.form.simple.tsx.ejs +77 -0
- package/templates/react/add-on/form/info.json +26 -0
- package/templates/react/add-on/form/package.json +6 -0
- package/templates/react/add-on/module-federation/assets/module-federation.config.js.ejs +31 -0
- package/templates/react/add-on/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/templates/react/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +11 -0
- package/templates/react/add-on/module-federation/info.json +7 -0
- package/templates/react/add-on/module-federation/package.json +5 -0
- package/templates/react/add-on/netlify/README.md +11 -0
- package/templates/react/add-on/netlify/info.json +7 -0
- package/templates/react/add-on/sentry/assets/_dot_cursorrules.append +22 -0
- package/templates/react/add-on/sentry/assets/_dot_env.local.append +11 -0
- package/templates/react/add-on/sentry/assets/src/app/global-middleware.ts +11 -0
- package/templates/react/add-on/sentry/assets/src/routes/demo.sentry.testing.tsx +489 -0
- package/templates/react/add-on/sentry/info.json +14 -0
- package/templates/react/add-on/sentry/package.json +5 -0
- package/templates/react/add-on/shadcn/README.md +7 -0
- package/templates/react/add-on/shadcn/assets/_dot_cursorrules.append +7 -0
- package/templates/react/add-on/shadcn/assets/components.json +21 -0
- package/templates/react/add-on/shadcn/assets/src/lib/utils.ts +6 -0
- package/templates/react/add-on/shadcn/assets/src/styles.css +138 -0
- package/templates/react/add-on/shadcn/info.json +7 -0
- package/templates/react/add-on/shadcn/package.json +9 -0
- package/templates/react/add-on/start/assets/_dot_gitignore.append +2 -0
- package/templates/react/add-on/start/assets/app.config.ts.ejs +32 -0
- package/templates/react/add-on/start/assets/src/api.ts +6 -0
- package/templates/react/add-on/start/assets/src/client.tsx.ejs +33 -0
- package/templates/react/add-on/start/assets/src/router.tsx.ejs +48 -0
- package/templates/react/add-on/start/assets/src/routes/api.demo-names.ts +11 -0
- package/templates/react/add-on/start/assets/src/routes/demo.start.api-request.tsx.ejs +33 -0
- package/templates/react/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +50 -0
- package/templates/react/add-on/start/assets/src/ssr.tsx.ejs +30 -0
- package/templates/react/add-on/start/info.json +18 -0
- package/templates/react/add-on/start/package.json +13 -0
- package/templates/react/add-on/store/assets/src/lib/demo-store.ts +13 -0
- package/templates/react/add-on/store/assets/src/routes/demo.store.tsx.ejs +75 -0
- package/templates/react/add-on/store/info.json +13 -0
- package/templates/react/add-on/store/package.json +6 -0
- package/templates/react/add-on/t3env/README.md +16 -0
- package/templates/react/add-on/t3env/assets/src/env.ts +39 -0
- package/templates/react/add-on/t3env/info.json +10 -0
- package/templates/react/add-on/t3env/package.json +6 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/init.ts +9 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/react.ts +4 -0
- package/templates/react/add-on/tRPC/assets/src/integrations/trpc/router.ts +18 -0
- package/templates/react/add-on/tRPC/assets/src/routes/api.trpc.$.tsx +16 -0
- package/templates/react/add-on/tRPC/info.json +9 -0
- package/templates/react/add-on/tRPC/package.json +9 -0
- package/templates/react/add-on/table/assets/src/data/demo-table-data.ts +50 -0
- package/templates/react/add-on/table/assets/src/routes/demo.table.tsx.ejs +373 -0
- package/templates/react/add-on/table/info.json +13 -0
- package/templates/react/add-on/table/package.json +7 -0
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/layout.tsx +5 -0
- package/templates/react/add-on/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +70 -0
- package/templates/react/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx.ejs +53 -0
- package/templates/react/add-on/tanstack-query/info.json +13 -0
- package/templates/react/add-on/tanstack-query/package.json +6 -0
- package/templates/react/base/README.md.ejs +558 -0
- package/templates/react/base/_dot_gitignore +5 -0
- package/templates/react/base/_dot_vscode/settings.biome.json +35 -0
- package/templates/react/base/_dot_vscode/settings.json +11 -0
- package/templates/react/base/index.html.ejs +20 -0
- package/templates/react/base/package.biome.json +10 -0
- package/templates/react/base/package.eslintprettier.json +11 -0
- package/templates/react/base/package.json +30 -0
- package/templates/react/base/package.ts.json +7 -0
- package/templates/react/base/package.tw.json +6 -0
- package/templates/react/base/public/favicon.ico +0 -0
- package/templates/react/base/public/logo192.png +0 -0
- package/templates/react/base/public/logo512.png +0 -0
- package/templates/react/base/public/manifest.json +25 -0
- package/templates/react/base/public/robots.txt +3 -0
- package/templates/react/base/src/App.css +38 -0
- package/templates/react/base/src/App.test.tsx.ejs +10 -0
- package/templates/react/base/src/App.tsx.ejs +74 -0
- package/templates/react/base/src/components/Header.tsx.ejs +27 -0
- package/templates/react/base/src/logo.svg +44 -0
- package/templates/react/base/src/reportWebVitals.ts.ejs +28 -0
- package/templates/react/base/src/styles.css.ejs +15 -0
- package/templates/react/base/toolchain/.prettierignore +3 -0
- package/templates/react/base/toolchain/biome.json +31 -0
- package/templates/react/base/toolchain/eslint.config.js +5 -0
- package/templates/react/base/toolchain/prettier.config.js +10 -0
- package/templates/react/base/tsconfig.json.ejs +29 -0
- package/templates/react/base/vite.config.js.ejs +23 -0
- package/templates/react/code-router/src/main.tsx.ejs +92 -0
- package/templates/react/example/tanchat/README.md +37 -0
- package/templates/react/example/tanchat/assets/_dot_env.local.append +2 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-flowers.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-motherboard.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-racing.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-steamer-trunk.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-superhero.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-traveling.jpg +0 -0
- package/templates/react/example/tanchat/assets/public/example-guitar-video-games.jpg +0 -0
- package/templates/react/example/tanchat/assets/src/components/example-AIAssistant.tsx +173 -0
- package/templates/react/example/tanchat/assets/src/components/example-GuitarRecommendation.tsx +47 -0
- package/templates/react/example/tanchat/assets/src/data/example-guitars.ts +83 -0
- package/templates/react/example/tanchat/assets/src/demo.index.css +220 -0
- package/templates/react/example/tanchat/assets/src/integrations/tanchat/header-user.tsx +5 -0
- package/templates/react/example/tanchat/assets/src/routes/api.messages.ts +24 -0
- package/templates/react/example/tanchat/assets/src/routes/api.sse.ts +23 -0
- package/templates/react/example/tanchat/assets/src/routes/example.chat.tsx +159 -0
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/$guitarId.tsx +50 -0
- package/templates/react/example/tanchat/assets/src/routes/example.guitars/index.tsx +54 -0
- package/templates/react/example/tanchat/assets/src/store/example-assistant.ts +3 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.ai.ts +62 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.sse.ts +31 -0
- package/templates/react/example/tanchat/assets/src/utils/demo.tools.ts +47 -0
- package/templates/react/example/tanchat/info.json +19 -0
- package/templates/react/example/tanchat/package.json +16 -0
- package/templates/react/file-router/package.fr.json +5 -0
- package/templates/react/file-router/src/main.tsx.ejs +55 -0
- package/templates/react/file-router/src/routes/__root.tsx.ejs +82 -0
- package/templates/solid/add-on/form/assets/src/routes/demo.form.tsx.ejs +352 -0
- package/templates/solid/add-on/form/info.json +13 -0
- package/templates/solid/add-on/form/package.json +5 -0
- package/templates/solid/add-on/module-federation/assets/module-federation.config.js.ejs +27 -0
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/templates/solid/add-on/module-federation/assets/src/demo-mf-self-contained.tsx +9 -0
- package/templates/solid/add-on/module-federation/info.json +7 -0
- package/templates/solid/add-on/module-federation/package.json +5 -0
- package/templates/solid/add-on/sentry/assets/_dot_cursorrules.append +22 -0
- package/templates/solid/add-on/sentry/assets/_dot_env.local.append +2 -0
- package/templates/solid/add-on/sentry/assets/src/routes/demo.sentry.bad-event-handler.tsx +20 -0
- package/templates/solid/add-on/sentry/info.json +13 -0
- package/templates/solid/add-on/sentry/package.json +5 -0
- package/templates/solid/add-on/solid-ui/README.md +9 -0
- package/templates/solid/add-on/solid-ui/assets/src/lib/utils.ts +6 -0
- package/templates/solid/add-on/solid-ui/assets/src/styles.css +138 -0
- package/templates/solid/add-on/solid-ui/assets/ui.config.json +13 -0
- package/templates/solid/add-on/solid-ui/info.json +11 -0
- package/templates/solid/add-on/solid-ui/package.json +9 -0
- package/templates/solid/add-on/start/assets/app.config.ts +16 -0
- package/templates/solid/add-on/start/assets/src/api.ts +6 -0
- package/templates/solid/add-on/start/assets/src/client.tsx +7 -0
- package/templates/solid/add-on/start/assets/src/router.tsx.ejs +24 -0
- package/templates/solid/add-on/start/assets/src/routes/demo.start.server-funcs.tsx +49 -0
- package/templates/solid/add-on/start/assets/src/ssr.tsx +12 -0
- package/templates/solid/add-on/start/info.json +14 -0
- package/templates/solid/add-on/start/package.json +12 -0
- package/templates/solid/add-on/store/assets/src/lib/demo-store.ts +13 -0
- package/templates/solid/add-on/store/assets/src/routes/demo.store.tsx.ejs +77 -0
- package/templates/solid/add-on/store/info.json +13 -0
- package/templates/solid/add-on/store/package.json +6 -0
- package/templates/solid/add-on/t3env/README.md +16 -0
- package/templates/solid/add-on/t3env/assets/src/env.ts +39 -0
- package/templates/solid/add-on/t3env/info.json +10 -0
- package/templates/solid/add-on/t3env/package.json +6 -0
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/header-user.tsx +5 -0
- package/templates/solid/add-on/tanstack-query/assets/src/integrations/tanstack-query/provider.tsx +15 -0
- package/templates/solid/add-on/tanstack-query/assets/src/routes/demo.tanstack-query.tsx +30 -0
- package/templates/solid/add-on/tanstack-query/info.json +13 -0
- package/templates/solid/add-on/tanstack-query/package.json +6 -0
- package/templates/solid/base/README.md.ejs +215 -0
- package/templates/solid/base/_dot_cursorrules.append +35 -0
- package/templates/solid/base/_dot_gitignore +5 -0
- package/templates/solid/base/_dot_vscode/settings.biome.json +35 -0
- package/templates/solid/base/_dot_vscode/settings.json +11 -0
- package/templates/solid/base/index.html.ejs +20 -0
- package/templates/solid/base/package.biome.json +10 -0
- package/templates/solid/base/package.eslintprettier.json +11 -0
- package/templates/solid/base/package.json +23 -0
- package/templates/solid/base/package.ts.json +5 -0
- package/templates/solid/base/package.tw.json +6 -0
- package/templates/solid/base/public/favicon.ico +0 -0
- package/templates/solid/base/public/logo192.png +0 -0
- package/templates/solid/base/public/logo512.png +0 -0
- package/templates/solid/base/public/manifest.json +25 -0
- package/templates/solid/base/public/robots.txt +3 -0
- package/templates/solid/base/src/App.css +0 -0
- package/templates/solid/base/src/App.tsx.ejs +47 -0
- package/templates/solid/base/src/components/Header.tsx.ejs +26 -0
- package/templates/solid/base/src/logo.svg +120 -0
- package/templates/solid/base/src/styles.css.ejs +15 -0
- package/templates/solid/base/toolchain/.prettierignore +3 -0
- package/templates/solid/base/toolchain/biome.json +31 -0
- package/templates/solid/base/toolchain/eslint.config.js +5 -0
- package/templates/solid/base/toolchain/prettier.config.js +10 -0
- package/templates/solid/base/tsconfig.json.ejs +31 -0
- package/templates/solid/base/vite.config.js.ejs +22 -0
- package/templates/solid/code-router/src/main.tsx.ejs +71 -0
- package/templates/solid/example/tanchat/README.md +52 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/README.md +110 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/_dot_env.example +1 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/package.json +26 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/src/index.ts +102 -0
- package/templates/solid/example/tanchat/assets/ai-streaming-server/tsconfig.json +15 -0
- package/templates/solid/example/tanchat/assets/src/components/demo.SettingsDialog.tsx +149 -0
- package/templates/solid/example/tanchat/assets/src/demo.index.css +227 -0
- package/templates/solid/example/tanchat/assets/src/lib/demo-store.ts +13 -0
- package/templates/solid/example/tanchat/assets/src/routes/example.chat.tsx +435 -0
- package/templates/solid/example/tanchat/assets/src/store/demo.hooks.ts +17 -0
- package/templates/solid/example/tanchat/assets/src/store/demo.store.ts +133 -0
- package/templates/solid/example/tanchat/info.json +14 -0
- package/templates/solid/example/tanchat/package.json +7 -0
- package/templates/solid/file-router/package.fr.json +5 -0
- package/templates/solid/file-router/src/main.tsx.ejs +47 -0
- package/templates/solid/file-router/src/routes/__root.tsx.ejs +41 -0
- package/templates/solid/file-router/src/routes/index.tsx +43 -0
- package/tests/cra.test.ts +293 -0
- package/tests/snapshots/cra/cr-js-npm.json +33 -0
- package/tests/snapshots/cra/cr-ts-npm.json +34 -0
- package/tests/snapshots/cra/cr-ts-start-npm.json +38 -0
- package/tests/snapshots/cra/fr-ts-npm.json +34 -0
- package/tests/snapshots/cra/fr-ts-tw-npm.json +33 -0
- package/tests/snapshots/cra/solid-cr-js-npm.json +31 -0
- package/tests/snapshots/cra/solid-cr-ts-npm.json +32 -0
- package/tests/snapshots/cra/solid-cr-ts-start-npm.json +36 -0
- package/tests/snapshots/cra/solid-fr-ts-npm.json +33 -0
- package/tests/snapshots/cra/solid-fr-ts-tw-npm.json +32 -0
- package/tests/test-utilities.ts +87 -0
- package/dist/add-to-app.js +0 -169
- package/dist/custom-add-ons/add-on.js +0 -175
- package/dist/custom-add-ons/shared.js +0 -117
- package/dist/custom-add-ons/starter.js +0 -84
- package/dist/file-helpers.js +0 -165
- package/dist/frameworks.js +0 -92
- package/dist/integrations/git.js +0 -4
- package/dist/integrations/shadcn.js +0 -33
- package/dist/package-json.js +0 -48
- package/dist/special-steps/index.js +0 -24
- package/dist/special-steps/rimraf-node-modules.js +0 -16
- package/dist/template-file.js +0 -112
- package/dist/types/add-to-app.d.ts +0 -17
- package/dist/types/custom-add-ons/add-on.d.ts +0 -69
- package/dist/types/custom-add-ons/shared.d.ts +0 -15
- package/dist/types/custom-add-ons/starter.d.ts +0 -7
- package/dist/types/file-helpers.d.ts +0 -15
- package/dist/types/frameworks.d.ts +0 -7
- package/dist/types/integrations/git.d.ts +0 -2
- package/dist/types/integrations/shadcn.d.ts +0 -2
- package/dist/types/package-json.d.ts +0 -7
- package/dist/types/special-steps/index.d.ts +0 -2
- package/dist/types/special-steps/rimraf-node-modules.d.ts +0 -2
- package/dist/types/template-file.d.ts +0 -2
- package/src/add-to-app.ts +0 -274
- package/src/custom-add-ons/add-on.ts +0 -261
- package/src/custom-add-ons/shared.ts +0 -161
- package/src/custom-add-ons/starter.ts +0 -126
- package/src/file-helpers.ts +0 -235
- package/src/frameworks.ts +0 -134
- package/src/integrations/git.ts +0 -7
- package/src/integrations/shadcn.ts +0 -54
- package/src/package-json.ts +0 -69
- package/src/special-steps/index.ts +0 -36
- package/src/special-steps/rimraf-node-modules.ts +0 -25
- package/src/template-file.ts +0 -150
- package/tests/add-ons.test.ts +0 -67
- package/tests/add-to-app.test.ts +0 -358
- package/tests/config-file.test.ts +0 -68
- package/tests/create-app.test.ts +0 -120
- package/tests/custom-add-ons/add-on.test.ts +0 -12
- package/tests/custom-add-ons/shared.test.ts +0 -257
- package/tests/custom-add-ons/starter.test.ts +0 -58
- package/tests/environment.test.ts +0 -115
- package/tests/file-helper.test.ts +0 -90
- package/tests/frameworks.test.ts +0 -95
- package/tests/index.test.ts +0 -9
- package/tests/integrations/git.test.ts +0 -20
- package/tests/integrations/shadcn.test.ts +0 -91
- package/tests/options.test.ts +0 -42
- package/tests/package-json.test.ts +0 -63
- package/tests/package-manager.test.ts +0 -154
- package/tests/setupVitest.ts +0 -6
- package/tests/template-file.test.ts +0 -178
- package/tests/utils.test.ts +0 -23
- package/vitest.config.ts +0 -21
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Suspense } from 'react'
|
|
2
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
3
|
+
import { useQuery } from 'convex/react'
|
|
4
|
+
|
|
5
|
+
import { api } from '../../convex/_generated/api'
|
|
6
|
+
|
|
7
|
+
export const Route = createFileRoute('/demo/convex')({
|
|
8
|
+
component: App,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
function Products() {
|
|
12
|
+
const products = useQuery(api.products.get)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ul>
|
|
16
|
+
{(products || []).map((p) => (
|
|
17
|
+
<li key={p._id}>
|
|
18
|
+
{p.title} - {p.price}
|
|
19
|
+
</li>
|
|
20
|
+
))}
|
|
21
|
+
</ul>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<div className="p-4">
|
|
28
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
29
|
+
<Products />
|
|
30
|
+
</Suspense>
|
|
31
|
+
</div>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { useStore } from '@tanstack/react-form'
|
|
2
|
+
|
|
3
|
+
import { useFieldContext, useFormContext } from '../hooks/demo.form-context'
|
|
4
|
+
<% if (addOnEnabled.shadcn) { %>
|
|
5
|
+
import { Button } from '@/components/ui/button'
|
|
6
|
+
import { Input } from '@/components/ui/input'
|
|
7
|
+
import { Textarea as ShadcnTextarea } from '@/components/ui/textarea'
|
|
8
|
+
import * as ShadcnSelect from '@/components/ui/select'
|
|
9
|
+
import { Slider as ShadcnSlider } from '@/components/ui/slider'
|
|
10
|
+
import { Switch as ShadcnSwitch } from '@/components/ui/switch'
|
|
11
|
+
import { Label } from '@/components/ui/label'
|
|
12
|
+
|
|
13
|
+
export function SubscribeButton({ label }: { label: string }) {
|
|
14
|
+
const form = useFormContext()
|
|
15
|
+
return (
|
|
16
|
+
<form.Subscribe selector={(state) => state.isSubmitting}>
|
|
17
|
+
{(isSubmitting) => (
|
|
18
|
+
<Button type="submit" disabled={isSubmitting}>
|
|
19
|
+
{label}
|
|
20
|
+
</Button>
|
|
21
|
+
)}
|
|
22
|
+
</form.Subscribe>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ErrorMessages({
|
|
27
|
+
errors,
|
|
28
|
+
}: {
|
|
29
|
+
errors: Array<string | { message: string }>
|
|
30
|
+
}) {
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
{errors.map((error) => (
|
|
34
|
+
<div
|
|
35
|
+
key={typeof error === 'string' ? error : error.message}
|
|
36
|
+
className="text-red-500 mt-1 font-bold"
|
|
37
|
+
>
|
|
38
|
+
{typeof error === 'string' ? error : error.message}
|
|
39
|
+
</div>
|
|
40
|
+
))}
|
|
41
|
+
</>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function TextField({
|
|
46
|
+
label,
|
|
47
|
+
placeholder,
|
|
48
|
+
}: {
|
|
49
|
+
label: string
|
|
50
|
+
placeholder?: string
|
|
51
|
+
}) {
|
|
52
|
+
const field = useFieldContext<string>()
|
|
53
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div>
|
|
57
|
+
<Label htmlFor={label} className="mb-2 text-xl font-bold">
|
|
58
|
+
{label}
|
|
59
|
+
</Label>
|
|
60
|
+
<Input
|
|
61
|
+
value={field.state.value}
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
onBlur={field.handleBlur}
|
|
64
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
65
|
+
/>
|
|
66
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function TextArea({
|
|
72
|
+
label,
|
|
73
|
+
rows = 3,
|
|
74
|
+
}: {
|
|
75
|
+
label: string
|
|
76
|
+
rows?: number
|
|
77
|
+
}) {
|
|
78
|
+
const field = useFieldContext<string>()
|
|
79
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div>
|
|
83
|
+
<Label htmlFor={label} className="mb-2 text-xl font-bold">
|
|
84
|
+
{label}
|
|
85
|
+
</Label>
|
|
86
|
+
<ShadcnTextarea
|
|
87
|
+
id={label}
|
|
88
|
+
value={field.state.value}
|
|
89
|
+
onBlur={field.handleBlur}
|
|
90
|
+
rows={rows}
|
|
91
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
92
|
+
/>
|
|
93
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
94
|
+
</div>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function Select({
|
|
99
|
+
label,
|
|
100
|
+
values,
|
|
101
|
+
placeholder,
|
|
102
|
+
}: {
|
|
103
|
+
label: string
|
|
104
|
+
values: Array<{ label: string; value: string }>
|
|
105
|
+
placeholder?: string
|
|
106
|
+
}) {
|
|
107
|
+
const field = useFieldContext<string>()
|
|
108
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div>
|
|
112
|
+
<ShadcnSelect.Select
|
|
113
|
+
name={field.name}
|
|
114
|
+
value={field.state.value}
|
|
115
|
+
onValueChange={(value) => field.handleChange(value)}
|
|
116
|
+
>
|
|
117
|
+
<ShadcnSelect.SelectTrigger className="w-full">
|
|
118
|
+
<ShadcnSelect.SelectValue placeholder={placeholder} />
|
|
119
|
+
</ShadcnSelect.SelectTrigger>
|
|
120
|
+
<ShadcnSelect.SelectContent>
|
|
121
|
+
<ShadcnSelect.SelectGroup>
|
|
122
|
+
<ShadcnSelect.SelectLabel>{label}</ShadcnSelect.SelectLabel>
|
|
123
|
+
{values.map((value) => (
|
|
124
|
+
<ShadcnSelect.SelectItem key={value.value} value={value.value}>
|
|
125
|
+
{value.label}
|
|
126
|
+
</ShadcnSelect.SelectItem>
|
|
127
|
+
))}
|
|
128
|
+
</ShadcnSelect.SelectGroup>
|
|
129
|
+
</ShadcnSelect.SelectContent>
|
|
130
|
+
</ShadcnSelect.Select>
|
|
131
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function Slider({ label }: { label: string }) {
|
|
137
|
+
const field = useFieldContext<number>()
|
|
138
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div>
|
|
142
|
+
<Label htmlFor={label} className="mb-2 text-xl font-bold">
|
|
143
|
+
{label}
|
|
144
|
+
</Label>
|
|
145
|
+
<ShadcnSlider
|
|
146
|
+
id={label}
|
|
147
|
+
onBlur={field.handleBlur}
|
|
148
|
+
value={[field.state.value]}
|
|
149
|
+
onValueChange={(value) => field.handleChange(value[0])}
|
|
150
|
+
/>
|
|
151
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
152
|
+
</div>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function Switch({ label }: { label: string }) {
|
|
157
|
+
const field = useFieldContext<boolean>()
|
|
158
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div>
|
|
162
|
+
<div className="flex items-center gap-2">
|
|
163
|
+
<ShadcnSwitch
|
|
164
|
+
id={label}
|
|
165
|
+
onBlur={field.handleBlur}
|
|
166
|
+
checked={field.state.value}
|
|
167
|
+
onCheckedChange={(checked) => field.handleChange(checked)}
|
|
168
|
+
/>
|
|
169
|
+
<Label htmlFor={label}>{label}</Label>
|
|
170
|
+
</div>
|
|
171
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
172
|
+
</div>
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
<% } else { %>
|
|
177
|
+
export function SubscribeButton({ label }: { label: string }) {
|
|
178
|
+
const form = useFormContext()
|
|
179
|
+
return (
|
|
180
|
+
<form.Subscribe selector={(state) => state.isSubmitting}>
|
|
181
|
+
{(isSubmitting) => (
|
|
182
|
+
<button
|
|
183
|
+
type="submit"
|
|
184
|
+
disabled={isSubmitting}
|
|
185
|
+
className="px-6 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition-colors disabled:opacity-50"
|
|
186
|
+
>
|
|
187
|
+
{label}
|
|
188
|
+
</button>
|
|
189
|
+
)}
|
|
190
|
+
</form.Subscribe>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function ErrorMessages({
|
|
195
|
+
errors,
|
|
196
|
+
}: {
|
|
197
|
+
errors: Array<string | { message: string }>
|
|
198
|
+
}) {
|
|
199
|
+
return (
|
|
200
|
+
<>
|
|
201
|
+
{errors.map((error) => (
|
|
202
|
+
<div
|
|
203
|
+
key={typeof error === 'string' ? error : error.message}
|
|
204
|
+
className="text-red-500 mt-1 font-bold"
|
|
205
|
+
>
|
|
206
|
+
{typeof error === 'string' ? error : error.message}
|
|
207
|
+
</div>
|
|
208
|
+
))}
|
|
209
|
+
</>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function TextField({
|
|
214
|
+
label,
|
|
215
|
+
placeholder,
|
|
216
|
+
}: {
|
|
217
|
+
label: string
|
|
218
|
+
placeholder?: string
|
|
219
|
+
}) {
|
|
220
|
+
const field = useFieldContext<string>()
|
|
221
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<div>
|
|
225
|
+
<label htmlFor={label} className="block font-bold mb-1 text-xl">
|
|
226
|
+
{label}
|
|
227
|
+
<input
|
|
228
|
+
value={field.state.value}
|
|
229
|
+
placeholder={placeholder}
|
|
230
|
+
onBlur={field.handleBlur}
|
|
231
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
232
|
+
className="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
|
233
|
+
/>
|
|
234
|
+
</label>
|
|
235
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
236
|
+
</div>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function TextArea({
|
|
241
|
+
label,
|
|
242
|
+
rows = 3,
|
|
243
|
+
}: {
|
|
244
|
+
label: string
|
|
245
|
+
rows?: number
|
|
246
|
+
}) {
|
|
247
|
+
const field = useFieldContext<string>()
|
|
248
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div>
|
|
252
|
+
<label htmlFor={label} className="block font-bold mb-1 text-xl">
|
|
253
|
+
{label}
|
|
254
|
+
<textarea
|
|
255
|
+
value={field.state.value}
|
|
256
|
+
onBlur={field.handleBlur}
|
|
257
|
+
rows={rows}
|
|
258
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
259
|
+
className="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
|
260
|
+
/>
|
|
261
|
+
</label>
|
|
262
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
263
|
+
</div>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function Select({
|
|
268
|
+
label,
|
|
269
|
+
values,
|
|
270
|
+
}: {
|
|
271
|
+
label: string
|
|
272
|
+
values: Array<{ label: string; value: string }>
|
|
273
|
+
placeholder?: string
|
|
274
|
+
}) {
|
|
275
|
+
const field = useFieldContext<string>()
|
|
276
|
+
const errors = useStore(field.store, (state) => state.meta.errors)
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<div>
|
|
280
|
+
<label htmlFor={label} className="block font-bold mb-1 text-xl">
|
|
281
|
+
{label}
|
|
282
|
+
</label>
|
|
283
|
+
<select
|
|
284
|
+
name={field.name}
|
|
285
|
+
value={field.state.value}
|
|
286
|
+
onBlur={field.handleBlur}
|
|
287
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
288
|
+
className="w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"
|
|
289
|
+
>
|
|
290
|
+
{values.map((value) => (
|
|
291
|
+
<option key={value.value} value={value.value}>
|
|
292
|
+
{value.label}
|
|
293
|
+
</option>
|
|
294
|
+
))}
|
|
295
|
+
</select>
|
|
296
|
+
{field.state.meta.isTouched && <ErrorMessages errors={errors} />}
|
|
297
|
+
</div>
|
|
298
|
+
)
|
|
299
|
+
}
|
|
300
|
+
<% } %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createFormHook } from '@tanstack/react-form'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Select,
|
|
5
|
+
SubscribeButton,
|
|
6
|
+
TextArea,
|
|
7
|
+
TextField,
|
|
8
|
+
} from '../components/demo.FormComponents'
|
|
9
|
+
import { fieldContext, formContext } from './demo.form-context'
|
|
10
|
+
|
|
11
|
+
export const { useAppForm } = createFormHook({
|
|
12
|
+
fieldComponents: {
|
|
13
|
+
TextField,
|
|
14
|
+
Select,
|
|
15
|
+
TextArea,
|
|
16
|
+
},
|
|
17
|
+
formComponents: {
|
|
18
|
+
SubscribeButton,
|
|
19
|
+
},
|
|
20
|
+
fieldContext,
|
|
21
|
+
formContext,
|
|
22
|
+
})
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/react-router'
|
|
2
|
+
|
|
3
|
+
import { useAppForm } from '../hooks/demo.form'
|
|
4
|
+
|
|
5
|
+
<% if (codeRouter) { %>
|
|
6
|
+
import type { RootRoute } from '@tanstack/react-router'
|
|
7
|
+
<% } else { %>
|
|
8
|
+
export const Route = createFileRoute('/demo/form')({
|
|
9
|
+
component: AddressForm,
|
|
10
|
+
})
|
|
11
|
+
<% } %>
|
|
12
|
+
|
|
13
|
+
function AddressForm() {
|
|
14
|
+
const form = useAppForm({
|
|
15
|
+
defaultValues: {
|
|
16
|
+
fullName: '',
|
|
17
|
+
email: '',
|
|
18
|
+
address: {
|
|
19
|
+
street: '',
|
|
20
|
+
city: '',
|
|
21
|
+
state: '',
|
|
22
|
+
zipCode: '',
|
|
23
|
+
country: '',
|
|
24
|
+
},
|
|
25
|
+
phone: '',
|
|
26
|
+
},
|
|
27
|
+
validators: {
|
|
28
|
+
onBlur: ({ value }) => {
|
|
29
|
+
const errors = {
|
|
30
|
+
fields: {},
|
|
31
|
+
} as {
|
|
32
|
+
fields: Record<string, string>
|
|
33
|
+
}
|
|
34
|
+
if (value.fullName.trim().length === 0) {
|
|
35
|
+
errors.fields.fullName = 'Full name is required'
|
|
36
|
+
}
|
|
37
|
+
return errors
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
onSubmit: ({ value }) => {
|
|
41
|
+
console.log(value)
|
|
42
|
+
// Show success message
|
|
43
|
+
alert('Form submitted successfully!')
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
className="flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-100 to-blue-100 p-4 text-white"
|
|
50
|
+
style={{
|
|
51
|
+
backgroundImage:
|
|
52
|
+
'radial-gradient(50% 50% at 5% 40%, #f4a460 0%, #8b4513 70%, #1a0f0a 100%)',
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
<div className="w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10">
|
|
56
|
+
<form
|
|
57
|
+
onSubmit={(e) => {
|
|
58
|
+
e.preventDefault()
|
|
59
|
+
e.stopPropagation()
|
|
60
|
+
form.handleSubmit()
|
|
61
|
+
}}
|
|
62
|
+
className="space-y-6"
|
|
63
|
+
>
|
|
64
|
+
<form.AppField name="fullName">
|
|
65
|
+
{(field) => <field.TextField label="Full Name" />}
|
|
66
|
+
</form.AppField>
|
|
67
|
+
|
|
68
|
+
<form.AppField
|
|
69
|
+
name="email"
|
|
70
|
+
validators={{
|
|
71
|
+
onBlur: ({ value }) => {
|
|
72
|
+
if (!value || value.trim().length === 0) {
|
|
73
|
+
return 'Email is required'
|
|
74
|
+
}
|
|
75
|
+
if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value)) {
|
|
76
|
+
return 'Invalid email address'
|
|
77
|
+
}
|
|
78
|
+
return undefined
|
|
79
|
+
},
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
{(field) => <field.TextField label="Email" />}
|
|
83
|
+
</form.AppField>
|
|
84
|
+
|
|
85
|
+
<form.AppField
|
|
86
|
+
name="address.street"
|
|
87
|
+
validators={{
|
|
88
|
+
onBlur: ({ value }) => {
|
|
89
|
+
if (!value || value.trim().length === 0) {
|
|
90
|
+
return 'Street address is required'
|
|
91
|
+
}
|
|
92
|
+
return undefined
|
|
93
|
+
},
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
{(field) => <field.TextField label="Street Address" />}
|
|
97
|
+
</form.AppField>
|
|
98
|
+
|
|
99
|
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
100
|
+
<form.AppField
|
|
101
|
+
name="address.city"
|
|
102
|
+
validators={{
|
|
103
|
+
onBlur: ({ value }) => {
|
|
104
|
+
if (!value || value.trim().length === 0) {
|
|
105
|
+
return 'City is required'
|
|
106
|
+
}
|
|
107
|
+
return undefined
|
|
108
|
+
},
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
{(field) => <field.TextField label="City" />}
|
|
112
|
+
</form.AppField>
|
|
113
|
+
<form.AppField
|
|
114
|
+
name="address.state"
|
|
115
|
+
validators={{
|
|
116
|
+
onBlur: ({ value }) => {
|
|
117
|
+
if (!value || value.trim().length === 0) {
|
|
118
|
+
return 'State is required'
|
|
119
|
+
}
|
|
120
|
+
return undefined
|
|
121
|
+
},
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
{(field) => <field.TextField label="State" />}
|
|
125
|
+
</form.AppField>
|
|
126
|
+
<form.AppField
|
|
127
|
+
name="address.zipCode"
|
|
128
|
+
validators={{
|
|
129
|
+
onBlur: ({ value }) => {
|
|
130
|
+
if (!value || value.trim().length === 0) {
|
|
131
|
+
return 'Zip code is required'
|
|
132
|
+
}
|
|
133
|
+
if (!/^\d{5}(-\d{4})?$/.test(value)) {
|
|
134
|
+
return 'Invalid zip code format'
|
|
135
|
+
}
|
|
136
|
+
return undefined
|
|
137
|
+
},
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{(field) => <field.TextField label="Zip Code" />}
|
|
141
|
+
</form.AppField>
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<form.AppField
|
|
145
|
+
name="address.country"
|
|
146
|
+
validators={{
|
|
147
|
+
onBlur: ({ value }) => {
|
|
148
|
+
if (!value || value.trim().length === 0) {
|
|
149
|
+
return 'Country is required'
|
|
150
|
+
}
|
|
151
|
+
return undefined
|
|
152
|
+
},
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{(field) => (
|
|
156
|
+
<field.Select
|
|
157
|
+
label="Country"
|
|
158
|
+
values={[
|
|
159
|
+
{ label: 'United States', value: 'US' },
|
|
160
|
+
{ label: 'Canada', value: 'CA' },
|
|
161
|
+
{ label: 'United Kingdom', value: 'UK' },
|
|
162
|
+
{ label: 'Australia', value: 'AU' },
|
|
163
|
+
{ label: 'Germany', value: 'DE' },
|
|
164
|
+
{ label: 'France', value: 'FR' },
|
|
165
|
+
{ label: 'Japan', value: 'JP' },
|
|
166
|
+
]}
|
|
167
|
+
placeholder="Select a country"
|
|
168
|
+
/>
|
|
169
|
+
)}
|
|
170
|
+
</form.AppField>
|
|
171
|
+
|
|
172
|
+
<form.AppField
|
|
173
|
+
name="phone"
|
|
174
|
+
validators={{
|
|
175
|
+
onBlur: ({ value }) => {
|
|
176
|
+
if (!value || value.trim().length === 0) {
|
|
177
|
+
return 'Phone number is required'
|
|
178
|
+
}
|
|
179
|
+
if (
|
|
180
|
+
!/^(\+\d{1,3})?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/.test(
|
|
181
|
+
value,
|
|
182
|
+
)
|
|
183
|
+
) {
|
|
184
|
+
return 'Invalid phone number format'
|
|
185
|
+
}
|
|
186
|
+
return undefined
|
|
187
|
+
},
|
|
188
|
+
}}
|
|
189
|
+
>
|
|
190
|
+
{(field) => (
|
|
191
|
+
<field.TextField label="Phone" placeholder="123-456-7890" />
|
|
192
|
+
)}
|
|
193
|
+
</form.AppField>
|
|
194
|
+
|
|
195
|
+
<div className="flex justify-end">
|
|
196
|
+
<form.AppForm>
|
|
197
|
+
<form.SubscribeButton label="Submit" />
|
|
198
|
+
</form.AppForm>
|
|
199
|
+
</div>
|
|
200
|
+
</form>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
<% if (codeRouter) { %>
|
|
208
|
+
export default (parentRoute: RootRoute) => createRoute({
|
|
209
|
+
path: '/demo/form/address',
|
|
210
|
+
component: AddressForm,
|
|
211
|
+
getParentRoute: () => parentRoute,
|
|
212
|
+
})
|
|
213
|
+
<% } %>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/react-router'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
import { useAppForm } from '../hooks/demo.form'
|
|
5
|
+
|
|
6
|
+
<% if (codeRouter) { %>
|
|
7
|
+
import type { RootRoute } from '@tanstack/react-router'
|
|
8
|
+
<% } else { %>
|
|
9
|
+
export const Route = createFileRoute('/demo/form')({
|
|
10
|
+
component: SimpleForm,
|
|
11
|
+
})
|
|
12
|
+
<% } %>
|
|
13
|
+
|
|
14
|
+
const schema = z.object({
|
|
15
|
+
title: z.string().min(1, 'Title is required'),
|
|
16
|
+
description: z.string().min(1, 'Description is required'),
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
function SimpleForm() {
|
|
20
|
+
const form = useAppForm({
|
|
21
|
+
defaultValues: {
|
|
22
|
+
title: '',
|
|
23
|
+
description: '',
|
|
24
|
+
},
|
|
25
|
+
validators: {
|
|
26
|
+
onBlur: schema,
|
|
27
|
+
},
|
|
28
|
+
onSubmit: ({ value }) => {
|
|
29
|
+
console.log(value)
|
|
30
|
+
// Show success message
|
|
31
|
+
alert('Form submitted successfully!')
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
className="flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-100 to-blue-100 p-4 text-white"
|
|
38
|
+
style={{
|
|
39
|
+
backgroundImage:
|
|
40
|
+
'radial-gradient(50% 50% at 5% 40%, #add8e6 0%, #0000ff 70%, #00008b 100%)',
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<div className="w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10">
|
|
44
|
+
<form
|
|
45
|
+
onSubmit={(e) => {
|
|
46
|
+
e.preventDefault()
|
|
47
|
+
e.stopPropagation()
|
|
48
|
+
form.handleSubmit()
|
|
49
|
+
}}
|
|
50
|
+
className="space-y-6"
|
|
51
|
+
>
|
|
52
|
+
<form.AppField name="title">
|
|
53
|
+
{(field) => <field.TextField label="Title" />}
|
|
54
|
+
</form.AppField>
|
|
55
|
+
|
|
56
|
+
<form.AppField name="description">
|
|
57
|
+
{(field) => <field.TextArea label="Description" />}
|
|
58
|
+
</form.AppField>
|
|
59
|
+
|
|
60
|
+
<div className="flex justify-end">
|
|
61
|
+
<form.AppForm>
|
|
62
|
+
<form.SubscribeButton label="Submit" />
|
|
63
|
+
</form.AppForm>
|
|
64
|
+
</div>
|
|
65
|
+
</form>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
<% if (codeRouter) { %>
|
|
72
|
+
export default (parentRoute: RootRoute) => createRoute({
|
|
73
|
+
path: '/demo/form/simple',
|
|
74
|
+
component: SimpleForm,
|
|
75
|
+
getParentRoute: () => parentRoute,
|
|
76
|
+
})
|
|
77
|
+
<% } %>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Form",
|
|
3
|
+
"description": "TanStack Form",
|
|
4
|
+
"phase": "add-on",
|
|
5
|
+
"templates": ["file-router", "code-router"],
|
|
6
|
+
"link": "https://tanstack.com/form/latest",
|
|
7
|
+
"routes": [
|
|
8
|
+
{
|
|
9
|
+
"url": "/demo/form/simple",
|
|
10
|
+
"name": "Simple Form"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"url": "/demo/form/address",
|
|
14
|
+
"name": "Address Form"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"shadcnComponents": [
|
|
18
|
+
"button",
|
|
19
|
+
"select",
|
|
20
|
+
"input",
|
|
21
|
+
"textarea",
|
|
22
|
+
"slider",
|
|
23
|
+
"switch",
|
|
24
|
+
"label"
|
|
25
|
+
]
|
|
26
|
+
}
|