skillfullstack 0.0.0-stage → 1.0.1
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/.skillsRegistry/catalog.json +231 -0
- package/AGENTS.md +89 -0
- package/README.md +210 -2
- package/bin/index.js +508 -0
- package/package.json +57 -4
- package/skills/backend/apiEngineering/SKILL.md +102 -0
- package/skills/backend/apiEngineering/evals/evalApiEngineering.py +81 -0
- package/skills/backend/apiEngineering/evals/fixtures/invalid/sampleInvalidOpenApi.json +40 -0
- package/skills/backend/apiEngineering/evals/fixtures/valid/sampleValidOpenApi.json +47 -0
- package/skills/backend/apiEngineering/policies/compatibility.md +42 -0
- package/skills/backend/apiEngineering/policies/mandatory.md +48 -0
- package/skills/backend/apiEngineering/policies/performance.md +39 -0
- package/skills/backend/apiEngineering/policies/security.md +36 -0
- package/skills/backend/apiEngineering/references/apiObservability.md +39 -0
- package/skills/backend/apiEngineering/references/apiReference.md +3 -0
- package/skills/backend/apiEngineering/references/apiSecurityOwasp.md +47 -0
- package/skills/backend/apiEngineering/references/contractCompatibility.md +26 -0
- package/skills/backend/apiEngineering/references/databaseTransactions.md +40 -0
- package/skills/backend/apiEngineering/references/distributedReliability.md +26 -0
- package/skills/backend/apiEngineering/references/multiTenancy.md +27 -0
- package/skills/backend/apiEngineering/references/openApi32Standards.md +58 -0
- package/skills/backend/apiEngineering/references/paginationVersioning.md +57 -0
- package/skills/backend/apiEngineering/references/responseStandards.md +94 -0
- package/skills/backend/apiEngineering/scripts/auditApiContract.py +123 -0
- package/skills/backend/apiEngineering/scripts/checkBreakingChanges.py +77 -0
- package/skills/backend/apiEngineering/scripts/generateResponseEnvelope.py +88 -0
- package/skills/backend/apiEngineering/templates/apiChecklist.md +27 -0
- package/skills/backend/apiEngineering/templates/openapi.yaml +125 -0
- package/skills/backend/apiEngineering/templates/problemDetails.json +44 -0
- package/skills/backend/databaseArchitecture/SKILL.md +118 -0
- package/skills/backend/databaseArchitecture/evals/evalDatabaseArchitecture.py +85 -0
- package/skills/backend/databaseArchitecture/evals/fixtures/dangerousMigration.sql +4 -0
- package/skills/backend/databaseArchitecture/evals/fixtures/invalidSchema.sql +23 -0
- package/skills/backend/databaseArchitecture/evals/fixtures/safeMigration.sql +3 -0
- package/skills/backend/databaseArchitecture/evals/fixtures/validSchema.sql +37 -0
- package/skills/backend/databaseArchitecture/policies/integrity.md +25 -0
- package/skills/backend/databaseArchitecture/policies/mandatory.md +32 -0
- package/skills/backend/databaseArchitecture/policies/migration.md +22 -0
- package/skills/backend/databaseArchitecture/policies/normalization.md +25 -0
- package/skills/backend/databaseArchitecture/policies/performance.md +26 -0
- package/skills/backend/databaseArchitecture/policies/recovery.md +23 -0
- package/skills/backend/databaseArchitecture/policies/security.md +26 -0
- package/skills/backend/databaseArchitecture/policies/tableCreationChecklist.md +70 -0
- package/skills/backend/databaseArchitecture/references/analyticsWarehousing.md +32 -0
- package/skills/backend/databaseArchitecture/references/apiReference.md +3 -0
- package/skills/backend/databaseArchitecture/references/backupDisasterRecovery.md +27 -0
- package/skills/backend/databaseArchitecture/references/dataModelingLifecycle.md +30 -0
- package/skills/backend/databaseArchitecture/references/databaseTaxonomy.md +32 -0
- package/skills/backend/databaseArchitecture/references/indexingOptimization.md +32 -0
- package/skills/backend/databaseArchitecture/references/normalizationTheory.md +61 -0
- package/skills/backend/databaseArchitecture/references/scalabilitySharding.md +37 -0
- package/skills/backend/databaseArchitecture/references/transactionConcurrency.md +39 -0
- package/skills/backend/databaseArchitecture/scripts/analyzeMigration.py +99 -0
- package/skills/backend/databaseArchitecture/scripts/auditDatabaseSchema.py +177 -0
- package/skills/backend/databaseArchitecture/scripts/inspectDatabaseIndexes.py +149 -0
- package/skills/backend/databaseArchitecture/templates/adrTemplate.md +32 -0
- package/skills/backend/databaseArchitecture/templates/databaseChecklist.md +29 -0
- package/skills/backend/databaseArchitecture/templates/migrationPlan.md +40 -0
- package/skills/backend/durableBackgroundJobs/SKILL.md +112 -0
- package/skills/backend/durableBackgroundJobs/evals/durableJobVerification.json +14 -0
- package/skills/backend/durableBackgroundJobs/references/apiReference.md +3 -0
- package/skills/backend/durableBackgroundJobs/references/durableStepPatterns.md +6 -0
- package/skills/backend/durableBackgroundJobs/references/idempotencyKeys.md +5 -0
- package/skills/backend/durableBackgroundJobs/scripts/testWorkflowDispatch.py +24 -0
- package/skills/backend/golangStandard/SKILL.md +155 -0
- package/skills/backend/golangStandard/evals/goVerification.json +14 -0
- package/skills/backend/golangStandard/references/apiReference.md +3 -0
- package/skills/backend/golangStandard/references/layoutGuide.md +26 -0
- package/skills/backend/golangStandard/references/slogPatterns.md +26 -0
- package/skills/backend/golangStandard/scripts/scaffoldGoModule.py +105 -0
- package/skills/backend/pythonStandard/SKILL.md +138 -0
- package/skills/backend/pythonStandard/evals/pythonVerification.json +14 -0
- package/skills/backend/pythonStandard/references/apiReference.md +3 -0
- package/skills/backend/pythonStandard/references/pydanticPatterns.md +16 -0
- package/skills/backend/pythonStandard/references/pyprojectSpecs.md +37 -0
- package/skills/backend/pythonStandard/scripts/scaffoldUvProject.py +79 -0
- package/skills/backend/upstash/SKILL.md +98 -0
- package/skills/backend/upstash/evals/upstashVerification.json +14 -0
- package/skills/backend/upstash/references/apiReference.md +3 -0
- package/skills/backend/upstash/references/qstashFlowControl.md +34 -0
- package/skills/backend/upstash/references/ratelimitPatterns.md +53 -0
- package/skills/backend/upstash/references/workflowPatterns.md +35 -0
- package/skills/backend/upstash/scripts/testRedisConnection.py +36 -0
- package/skills/cicdDevops/cicdPipeline/SKILL.md +148 -0
- package/skills/cicdDevops/cicdPipeline/evals/evalCicd.py +37 -0
- package/skills/cicdDevops/cicdPipeline/references/apiReference.md +3 -0
- package/skills/cicdDevops/cicdPipeline/references/cicdDeploymentPatterns.md +27 -0
- package/skills/cicdDevops/cicdPipeline/scripts/auditDockerfileSecurity.py +56 -0
- package/skills/dataAi/mcpServerDevelopment/SKILL.md +123 -0
- package/skills/dataAi/mcpServerDevelopment/evals/mcpVerification.json +14 -0
- package/skills/dataAi/mcpServerDevelopment/references/apiReference.md +3 -0
- package/skills/dataAi/mcpServerDevelopment/references/mcpClientConfigs.md +38 -0
- package/skills/dataAi/mcpServerDevelopment/references/toolSchemaDesign.md +6 -0
- package/skills/dataAi/mcpServerDevelopment/scripts/runFastMcpBoilerplate.py +36 -0
- package/skills/dataAi/ragPipelineProduction/SKILL.md +113 -0
- package/skills/dataAi/ragPipelineProduction/evals/ragVerification.json +14 -0
- package/skills/dataAi/ragPipelineProduction/references/apiReference.md +3 -0
- package/skills/dataAi/ragPipelineProduction/references/chunkingStrategies.md +10 -0
- package/skills/dataAi/ragPipelineProduction/references/rrfAlgorithm.md +13 -0
- package/skills/dataAi/ragPipelineProduction/scripts/runHybridRrfSearch.py +33 -0
- package/skills/devopsCloud/cloudflare/SKILL.md +282 -0
- package/skills/devopsCloud/cloudflare/assets/README.md +48 -0
- package/skills/devopsCloud/cloudflare/assets/ai/agents-sdk.md +118 -0
- package/skills/devopsCloud/cloudflare/assets/ai/ai-gateway.md +105 -0
- package/skills/devopsCloud/cloudflare/assets/ai/ai-search.md +129 -0
- package/skills/devopsCloud/cloudflare/assets/ai/workers-ai.md +127 -0
- package/skills/devopsCloud/cloudflare/assets/cli/c3.md +292 -0
- package/skills/devopsCloud/cloudflare/assets/cli/cf-cli.md +90 -0
- package/skills/devopsCloud/cloudflare/assets/cli/wrangler.md +43 -0
- package/skills/devopsCloud/cloudflare/assets/compute/cron-triggers.md +486 -0
- package/skills/devopsCloud/cloudflare/assets/compute/service-bindings.md +251 -0
- package/skills/devopsCloud/cloudflare/assets/compute/smart-placement.md +435 -0
- package/skills/devopsCloud/cloudflare/assets/compute/static-assets.md +220 -0
- package/skills/devopsCloud/cloudflare/assets/compute/workers.md +129 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/d1.md +105 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/durable-objects.md +122 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/hyperdrive.md +210 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/kv.md +198 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/queues.md +105 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/r2.md +105 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/vectorize.md +97 -0
- package/skills/devopsCloud/cloudflare/assets/database-storage/workflows.md +141 -0
- package/skills/devopsCloud/cloudflare/assets/llms.txt +143 -0
- package/skills/devopsCloud/cloudflare/assets/networking-security/cache-cdn.md +109 -0
- package/skills/devopsCloud/cloudflare/assets/networking-security/dns.md +71 -0
- package/skills/devopsCloud/cloudflare/assets/networking-security/rate-limiting.md +130 -0
- package/skills/devopsCloud/cloudflare/assets/networking-security/tunnels.md +57 -0
- package/skills/devopsCloud/cloudflare/assets/networking-security/waf.md +143 -0
- package/skills/devopsCloud/cloudflare/assets/troubleshooting/1xxx-errors.md +209 -0
- package/skills/devopsCloud/cloudflare/assets/troubleshooting/5xx-errors.md +111 -0
- package/skills/devopsCloud/cloudflare/assets/troubleshooting/http-status-codes.md +38 -0
- package/skills/devopsCloud/cloudflare/evals/evals.json +75 -0
- package/skills/devopsCloud/cloudflare/references/ai-gateway/README.md +27 -0
- package/skills/devopsCloud/cloudflare/references/ai-gateway/configuration.md +18 -0
- package/skills/devopsCloud/cloudflare/references/ai-gateway/dynamic-routing.md +15 -0
- package/skills/devopsCloud/cloudflare/references/ai-gateway/features.md +22 -0
- package/skills/devopsCloud/cloudflare/references/ai-gateway/sdk-integration.md +19 -0
- package/skills/devopsCloud/cloudflare/references/ai-gateway/troubleshooting.md +16 -0
- package/skills/devopsCloud/cloudflare/references/ai-search/README.md +25 -0
- package/skills/devopsCloud/cloudflare/references/ai-search/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/ai-search/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/ai-search/gotchas.md +13 -0
- package/skills/devopsCloud/cloudflare/references/ai-search/patterns.md +15 -0
- package/skills/devopsCloud/cloudflare/references/bindings/README.md +16 -0
- package/skills/devopsCloud/cloudflare/references/bindings/api.md +19 -0
- package/skills/devopsCloud/cloudflare/references/bindings/configuration.md +20 -0
- package/skills/devopsCloud/cloudflare/references/bindings/gotchas.md +18 -0
- package/skills/devopsCloud/cloudflare/references/bindings/patterns.md +20 -0
- package/skills/devopsCloud/cloudflare/references/browser-rendering/README.md +18 -0
- package/skills/devopsCloud/cloudflare/references/browser-rendering/api.md +12 -0
- package/skills/devopsCloud/cloudflare/references/browser-rendering/configuration.md +12 -0
- package/skills/devopsCloud/cloudflare/references/browser-rendering/gotchas.md +15 -0
- package/skills/devopsCloud/cloudflare/references/browser-rendering/patterns.md +12 -0
- package/skills/devopsCloud/cloudflare/references/cliComparison.md +93 -0
- package/skills/devopsCloud/cloudflare/references/containers/README.md +23 -0
- package/skills/devopsCloud/cloudflare/references/containers/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/containers/configuration.md +15 -0
- package/skills/devopsCloud/cloudflare/references/containers/gotchas.md +16 -0
- package/skills/devopsCloud/cloudflare/references/containers/patterns.md +18 -0
- package/skills/devopsCloud/cloudflare/references/cron-triggers/README.md +20 -0
- package/skills/devopsCloud/cloudflare/references/cron-triggers/api.md +16 -0
- package/skills/devopsCloud/cloudflare/references/cron-triggers/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/cron-triggers/gotchas.md +17 -0
- package/skills/devopsCloud/cloudflare/references/cron-triggers/patterns.md +18 -0
- package/skills/devopsCloud/cloudflare/references/d1/README.md +15 -0
- package/skills/devopsCloud/cloudflare/references/d1/api.md +18 -0
- package/skills/devopsCloud/cloudflare/references/d1/configuration.md +18 -0
- package/skills/devopsCloud/cloudflare/references/d1/gotchas.md +18 -0
- package/skills/devopsCloud/cloudflare/references/d1/patterns.md +21 -0
- package/skills/devopsCloud/cloudflare/references/frameworkCompatibility.md +110 -0
- package/skills/devopsCloud/cloudflare/references/hyperdrive/README.md +28 -0
- package/skills/devopsCloud/cloudflare/references/hyperdrive/api.md +26 -0
- package/skills/devopsCloud/cloudflare/references/hyperdrive/configuration.md +34 -0
- package/skills/devopsCloud/cloudflare/references/hyperdrive/gotchas.md +20 -0
- package/skills/devopsCloud/cloudflare/references/hyperdrive/patterns.md +15 -0
- package/skills/devopsCloud/cloudflare/references/images/README.md +12 -0
- package/skills/devopsCloud/cloudflare/references/images/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/images/configuration.md +17 -0
- package/skills/devopsCloud/cloudflare/references/images/gotchas.md +16 -0
- package/skills/devopsCloud/cloudflare/references/images/patterns.md +16 -0
- package/skills/devopsCloud/cloudflare/references/kv/README.md +15 -0
- package/skills/devopsCloud/cloudflare/references/kv/api.md +18 -0
- package/skills/devopsCloud/cloudflare/references/kv/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/kv/gotchas.md +17 -0
- package/skills/devopsCloud/cloudflare/references/kv/patterns.md +21 -0
- package/skills/devopsCloud/cloudflare/references/miniflare/README.md +22 -0
- package/skills/devopsCloud/cloudflare/references/miniflare/api.md +16 -0
- package/skills/devopsCloud/cloudflare/references/miniflare/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/miniflare/gotchas.md +15 -0
- package/skills/devopsCloud/cloudflare/references/miniflare/patterns.md +19 -0
- package/skills/devopsCloud/cloudflare/references/observability/README.md +27 -0
- package/skills/devopsCloud/cloudflare/references/observability/api.md +20 -0
- package/skills/devopsCloud/cloudflare/references/observability/configuration.md +23 -0
- package/skills/devopsCloud/cloudflare/references/observability/gotchas.md +25 -0
- package/skills/devopsCloud/cloudflare/references/observability/patterns.md +14 -0
- package/skills/devopsCloud/cloudflare/references/pages/README.md +20 -0
- package/skills/devopsCloud/cloudflare/references/pages/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/pages/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/pages/gotchas.md +19 -0
- package/skills/devopsCloud/cloudflare/references/pages/patterns.md +15 -0
- package/skills/devopsCloud/cloudflare/references/pages-functions/README.md +20 -0
- package/skills/devopsCloud/cloudflare/references/pages-functions/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/pages-functions/configuration.md +14 -0
- package/skills/devopsCloud/cloudflare/references/pages-functions/gotchas.md +17 -0
- package/skills/devopsCloud/cloudflare/references/pages-functions/patterns.md +16 -0
- package/skills/devopsCloud/cloudflare/references/productSelectionMatrix.md +54 -0
- package/skills/devopsCloud/cloudflare/references/queues/README.md +24 -0
- package/skills/devopsCloud/cloudflare/references/queues/api.md +16 -0
- package/skills/devopsCloud/cloudflare/references/queues/configuration.md +20 -0
- package/skills/devopsCloud/cloudflare/references/queues/gotchas.md +18 -0
- package/skills/devopsCloud/cloudflare/references/queues/patterns.md +21 -0
- package/skills/devopsCloud/cloudflare/references/r2/README.md +26 -0
- package/skills/devopsCloud/cloudflare/references/r2/api.md +16 -0
- package/skills/devopsCloud/cloudflare/references/r2/configuration.md +19 -0
- package/skills/devopsCloud/cloudflare/references/r2/gotchas.md +17 -0
- package/skills/devopsCloud/cloudflare/references/r2/patterns.md +18 -0
- package/skills/devopsCloud/cloudflare/references/secrets-store/README.md +22 -0
- package/skills/devopsCloud/cloudflare/references/secrets-store/api.md +21 -0
- package/skills/devopsCloud/cloudflare/references/secrets-store/configuration.md +25 -0
- package/skills/devopsCloud/cloudflare/references/secrets-store/gotchas.md +19 -0
- package/skills/devopsCloud/cloudflare/references/secrets-store/patterns.md +27 -0
- package/skills/devopsCloud/cloudflare/references/skill-feedback.md +41 -0
- package/skills/devopsCloud/cloudflare/references/static-assets/README.md +21 -0
- package/skills/devopsCloud/cloudflare/references/static-assets/api.md +16 -0
- package/skills/devopsCloud/cloudflare/references/static-assets/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/static-assets/gotchas.md +18 -0
- package/skills/devopsCloud/cloudflare/references/static-assets/patterns.md +17 -0
- package/skills/devopsCloud/cloudflare/references/stream/README.md +22 -0
- package/skills/devopsCloud/cloudflare/references/stream/api-live.md +18 -0
- package/skills/devopsCloud/cloudflare/references/stream/api.md +21 -0
- package/skills/devopsCloud/cloudflare/references/stream/configuration.md +18 -0
- package/skills/devopsCloud/cloudflare/references/stream/gotchas.md +18 -0
- package/skills/devopsCloud/cloudflare/references/stream/patterns.md +22 -0
- package/skills/devopsCloud/cloudflare/references/tail-workers/README.md +21 -0
- package/skills/devopsCloud/cloudflare/references/tail-workers/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/tail-workers/configuration.md +15 -0
- package/skills/devopsCloud/cloudflare/references/tail-workers/gotchas.md +16 -0
- package/skills/devopsCloud/cloudflare/references/tail-workers/patterns.md +15 -0
- package/skills/devopsCloud/cloudflare/references/tunnel/README.md +20 -0
- package/skills/devopsCloud/cloudflare/references/tunnel/api.md +14 -0
- package/skills/devopsCloud/cloudflare/references/tunnel/configuration.md +14 -0
- package/skills/devopsCloud/cloudflare/references/tunnel/gotchas.md +15 -0
- package/skills/devopsCloud/cloudflare/references/tunnel/networking.md +14 -0
- package/skills/devopsCloud/cloudflare/references/tunnel/patterns.md +15 -0
- package/skills/devopsCloud/cloudflare/references/vectorize/README.md +22 -0
- package/skills/devopsCloud/cloudflare/references/vectorize/api.md +18 -0
- package/skills/devopsCloud/cloudflare/references/vectorize/configuration.md +19 -0
- package/skills/devopsCloud/cloudflare/references/vectorize/gotchas.md +15 -0
- package/skills/devopsCloud/cloudflare/references/vectorize/patterns.md +24 -0
- package/skills/devopsCloud/cloudflare/references/waf/README.md +21 -0
- package/skills/devopsCloud/cloudflare/references/waf/api.md +17 -0
- package/skills/devopsCloud/cloudflare/references/waf/configuration.md +18 -0
- package/skills/devopsCloud/cloudflare/references/waf/gotchas.md +19 -0
- package/skills/devopsCloud/cloudflare/references/waf/patterns.md +17 -0
- package/skills/devopsCloud/cloudflare/references/workers-ai/README.md +24 -0
- package/skills/devopsCloud/cloudflare/references/workers-ai/api.md +13 -0
- package/skills/devopsCloud/cloudflare/references/workers-ai/configuration.md +16 -0
- package/skills/devopsCloud/cloudflare/references/workers-ai/gotchas.md +15 -0
- package/skills/devopsCloud/cloudflare/references/workers-ai/patterns.md +14 -0
- package/skills/devopsCloud/cloudflare/references/workflows/README.md +23 -0
- package/skills/devopsCloud/cloudflare/references/workflows/api.md +17 -0
- package/skills/devopsCloud/cloudflare/references/workflows/configuration.md +18 -0
- package/skills/devopsCloud/cloudflare/references/workflows/gotchas.md +19 -0
- package/skills/devopsCloud/cloudflare/references/workflows/patterns.md +30 -0
- package/skills/devopsCloud/cloudflare/scripts/auditCloudflareProduction.py +95 -0
- package/skills/foundation/promptEvalTesting/SKILL.md +114 -0
- package/skills/foundation/promptEvalTesting/evals/promptEvalVerification.json +14 -0
- package/skills/foundation/promptEvalTesting/references/apiReference.md +3 -0
- package/skills/foundation/promptEvalTesting/references/evalMetricsCatalog.md +7 -0
- package/skills/foundation/promptEvalTesting/references/promptfooConfigSpecs.md +16 -0
- package/skills/foundation/promptEvalTesting/scripts/runPromptEvalSuite.py +29 -0
- package/skills/frontend/astro/SKILL.md +327 -0
- package/skills/frontend/astro/assets/README.md +71 -0
- package/skills/frontend/astro/assets/add-content-to-your-site/content-collections.md +1061 -0
- package/skills/frontend/astro/assets/add-content-to-your-site/data-fetching.md +109 -0
- package/skills/frontend/astro/assets/add-content-to-your-site/images.md +719 -0
- package/skills/frontend/astro/assets/add-content-to-your-site/markdown.md +725 -0
- package/skills/frontend/astro/assets/build-your-ui/components.md +402 -0
- package/skills/frontend/astro/assets/build-your-ui/fonts.md +437 -0
- package/skills/frontend/astro/assets/build-your-ui/front-end-frameworks.md +245 -0
- package/skills/frontend/astro/assets/build-your-ui/layouts.md +267 -0
- package/skills/frontend/astro/assets/build-your-ui/scripts-and-event-handling.md +229 -0
- package/skills/frontend/astro/assets/build-your-ui/styles-and-css.md +782 -0
- package/skills/frontend/astro/assets/build-your-ui/syntax-highlighting.md +269 -0
- package/skills/frontend/astro/assets/configuration/build-with-ai.md +389 -0
- package/skills/frontend/astro/assets/configuration/configuration-overview.md +122 -0
- package/skills/frontend/astro/assets/configuration/dev-toolbar.md +86 -0
- package/skills/frontend/astro/assets/configuration/editor-setup.md +166 -0
- package/skills/frontend/astro/assets/configuration/environment-variables.md +352 -0
- package/skills/frontend/astro/assets/configuration/typescript.md +379 -0
- package/skills/frontend/astro/assets/configuration/working-with-integrations.md +606 -0
- package/skills/frontend/astro/assets/reference/adapter-reference.md +1242 -0
- package/skills/frontend/astro/assets/reference/cli-reference.md +575 -0
- package/skills/frontend/astro/assets/reference/configuration-reference.md +3144 -0
- package/skills/frontend/astro/assets/reference/content-loader-reference.md +1682 -0
- package/skills/frontend/astro/assets/reference/directives-reference.md +324 -0
- package/skills/frontend/astro/assets/reference/image-service-reference.md +346 -0
- package/skills/frontend/astro/assets/reference/integrations-reference.md +2813 -0
- package/skills/frontend/astro/assets/reference/modules/astro-actions.md +604 -0
- package/skills/frontend/astro/assets/reference/modules/astro-app.md +460 -0
- package/skills/frontend/astro/assets/reference/modules/astro-assets.md +1657 -0
- package/skills/frontend/astro/assets/reference/modules/astro-config.md +395 -0
- package/skills/frontend/astro/assets/reference/modules/astro-content.md +720 -0
- package/skills/frontend/astro/assets/reference/modules/astro-env.md +46 -0
- package/skills/frontend/astro/assets/reference/modules/astro-fetch.md +346 -0
- package/skills/frontend/astro/assets/reference/modules/astro-hono.md +37 -0
- package/skills/frontend/astro/assets/reference/modules/astro-i18n.md +462 -0
- package/skills/frontend/astro/assets/reference/modules/astro-middleware.md +292 -0
- package/skills/frontend/astro/assets/reference/modules/astro-static-paths.md +74 -0
- package/skills/frontend/astro/assets/reference/modules/astro-transitions.md +595 -0
- package/skills/frontend/astro/assets/reference/modules/astro-zod.md +120 -0
- package/skills/frontend/astro/assets/reference/session-driver-reference.md +205 -0
- package/skills/frontend/astro/assets/routing-and-navigation/endpoints.md +251 -0
- package/skills/frontend/astro/assets/routing-and-navigation/internationalization.md +374 -0
- package/skills/frontend/astro/assets/routing-and-navigation/middleware.md +288 -0
- package/skills/frontend/astro/assets/routing-and-navigation/pages.md +205 -0
- package/skills/frontend/astro/assets/routing-and-navigation/prefetch.md +273 -0
- package/skills/frontend/astro/assets/routing-and-navigation/routing.md +760 -0
- package/skills/frontend/astro/assets/routing-and-navigation/view-transitions.md +792 -0
- package/skills/frontend/astro/assets/server-rendering/actions.md +770 -0
- package/skills/frontend/astro/assets/server-rendering/caching.md +255 -0
- package/skills/frontend/astro/assets/server-rendering/on-demand-rendering.md +289 -0
- package/skills/frontend/astro/assets/server-rendering/server-islands.md +126 -0
- package/skills/frontend/astro/assets/server-rendering/sessions.md +270 -0
- package/skills/frontend/astro/assets/start-a-new-project/develop-and-build.md +147 -0
- package/skills/frontend/astro/assets/start-a-new-project/installation.md +342 -0
- package/skills/frontend/astro/assets/start-a-new-project/project-structure.md +137 -0
- package/skills/frontend/astro/assets/upgrade-and-troubleshooting/testing.md +412 -0
- package/skills/frontend/astro/assets/upgrade-and-troubleshooting/troubleshooting.md +229 -0
- package/skills/frontend/astro/assets/upgrade-and-troubleshooting/upgrade-astro.md +205 -0
- package/skills/frontend/astro/assets/welcome/courses.md +46 -0
- package/skills/frontend/astro/assets/welcome/islands-architecture.md +135 -0
- package/skills/frontend/astro/assets/welcome/why-astro.md +90 -0
- package/skills/frontend/astro/evals/evals.json +66 -0
- package/skills/frontend/astro/references/contentCollections.md +164 -0
- package/skills/frontend/astro/references/islandsArchitecture.md +128 -0
- package/skills/frontend/astro/references/serverIslandsAndActions.md +187 -0
- package/skills/frontend/astro/scripts/auditAstroProduction.py +78 -0
- package/skills/frontend/generativeUi/SKILL.md +128 -0
- package/skills/frontend/generativeUi/evals/generativeUiVerification.json +14 -0
- package/skills/frontend/generativeUi/references/apiReference.md +3 -0
- package/skills/frontend/generativeUi/references/clientToolComponentMapping.md +8 -0
- package/skills/frontend/generativeUi/references/dataStreamProtocol.md +10 -0
- package/skills/frontend/generativeUi/scripts/generateUiComponentStub.py +46 -0
- package/skills/frontend/nextjs/SKILL.md +138 -0
- package/skills/frontend/nextjs/assets/README.md +67 -0
- package/skills/frontend/nextjs/assets/api-reference/cli/create-next-app.md +210 -0
- package/skills/frontend/nextjs/assets/api-reference/cli/next.md +484 -0
- package/skills/frontend/nextjs/assets/api-reference/components/font.md +952 -0
- package/skills/frontend/nextjs/assets/api-reference/components/form.md +387 -0
- package/skills/frontend/nextjs/assets/api-reference/components/image.md +1372 -0
- package/skills/frontend/nextjs/assets/api-reference/components/link.md +954 -0
- package/skills/frontend/nextjs/assets/api-reference/components/script.md +421 -0
- package/skills/frontend/nextjs/assets/api-reference/directives/use-cache-private.md +211 -0
- package/skills/frontend/nextjs/assets/api-reference/directives/use-cache-remote.md +652 -0
- package/skills/frontend/nextjs/assets/api-reference/directives/use-cache.md +848 -0
- package/skills/frontend/nextjs/assets/api-reference/directives/use-client.md +149 -0
- package/skills/frontend/nextjs/assets/api-reference/directives/use-server.md +234 -0
- package/skills/frontend/nextjs/assets/api-reference/edge-runtime.md +188 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/default.md +80 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/dynamic-routes.md +417 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/error.md +361 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/forbidden.md +75 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/instrumentation-client.md +308 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/instrumentation.md +177 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/intercepting-routes.md +78 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/layout.md +803 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/loading.md +209 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/mdx-components.md +84 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/metadata/app-icons.md +302 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/metadata/manifest.md +90 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/metadata/opengraph-image.md +580 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/metadata/robots.md +234 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/metadata/sitemap.md +459 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/not-found.md +278 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/page.md +283 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/parallel-routes.md +517 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/proxy.md +857 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/public-folder.md +47 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-groups.md +40 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/dynamicParams.md +40 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/ensureStatic.md +195 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/instant.md +204 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/maxDuration.md +42 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/preferredRegion.md +55 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/prefetch.md +113 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route-segment-config/runtime.md +43 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/route.md +772 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/src-folder.md +42 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/template.md +174 -0
- package/skills/frontend/nextjs/assets/api-reference/file-conventions/unauthorized.md +143 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/after.md +332 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/cacheLife.md +642 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/cacheTag.md +272 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/catchError.md +267 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/connection.md +114 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/cookies.md +349 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/draft-mode.md +173 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/fetch.md +141 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/forbidden.md +327 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/generate-image-metadata.md +311 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/generate-metadata.md +1510 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/generate-sitemaps.md +102 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/generate-static-params.md +606 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/generate-viewport.md +347 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/headers.md +92 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/image-response.md +225 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/io.md +131 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/navigation.md +220 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/next-request.md +116 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/next-response.md +219 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/next-root-params.md +479 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/not-found.md +269 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/permanentRedirect.md +92 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/prefetch.md +202 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/redirect.md +255 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/refresh.md +91 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/revalidatePath.md +248 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/revalidateTag.md +175 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/unauthorized.md +389 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/unstable_cache.md +131 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/unstable_noStore.md +61 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/unstable_rethrow.md +79 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/updateTag.md +173 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-link-status.md +268 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-offline.md +222 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-params.md +102 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-pathname.md +189 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-report-web-vitals.md +175 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-router.md +214 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-search-params.md +416 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-selected-layout-segment.md +214 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-selected-layout-segments.md +116 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/use-server-inserted-html.md +145 -0
- package/skills/frontend/nextjs/assets/api-reference/functions/userAgent.md +95 -0
- package/skills/frontend/nextjs/assets/api-reference/turbopack.md +552 -0
- package/skills/frontend/nextjs/assets/architecture/accessibility.md +47 -0
- package/skills/frontend/nextjs/assets/architecture/fast-refresh.md +122 -0
- package/skills/frontend/nextjs/assets/architecture/nextjs-compiler.md +376 -0
- package/skills/frontend/nextjs/assets/architecture/supported-browsers.md +146 -0
- package/skills/frontend/nextjs/assets/community/contribution-guide.md +459 -0
- package/skills/frontend/nextjs/assets/community/rspack.md +25 -0
- package/skills/frontend/nextjs/assets/getting-started/caching.md +626 -0
- package/skills/frontend/nextjs/assets/getting-started/css.md +336 -0
- package/skills/frontend/nextjs/assets/getting-started/deploying.md +115 -0
- package/skills/frontend/nextjs/assets/getting-started/error-handling.md +485 -0
- package/skills/frontend/nextjs/assets/getting-started/fetching-data.md +743 -0
- package/skills/frontend/nextjs/assets/getting-started/fonts.md +232 -0
- package/skills/frontend/nextjs/assets/getting-started/images.md +272 -0
- package/skills/frontend/nextjs/assets/getting-started/installation.md +446 -0
- package/skills/frontend/nextjs/assets/getting-started/layouts-and-pages.md +386 -0
- package/skills/frontend/nextjs/assets/getting-started/linking-and-navigating.md +475 -0
- package/skills/frontend/nextjs/assets/getting-started/metadata-and-og-images.md +370 -0
- package/skills/frontend/nextjs/assets/getting-started/mutating-data.md +679 -0
- package/skills/frontend/nextjs/assets/getting-started/project-structure.md +290 -0
- package/skills/frontend/nextjs/assets/getting-started/proxy.md +107 -0
- package/skills/frontend/nextjs/assets/getting-started/revalidating.md +241 -0
- package/skills/frontend/nextjs/assets/getting-started/route-handlers.md +233 -0
- package/skills/frontend/nextjs/assets/getting-started/server-and-client-components.md +683 -0
- package/skills/frontend/nextjs/assets/getting-started/upgrading.md +137 -0
- package/skills/frontend/nextjs/assets/glossary.md +315 -0
- package/skills/frontend/nextjs/evals/nextjsVerification.json +14 -0
- package/skills/frontend/nextjs/references/apiReference.md +3 -0
- package/skills/frontend/nextjs/references/dataAccessLayer.md +39 -0
- package/skills/frontend/nextjs/references/nextjsFeatureMap.md +276 -0
- package/skills/frontend/nextjs/references/productionChecklist.md +49 -0
- package/skills/frontend/nextjs/references/securityHeadersCsp.md +44 -0
- package/skills/frontend/nextjs/scripts/auditProductionReadiness.py +85 -0
- package/skills/frontend/shadcn-ui/SKILL.md +102 -0
- package/skills/frontend/shadcn-ui/assets/README.md +82 -0
- package/skills/frontend/shadcn-ui/assets/advanced/javascript.md +44 -0
- package/skills/frontend/shadcn-ui/assets/advanced/monorepo.md +254 -0
- package/skills/frontend/shadcn-ui/assets/advanced/react-19.md +166 -0
- package/skills/frontend/shadcn-ui/assets/advanced/tailwind-v4.md +333 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/chain-of-thought.md +519 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/chat.md +581 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/checkpoint.md +243 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/confirmation.md +382 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/context.md +188 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/file-tree.md +248 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/index.md +307 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/inline-citation.md +219 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/message.md +298 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/model-selector.md +368 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/plan.md +398 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/prompt-input.md +403 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/queue.md +517 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/reasoning.md +349 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/sources.md +303 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/stack-trace.md +514 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/subagent.md +551 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/suggestion.md +246 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/task.md +380 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/terminal.md +463 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/test-results.md +641 -0
- package/skills/frontend/shadcn-ui/assets/ai-elements/tool.md +915 -0
- package/skills/frontend/shadcn-ui/assets/components/accordion.md +490 -0
- package/skills/frontend/shadcn-ui/assets/components/alert-dialog.md +520 -0
- package/skills/frontend/shadcn-ui/assets/components/alert.md +351 -0
- package/skills/frontend/shadcn-ui/assets/components/aspect-ratio.md +206 -0
- package/skills/frontend/shadcn-ui/assets/components/attachment.md +715 -0
- package/skills/frontend/shadcn-ui/assets/components/avatar.md +581 -0
- package/skills/frontend/shadcn-ui/assets/components/badge.md +276 -0
- package/skills/frontend/shadcn-ui/assets/components/breadcrumb.md +556 -0
- package/skills/frontend/shadcn-ui/assets/components/bubble.md +706 -0
- package/skills/frontend/shadcn-ui/assets/components/button-group.md +969 -0
- package/skills/frontend/shadcn-ui/assets/components/button.md +523 -0
- package/skills/frontend/shadcn-ui/assets/components/calendar.md +959 -0
- package/skills/frontend/shadcn-ui/assets/components/card.md +684 -0
- package/skills/frontend/shadcn-ui/assets/components/carousel.md +643 -0
- package/skills/frontend/shadcn-ui/assets/components/chart.md +1295 -0
- package/skills/frontend/shadcn-ui/assets/components/checkbox.md +553 -0
- package/skills/frontend/shadcn-ui/assets/components/code-block.md +2041 -0
- package/skills/frontend/shadcn-ui/assets/components/collapsible.md +504 -0
- package/skills/frontend/shadcn-ui/assets/components/combobox.md +1102 -0
- package/skills/frontend/shadcn-ui/assets/components/command.md +682 -0
- package/skills/frontend/shadcn-ui/assets/components/context-menu.md +949 -0
- package/skills/frontend/shadcn-ui/assets/components/data-table.md +1667 -0
- package/skills/frontend/shadcn-ui/assets/components/date-picker.md +698 -0
- package/skills/frontend/shadcn-ui/assets/components/dialog.md +454 -0
- package/skills/frontend/shadcn-ui/assets/components/direction.md +205 -0
- package/skills/frontend/shadcn-ui/assets/components/drawer.md +806 -0
- package/skills/frontend/shadcn-ui/assets/components/dropdown-menu.md +1315 -0
- package/skills/frontend/shadcn-ui/assets/components/empty.md +562 -0
- package/skills/frontend/shadcn-ui/assets/components/field.md +1321 -0
- package/skills/frontend/shadcn-ui/assets/components/hover-card.md +342 -0
- package/skills/frontend/shadcn-ui/assets/components/index.md +82 -0
- package/skills/frontend/shadcn-ui/assets/components/input-group.md +980 -0
- package/skills/frontend/shadcn-ui/assets/components/input-otp.md +551 -0
- package/skills/frontend/shadcn-ui/assets/components/input.md +555 -0
- package/skills/frontend/shadcn-ui/assets/components/item.md +937 -0
- package/skills/frontend/shadcn-ui/assets/components/kbd.md +290 -0
- package/skills/frontend/shadcn-ui/assets/components/label.md +327 -0
- package/skills/frontend/shadcn-ui/assets/components/marker.md +445 -0
- package/skills/frontend/shadcn-ui/assets/components/menubar.md +804 -0
- package/skills/frontend/shadcn-ui/assets/components/message-scroller.md +2770 -0
- package/skills/frontend/shadcn-ui/assets/components/message.md +618 -0
- package/skills/frontend/shadcn-ui/assets/components/native-select.md +321 -0
- package/skills/frontend/shadcn-ui/assets/components/navigation-menu.md +568 -0
- package/skills/frontend/shadcn-ui/assets/components/pagination.md +425 -0
- package/skills/frontend/shadcn-ui/assets/components/popover.md +402 -0
- package/skills/frontend/shadcn-ui/assets/components/progress.md +240 -0
- package/skills/frontend/shadcn-ui/assets/components/questionnaire.md +2055 -0
- package/skills/frontend/shadcn-ui/assets/components/radio-group.md +440 -0
- package/skills/frontend/shadcn-ui/assets/components/resizable.md +302 -0
- package/skills/frontend/shadcn-ui/assets/components/scroll-area.md +226 -0
- package/skills/frontend/shadcn-ui/assets/components/select.md +647 -0
- package/skills/frontend/shadcn-ui/assets/components/separator.md +235 -0
- package/skills/frontend/shadcn-ui/assets/components/sheet.md +354 -0
- package/skills/frontend/shadcn-ui/assets/components/sidebar.md +1156 -0
- package/skills/frontend/shadcn-ui/assets/components/skeleton.md +217 -0
- package/skills/frontend/shadcn-ui/assets/components/slider.md +253 -0
- package/skills/frontend/shadcn-ui/assets/components/spinner.md +352 -0
- package/skills/frontend/shadcn-ui/assets/components/switch.md +296 -0
- package/skills/frontend/shadcn-ui/assets/components/table.md +572 -0
- package/skills/frontend/shadcn-ui/assets/components/tabs.md +425 -0
- package/skills/frontend/shadcn-ui/assets/components/textarea.md +218 -0
- package/skills/frontend/shadcn-ui/assets/components/toast.md +260 -0
- package/skills/frontend/shadcn-ui/assets/components/toggle-group.md +419 -0
- package/skills/frontend/shadcn-ui/assets/components/toggle.md +220 -0
- package/skills/frontend/shadcn-ui/assets/components/tooltip.md +332 -0
- package/skills/frontend/shadcn-ui/assets/components/trace.md +1890 -0
- package/skills/frontend/shadcn-ui/assets/components/typography.md +561 -0
- package/skills/frontend/shadcn-ui/assets/dark-mode/next.md +108 -0
- package/skills/frontend/shadcn-ui/assets/dark-mode/overview.md +75 -0
- package/skills/frontend/shadcn-ui/assets/dark-mode/vite.md +144 -0
- package/skills/frontend/shadcn-ui/assets/forms/next.md +716 -0
- package/skills/frontend/shadcn-ui/assets/forms/overview.md +60 -0
- package/skills/frontend/shadcn-ui/assets/forms/react-hook-form.md +2055 -0
- package/skills/frontend/shadcn-ui/assets/forms/tanstack-form.md +2236 -0
- package/skills/frontend/shadcn-ui/assets/installation/astro.md +252 -0
- package/skills/frontend/shadcn-ui/assets/installation/manual.md +255 -0
- package/skills/frontend/shadcn-ui/assets/installation/next.md +256 -0
- package/skills/frontend/shadcn-ui/assets/installation/react-router.md +226 -0
- package/skills/frontend/shadcn-ui/assets/installation/remix.md +52 -0
- package/skills/frontend/shadcn-ui/assets/installation/vite.md +314 -0
- package/skills/frontend/shadcn-ui/assets/mcp/mcp.md +338 -0
- package/skills/frontend/shadcn-ui/assets/overview/changelog.md +6 -0
- package/skills/frontend/shadcn-ui/assets/overview/cli.md +738 -0
- package/skills/frontend/shadcn-ui/assets/overview/components-json.md +379 -0
- package/skills/frontend/shadcn-ui/assets/overview/directory.md +74 -0
- package/skills/frontend/shadcn-ui/assets/overview/introduction.md +77 -0
- package/skills/frontend/shadcn-ui/assets/overview/skills.md +71 -0
- package/skills/frontend/shadcn-ui/assets/overview/theming.md +304 -0
- package/skills/frontend/shadcn-ui/assets/overview/typeset.md +242 -0
- package/skills/frontend/shadcn-ui/assets/registry/getting-started.md +648 -0
- package/skills/frontend/shadcn-ui/assets/registry/overview.md +90 -0
- package/skills/frontend/shadcn-ui/assets/registry/registry-item-json.md +483 -0
- package/skills/frontend/shadcn-ui/assets/registry/registry-json.md +178 -0
- package/skills/frontend/shadcn-ui/evals/componentVerification.json +19 -0
- package/skills/frontend/shadcn-ui/references/aiComponentsCatalog.md +51 -0
- package/skills/frontend/shadcn-ui/references/apiReference.md +3 -0
- package/skills/frontend/shadcn-ui/references/blocksCatalog.md +32 -0
- package/skills/frontend/shadcn-ui/references/cliCommands.md +47 -0
- package/skills/frontend/shadcn-ui/references/componentMarkdownSources.md +48 -0
- package/skills/frontend/shadcn-ui/scripts/fetchComponentDocs.py +43 -0
- package/skills/frontend/tsxReactStandard/SKILL.md +150 -0
- package/skills/frontend/tsxReactStandard/evals/tsxVerification.json +14 -0
- package/skills/frontend/tsxReactStandard/references/apiReference.md +3 -0
- package/skills/frontend/tsxReactStandard/references/discriminatedUnions.md +31 -0
- package/skills/frontend/tsxReactStandard/references/tsconfigStrict.md +36 -0
- package/skills/frontend/tsxReactStandard/scripts/validateTsxTypes.py +44 -0
- package/skills/gitVersionControl/gitWorkflow/SKILL.md +128 -0
- package/skills/gitVersionControl/gitWorkflow/assets/README.md +23 -0
- package/skills/gitVersionControl/gitWorkflow/assets/cli/gh-environment.md +87 -0
- package/skills/gitVersionControl/gitWorkflow/assets/cli/gh-formatting.md +156 -0
- package/skills/gitVersionControl/gitWorkflow/assets/cli/gh-reference.md +2363 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/about-git.md +156 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/about-remote-repositories.md +65 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/associating-text-editors-with-git.md +93 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/caching-your-github-credentials.md +115 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/getting-changes-from-a-remote-repository.md +76 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/ignoring-files.md +51 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/managing-remote-repositories.md +231 -0
- package/skills/gitVersionControl/gitWorkflow/assets/using-git/pushing-commits-to-a-remote-repository.md +119 -0
- package/skills/gitVersionControl/gitWorkflow/evals/evalGitWorkflow.py +43 -0
- package/skills/gitVersionControl/gitWorkflow/references/apiReference.md +3 -0
- package/skills/gitVersionControl/gitWorkflow/references/branchingModels.md +32 -0
- package/skills/gitVersionControl/gitWorkflow/scripts/diagnoseGitGraph.py +68 -0
- package/skills/github/assets/README.md +39 -0
- package/skills/github/assets/cli/gh-environment.md +87 -0
- package/skills/github/assets/cli/gh-formatting.md +156 -0
- package/skills/github/assets/cli/gh-reference.md +2363 -0
- package/skills/github/assets/docs-api/github-docs-api.md +60 -0
- package/skills/github/assets/rest-api/actions-secrets.md +1272 -0
- package/skills/github/assets/rest-api/actions-variables.md +1247 -0
- package/skills/github/assets/rest-api/actions-workflow-runs.md +1697 -0
- package/skills/github/assets/rest-api/actions-workflows.md +348 -0
- package/skills/github/assets/rest-api/authenticating.md +174 -0
- package/skills/github/assets/rest-api/branches.md +727 -0
- package/skills/github/assets/rest-api/checks-runs.md +1013 -0
- package/skills/github/assets/rest-api/checks-suites.md +1142 -0
- package/skills/github/assets/rest-api/code-scanning.md +2957 -0
- package/skills/github/assets/rest-api/collaborators.md +547 -0
- package/skills/github/assets/rest-api/commits.md +957 -0
- package/skills/github/assets/rest-api/dependabot-alerts.md +895 -0
- package/skills/github/assets/rest-api/orgs.md +1172 -0
- package/skills/github/assets/rest-api/overview.md +875 -0
- package/skills/github/assets/rest-api/pull-reviews.md +722 -0
- package/skills/github/assets/rest-api/pulls.md +1605 -0
- package/skills/github/assets/rest-api/quickstart.md +344 -0
- package/skills/github/assets/rest-api/releases.md +650 -0
- package/skills/github/assets/rest-api/repos.md +2957 -0
- package/skills/github/assets/rest-api/rules.md +1507 -0
- package/skills/github/assets/rest-api/secret-scanning.md +947 -0
- package/skills/github/assets/rest-api/teams.md +1690 -0
- package/skills/github/githubAction/SKILL.md +159 -0
- package/skills/github/githubAction/assets/README.md +38 -0
- package/skills/github/githubAction/assets/reference/contexts.md +918 -0
- package/skills/github/githubAction/assets/reference/dependency-caching.md +393 -0
- package/skills/github/githubAction/assets/reference/events-that-trigger-workflows.md +1348 -0
- package/skills/github/githubAction/assets/reference/expressions.md +441 -0
- package/skills/github/githubAction/assets/reference/metadata-syntax.md +803 -0
- package/skills/github/githubAction/assets/reference/variables.md +149 -0
- package/skills/github/githubAction/assets/reference/workflow-cancellation.md +22 -0
- package/skills/github/githubAction/assets/reference/workflow-commands.md +1056 -0
- package/skills/github/githubAction/assets/reference/workflow-syntax.md +1721 -0
- package/skills/github/githubAction/assets/rest-api/secrets.md +1272 -0
- package/skills/github/githubAction/assets/rest-api/workflow-runs.md +1697 -0
- package/skills/github/githubAction/assets/rest-api/workflows.md +348 -0
- package/skills/github/githubAction/assets/starter-workflows/automation/stale.yml +27 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/blank.yml +36 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/docker-image.yml +18 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/go.yml +28 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/maven.yml +35 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/node.js.yml +31 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/python-app.yml +39 -0
- package/skills/github/githubAction/assets/starter-workflows/ci/rust.yml +22 -0
- package/skills/github/githubAction/assets/starter-workflows/code-scanning/codeql.yml +97 -0
- package/skills/github/githubAction/evals/actionVerification.json +14 -0
- package/skills/github/githubAction/references/apiReference.md +3 -0
- package/skills/github/githubAction/references/workflowPatterns.md +81 -0
- package/skills/github/githubAction/scripts/validateWorkflowYaml.py +53 -0
- package/skills/github/githubQuality/SKILL.md +136 -0
- package/skills/github/githubQuality/assets/README.md +24 -0
- package/skills/github/githubQuality/assets/pull-requests/about-code-owners.md +178 -0
- package/skills/github/githubQuality/assets/pull-requests/about-merge-methods.md +48 -0
- package/skills/github/githubQuality/assets/pull-requests/creating-a-pull-request.md +170 -0
- package/skills/github/githubQuality/assets/pull-requests/giving-reviews.md +48 -0
- package/skills/github/githubQuality/assets/pull-requests/managing-a-merge-queue.md +134 -0
- package/skills/github/githubQuality/assets/pull-requests/merging-a-pull-request.md +101 -0
- package/skills/github/githubQuality/assets/pull-requests/resolving-reviews.md +59 -0
- package/skills/github/githubQuality/assets/pull-requests/status-checks.md +135 -0
- package/skills/github/githubQuality/assets/rest-api/checks-runs.md +1013 -0
- package/skills/github/githubQuality/assets/rest-api/checks-suites.md +1142 -0
- package/skills/github/githubQuality/assets/rest-api/commits.md +957 -0
- package/skills/github/githubQuality/assets/rest-api/pulls.md +1605 -0
- package/skills/github/githubQuality/assets/rest-api/reviews.md +722 -0
- package/skills/github/githubQuality/evals/qualityVerification.json +14 -0
- package/skills/github/githubQuality/references/apiReference.md +3 -0
- package/skills/github/githubQuality/references/codeownersExample.md +26 -0
- package/skills/github/githubQuality/references/prTemplate.md +20 -0
- package/skills/github/githubQuality/scripts/auditPrQuality.py +52 -0
- package/skills/github/githubSecurity/SKILL.md +170 -0
- package/skills/github/githubSecurity/assets/README.md +32 -0
- package/skills/github/githubSecurity/assets/code-scanning/code-scanning-alerts.md +133 -0
- package/skills/github/githubSecurity/assets/code-scanning/code-scanning.md +67 -0
- package/skills/github/githubSecurity/assets/code-scanning/codeql-code-scanning.md +79 -0
- package/skills/github/githubSecurity/assets/code-scanning/configure-code-scanning.md +121 -0
- package/skills/github/githubSecurity/assets/dependabot/about-the-dependabot-yml-file.md +74 -0
- package/skills/github/githubSecurity/assets/dependabot/dependabot-alerts.md +133 -0
- package/skills/github/githubSecurity/assets/dependabot/dependabot-security-updates.md +95 -0
- package/skills/github/githubSecurity/assets/dependabot/dependabot-version-updates.md +80 -0
- package/skills/github/githubSecurity/assets/rest-api/code-scanning.md +2957 -0
- package/skills/github/githubSecurity/assets/rest-api/dependabot-alerts.md +895 -0
- package/skills/github/githubSecurity/assets/rest-api/secret-scanning.md +947 -0
- package/skills/github/githubSecurity/assets/secret-scanning/enable-secret-scanning.md +59 -0
- package/skills/github/githubSecurity/assets/secret-scanning/secret-scanning.md +105 -0
- package/skills/github/githubSecurity/assets/security-advisories/github-advisory-database.md +148 -0
- package/skills/github/githubSecurity/evals/securityVerification.json +14 -0
- package/skills/github/githubSecurity/references/apiReference.md +3 -0
- package/skills/github/githubSecurity/references/codeqlAnalysis.yml +42 -0
- package/skills/github/githubSecurity/references/dependabotConfig.yml +27 -0
- package/skills/github/githubSecurity/scripts/auditRepoSecurity.py +47 -0
- package/skills/github/githubSetup/SKILL.md +137 -0
- package/skills/github/githubSetup/assets/README.md +40 -0
- package/skills/github/githubSetup/assets/branches/about-protected-branches.md +198 -0
- package/skills/github/githubSetup/assets/branches/changing-the-default-branch.md +49 -0
- package/skills/github/githubSetup/assets/branches/deleting-and-restoring-branches.md +44 -0
- package/skills/github/githubSetup/assets/branches/managing-a-branch-protection-rule.md +115 -0
- package/skills/github/githubSetup/assets/branches/renaming-a-branch.md +74 -0
- package/skills/github/githubSetup/assets/branches/viewing-branches-in-your-repository.md +30 -0
- package/skills/github/githubSetup/assets/repositories/about-repositories.md +127 -0
- package/skills/github/githubSetup/assets/repositories/cloning-a-repository.md +114 -0
- package/skills/github/githubSetup/assets/repositories/creating-a-new-repository.md +82 -0
- package/skills/github/githubSetup/assets/repositories/creating-a-repository-from-a-template.md +51 -0
- package/skills/github/githubSetup/assets/repositories/deleting-a-repository.md +34 -0
- package/skills/github/githubSetup/assets/repositories/managing-teams-and-people-with-access.md +69 -0
- package/skills/github/githubSetup/assets/repositories/renaming-a-repository.md +47 -0
- package/skills/github/githubSetup/assets/repositories/restoring-a-deleted-repository.md +61 -0
- package/skills/github/githubSetup/assets/repositories/setting-repository-visibility.md +137 -0
- package/skills/github/githubSetup/assets/rest-api/branches.md +727 -0
- package/skills/github/githubSetup/assets/rest-api/quickstart.md +344 -0
- package/skills/github/githubSetup/assets/rest-api/repos.md +2957 -0
- package/skills/github/githubSetup/assets/rulesets/about-rulesets.md +72 -0
- package/skills/github/githubSetup/assets/rulesets/available-rules-for-rulesets.md +383 -0
- package/skills/github/githubSetup/assets/rulesets/converting-branch-protections-to-rulesets.md +92 -0
- package/skills/github/githubSetup/assets/rulesets/creating-rulesets-for-a-repository.md +108 -0
- package/skills/github/githubSetup/assets/rulesets/managing-rulesets-for-a-repository.md +149 -0
- package/skills/github/githubSetup/assets/rulesets/troubleshooting-rules.md +122 -0
- package/skills/github/githubSetup/evals/setupVerification.json +14 -0
- package/skills/github/githubSetup/references/apiReference.md +3 -0
- package/skills/github/githubSetup/references/repoSettingsBlueprint.md +13 -0
- package/skills/github/githubSetup/references/rulesetTemplates.json +42 -0
- package/skills/github/githubSetup/scripts/configureRepoBaseline.py +46 -0
- package/skills/github/githubTeam/SKILL.md +115 -0
- package/skills/github/githubTeam/assets/README.md +21 -0
- package/skills/github/githubTeam/assets/organizations/about-organizations.md +69 -0
- package/skills/github/githubTeam/assets/organizations/repository-roles-for-an-organization.md +94 -0
- package/skills/github/githubTeam/assets/rest-api/collaborators.md +547 -0
- package/skills/github/githubTeam/assets/rest-api/orgs.md +1172 -0
- package/skills/github/githubTeam/assets/rest-api/teams.md +1690 -0
- package/skills/github/githubTeam/assets/teams/about-teams.md +82 -0
- package/skills/github/githubTeam/assets/teams/adding-members-to-a-team.md +55 -0
- package/skills/github/githubTeam/evals/teamVerification.json +14 -0
- package/skills/github/githubTeam/references/apiReference.md +3 -0
- package/skills/github/githubTeam/references/permissionMatrix.md +17 -0
- package/skills/github/githubTeam/references/reviewAssignment.md +17 -0
- package/skills/github/githubTeam/scripts/manageTeamSync.py +31 -0
- package/skills/securityQa/llmSecurityRedteaming/SKILL.md +86 -0
- package/skills/securityQa/llmSecurityRedteaming/evals/securityRedteamVerification.json +14 -0
- package/skills/securityQa/llmSecurityRedteaming/references/apiReference.md +3 -0
- package/skills/securityQa/llmSecurityRedteaming/references/jailbreakTaxonomy.md +6 -0
- package/skills/securityQa/llmSecurityRedteaming/references/owaspLlmTopTen.md +12 -0
- package/skills/securityQa/llmSecurityRedteaming/scripts/testPromptInjection.py +34 -0
- package/skills/softwareDevelopment/requirementsEngineering/SKILL.md +110 -0
- package/skills/softwareDevelopment/requirementsEngineering/evals/evalRequirements.py +33 -0
- package/skills/softwareDevelopment/requirementsEngineering/references/apiReference.md +3 -0
- package/skills/softwareDevelopment/requirementsEngineering/references/requirementsAnalysisModels.md +34 -0
- package/skills/softwareDevelopment/requirementsEngineering/scripts/validateUserStories.py +49 -0
- package/skills/testing/testDrivenDevelopment/SKILL.md +122 -0
- package/skills/testing/testDrivenDevelopment/evals/evalTdd.py +25 -0
- package/skills/testing/testDrivenDevelopment/references/apiReference.md +3 -0
- package/skills/testing/testDrivenDevelopment/references/testPyramidDoubles.md +35 -0
- package/skills/testing/testDrivenDevelopment/scripts/auditTestPyramid.py +58 -0
|
@@ -0,0 +1,2236 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: TanStack Form
|
|
3
|
+
description: Build forms in React using TanStack Form and Zod.
|
|
4
|
+
links:
|
|
5
|
+
doc: https://tanstack.com/form
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
import { InfoIcon } from "lucide-react"
|
|
9
|
+
|
|
10
|
+
This guide explores how to build forms using TanStack Form. You'll learn to create forms with the `<Field />` component, implement schema validation with Zod, handle errors, and ensure accessibility.
|
|
11
|
+
|
|
12
|
+
## Demo
|
|
13
|
+
|
|
14
|
+
We'll start by building the following form. It has a simple text input and a textarea. On submit, we'll validate the form data and display any errors.
|
|
15
|
+
|
|
16
|
+
<Callout icon={<InfoIcon />}>
|
|
17
|
+
**Note:** For the purpose of this demo, we have intentionally disabled browser
|
|
18
|
+
validation to show how schema validation and form errors work in TanStack
|
|
19
|
+
Form. It is recommended to add basic browser validation in your production
|
|
20
|
+
code.
|
|
21
|
+
</Callout>
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
/* eslint-disable react/no-children-prop */
|
|
25
|
+
"use client"
|
|
26
|
+
|
|
27
|
+
import * as React from "react"
|
|
28
|
+
import { useForm } from "@tanstack/react-form"
|
|
29
|
+
import { toast } from "sonner"
|
|
30
|
+
import * as z from "zod"
|
|
31
|
+
|
|
32
|
+
import { Button } from "@/components/ui/button"
|
|
33
|
+
import {
|
|
34
|
+
Card,
|
|
35
|
+
CardContent,
|
|
36
|
+
CardDescription,
|
|
37
|
+
CardFooter,
|
|
38
|
+
CardHeader,
|
|
39
|
+
CardTitle,
|
|
40
|
+
} from "@/components/ui/card"
|
|
41
|
+
import {
|
|
42
|
+
Field,
|
|
43
|
+
FieldDescription,
|
|
44
|
+
FieldError,
|
|
45
|
+
FieldGroup,
|
|
46
|
+
FieldLabel,
|
|
47
|
+
} from "@/components/ui/field"
|
|
48
|
+
import { Input } from "@/components/ui/input"
|
|
49
|
+
import {
|
|
50
|
+
InputGroup,
|
|
51
|
+
InputGroupAddon,
|
|
52
|
+
InputGroupText,
|
|
53
|
+
InputGroupTextarea,
|
|
54
|
+
} from "@/components/ui/input-group"
|
|
55
|
+
|
|
56
|
+
const formSchema = z.object({
|
|
57
|
+
title: z
|
|
58
|
+
.string()
|
|
59
|
+
.min(5, "Bug title must be at least 5 characters.")
|
|
60
|
+
.max(32, "Bug title must be at most 32 characters."),
|
|
61
|
+
description: z
|
|
62
|
+
.string()
|
|
63
|
+
.min(20, "Description must be at least 20 characters.")
|
|
64
|
+
.max(100, "Description must be at most 100 characters."),
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
export function BugReportForm() {
|
|
68
|
+
const form = useForm({
|
|
69
|
+
defaultValues: {
|
|
70
|
+
title: "",
|
|
71
|
+
description: "",
|
|
72
|
+
},
|
|
73
|
+
validators: {
|
|
74
|
+
onSubmit: formSchema,
|
|
75
|
+
},
|
|
76
|
+
onSubmit: async ({ value }) => {
|
|
77
|
+
toast("You submitted the following values:", {
|
|
78
|
+
description: (
|
|
79
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
80
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
81
|
+
</pre>
|
|
82
|
+
),
|
|
83
|
+
position: "bottom-right",
|
|
84
|
+
classNames: {
|
|
85
|
+
content: "flex flex-col gap-2",
|
|
86
|
+
},
|
|
87
|
+
style: {
|
|
88
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
89
|
+
} as React.CSSProperties,
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Card className="w-full sm:max-w-md">
|
|
96
|
+
<CardHeader>
|
|
97
|
+
<CardTitle>Bug Report</CardTitle>
|
|
98
|
+
<CardDescription>
|
|
99
|
+
Help us improve by reporting bugs you encounter.
|
|
100
|
+
</CardDescription>
|
|
101
|
+
</CardHeader>
|
|
102
|
+
<CardContent>
|
|
103
|
+
<form
|
|
104
|
+
id="bug-report-form"
|
|
105
|
+
onSubmit={(e) => {
|
|
106
|
+
e.preventDefault()
|
|
107
|
+
form.handleSubmit()
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<FieldGroup>
|
|
111
|
+
<form.Field
|
|
112
|
+
name="title"
|
|
113
|
+
children={(field) => {
|
|
114
|
+
const isInvalid =
|
|
115
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
116
|
+
return (
|
|
117
|
+
<Field data-invalid={isInvalid}>
|
|
118
|
+
<FieldLabel htmlFor={field.name}>Bug Title</FieldLabel>
|
|
119
|
+
<Input
|
|
120
|
+
id={field.name}
|
|
121
|
+
name={field.name}
|
|
122
|
+
value={field.state.value}
|
|
123
|
+
onBlur={field.handleBlur}
|
|
124
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
125
|
+
aria-invalid={isInvalid}
|
|
126
|
+
placeholder="Login button not working on mobile"
|
|
127
|
+
autoComplete="off"
|
|
128
|
+
/>
|
|
129
|
+
{isInvalid && (
|
|
130
|
+
<FieldError errors={field.state.meta.errors} />
|
|
131
|
+
)}
|
|
132
|
+
</Field>
|
|
133
|
+
)
|
|
134
|
+
}}
|
|
135
|
+
/>
|
|
136
|
+
<form.Field
|
|
137
|
+
name="description"
|
|
138
|
+
children={(field) => {
|
|
139
|
+
const isInvalid =
|
|
140
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
141
|
+
return (
|
|
142
|
+
<Field data-invalid={isInvalid}>
|
|
143
|
+
<FieldLabel htmlFor={field.name}>Description</FieldLabel>
|
|
144
|
+
<InputGroup>
|
|
145
|
+
<InputGroupTextarea
|
|
146
|
+
id={field.name}
|
|
147
|
+
name={field.name}
|
|
148
|
+
value={field.state.value}
|
|
149
|
+
onBlur={field.handleBlur}
|
|
150
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
151
|
+
placeholder="I'm having an issue with the login button on mobile."
|
|
152
|
+
rows={6}
|
|
153
|
+
className="min-h-24 resize-none"
|
|
154
|
+
aria-invalid={isInvalid}
|
|
155
|
+
/>
|
|
156
|
+
<InputGroupAddon align="block-end">
|
|
157
|
+
<InputGroupText className="tabular-nums">
|
|
158
|
+
{field.state.value.length}/100 characters
|
|
159
|
+
</InputGroupText>
|
|
160
|
+
</InputGroupAddon>
|
|
161
|
+
</InputGroup>
|
|
162
|
+
<FieldDescription>
|
|
163
|
+
Include steps to reproduce, expected behavior, and what
|
|
164
|
+
actually happened.
|
|
165
|
+
</FieldDescription>
|
|
166
|
+
{isInvalid && (
|
|
167
|
+
<FieldError errors={field.state.meta.errors} />
|
|
168
|
+
)}
|
|
169
|
+
</Field>
|
|
170
|
+
)
|
|
171
|
+
}}
|
|
172
|
+
/>
|
|
173
|
+
</FieldGroup>
|
|
174
|
+
</form>
|
|
175
|
+
</CardContent>
|
|
176
|
+
<CardFooter>
|
|
177
|
+
<Field orientation="horizontal">
|
|
178
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
179
|
+
Reset
|
|
180
|
+
</Button>
|
|
181
|
+
<Button type="submit" form="bug-report-form">
|
|
182
|
+
Submit
|
|
183
|
+
</Button>
|
|
184
|
+
</Field>
|
|
185
|
+
</CardFooter>
|
|
186
|
+
</Card>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Approach
|
|
193
|
+
|
|
194
|
+
This form leverages TanStack Form for powerful, headless form handling. We'll build our form using the `<Field />` component, which gives you **complete flexibility over the markup and styling**.
|
|
195
|
+
|
|
196
|
+
- Uses TanStack Form's `useForm` hook for form state management.
|
|
197
|
+
- `form.Field` component with render prop pattern for controlled inputs.
|
|
198
|
+
- `<Field />` components for building accessible forms.
|
|
199
|
+
- Client-side validation using Zod.
|
|
200
|
+
- Real-time validation feedback.
|
|
201
|
+
|
|
202
|
+
## Anatomy
|
|
203
|
+
|
|
204
|
+
Here's a basic example of a form using TanStack Form with the `<Field />` component.
|
|
205
|
+
|
|
206
|
+
```tsx showLineNumbers {15-31}
|
|
207
|
+
<form
|
|
208
|
+
onSubmit={(e) => {
|
|
209
|
+
e.preventDefault()
|
|
210
|
+
form.handleSubmit()
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
<FieldGroup>
|
|
214
|
+
<form.Field
|
|
215
|
+
name="title"
|
|
216
|
+
children={(field) => {
|
|
217
|
+
const isInvalid =
|
|
218
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
219
|
+
return (
|
|
220
|
+
<Field data-invalid={isInvalid}>
|
|
221
|
+
<FieldLabel htmlFor={field.name}>Bug Title</FieldLabel>
|
|
222
|
+
<Input
|
|
223
|
+
id={field.name}
|
|
224
|
+
name={field.name}
|
|
225
|
+
value={field.state.value}
|
|
226
|
+
onBlur={field.handleBlur}
|
|
227
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
228
|
+
aria-invalid={isInvalid}
|
|
229
|
+
placeholder="Login button not working on mobile"
|
|
230
|
+
autoComplete="off"
|
|
231
|
+
/>
|
|
232
|
+
<FieldDescription>
|
|
233
|
+
Provide a concise title for your bug report.
|
|
234
|
+
</FieldDescription>
|
|
235
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
236
|
+
</Field>
|
|
237
|
+
)
|
|
238
|
+
}}
|
|
239
|
+
/>
|
|
240
|
+
</FieldGroup>
|
|
241
|
+
<Button type="submit">Submit</Button>
|
|
242
|
+
</form>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Form
|
|
246
|
+
|
|
247
|
+
### Create a schema
|
|
248
|
+
|
|
249
|
+
We'll start by defining the shape of our form using a Zod schema.
|
|
250
|
+
|
|
251
|
+
<Callout icon={<InfoIcon />}>
|
|
252
|
+
**Note:** This example uses `zod v3` for schema validation. TanStack Form
|
|
253
|
+
integrates seamlessly with Zod and other Standard Schema validation libraries
|
|
254
|
+
through its validators API.
|
|
255
|
+
</Callout>
|
|
256
|
+
|
|
257
|
+
```tsx showLineNumbers title="form.tsx"
|
|
258
|
+
import * as z from "zod"
|
|
259
|
+
|
|
260
|
+
const formSchema = z.object({
|
|
261
|
+
title: z
|
|
262
|
+
.string()
|
|
263
|
+
.min(5, "Bug title must be at least 5 characters.")
|
|
264
|
+
.max(32, "Bug title must be at most 32 characters."),
|
|
265
|
+
description: z
|
|
266
|
+
.string()
|
|
267
|
+
.min(20, "Description must be at least 20 characters.")
|
|
268
|
+
.max(100, "Description must be at most 100 characters."),
|
|
269
|
+
})
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Set up the form
|
|
273
|
+
|
|
274
|
+
Use the `useForm` hook from TanStack Form to create your form instance with Zod validation.
|
|
275
|
+
|
|
276
|
+
```tsx showLineNumbers title="form.tsx" {10-21}
|
|
277
|
+
import { useForm } from "@tanstack/react-form"
|
|
278
|
+
import { toast } from "sonner"
|
|
279
|
+
import * as z from "zod"
|
|
280
|
+
|
|
281
|
+
const formSchema = z.object({
|
|
282
|
+
// ...
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
export function BugReportForm() {
|
|
286
|
+
const form = useForm({
|
|
287
|
+
defaultValues: {
|
|
288
|
+
title: "",
|
|
289
|
+
description: "",
|
|
290
|
+
},
|
|
291
|
+
validators: {
|
|
292
|
+
onSubmit: formSchema,
|
|
293
|
+
},
|
|
294
|
+
onSubmit: async ({ value }) => {
|
|
295
|
+
toast.success("Form submitted successfully")
|
|
296
|
+
},
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<form
|
|
301
|
+
onSubmit={(e) => {
|
|
302
|
+
e.preventDefault()
|
|
303
|
+
form.handleSubmit()
|
|
304
|
+
}}
|
|
305
|
+
>
|
|
306
|
+
{/* ... */}
|
|
307
|
+
</form>
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
We are using `onSubmit` to validate the form data here. TanStack Form supports other validation modes, which you can read about in the [documentation](https://tanstack.com/form/latest/docs/framework/react/guides/dynamic-validation).
|
|
313
|
+
|
|
314
|
+
### Build the form
|
|
315
|
+
|
|
316
|
+
We can now build the form using the `form.Field` component from TanStack Form and the `<Field />` component.
|
|
317
|
+
|
|
318
|
+
<ComponentSource
|
|
319
|
+
src="/registry/new-york-v4/examples/form-tanstack-demo.tsx"
|
|
320
|
+
title="form.tsx"
|
|
321
|
+
/>
|
|
322
|
+
|
|
323
|
+
### Done
|
|
324
|
+
|
|
325
|
+
That's it. You now have a fully accessible form with client-side validation.
|
|
326
|
+
|
|
327
|
+
When you submit the form, the `onSubmit` function will be called with the validated form data. If the form data is invalid, TanStack Form will display the errors next to each field.
|
|
328
|
+
|
|
329
|
+
## Validation
|
|
330
|
+
|
|
331
|
+
### Client-side Validation
|
|
332
|
+
|
|
333
|
+
TanStack Form validates your form data using the Zod schema. Validation happens in real-time as the user types.
|
|
334
|
+
|
|
335
|
+
```tsx showLineNumbers title="form.tsx" {13-15}
|
|
336
|
+
import { useForm } from "@tanstack/react-form"
|
|
337
|
+
|
|
338
|
+
const formSchema = z.object({
|
|
339
|
+
// ...
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
export function BugReportForm() {
|
|
343
|
+
const form = useForm({
|
|
344
|
+
defaultValues: {
|
|
345
|
+
title: "",
|
|
346
|
+
description: "",
|
|
347
|
+
},
|
|
348
|
+
validators: {
|
|
349
|
+
onSubmit: formSchema,
|
|
350
|
+
},
|
|
351
|
+
onSubmit: async ({ value }) => {
|
|
352
|
+
console.log(value)
|
|
353
|
+
},
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
return <form onSubmit={/* ... */}>{/* ... */}</form>
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Validation Modes
|
|
361
|
+
|
|
362
|
+
TanStack Form supports different validation strategies through the `validators` option:
|
|
363
|
+
|
|
364
|
+
| Mode | Description |
|
|
365
|
+
| ------------ | ------------------------------------ |
|
|
366
|
+
| `"onChange"` | Validation triggers on every change. |
|
|
367
|
+
| `"onBlur"` | Validation triggers on blur. |
|
|
368
|
+
| `"onSubmit"` | Validation triggers on submit. |
|
|
369
|
+
|
|
370
|
+
```tsx showLineNumbers title="form.tsx" {6-9}
|
|
371
|
+
const form = useForm({
|
|
372
|
+
defaultValues: {
|
|
373
|
+
title: "",
|
|
374
|
+
description: "",
|
|
375
|
+
},
|
|
376
|
+
validators: {
|
|
377
|
+
onSubmit: formSchema,
|
|
378
|
+
onChange: formSchema,
|
|
379
|
+
onBlur: formSchema,
|
|
380
|
+
},
|
|
381
|
+
})
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## Displaying Errors
|
|
385
|
+
|
|
386
|
+
Display errors next to the field using `<FieldError />`. For styling and accessibility:
|
|
387
|
+
|
|
388
|
+
- Add the `data-invalid` prop to the `<Field />` component.
|
|
389
|
+
- Add the `aria-invalid` prop to the form control such as `<Input />`, `<SelectTrigger />`, `<Checkbox />`, etc.
|
|
390
|
+
|
|
391
|
+
```tsx showLineNumbers title="form.tsx" {4,18}
|
|
392
|
+
<form.Field
|
|
393
|
+
name="email"
|
|
394
|
+
children={(field) => {
|
|
395
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
<Field data-invalid={isInvalid}>
|
|
399
|
+
<FieldLabel htmlFor={field.name}>Email</FieldLabel>
|
|
400
|
+
<Input
|
|
401
|
+
id={field.name}
|
|
402
|
+
name={field.name}
|
|
403
|
+
value={field.state.value}
|
|
404
|
+
onBlur={field.handleBlur}
|
|
405
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
406
|
+
type="email"
|
|
407
|
+
aria-invalid={isInvalid}
|
|
408
|
+
/>
|
|
409
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
410
|
+
</Field>
|
|
411
|
+
)
|
|
412
|
+
}}
|
|
413
|
+
/>
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Working with Different Field Types
|
|
417
|
+
|
|
418
|
+
### Input
|
|
419
|
+
|
|
420
|
+
- For input fields, use `field.state.value` and `field.handleChange` on the `<Input />` component.
|
|
421
|
+
- To show errors, add the `aria-invalid` prop to the `<Input />` component and the `data-invalid` prop to the `<Field />` component.
|
|
422
|
+
|
|
423
|
+
```tsx
|
|
424
|
+
/* eslint-disable react/no-children-prop */
|
|
425
|
+
"use client"
|
|
426
|
+
|
|
427
|
+
import { useForm } from "@tanstack/react-form"
|
|
428
|
+
import { toast } from "sonner"
|
|
429
|
+
import * as z from "zod"
|
|
430
|
+
|
|
431
|
+
import { Button } from "@/components/ui/button"
|
|
432
|
+
import {
|
|
433
|
+
Card,
|
|
434
|
+
CardContent,
|
|
435
|
+
CardDescription,
|
|
436
|
+
CardFooter,
|
|
437
|
+
CardHeader,
|
|
438
|
+
CardTitle,
|
|
439
|
+
} from "@/components/ui/card"
|
|
440
|
+
import {
|
|
441
|
+
Field,
|
|
442
|
+
FieldDescription,
|
|
443
|
+
FieldError,
|
|
444
|
+
FieldGroup,
|
|
445
|
+
FieldLabel,
|
|
446
|
+
} from "@/components/ui/field"
|
|
447
|
+
import { Input } from "@/components/ui/input"
|
|
448
|
+
|
|
449
|
+
const formSchema = z.object({
|
|
450
|
+
username: z
|
|
451
|
+
.string()
|
|
452
|
+
.min(3, "Username must be at least 3 characters.")
|
|
453
|
+
.max(10, "Username must be at most 10 characters.")
|
|
454
|
+
.regex(
|
|
455
|
+
/^[a-zA-Z0-9_]+$/,
|
|
456
|
+
"Username can only contain letters, numbers, and underscores."
|
|
457
|
+
),
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
export function FormTanstackInput() {
|
|
461
|
+
const form = useForm({
|
|
462
|
+
defaultValues: {
|
|
463
|
+
username: "",
|
|
464
|
+
},
|
|
465
|
+
validators: {
|
|
466
|
+
onSubmit: formSchema,
|
|
467
|
+
},
|
|
468
|
+
onSubmit: async ({ value }) => {
|
|
469
|
+
toast("You submitted the following values:", {
|
|
470
|
+
description: (
|
|
471
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
472
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
473
|
+
</pre>
|
|
474
|
+
),
|
|
475
|
+
position: "bottom-right",
|
|
476
|
+
classNames: {
|
|
477
|
+
content: "flex flex-col gap-2",
|
|
478
|
+
},
|
|
479
|
+
style: {
|
|
480
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
481
|
+
} as React.CSSProperties,
|
|
482
|
+
})
|
|
483
|
+
},
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
return (
|
|
487
|
+
<Card className="w-full sm:max-w-md">
|
|
488
|
+
<CardHeader>
|
|
489
|
+
<CardTitle>Profile Settings</CardTitle>
|
|
490
|
+
<CardDescription>
|
|
491
|
+
Update your profile information below.
|
|
492
|
+
</CardDescription>
|
|
493
|
+
</CardHeader>
|
|
494
|
+
<CardContent>
|
|
495
|
+
<form
|
|
496
|
+
id="form-tanstack-input"
|
|
497
|
+
onSubmit={(e) => {
|
|
498
|
+
e.preventDefault()
|
|
499
|
+
form.handleSubmit()
|
|
500
|
+
}}
|
|
501
|
+
>
|
|
502
|
+
<FieldGroup>
|
|
503
|
+
<form.Field
|
|
504
|
+
name="username"
|
|
505
|
+
children={(field) => {
|
|
506
|
+
const isInvalid =
|
|
507
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
508
|
+
return (
|
|
509
|
+
<Field data-invalid={isInvalid}>
|
|
510
|
+
<FieldLabel htmlFor="form-tanstack-input-username">
|
|
511
|
+
Username
|
|
512
|
+
</FieldLabel>
|
|
513
|
+
<Input
|
|
514
|
+
id="form-tanstack-input-username"
|
|
515
|
+
name={field.name}
|
|
516
|
+
value={field.state.value}
|
|
517
|
+
onBlur={field.handleBlur}
|
|
518
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
519
|
+
aria-invalid={isInvalid}
|
|
520
|
+
placeholder="shadcn"
|
|
521
|
+
autoComplete="username"
|
|
522
|
+
/>
|
|
523
|
+
<FieldDescription>
|
|
524
|
+
This is your public display name. Must be between 3 and 10
|
|
525
|
+
characters. Must only contain letters, numbers, and
|
|
526
|
+
underscores.
|
|
527
|
+
</FieldDescription>
|
|
528
|
+
{isInvalid && (
|
|
529
|
+
<FieldError errors={field.state.meta.errors} />
|
|
530
|
+
)}
|
|
531
|
+
</Field>
|
|
532
|
+
)
|
|
533
|
+
}}
|
|
534
|
+
/>
|
|
535
|
+
</FieldGroup>
|
|
536
|
+
</form>
|
|
537
|
+
</CardContent>
|
|
538
|
+
<CardFooter>
|
|
539
|
+
<Field orientation="horizontal">
|
|
540
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
541
|
+
Reset
|
|
542
|
+
</Button>
|
|
543
|
+
<Button type="submit" form="form-tanstack-input">
|
|
544
|
+
Save
|
|
545
|
+
</Button>
|
|
546
|
+
</Field>
|
|
547
|
+
</CardFooter>
|
|
548
|
+
</Card>
|
|
549
|
+
)
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
```tsx showLineNumbers title="form.tsx" {6,11-14,22}
|
|
555
|
+
<form.Field
|
|
556
|
+
name="username"
|
|
557
|
+
children={(field) => {
|
|
558
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
559
|
+
return (
|
|
560
|
+
<Field data-invalid={isInvalid}>
|
|
561
|
+
<FieldLabel htmlFor="form-tanstack-input-username">Username</FieldLabel>
|
|
562
|
+
<Input
|
|
563
|
+
id="form-tanstack-input-username"
|
|
564
|
+
name={field.name}
|
|
565
|
+
value={field.state.value}
|
|
566
|
+
onBlur={field.handleBlur}
|
|
567
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
568
|
+
aria-invalid={isInvalid}
|
|
569
|
+
placeholder="shadcn"
|
|
570
|
+
autoComplete="username"
|
|
571
|
+
/>
|
|
572
|
+
<FieldDescription>
|
|
573
|
+
This is your public display name. Must be between 3 and 10 characters.
|
|
574
|
+
Must only contain letters, numbers, and underscores.
|
|
575
|
+
</FieldDescription>
|
|
576
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
577
|
+
</Field>
|
|
578
|
+
)
|
|
579
|
+
}}
|
|
580
|
+
/>
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### Textarea
|
|
584
|
+
|
|
585
|
+
- For textarea fields, use `field.state.value` and `field.handleChange` on the `<Textarea />` component.
|
|
586
|
+
- To show errors, add the `aria-invalid` prop to the `<Textarea />` component and the `data-invalid` prop to the `<Field />` component.
|
|
587
|
+
|
|
588
|
+
```tsx
|
|
589
|
+
/* eslint-disable react/no-children-prop */
|
|
590
|
+
"use client"
|
|
591
|
+
|
|
592
|
+
import { useForm } from "@tanstack/react-form"
|
|
593
|
+
import { toast } from "sonner"
|
|
594
|
+
import * as z from "zod"
|
|
595
|
+
|
|
596
|
+
import { Button } from "@/components/ui/button"
|
|
597
|
+
import {
|
|
598
|
+
Card,
|
|
599
|
+
CardContent,
|
|
600
|
+
CardDescription,
|
|
601
|
+
CardFooter,
|
|
602
|
+
CardHeader,
|
|
603
|
+
CardTitle,
|
|
604
|
+
} from "@/components/ui/card"
|
|
605
|
+
import {
|
|
606
|
+
Field,
|
|
607
|
+
FieldDescription,
|
|
608
|
+
FieldError,
|
|
609
|
+
FieldGroup,
|
|
610
|
+
FieldLabel,
|
|
611
|
+
} from "@/components/ui/field"
|
|
612
|
+
import { Textarea } from "@/components/ui/textarea"
|
|
613
|
+
|
|
614
|
+
const formSchema = z.object({
|
|
615
|
+
about: z
|
|
616
|
+
.string()
|
|
617
|
+
.min(10, "Please provide at least 10 characters.")
|
|
618
|
+
.max(200, "Please keep it under 200 characters."),
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
export function FormTanstackTextarea() {
|
|
622
|
+
const form = useForm({
|
|
623
|
+
defaultValues: {
|
|
624
|
+
about: "",
|
|
625
|
+
},
|
|
626
|
+
validators: {
|
|
627
|
+
onSubmit: formSchema,
|
|
628
|
+
},
|
|
629
|
+
onSubmit: async ({ value }) => {
|
|
630
|
+
toast("You submitted the following values:", {
|
|
631
|
+
description: (
|
|
632
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
633
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
634
|
+
</pre>
|
|
635
|
+
),
|
|
636
|
+
position: "bottom-right",
|
|
637
|
+
classNames: {
|
|
638
|
+
content: "flex flex-col gap-2",
|
|
639
|
+
},
|
|
640
|
+
style: {
|
|
641
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
642
|
+
} as React.CSSProperties,
|
|
643
|
+
})
|
|
644
|
+
},
|
|
645
|
+
})
|
|
646
|
+
|
|
647
|
+
return (
|
|
648
|
+
<Card className="w-full sm:max-w-md">
|
|
649
|
+
<CardHeader>
|
|
650
|
+
<CardTitle>Personalization</CardTitle>
|
|
651
|
+
<CardDescription>
|
|
652
|
+
Customize your experience by telling us more about yourself.
|
|
653
|
+
</CardDescription>
|
|
654
|
+
</CardHeader>
|
|
655
|
+
<CardContent>
|
|
656
|
+
<form
|
|
657
|
+
id="form-tanstack-textarea"
|
|
658
|
+
onSubmit={(e) => {
|
|
659
|
+
e.preventDefault()
|
|
660
|
+
form.handleSubmit()
|
|
661
|
+
}}
|
|
662
|
+
>
|
|
663
|
+
<FieldGroup>
|
|
664
|
+
<form.Field
|
|
665
|
+
name="about"
|
|
666
|
+
children={(field) => {
|
|
667
|
+
const isInvalid =
|
|
668
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
669
|
+
return (
|
|
670
|
+
<Field data-invalid={isInvalid}>
|
|
671
|
+
<FieldLabel htmlFor="form-tanstack-textarea-about">
|
|
672
|
+
More about you
|
|
673
|
+
</FieldLabel>
|
|
674
|
+
<Textarea
|
|
675
|
+
id="form-tanstack-textarea-about"
|
|
676
|
+
name={field.name}
|
|
677
|
+
value={field.state.value}
|
|
678
|
+
onBlur={field.handleBlur}
|
|
679
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
680
|
+
aria-invalid={isInvalid}
|
|
681
|
+
placeholder="I'm a software engineer..."
|
|
682
|
+
className="min-h-[120px]"
|
|
683
|
+
/>
|
|
684
|
+
<FieldDescription>
|
|
685
|
+
Tell us more about yourself. This will be used to help us
|
|
686
|
+
personalize your experience.
|
|
687
|
+
</FieldDescription>
|
|
688
|
+
{isInvalid && (
|
|
689
|
+
<FieldError errors={field.state.meta.errors} />
|
|
690
|
+
)}
|
|
691
|
+
</Field>
|
|
692
|
+
)
|
|
693
|
+
}}
|
|
694
|
+
/>
|
|
695
|
+
</FieldGroup>
|
|
696
|
+
</form>
|
|
697
|
+
</CardContent>
|
|
698
|
+
<CardFooter>
|
|
699
|
+
<Field orientation="horizontal">
|
|
700
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
701
|
+
Reset
|
|
702
|
+
</Button>
|
|
703
|
+
<Button type="submit" form="form-tanstack-textarea">
|
|
704
|
+
Save
|
|
705
|
+
</Button>
|
|
706
|
+
</Field>
|
|
707
|
+
</CardFooter>
|
|
708
|
+
</Card>
|
|
709
|
+
)
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
```tsx showLineNumbers title="form.tsx" {6,13-16,24}
|
|
715
|
+
<form.Field
|
|
716
|
+
name="about"
|
|
717
|
+
children={(field) => {
|
|
718
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
719
|
+
return (
|
|
720
|
+
<Field data-invalid={isInvalid}>
|
|
721
|
+
<FieldLabel htmlFor="form-tanstack-textarea-about">
|
|
722
|
+
More about you
|
|
723
|
+
</FieldLabel>
|
|
724
|
+
<Textarea
|
|
725
|
+
id="form-tanstack-textarea-about"
|
|
726
|
+
name={field.name}
|
|
727
|
+
value={field.state.value}
|
|
728
|
+
onBlur={field.handleBlur}
|
|
729
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
730
|
+
aria-invalid={isInvalid}
|
|
731
|
+
placeholder="I'm a software engineer..."
|
|
732
|
+
className="min-h-[120px]"
|
|
733
|
+
/>
|
|
734
|
+
<FieldDescription>
|
|
735
|
+
Tell us more about yourself. This will be used to help us personalize
|
|
736
|
+
your experience.
|
|
737
|
+
</FieldDescription>
|
|
738
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
739
|
+
</Field>
|
|
740
|
+
)
|
|
741
|
+
}}
|
|
742
|
+
/>
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
### Select
|
|
746
|
+
|
|
747
|
+
- For select components, use `field.state.value` and `field.handleChange` on the `<Select />` component.
|
|
748
|
+
- To show errors, add the `aria-invalid` prop to the `<SelectTrigger />` component and the `data-invalid` prop to the `<Field />` component.
|
|
749
|
+
|
|
750
|
+
```tsx
|
|
751
|
+
/* eslint-disable react/no-children-prop */
|
|
752
|
+
"use client"
|
|
753
|
+
|
|
754
|
+
import { useForm } from "@tanstack/react-form"
|
|
755
|
+
import { toast } from "sonner"
|
|
756
|
+
import * as z from "zod"
|
|
757
|
+
|
|
758
|
+
import { Button } from "@/components/ui/button"
|
|
759
|
+
import {
|
|
760
|
+
Card,
|
|
761
|
+
CardContent,
|
|
762
|
+
CardDescription,
|
|
763
|
+
CardFooter,
|
|
764
|
+
CardHeader,
|
|
765
|
+
CardTitle,
|
|
766
|
+
} from "@/components/ui/card"
|
|
767
|
+
import {
|
|
768
|
+
Field,
|
|
769
|
+
FieldContent,
|
|
770
|
+
FieldDescription,
|
|
771
|
+
FieldError,
|
|
772
|
+
FieldGroup,
|
|
773
|
+
FieldLabel,
|
|
774
|
+
} from "@/components/ui/field"
|
|
775
|
+
import {
|
|
776
|
+
Select,
|
|
777
|
+
SelectContent,
|
|
778
|
+
SelectItem,
|
|
779
|
+
SelectSeparator,
|
|
780
|
+
SelectTrigger,
|
|
781
|
+
SelectValue,
|
|
782
|
+
} from "@/components/ui/select"
|
|
783
|
+
|
|
784
|
+
const spokenLanguages = [
|
|
785
|
+
{ label: "English", value: "en" },
|
|
786
|
+
{ label: "Spanish", value: "es" },
|
|
787
|
+
{ label: "French", value: "fr" },
|
|
788
|
+
{ label: "German", value: "de" },
|
|
789
|
+
{ label: "Italian", value: "it" },
|
|
790
|
+
{ label: "Chinese", value: "zh" },
|
|
791
|
+
{ label: "Japanese", value: "ja" },
|
|
792
|
+
] as const
|
|
793
|
+
|
|
794
|
+
const formSchema = z.object({
|
|
795
|
+
language: z
|
|
796
|
+
.string()
|
|
797
|
+
.min(1, "Please select your spoken language.")
|
|
798
|
+
.refine((val) => val !== "auto", {
|
|
799
|
+
message:
|
|
800
|
+
"Auto-detection is not allowed. Please select a specific language.",
|
|
801
|
+
}),
|
|
802
|
+
})
|
|
803
|
+
|
|
804
|
+
export function FormTanstackSelect() {
|
|
805
|
+
const form = useForm({
|
|
806
|
+
defaultValues: {
|
|
807
|
+
language: "",
|
|
808
|
+
},
|
|
809
|
+
validators: {
|
|
810
|
+
onSubmit: formSchema,
|
|
811
|
+
},
|
|
812
|
+
onSubmit: async ({ value }) => {
|
|
813
|
+
toast("You submitted the following values:", {
|
|
814
|
+
description: (
|
|
815
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
816
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
817
|
+
</pre>
|
|
818
|
+
),
|
|
819
|
+
position: "bottom-right",
|
|
820
|
+
classNames: {
|
|
821
|
+
content: "flex flex-col gap-2",
|
|
822
|
+
},
|
|
823
|
+
style: {
|
|
824
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
825
|
+
} as React.CSSProperties,
|
|
826
|
+
})
|
|
827
|
+
},
|
|
828
|
+
})
|
|
829
|
+
|
|
830
|
+
return (
|
|
831
|
+
<Card className="w-full sm:max-w-lg">
|
|
832
|
+
<CardHeader>
|
|
833
|
+
<CardTitle>Language Preferences</CardTitle>
|
|
834
|
+
<CardDescription>
|
|
835
|
+
Select your preferred spoken language.
|
|
836
|
+
</CardDescription>
|
|
837
|
+
</CardHeader>
|
|
838
|
+
<CardContent>
|
|
839
|
+
<form
|
|
840
|
+
id="form-tanstack-select"
|
|
841
|
+
onSubmit={(e) => {
|
|
842
|
+
e.preventDefault()
|
|
843
|
+
form.handleSubmit()
|
|
844
|
+
}}
|
|
845
|
+
>
|
|
846
|
+
<FieldGroup>
|
|
847
|
+
<form.Field
|
|
848
|
+
name="language"
|
|
849
|
+
children={(field) => {
|
|
850
|
+
const isInvalid =
|
|
851
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
852
|
+
return (
|
|
853
|
+
<Field orientation="responsive" data-invalid={isInvalid}>
|
|
854
|
+
<FieldContent>
|
|
855
|
+
<FieldLabel htmlFor="form-tanstack-select-language">
|
|
856
|
+
Spoken Language
|
|
857
|
+
</FieldLabel>
|
|
858
|
+
<FieldDescription>
|
|
859
|
+
For best results, select the language you speak.
|
|
860
|
+
</FieldDescription>
|
|
861
|
+
{isInvalid && (
|
|
862
|
+
<FieldError errors={field.state.meta.errors} />
|
|
863
|
+
)}
|
|
864
|
+
</FieldContent>
|
|
865
|
+
<Select
|
|
866
|
+
name={field.name}
|
|
867
|
+
value={field.state.value}
|
|
868
|
+
onValueChange={field.handleChange}
|
|
869
|
+
>
|
|
870
|
+
<SelectTrigger
|
|
871
|
+
id="form-tanstack-select-language"
|
|
872
|
+
aria-invalid={isInvalid}
|
|
873
|
+
className="min-w-[120px]"
|
|
874
|
+
>
|
|
875
|
+
<SelectValue placeholder="Select" />
|
|
876
|
+
</SelectTrigger>
|
|
877
|
+
<SelectContent position="item-aligned">
|
|
878
|
+
<SelectItem value="auto">Auto</SelectItem>
|
|
879
|
+
<SelectSeparator />
|
|
880
|
+
{spokenLanguages.map((language) => (
|
|
881
|
+
<SelectItem
|
|
882
|
+
key={language.value}
|
|
883
|
+
value={language.value}
|
|
884
|
+
>
|
|
885
|
+
{language.label}
|
|
886
|
+
</SelectItem>
|
|
887
|
+
))}
|
|
888
|
+
</SelectContent>
|
|
889
|
+
</Select>
|
|
890
|
+
</Field>
|
|
891
|
+
)
|
|
892
|
+
}}
|
|
893
|
+
/>
|
|
894
|
+
</FieldGroup>
|
|
895
|
+
</form>
|
|
896
|
+
</CardContent>
|
|
897
|
+
<CardFooter>
|
|
898
|
+
<Field orientation="horizontal">
|
|
899
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
900
|
+
Reset
|
|
901
|
+
</Button>
|
|
902
|
+
<Button type="submit" form="form-tanstack-select">
|
|
903
|
+
Save
|
|
904
|
+
</Button>
|
|
905
|
+
</Field>
|
|
906
|
+
</CardFooter>
|
|
907
|
+
</Card>
|
|
908
|
+
)
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
```
|
|
912
|
+
|
|
913
|
+
```tsx showLineNumbers title="form.tsx" {6,18-19,23}
|
|
914
|
+
<form.Field
|
|
915
|
+
name="language"
|
|
916
|
+
children={(field) => {
|
|
917
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
918
|
+
return (
|
|
919
|
+
<Field orientation="responsive" data-invalid={isInvalid}>
|
|
920
|
+
<FieldContent>
|
|
921
|
+
<FieldLabel htmlFor="form-tanstack-select-language">
|
|
922
|
+
Spoken Language
|
|
923
|
+
</FieldLabel>
|
|
924
|
+
<FieldDescription>
|
|
925
|
+
For best results, select the language you speak.
|
|
926
|
+
</FieldDescription>
|
|
927
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
928
|
+
</FieldContent>
|
|
929
|
+
<Select
|
|
930
|
+
name={field.name}
|
|
931
|
+
value={field.state.value}
|
|
932
|
+
onValueChange={field.handleChange}
|
|
933
|
+
>
|
|
934
|
+
<SelectTrigger
|
|
935
|
+
id="form-tanstack-select-language"
|
|
936
|
+
aria-invalid={isInvalid}
|
|
937
|
+
className="min-w-[120px]"
|
|
938
|
+
>
|
|
939
|
+
<SelectValue placeholder="Select" />
|
|
940
|
+
</SelectTrigger>
|
|
941
|
+
<SelectContent position="item-aligned">
|
|
942
|
+
<SelectItem value="auto">Auto</SelectItem>
|
|
943
|
+
<SelectItem value="en">English</SelectItem>
|
|
944
|
+
</SelectContent>
|
|
945
|
+
</Select>
|
|
946
|
+
</Field>
|
|
947
|
+
)
|
|
948
|
+
}}
|
|
949
|
+
/>
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
### Checkbox
|
|
953
|
+
|
|
954
|
+
- For checkbox, use `field.state.value` and `field.handleChange` on the `<Checkbox />` component.
|
|
955
|
+
- To show errors, add the `aria-invalid` prop to the `<Checkbox />` component and the `data-invalid` prop to the `<Field />` component.
|
|
956
|
+
- For checkbox arrays, use `mode="array"` on the `<form.Field />` component and TanStack Form's array helpers.
|
|
957
|
+
- Remember to add `data-slot="checkbox-group"` to the `<FieldGroup />` component for proper styling and spacing.
|
|
958
|
+
|
|
959
|
+
```tsx
|
|
960
|
+
/* eslint-disable react/no-children-prop */
|
|
961
|
+
"use client"
|
|
962
|
+
|
|
963
|
+
import { useForm } from "@tanstack/react-form"
|
|
964
|
+
import { toast } from "sonner"
|
|
965
|
+
import * as z from "zod"
|
|
966
|
+
|
|
967
|
+
import { Button } from "@/components/ui/button"
|
|
968
|
+
import {
|
|
969
|
+
Card,
|
|
970
|
+
CardContent,
|
|
971
|
+
CardDescription,
|
|
972
|
+
CardFooter,
|
|
973
|
+
CardHeader,
|
|
974
|
+
CardTitle,
|
|
975
|
+
} from "@/components/ui/card"
|
|
976
|
+
import { Checkbox } from "@/components/ui/checkbox"
|
|
977
|
+
import {
|
|
978
|
+
Field,
|
|
979
|
+
FieldDescription,
|
|
980
|
+
FieldError,
|
|
981
|
+
FieldGroup,
|
|
982
|
+
FieldLabel,
|
|
983
|
+
FieldLegend,
|
|
984
|
+
FieldSeparator,
|
|
985
|
+
FieldSet,
|
|
986
|
+
} from "@/components/ui/field"
|
|
987
|
+
|
|
988
|
+
const tasks = [
|
|
989
|
+
{
|
|
990
|
+
id: "push",
|
|
991
|
+
label: "Push notifications",
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
id: "email",
|
|
995
|
+
label: "Email notifications",
|
|
996
|
+
},
|
|
997
|
+
] as const
|
|
998
|
+
|
|
999
|
+
const formSchema = z.object({
|
|
1000
|
+
responses: z.boolean(),
|
|
1001
|
+
tasks: z
|
|
1002
|
+
.array(z.string())
|
|
1003
|
+
.min(1, "Please select at least one notification type.")
|
|
1004
|
+
.refine(
|
|
1005
|
+
(value) => value.every((task) => tasks.some((t) => t.id === task)),
|
|
1006
|
+
{
|
|
1007
|
+
message: "Invalid notification type selected.",
|
|
1008
|
+
}
|
|
1009
|
+
),
|
|
1010
|
+
})
|
|
1011
|
+
|
|
1012
|
+
export function FormTanstackCheckbox() {
|
|
1013
|
+
const form = useForm({
|
|
1014
|
+
defaultValues: {
|
|
1015
|
+
responses: true,
|
|
1016
|
+
tasks: [] as string[],
|
|
1017
|
+
},
|
|
1018
|
+
validators: {
|
|
1019
|
+
onSubmit: formSchema,
|
|
1020
|
+
},
|
|
1021
|
+
onSubmit: async ({ value }) => {
|
|
1022
|
+
toast("You submitted the following values:", {
|
|
1023
|
+
description: (
|
|
1024
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
1025
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
1026
|
+
</pre>
|
|
1027
|
+
),
|
|
1028
|
+
position: "bottom-right",
|
|
1029
|
+
classNames: {
|
|
1030
|
+
content: "flex flex-col gap-2",
|
|
1031
|
+
},
|
|
1032
|
+
style: {
|
|
1033
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
1034
|
+
} as React.CSSProperties,
|
|
1035
|
+
})
|
|
1036
|
+
},
|
|
1037
|
+
})
|
|
1038
|
+
|
|
1039
|
+
return (
|
|
1040
|
+
<Card className="w-full sm:max-w-md">
|
|
1041
|
+
<CardHeader>
|
|
1042
|
+
<CardTitle>Notifications</CardTitle>
|
|
1043
|
+
<CardDescription>Manage your notification preferences.</CardDescription>
|
|
1044
|
+
</CardHeader>
|
|
1045
|
+
<CardContent>
|
|
1046
|
+
<form
|
|
1047
|
+
id="form-tanstack-checkbox"
|
|
1048
|
+
onSubmit={(e) => {
|
|
1049
|
+
e.preventDefault()
|
|
1050
|
+
form.handleSubmit()
|
|
1051
|
+
}}
|
|
1052
|
+
>
|
|
1053
|
+
<FieldGroup>
|
|
1054
|
+
<form.Field
|
|
1055
|
+
name="responses"
|
|
1056
|
+
children={(field) => {
|
|
1057
|
+
const isInvalid =
|
|
1058
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1059
|
+
return (
|
|
1060
|
+
<div>
|
|
1061
|
+
<FieldSet>
|
|
1062
|
+
<FieldLegend variant="label">Responses</FieldLegend>
|
|
1063
|
+
<FieldDescription>
|
|
1064
|
+
Get notified for requests that take time, like research
|
|
1065
|
+
or image generation.
|
|
1066
|
+
</FieldDescription>
|
|
1067
|
+
<FieldGroup data-slot="checkbox-group">
|
|
1068
|
+
<Field
|
|
1069
|
+
orientation="horizontal"
|
|
1070
|
+
data-invalid={isInvalid}
|
|
1071
|
+
>
|
|
1072
|
+
<Checkbox
|
|
1073
|
+
id="form-tanstack-checkbox-responses"
|
|
1074
|
+
name={field.name}
|
|
1075
|
+
checked={field.state.value}
|
|
1076
|
+
onCheckedChange={(checked) =>
|
|
1077
|
+
field.handleChange(checked === true)
|
|
1078
|
+
}
|
|
1079
|
+
disabled
|
|
1080
|
+
/>
|
|
1081
|
+
<FieldLabel
|
|
1082
|
+
htmlFor="form-tanstack-checkbox-responses"
|
|
1083
|
+
className="font-normal"
|
|
1084
|
+
>
|
|
1085
|
+
Push notifications
|
|
1086
|
+
</FieldLabel>
|
|
1087
|
+
</Field>
|
|
1088
|
+
</FieldGroup>
|
|
1089
|
+
</FieldSet>
|
|
1090
|
+
{isInvalid && (
|
|
1091
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1092
|
+
)}
|
|
1093
|
+
</div>
|
|
1094
|
+
)
|
|
1095
|
+
}}
|
|
1096
|
+
/>
|
|
1097
|
+
<FieldSeparator />
|
|
1098
|
+
<form.Field
|
|
1099
|
+
name="tasks"
|
|
1100
|
+
mode="array"
|
|
1101
|
+
children={(field) => {
|
|
1102
|
+
const isInvalid =
|
|
1103
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1104
|
+
return (
|
|
1105
|
+
<FieldGroup>
|
|
1106
|
+
<FieldSet data-invalid={isInvalid}>
|
|
1107
|
+
<FieldLegend variant="label">Tasks</FieldLegend>
|
|
1108
|
+
<FieldDescription>
|
|
1109
|
+
Get notified when tasks you've created have
|
|
1110
|
+
updates.
|
|
1111
|
+
</FieldDescription>
|
|
1112
|
+
<FieldGroup data-slot="checkbox-group">
|
|
1113
|
+
{tasks.map((task) => (
|
|
1114
|
+
<Field
|
|
1115
|
+
key={task.id}
|
|
1116
|
+
orientation="horizontal"
|
|
1117
|
+
data-invalid={isInvalid}
|
|
1118
|
+
>
|
|
1119
|
+
<Checkbox
|
|
1120
|
+
id={`form-tanstack-checkbox-${task.id}`}
|
|
1121
|
+
name={field.name}
|
|
1122
|
+
aria-invalid={isInvalid}
|
|
1123
|
+
checked={field.state.value.includes(task.id)}
|
|
1124
|
+
onCheckedChange={(checked) => {
|
|
1125
|
+
if (checked) {
|
|
1126
|
+
field.pushValue(task.id)
|
|
1127
|
+
} else {
|
|
1128
|
+
const index = field.state.value.indexOf(
|
|
1129
|
+
task.id
|
|
1130
|
+
)
|
|
1131
|
+
if (index > -1) {
|
|
1132
|
+
field.removeValue(index)
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}}
|
|
1136
|
+
/>
|
|
1137
|
+
<FieldLabel
|
|
1138
|
+
htmlFor={`form-tanstack-checkbox-${task.id}`}
|
|
1139
|
+
className="font-normal"
|
|
1140
|
+
>
|
|
1141
|
+
{task.label}
|
|
1142
|
+
</FieldLabel>
|
|
1143
|
+
</Field>
|
|
1144
|
+
))}
|
|
1145
|
+
</FieldGroup>
|
|
1146
|
+
</FieldSet>
|
|
1147
|
+
{isInvalid && (
|
|
1148
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1149
|
+
)}
|
|
1150
|
+
</FieldGroup>
|
|
1151
|
+
)
|
|
1152
|
+
}}
|
|
1153
|
+
/>
|
|
1154
|
+
</FieldGroup>
|
|
1155
|
+
</form>
|
|
1156
|
+
</CardContent>
|
|
1157
|
+
<CardFooter>
|
|
1158
|
+
<Field orientation="horizontal">
|
|
1159
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
1160
|
+
Reset
|
|
1161
|
+
</Button>
|
|
1162
|
+
<Button type="submit" form="form-tanstack-checkbox">
|
|
1163
|
+
Save
|
|
1164
|
+
</Button>
|
|
1165
|
+
</Field>
|
|
1166
|
+
</CardFooter>
|
|
1167
|
+
</Card>
|
|
1168
|
+
)
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
```tsx showLineNumbers title="form.tsx" {12,17,22-24,44}
|
|
1174
|
+
<form.Field
|
|
1175
|
+
name="tasks"
|
|
1176
|
+
mode="array"
|
|
1177
|
+
children={(field) => {
|
|
1178
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
1179
|
+
return (
|
|
1180
|
+
<FieldSet>
|
|
1181
|
+
<FieldLegend variant="label">Tasks</FieldLegend>
|
|
1182
|
+
<FieldDescription>
|
|
1183
|
+
Get notified when tasks you've created have updates.
|
|
1184
|
+
</FieldDescription>
|
|
1185
|
+
<FieldGroup data-slot="checkbox-group">
|
|
1186
|
+
{tasks.map((task) => (
|
|
1187
|
+
<Field
|
|
1188
|
+
key={task.id}
|
|
1189
|
+
orientation="horizontal"
|
|
1190
|
+
data-invalid={isInvalid}
|
|
1191
|
+
>
|
|
1192
|
+
<Checkbox
|
|
1193
|
+
id={`form-tanstack-checkbox-${task.id}`}
|
|
1194
|
+
name={field.name}
|
|
1195
|
+
aria-invalid={isInvalid}
|
|
1196
|
+
checked={field.state.value.includes(task.id)}
|
|
1197
|
+
onCheckedChange={(checked) => {
|
|
1198
|
+
if (checked) {
|
|
1199
|
+
field.pushValue(task.id)
|
|
1200
|
+
} else {
|
|
1201
|
+
const index = field.state.value.indexOf(task.id)
|
|
1202
|
+
if (index > -1) {
|
|
1203
|
+
field.removeValue(index)
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}}
|
|
1207
|
+
/>
|
|
1208
|
+
<FieldLabel
|
|
1209
|
+
htmlFor={`form-tanstack-checkbox-${task.id}`}
|
|
1210
|
+
className="font-normal"
|
|
1211
|
+
>
|
|
1212
|
+
{task.label}
|
|
1213
|
+
</FieldLabel>
|
|
1214
|
+
</Field>
|
|
1215
|
+
))}
|
|
1216
|
+
</FieldGroup>
|
|
1217
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
1218
|
+
</FieldSet>
|
|
1219
|
+
)
|
|
1220
|
+
}}
|
|
1221
|
+
/>
|
|
1222
|
+
```
|
|
1223
|
+
|
|
1224
|
+
### Radio Group
|
|
1225
|
+
|
|
1226
|
+
- For radio groups, use `field.state.value` and `field.handleChange` on the `<RadioGroup />` component.
|
|
1227
|
+
- To show errors, add the `aria-invalid` prop to the `<RadioGroupItem />` component and the `data-invalid` prop to the `<Field />` component.
|
|
1228
|
+
|
|
1229
|
+
```tsx
|
|
1230
|
+
/* eslint-disable react/no-children-prop */
|
|
1231
|
+
"use client"
|
|
1232
|
+
|
|
1233
|
+
import { useForm } from "@tanstack/react-form"
|
|
1234
|
+
import { toast } from "sonner"
|
|
1235
|
+
import * as z from "zod"
|
|
1236
|
+
|
|
1237
|
+
import { Button } from "@/components/ui/button"
|
|
1238
|
+
import {
|
|
1239
|
+
Card,
|
|
1240
|
+
CardContent,
|
|
1241
|
+
CardDescription,
|
|
1242
|
+
CardFooter,
|
|
1243
|
+
CardHeader,
|
|
1244
|
+
CardTitle,
|
|
1245
|
+
} from "@/components/ui/card"
|
|
1246
|
+
import {
|
|
1247
|
+
Field,
|
|
1248
|
+
FieldContent,
|
|
1249
|
+
FieldDescription,
|
|
1250
|
+
FieldError,
|
|
1251
|
+
FieldGroup,
|
|
1252
|
+
FieldLabel,
|
|
1253
|
+
FieldLegend,
|
|
1254
|
+
FieldSet,
|
|
1255
|
+
FieldTitle,
|
|
1256
|
+
} from "@/components/ui/field"
|
|
1257
|
+
import {
|
|
1258
|
+
RadioGroup,
|
|
1259
|
+
RadioGroupItem,
|
|
1260
|
+
} from "@/components/ui/radio-group"
|
|
1261
|
+
|
|
1262
|
+
const plans = [
|
|
1263
|
+
{
|
|
1264
|
+
id: "starter",
|
|
1265
|
+
title: "Starter (100K tokens/month)",
|
|
1266
|
+
description: "For everyday use with basic features.",
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
id: "pro",
|
|
1270
|
+
title: "Pro (1M tokens/month)",
|
|
1271
|
+
description: "For advanced AI usage with more features.",
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
id: "enterprise",
|
|
1275
|
+
title: "Enterprise (Unlimited tokens)",
|
|
1276
|
+
description: "For large teams and heavy usage.",
|
|
1277
|
+
},
|
|
1278
|
+
] as const
|
|
1279
|
+
|
|
1280
|
+
const formSchema = z.object({
|
|
1281
|
+
plan: z.string().min(1, "You must select a subscription plan to continue."),
|
|
1282
|
+
})
|
|
1283
|
+
|
|
1284
|
+
export function FormTanstackRadioGroup() {
|
|
1285
|
+
const form = useForm({
|
|
1286
|
+
defaultValues: {
|
|
1287
|
+
plan: "",
|
|
1288
|
+
},
|
|
1289
|
+
validators: {
|
|
1290
|
+
onSubmit: formSchema,
|
|
1291
|
+
},
|
|
1292
|
+
onSubmit: async ({ value }) => {
|
|
1293
|
+
toast("You submitted the following values:", {
|
|
1294
|
+
description: (
|
|
1295
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
1296
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
1297
|
+
</pre>
|
|
1298
|
+
),
|
|
1299
|
+
position: "bottom-right",
|
|
1300
|
+
classNames: {
|
|
1301
|
+
content: "flex flex-col gap-2",
|
|
1302
|
+
},
|
|
1303
|
+
style: {
|
|
1304
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
1305
|
+
} as React.CSSProperties,
|
|
1306
|
+
})
|
|
1307
|
+
},
|
|
1308
|
+
})
|
|
1309
|
+
|
|
1310
|
+
return (
|
|
1311
|
+
<Card className="w-full sm:max-w-md">
|
|
1312
|
+
<CardHeader>
|
|
1313
|
+
<CardTitle>Subscription Plan</CardTitle>
|
|
1314
|
+
<CardDescription>
|
|
1315
|
+
See pricing and features for each plan.
|
|
1316
|
+
</CardDescription>
|
|
1317
|
+
</CardHeader>
|
|
1318
|
+
<CardContent>
|
|
1319
|
+
<form
|
|
1320
|
+
id="form-tanstack-radiogroup"
|
|
1321
|
+
onSubmit={(e) => {
|
|
1322
|
+
e.preventDefault()
|
|
1323
|
+
form.handleSubmit()
|
|
1324
|
+
}}
|
|
1325
|
+
>
|
|
1326
|
+
<FieldGroup>
|
|
1327
|
+
<form.Field
|
|
1328
|
+
name="plan"
|
|
1329
|
+
children={(field) => {
|
|
1330
|
+
const isInvalid =
|
|
1331
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1332
|
+
return (
|
|
1333
|
+
<FieldSet>
|
|
1334
|
+
<FieldLegend>Plan</FieldLegend>
|
|
1335
|
+
<FieldDescription>
|
|
1336
|
+
You can upgrade or downgrade your plan at any time.
|
|
1337
|
+
</FieldDescription>
|
|
1338
|
+
<RadioGroup
|
|
1339
|
+
name={field.name}
|
|
1340
|
+
value={field.state.value}
|
|
1341
|
+
onValueChange={field.handleChange}
|
|
1342
|
+
>
|
|
1343
|
+
{plans.map((plan) => (
|
|
1344
|
+
<FieldLabel
|
|
1345
|
+
key={plan.id}
|
|
1346
|
+
htmlFor={`form-tanstack-radiogroup-${plan.id}`}
|
|
1347
|
+
>
|
|
1348
|
+
<Field
|
|
1349
|
+
orientation="horizontal"
|
|
1350
|
+
data-invalid={isInvalid}
|
|
1351
|
+
>
|
|
1352
|
+
<FieldContent>
|
|
1353
|
+
<FieldTitle>{plan.title}</FieldTitle>
|
|
1354
|
+
<FieldDescription>
|
|
1355
|
+
{plan.description}
|
|
1356
|
+
</FieldDescription>
|
|
1357
|
+
</FieldContent>
|
|
1358
|
+
<RadioGroupItem
|
|
1359
|
+
value={plan.id}
|
|
1360
|
+
id={`form-tanstack-radiogroup-${plan.id}`}
|
|
1361
|
+
aria-invalid={isInvalid}
|
|
1362
|
+
/>
|
|
1363
|
+
</Field>
|
|
1364
|
+
</FieldLabel>
|
|
1365
|
+
))}
|
|
1366
|
+
</RadioGroup>
|
|
1367
|
+
{isInvalid && (
|
|
1368
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1369
|
+
)}
|
|
1370
|
+
</FieldSet>
|
|
1371
|
+
)
|
|
1372
|
+
}}
|
|
1373
|
+
/>
|
|
1374
|
+
</FieldGroup>
|
|
1375
|
+
</form>
|
|
1376
|
+
</CardContent>
|
|
1377
|
+
<CardFooter>
|
|
1378
|
+
<Field orientation="horizontal">
|
|
1379
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
1380
|
+
Reset
|
|
1381
|
+
</Button>
|
|
1382
|
+
<Button type="submit" form="form-tanstack-radiogroup">
|
|
1383
|
+
Save
|
|
1384
|
+
</Button>
|
|
1385
|
+
</Field>
|
|
1386
|
+
</CardFooter>
|
|
1387
|
+
</Card>
|
|
1388
|
+
)
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
```
|
|
1392
|
+
|
|
1393
|
+
```tsx showLineNumbers title="form.tsx" {21,29,35}
|
|
1394
|
+
<form.Field
|
|
1395
|
+
name="plan"
|
|
1396
|
+
children={(field) => {
|
|
1397
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
1398
|
+
return (
|
|
1399
|
+
<FieldSet>
|
|
1400
|
+
<FieldLegend>Plan</FieldLegend>
|
|
1401
|
+
<FieldDescription>
|
|
1402
|
+
You can upgrade or downgrade your plan at any time.
|
|
1403
|
+
</FieldDescription>
|
|
1404
|
+
<RadioGroup
|
|
1405
|
+
name={field.name}
|
|
1406
|
+
value={field.state.value}
|
|
1407
|
+
onValueChange={field.handleChange}
|
|
1408
|
+
>
|
|
1409
|
+
{plans.map((plan) => (
|
|
1410
|
+
<FieldLabel
|
|
1411
|
+
key={plan.id}
|
|
1412
|
+
htmlFor={`form-tanstack-radiogroup-${plan.id}`}
|
|
1413
|
+
>
|
|
1414
|
+
<Field orientation="horizontal" data-invalid={isInvalid}>
|
|
1415
|
+
<FieldContent>
|
|
1416
|
+
<FieldTitle>{plan.title}</FieldTitle>
|
|
1417
|
+
<FieldDescription>{plan.description}</FieldDescription>
|
|
1418
|
+
</FieldContent>
|
|
1419
|
+
<RadioGroupItem
|
|
1420
|
+
value={plan.id}
|
|
1421
|
+
id={`form-tanstack-radiogroup-${plan.id}`}
|
|
1422
|
+
aria-invalid={isInvalid}
|
|
1423
|
+
/>
|
|
1424
|
+
</Field>
|
|
1425
|
+
</FieldLabel>
|
|
1426
|
+
))}
|
|
1427
|
+
</RadioGroup>
|
|
1428
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
1429
|
+
</FieldSet>
|
|
1430
|
+
)
|
|
1431
|
+
}}
|
|
1432
|
+
/>
|
|
1433
|
+
```
|
|
1434
|
+
|
|
1435
|
+
### Switch
|
|
1436
|
+
|
|
1437
|
+
- For switches, use `field.state.value` and `field.handleChange` on the `<Switch />` component.
|
|
1438
|
+
- To show errors, add the `aria-invalid` prop to the `<Switch />` component and the `data-invalid` prop to the `<Field />` component.
|
|
1439
|
+
|
|
1440
|
+
```tsx
|
|
1441
|
+
/* eslint-disable react/no-children-prop */
|
|
1442
|
+
"use client"
|
|
1443
|
+
|
|
1444
|
+
import { useForm } from "@tanstack/react-form"
|
|
1445
|
+
import { toast } from "sonner"
|
|
1446
|
+
import * as z from "zod"
|
|
1447
|
+
|
|
1448
|
+
import { Button } from "@/components/ui/button"
|
|
1449
|
+
import {
|
|
1450
|
+
Card,
|
|
1451
|
+
CardContent,
|
|
1452
|
+
CardDescription,
|
|
1453
|
+
CardFooter,
|
|
1454
|
+
CardHeader,
|
|
1455
|
+
CardTitle,
|
|
1456
|
+
} from "@/components/ui/card"
|
|
1457
|
+
import {
|
|
1458
|
+
Field,
|
|
1459
|
+
FieldContent,
|
|
1460
|
+
FieldDescription,
|
|
1461
|
+
FieldError,
|
|
1462
|
+
FieldGroup,
|
|
1463
|
+
FieldLabel,
|
|
1464
|
+
} from "@/components/ui/field"
|
|
1465
|
+
import { Switch } from "@/components/ui/switch"
|
|
1466
|
+
|
|
1467
|
+
const formSchema = z.object({
|
|
1468
|
+
twoFactor: z.boolean().refine((val) => val === true, {
|
|
1469
|
+
message: "It is highly recommended to enable two-factor authentication.",
|
|
1470
|
+
}),
|
|
1471
|
+
})
|
|
1472
|
+
|
|
1473
|
+
export function FormTanstackSwitch() {
|
|
1474
|
+
const form = useForm({
|
|
1475
|
+
defaultValues: {
|
|
1476
|
+
twoFactor: false,
|
|
1477
|
+
},
|
|
1478
|
+
validators: {
|
|
1479
|
+
onSubmit: formSchema,
|
|
1480
|
+
},
|
|
1481
|
+
onSubmit: async ({ value }) => {
|
|
1482
|
+
toast("You submitted the following values:", {
|
|
1483
|
+
description: (
|
|
1484
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
1485
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
1486
|
+
</pre>
|
|
1487
|
+
),
|
|
1488
|
+
position: "bottom-right",
|
|
1489
|
+
classNames: {
|
|
1490
|
+
content: "flex flex-col gap-2",
|
|
1491
|
+
},
|
|
1492
|
+
style: {
|
|
1493
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
1494
|
+
} as React.CSSProperties,
|
|
1495
|
+
})
|
|
1496
|
+
},
|
|
1497
|
+
})
|
|
1498
|
+
|
|
1499
|
+
return (
|
|
1500
|
+
<Card className="w-full sm:max-w-md">
|
|
1501
|
+
<CardHeader>
|
|
1502
|
+
<CardTitle>Security Settings</CardTitle>
|
|
1503
|
+
<CardDescription>
|
|
1504
|
+
Manage your account security preferences.
|
|
1505
|
+
</CardDescription>
|
|
1506
|
+
</CardHeader>
|
|
1507
|
+
<CardContent>
|
|
1508
|
+
<form
|
|
1509
|
+
id="form-tanstack-switch"
|
|
1510
|
+
onSubmit={(e) => {
|
|
1511
|
+
e.preventDefault()
|
|
1512
|
+
form.handleSubmit()
|
|
1513
|
+
}}
|
|
1514
|
+
>
|
|
1515
|
+
<FieldGroup>
|
|
1516
|
+
<form.Field
|
|
1517
|
+
name="twoFactor"
|
|
1518
|
+
children={(field) => {
|
|
1519
|
+
const isInvalid =
|
|
1520
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1521
|
+
return (
|
|
1522
|
+
<Field orientation="horizontal" data-invalid={isInvalid}>
|
|
1523
|
+
<FieldContent>
|
|
1524
|
+
<FieldLabel htmlFor="form-tanstack-switch-twoFactor">
|
|
1525
|
+
Multi-factor authentication
|
|
1526
|
+
</FieldLabel>
|
|
1527
|
+
<FieldDescription>
|
|
1528
|
+
Enable multi-factor authentication to secure your
|
|
1529
|
+
account.
|
|
1530
|
+
</FieldDescription>
|
|
1531
|
+
{isInvalid && (
|
|
1532
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1533
|
+
)}
|
|
1534
|
+
</FieldContent>
|
|
1535
|
+
<Switch
|
|
1536
|
+
id="form-tanstack-switch-twoFactor"
|
|
1537
|
+
name={field.name}
|
|
1538
|
+
checked={field.state.value}
|
|
1539
|
+
onCheckedChange={field.handleChange}
|
|
1540
|
+
aria-invalid={isInvalid}
|
|
1541
|
+
/>
|
|
1542
|
+
</Field>
|
|
1543
|
+
)
|
|
1544
|
+
}}
|
|
1545
|
+
/>
|
|
1546
|
+
</FieldGroup>
|
|
1547
|
+
</form>
|
|
1548
|
+
</CardContent>
|
|
1549
|
+
<CardFooter>
|
|
1550
|
+
<Field orientation="horizontal">
|
|
1551
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
1552
|
+
Reset
|
|
1553
|
+
</Button>
|
|
1554
|
+
<Button type="submit" form="form-tanstack-switch">
|
|
1555
|
+
Save
|
|
1556
|
+
</Button>
|
|
1557
|
+
</Field>
|
|
1558
|
+
</CardFooter>
|
|
1559
|
+
</Card>
|
|
1560
|
+
)
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
```
|
|
1564
|
+
|
|
1565
|
+
```tsx showLineNumbers title="form.tsx" {6,14,19-21}
|
|
1566
|
+
<form.Field
|
|
1567
|
+
name="twoFactor"
|
|
1568
|
+
children={(field) => {
|
|
1569
|
+
const isInvalid = field.state.meta.isTouched && !field.state.meta.isValid
|
|
1570
|
+
return (
|
|
1571
|
+
<Field orientation="horizontal" data-invalid={isInvalid}>
|
|
1572
|
+
<FieldContent>
|
|
1573
|
+
<FieldLabel htmlFor="form-tanstack-switch-twoFactor">
|
|
1574
|
+
Multi-factor authentication
|
|
1575
|
+
</FieldLabel>
|
|
1576
|
+
<FieldDescription>
|
|
1577
|
+
Enable multi-factor authentication to secure your account.
|
|
1578
|
+
</FieldDescription>
|
|
1579
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
1580
|
+
</FieldContent>
|
|
1581
|
+
<Switch
|
|
1582
|
+
id="form-tanstack-switch-twoFactor"
|
|
1583
|
+
name={field.name}
|
|
1584
|
+
checked={field.state.value}
|
|
1585
|
+
onCheckedChange={field.handleChange}
|
|
1586
|
+
aria-invalid={isInvalid}
|
|
1587
|
+
/>
|
|
1588
|
+
</Field>
|
|
1589
|
+
)
|
|
1590
|
+
}}
|
|
1591
|
+
/>
|
|
1592
|
+
```
|
|
1593
|
+
|
|
1594
|
+
### Complex Forms
|
|
1595
|
+
|
|
1596
|
+
Here is an example of a more complex form with multiple fields and validation.
|
|
1597
|
+
|
|
1598
|
+
```tsx
|
|
1599
|
+
/* eslint-disable react/no-children-prop */
|
|
1600
|
+
"use client"
|
|
1601
|
+
|
|
1602
|
+
import * as React from "react"
|
|
1603
|
+
import { useForm } from "@tanstack/react-form"
|
|
1604
|
+
import { toast } from "sonner"
|
|
1605
|
+
import * as z from "zod"
|
|
1606
|
+
|
|
1607
|
+
import { Button } from "@/components/ui/button"
|
|
1608
|
+
import { Card, CardContent, CardFooter } from "@/components/ui/card"
|
|
1609
|
+
import { Checkbox } from "@/components/ui/checkbox"
|
|
1610
|
+
import {
|
|
1611
|
+
Field,
|
|
1612
|
+
FieldContent,
|
|
1613
|
+
FieldDescription,
|
|
1614
|
+
FieldError,
|
|
1615
|
+
FieldGroup,
|
|
1616
|
+
FieldLabel,
|
|
1617
|
+
FieldLegend,
|
|
1618
|
+
FieldSeparator,
|
|
1619
|
+
FieldSet,
|
|
1620
|
+
FieldTitle,
|
|
1621
|
+
} from "@/components/ui/field"
|
|
1622
|
+
import {
|
|
1623
|
+
RadioGroup,
|
|
1624
|
+
RadioGroupItem,
|
|
1625
|
+
} from "@/components/ui/radio-group"
|
|
1626
|
+
import {
|
|
1627
|
+
Select,
|
|
1628
|
+
SelectContent,
|
|
1629
|
+
SelectItem,
|
|
1630
|
+
SelectTrigger,
|
|
1631
|
+
SelectValue,
|
|
1632
|
+
} from "@/components/ui/select"
|
|
1633
|
+
import { Switch } from "@/components/ui/switch"
|
|
1634
|
+
|
|
1635
|
+
const addons = [
|
|
1636
|
+
{
|
|
1637
|
+
id: "analytics",
|
|
1638
|
+
title: "Analytics",
|
|
1639
|
+
description: "Advanced analytics and reporting",
|
|
1640
|
+
},
|
|
1641
|
+
{
|
|
1642
|
+
id: "backup",
|
|
1643
|
+
title: "Backup",
|
|
1644
|
+
description: "Automated daily backups",
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
id: "support",
|
|
1648
|
+
title: "Priority Support",
|
|
1649
|
+
description: "24/7 premium customer support",
|
|
1650
|
+
},
|
|
1651
|
+
] as const
|
|
1652
|
+
|
|
1653
|
+
const formSchema = z.object({
|
|
1654
|
+
plan: z
|
|
1655
|
+
.string({
|
|
1656
|
+
required_error: "Please select a subscription plan",
|
|
1657
|
+
})
|
|
1658
|
+
.min(1, "Please select a subscription plan")
|
|
1659
|
+
.refine((value) => value === "basic" || value === "pro", {
|
|
1660
|
+
message: "Invalid plan selection. Please choose Basic or Pro",
|
|
1661
|
+
}),
|
|
1662
|
+
billingPeriod: z
|
|
1663
|
+
.string({
|
|
1664
|
+
required_error: "Please select a billing period",
|
|
1665
|
+
})
|
|
1666
|
+
.min(1, "Please select a billing period"),
|
|
1667
|
+
addons: z
|
|
1668
|
+
.array(z.string())
|
|
1669
|
+
.min(1, "Please select at least one add-on")
|
|
1670
|
+
.max(3, "You can select up to 3 add-ons")
|
|
1671
|
+
.refine(
|
|
1672
|
+
(value) => value.every((addon) => addons.some((a) => a.id === addon)),
|
|
1673
|
+
{
|
|
1674
|
+
message: "You selected an invalid add-on",
|
|
1675
|
+
}
|
|
1676
|
+
),
|
|
1677
|
+
emailNotifications: z.boolean(),
|
|
1678
|
+
})
|
|
1679
|
+
|
|
1680
|
+
export function FormTanstackComplex() {
|
|
1681
|
+
const form = useForm({
|
|
1682
|
+
defaultValues: {
|
|
1683
|
+
plan: "basic",
|
|
1684
|
+
billingPeriod: "monthly",
|
|
1685
|
+
addons: [] as string[],
|
|
1686
|
+
emailNotifications: false,
|
|
1687
|
+
},
|
|
1688
|
+
validators: {
|
|
1689
|
+
onSubmit: formSchema,
|
|
1690
|
+
},
|
|
1691
|
+
onSubmit: async ({ value }) => {
|
|
1692
|
+
toast("You submitted the following values:", {
|
|
1693
|
+
description: (
|
|
1694
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
1695
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
1696
|
+
</pre>
|
|
1697
|
+
),
|
|
1698
|
+
position: "bottom-right",
|
|
1699
|
+
classNames: {
|
|
1700
|
+
content: "flex flex-col gap-2",
|
|
1701
|
+
},
|
|
1702
|
+
style: {
|
|
1703
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
1704
|
+
} as React.CSSProperties,
|
|
1705
|
+
})
|
|
1706
|
+
},
|
|
1707
|
+
})
|
|
1708
|
+
|
|
1709
|
+
return (
|
|
1710
|
+
<Card className="w-full max-w-sm">
|
|
1711
|
+
<CardContent>
|
|
1712
|
+
<form
|
|
1713
|
+
id="subscription-form"
|
|
1714
|
+
onSubmit={(e) => {
|
|
1715
|
+
e.preventDefault()
|
|
1716
|
+
form.handleSubmit()
|
|
1717
|
+
}}
|
|
1718
|
+
>
|
|
1719
|
+
<FieldGroup>
|
|
1720
|
+
<form.Field
|
|
1721
|
+
name="plan"
|
|
1722
|
+
children={(field) => {
|
|
1723
|
+
const isInvalid =
|
|
1724
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1725
|
+
return (
|
|
1726
|
+
<FieldSet>
|
|
1727
|
+
<FieldLegend>Subscription Plan</FieldLegend>
|
|
1728
|
+
<FieldDescription>
|
|
1729
|
+
Choose your subscription plan.
|
|
1730
|
+
</FieldDescription>
|
|
1731
|
+
<RadioGroup
|
|
1732
|
+
name={field.name}
|
|
1733
|
+
value={field.state.value}
|
|
1734
|
+
onValueChange={field.handleChange}
|
|
1735
|
+
>
|
|
1736
|
+
<FieldLabel htmlFor="basic">
|
|
1737
|
+
<Field
|
|
1738
|
+
orientation="horizontal"
|
|
1739
|
+
data-invalid={isInvalid}
|
|
1740
|
+
>
|
|
1741
|
+
<FieldContent>
|
|
1742
|
+
<FieldTitle>Basic</FieldTitle>
|
|
1743
|
+
<FieldDescription>
|
|
1744
|
+
For individuals and small teams
|
|
1745
|
+
</FieldDescription>
|
|
1746
|
+
</FieldContent>
|
|
1747
|
+
<RadioGroupItem
|
|
1748
|
+
value="basic"
|
|
1749
|
+
id="basic"
|
|
1750
|
+
aria-invalid={isInvalid}
|
|
1751
|
+
/>
|
|
1752
|
+
</Field>
|
|
1753
|
+
</FieldLabel>
|
|
1754
|
+
<FieldLabel htmlFor="pro">
|
|
1755
|
+
<Field
|
|
1756
|
+
orientation="horizontal"
|
|
1757
|
+
data-invalid={isInvalid}
|
|
1758
|
+
>
|
|
1759
|
+
<FieldContent>
|
|
1760
|
+
<FieldTitle>Pro</FieldTitle>
|
|
1761
|
+
<FieldDescription>
|
|
1762
|
+
For businesses with higher demands
|
|
1763
|
+
</FieldDescription>
|
|
1764
|
+
</FieldContent>
|
|
1765
|
+
<RadioGroupItem
|
|
1766
|
+
value="pro"
|
|
1767
|
+
id="pro"
|
|
1768
|
+
aria-invalid={isInvalid}
|
|
1769
|
+
/>
|
|
1770
|
+
</Field>
|
|
1771
|
+
</FieldLabel>
|
|
1772
|
+
</RadioGroup>
|
|
1773
|
+
{isInvalid && (
|
|
1774
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1775
|
+
)}
|
|
1776
|
+
</FieldSet>
|
|
1777
|
+
)
|
|
1778
|
+
}}
|
|
1779
|
+
/>
|
|
1780
|
+
<FieldSeparator />
|
|
1781
|
+
<form.Field
|
|
1782
|
+
name="billingPeriod"
|
|
1783
|
+
children={(field) => {
|
|
1784
|
+
const isInvalid =
|
|
1785
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1786
|
+
return (
|
|
1787
|
+
<Field data-invalid={isInvalid}>
|
|
1788
|
+
<FieldLabel htmlFor={field.name}>Billing Period</FieldLabel>
|
|
1789
|
+
<Select
|
|
1790
|
+
name={field.name}
|
|
1791
|
+
value={field.state.value}
|
|
1792
|
+
onValueChange={field.handleChange}
|
|
1793
|
+
aria-invalid={isInvalid}
|
|
1794
|
+
>
|
|
1795
|
+
<SelectTrigger id={field.name}>
|
|
1796
|
+
<SelectValue placeholder="Select" />
|
|
1797
|
+
</SelectTrigger>
|
|
1798
|
+
<SelectContent>
|
|
1799
|
+
<SelectItem value="monthly">Monthly</SelectItem>
|
|
1800
|
+
<SelectItem value="yearly">Yearly</SelectItem>
|
|
1801
|
+
</SelectContent>
|
|
1802
|
+
</Select>
|
|
1803
|
+
<FieldDescription>
|
|
1804
|
+
Choose how often you want to be billed.
|
|
1805
|
+
</FieldDescription>
|
|
1806
|
+
{isInvalid && (
|
|
1807
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1808
|
+
)}
|
|
1809
|
+
</Field>
|
|
1810
|
+
)
|
|
1811
|
+
}}
|
|
1812
|
+
/>
|
|
1813
|
+
<FieldSeparator />
|
|
1814
|
+
<form.Field
|
|
1815
|
+
name="addons"
|
|
1816
|
+
mode="array"
|
|
1817
|
+
children={(field) => {
|
|
1818
|
+
const isInvalid =
|
|
1819
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1820
|
+
return (
|
|
1821
|
+
<FieldSet>
|
|
1822
|
+
<FieldLegend>Add-ons</FieldLegend>
|
|
1823
|
+
<FieldDescription>
|
|
1824
|
+
Select additional features you'd like to include.
|
|
1825
|
+
</FieldDescription>
|
|
1826
|
+
<FieldGroup data-slot="checkbox-group">
|
|
1827
|
+
{addons.map((addon) => (
|
|
1828
|
+
<Field
|
|
1829
|
+
key={addon.id}
|
|
1830
|
+
orientation="horizontal"
|
|
1831
|
+
data-invalid={isInvalid}
|
|
1832
|
+
>
|
|
1833
|
+
<Checkbox
|
|
1834
|
+
id={addon.id}
|
|
1835
|
+
name={field.name}
|
|
1836
|
+
aria-invalid={isInvalid}
|
|
1837
|
+
checked={field.state.value.includes(addon.id)}
|
|
1838
|
+
onCheckedChange={(checked) => {
|
|
1839
|
+
if (checked) {
|
|
1840
|
+
field.pushValue(addon.id)
|
|
1841
|
+
} else {
|
|
1842
|
+
const index = field.state.value.indexOf(
|
|
1843
|
+
addon.id
|
|
1844
|
+
)
|
|
1845
|
+
if (index > -1) {
|
|
1846
|
+
field.removeValue(index)
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
}}
|
|
1850
|
+
/>
|
|
1851
|
+
<FieldContent>
|
|
1852
|
+
<FieldLabel htmlFor={addon.id}>
|
|
1853
|
+
{addon.title}
|
|
1854
|
+
</FieldLabel>
|
|
1855
|
+
<FieldDescription>
|
|
1856
|
+
{addon.description}
|
|
1857
|
+
</FieldDescription>
|
|
1858
|
+
</FieldContent>
|
|
1859
|
+
</Field>
|
|
1860
|
+
))}
|
|
1861
|
+
</FieldGroup>
|
|
1862
|
+
{isInvalid && (
|
|
1863
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1864
|
+
)}
|
|
1865
|
+
</FieldSet>
|
|
1866
|
+
)
|
|
1867
|
+
}}
|
|
1868
|
+
/>
|
|
1869
|
+
<FieldSeparator />
|
|
1870
|
+
<form.Field
|
|
1871
|
+
name="emailNotifications"
|
|
1872
|
+
children={(field) => {
|
|
1873
|
+
const isInvalid =
|
|
1874
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
1875
|
+
return (
|
|
1876
|
+
<Field orientation="horizontal" data-invalid={isInvalid}>
|
|
1877
|
+
<FieldContent>
|
|
1878
|
+
<FieldLabel htmlFor={field.name}>
|
|
1879
|
+
Email Notifications
|
|
1880
|
+
</FieldLabel>
|
|
1881
|
+
<FieldDescription>
|
|
1882
|
+
Receive email updates about your subscription
|
|
1883
|
+
</FieldDescription>
|
|
1884
|
+
</FieldContent>
|
|
1885
|
+
<Switch
|
|
1886
|
+
id={field.name}
|
|
1887
|
+
name={field.name}
|
|
1888
|
+
checked={field.state.value}
|
|
1889
|
+
onCheckedChange={field.handleChange}
|
|
1890
|
+
aria-invalid={isInvalid}
|
|
1891
|
+
/>
|
|
1892
|
+
{isInvalid && (
|
|
1893
|
+
<FieldError errors={field.state.meta.errors} />
|
|
1894
|
+
)}
|
|
1895
|
+
</Field>
|
|
1896
|
+
)
|
|
1897
|
+
}}
|
|
1898
|
+
/>
|
|
1899
|
+
</FieldGroup>
|
|
1900
|
+
</form>
|
|
1901
|
+
</CardContent>
|
|
1902
|
+
<CardFooter>
|
|
1903
|
+
<Field orientation="horizontal" className="justify-end">
|
|
1904
|
+
<Button type="submit" form="subscription-form">
|
|
1905
|
+
Save Preferences
|
|
1906
|
+
</Button>
|
|
1907
|
+
</Field>
|
|
1908
|
+
</CardFooter>
|
|
1909
|
+
</Card>
|
|
1910
|
+
)
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
```
|
|
1914
|
+
|
|
1915
|
+
## Resetting the Form
|
|
1916
|
+
|
|
1917
|
+
Use `form.reset()` to reset the form to its default values.
|
|
1918
|
+
|
|
1919
|
+
```tsx showLineNumbers
|
|
1920
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
1921
|
+
Reset
|
|
1922
|
+
</Button>
|
|
1923
|
+
```
|
|
1924
|
+
|
|
1925
|
+
## Array Fields
|
|
1926
|
+
|
|
1927
|
+
TanStack Form provides powerful array field management with `mode="array"`. This allows you to dynamically add, remove, and update array items with full validation support.
|
|
1928
|
+
|
|
1929
|
+
```tsx
|
|
1930
|
+
/* eslint-disable react/no-children-prop */
|
|
1931
|
+
"use client"
|
|
1932
|
+
|
|
1933
|
+
import * as React from "react"
|
|
1934
|
+
import { useForm } from "@tanstack/react-form"
|
|
1935
|
+
import { XIcon } from "lucide-react"
|
|
1936
|
+
import { toast } from "sonner"
|
|
1937
|
+
import { z } from "zod"
|
|
1938
|
+
|
|
1939
|
+
import { Button } from "@/components/ui/button"
|
|
1940
|
+
import {
|
|
1941
|
+
Card,
|
|
1942
|
+
CardContent,
|
|
1943
|
+
CardDescription,
|
|
1944
|
+
CardFooter,
|
|
1945
|
+
CardHeader,
|
|
1946
|
+
CardTitle,
|
|
1947
|
+
} from "@/components/ui/card"
|
|
1948
|
+
import {
|
|
1949
|
+
Field,
|
|
1950
|
+
FieldContent,
|
|
1951
|
+
FieldDescription,
|
|
1952
|
+
FieldError,
|
|
1953
|
+
FieldGroup,
|
|
1954
|
+
FieldLegend,
|
|
1955
|
+
FieldSet,
|
|
1956
|
+
} from "@/components/ui/field"
|
|
1957
|
+
import {
|
|
1958
|
+
InputGroup,
|
|
1959
|
+
InputGroupAddon,
|
|
1960
|
+
InputGroupButton,
|
|
1961
|
+
InputGroupInput,
|
|
1962
|
+
} from "@/components/ui/input-group"
|
|
1963
|
+
|
|
1964
|
+
const formSchema = z.object({
|
|
1965
|
+
emails: z
|
|
1966
|
+
.array(
|
|
1967
|
+
z.object({
|
|
1968
|
+
address: z.string().email("Enter a valid email address."),
|
|
1969
|
+
})
|
|
1970
|
+
)
|
|
1971
|
+
.min(1, "Add at least one email address.")
|
|
1972
|
+
.max(5, "You can add up to 5 email addresses."),
|
|
1973
|
+
})
|
|
1974
|
+
|
|
1975
|
+
export function FormTanstackArray() {
|
|
1976
|
+
const form = useForm({
|
|
1977
|
+
defaultValues: {
|
|
1978
|
+
emails: [{ address: "" }],
|
|
1979
|
+
},
|
|
1980
|
+
validators: {
|
|
1981
|
+
onBlur: formSchema,
|
|
1982
|
+
},
|
|
1983
|
+
onSubmit: async ({ value }) => {
|
|
1984
|
+
toast("You submitted the following values:", {
|
|
1985
|
+
description: (
|
|
1986
|
+
<pre className="mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground">
|
|
1987
|
+
<code>{JSON.stringify(value, null, 2)}</code>
|
|
1988
|
+
</pre>
|
|
1989
|
+
),
|
|
1990
|
+
position: "bottom-right",
|
|
1991
|
+
classNames: {
|
|
1992
|
+
content: "flex flex-col gap-2",
|
|
1993
|
+
},
|
|
1994
|
+
style: {
|
|
1995
|
+
"--border-radius": "calc(var(--radius) + 4px)",
|
|
1996
|
+
} as React.CSSProperties,
|
|
1997
|
+
})
|
|
1998
|
+
},
|
|
1999
|
+
})
|
|
2000
|
+
|
|
2001
|
+
return (
|
|
2002
|
+
<Card className="w-full sm:max-w-md">
|
|
2003
|
+
<CardHeader className="border-b">
|
|
2004
|
+
<CardTitle>Contact Emails</CardTitle>
|
|
2005
|
+
<CardDescription>Manage your contact email addresses.</CardDescription>
|
|
2006
|
+
</CardHeader>
|
|
2007
|
+
<CardContent>
|
|
2008
|
+
<form
|
|
2009
|
+
id="form-tanstack-array"
|
|
2010
|
+
onSubmit={(e) => {
|
|
2011
|
+
e.preventDefault()
|
|
2012
|
+
form.handleSubmit()
|
|
2013
|
+
}}
|
|
2014
|
+
>
|
|
2015
|
+
<form.Field name="emails" mode="array">
|
|
2016
|
+
{(field) => {
|
|
2017
|
+
const isInvalid =
|
|
2018
|
+
field.state.meta.isTouched && !field.state.meta.isValid
|
|
2019
|
+
return (
|
|
2020
|
+
<FieldSet className="gap-4">
|
|
2021
|
+
<FieldLegend variant="label">Email Addresses</FieldLegend>
|
|
2022
|
+
<FieldDescription>
|
|
2023
|
+
Add up to 5 email addresses where we can contact you.
|
|
2024
|
+
</FieldDescription>
|
|
2025
|
+
<FieldGroup className="gap-4">
|
|
2026
|
+
{field.state.value.map((_, index) => (
|
|
2027
|
+
<form.Field
|
|
2028
|
+
key={index}
|
|
2029
|
+
name={`emails[${index}].address`}
|
|
2030
|
+
children={(subField) => {
|
|
2031
|
+
const isSubFieldInvalid =
|
|
2032
|
+
subField.state.meta.isTouched &&
|
|
2033
|
+
!subField.state.meta.isValid
|
|
2034
|
+
return (
|
|
2035
|
+
<Field
|
|
2036
|
+
orientation="horizontal"
|
|
2037
|
+
data-invalid={isSubFieldInvalid}
|
|
2038
|
+
>
|
|
2039
|
+
<FieldContent>
|
|
2040
|
+
<InputGroup>
|
|
2041
|
+
<InputGroupInput
|
|
2042
|
+
id={`form-tanstack-array-email-${index}`}
|
|
2043
|
+
name={subField.name}
|
|
2044
|
+
value={subField.state.value}
|
|
2045
|
+
onBlur={subField.handleBlur}
|
|
2046
|
+
onChange={(e) =>
|
|
2047
|
+
subField.handleChange(e.target.value)
|
|
2048
|
+
}
|
|
2049
|
+
aria-invalid={isSubFieldInvalid}
|
|
2050
|
+
placeholder="name@example.com"
|
|
2051
|
+
type="email"
|
|
2052
|
+
autoComplete="email"
|
|
2053
|
+
/>
|
|
2054
|
+
{field.state.value.length > 1 && (
|
|
2055
|
+
<InputGroupAddon align="inline-end">
|
|
2056
|
+
<InputGroupButton
|
|
2057
|
+
type="button"
|
|
2058
|
+
variant="ghost"
|
|
2059
|
+
size="icon-xs"
|
|
2060
|
+
onClick={() => field.removeValue(index)}
|
|
2061
|
+
aria-label={`Remove email ${index + 1}`}
|
|
2062
|
+
>
|
|
2063
|
+
<XIcon />
|
|
2064
|
+
</InputGroupButton>
|
|
2065
|
+
</InputGroupAddon>
|
|
2066
|
+
)}
|
|
2067
|
+
</InputGroup>
|
|
2068
|
+
{isSubFieldInvalid && (
|
|
2069
|
+
<FieldError
|
|
2070
|
+
errors={subField.state.meta.errors}
|
|
2071
|
+
/>
|
|
2072
|
+
)}
|
|
2073
|
+
</FieldContent>
|
|
2074
|
+
</Field>
|
|
2075
|
+
)
|
|
2076
|
+
}}
|
|
2077
|
+
/>
|
|
2078
|
+
))}
|
|
2079
|
+
<Button
|
|
2080
|
+
type="button"
|
|
2081
|
+
variant="outline"
|
|
2082
|
+
size="sm"
|
|
2083
|
+
onClick={() => field.pushValue({ address: "" })}
|
|
2084
|
+
disabled={field.state.value.length >= 5}
|
|
2085
|
+
>
|
|
2086
|
+
Add Email Address
|
|
2087
|
+
</Button>
|
|
2088
|
+
</FieldGroup>
|
|
2089
|
+
{isInvalid && <FieldError errors={field.state.meta.errors} />}
|
|
2090
|
+
</FieldSet>
|
|
2091
|
+
)
|
|
2092
|
+
}}
|
|
2093
|
+
</form.Field>
|
|
2094
|
+
</form>
|
|
2095
|
+
</CardContent>
|
|
2096
|
+
<CardFooter className="border-t">
|
|
2097
|
+
<Field orientation="horizontal">
|
|
2098
|
+
<Button type="button" variant="outline" onClick={() => form.reset()}>
|
|
2099
|
+
Reset
|
|
2100
|
+
</Button>
|
|
2101
|
+
<Button type="submit" form="form-tanstack-array">
|
|
2102
|
+
Save
|
|
2103
|
+
</Button>
|
|
2104
|
+
</Field>
|
|
2105
|
+
</CardFooter>
|
|
2106
|
+
</Card>
|
|
2107
|
+
)
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
```
|
|
2111
|
+
|
|
2112
|
+
This example demonstrates managing multiple email addresses with array fields. Users can add up to 5 email addresses, remove individual addresses, and each address is validated independently.
|
|
2113
|
+
|
|
2114
|
+
### Array Field Structure
|
|
2115
|
+
|
|
2116
|
+
Use `mode="array"` on the parent field to enable array field management.
|
|
2117
|
+
|
|
2118
|
+
```tsx showLineNumbers title="form.tsx" {3,12-14}
|
|
2119
|
+
<form.Field
|
|
2120
|
+
name="emails"
|
|
2121
|
+
mode="array"
|
|
2122
|
+
children={(field) => {
|
|
2123
|
+
return (
|
|
2124
|
+
<FieldSet>
|
|
2125
|
+
<FieldLegend variant="label">Email Addresses</FieldLegend>
|
|
2126
|
+
<FieldDescription>
|
|
2127
|
+
Add up to 5 email addresses where we can contact you.
|
|
2128
|
+
</FieldDescription>
|
|
2129
|
+
<FieldGroup>
|
|
2130
|
+
{field.state.value.map((_, index) => (
|
|
2131
|
+
// Nested field for each array item
|
|
2132
|
+
))}
|
|
2133
|
+
</FieldGroup>
|
|
2134
|
+
</FieldSet>
|
|
2135
|
+
)
|
|
2136
|
+
}}
|
|
2137
|
+
/>
|
|
2138
|
+
```
|
|
2139
|
+
|
|
2140
|
+
### Nested Fields
|
|
2141
|
+
|
|
2142
|
+
Access individual array items using bracket notation: `fieldName[index].propertyName`. This example uses `InputGroup` to display the remove button inline with the input.
|
|
2143
|
+
|
|
2144
|
+
```tsx showLineNumbers title="form.tsx"
|
|
2145
|
+
<form.Field
|
|
2146
|
+
name={`emails[${index}].address`}
|
|
2147
|
+
children={(subField) => {
|
|
2148
|
+
const isSubFieldInvalid =
|
|
2149
|
+
subField.state.meta.isTouched && !subField.state.meta.isValid
|
|
2150
|
+
return (
|
|
2151
|
+
<Field orientation="horizontal" data-invalid={isSubFieldInvalid}>
|
|
2152
|
+
<FieldContent>
|
|
2153
|
+
<InputGroup>
|
|
2154
|
+
<InputGroupInput
|
|
2155
|
+
id={`form-tanstack-array-email-${index}`}
|
|
2156
|
+
name={subField.name}
|
|
2157
|
+
value={subField.state.value}
|
|
2158
|
+
onBlur={subField.handleBlur}
|
|
2159
|
+
onChange={(e) => subField.handleChange(e.target.value)}
|
|
2160
|
+
aria-invalid={isSubFieldInvalid}
|
|
2161
|
+
placeholder="name@example.com"
|
|
2162
|
+
type="email"
|
|
2163
|
+
/>
|
|
2164
|
+
{field.state.value.length > 1 && (
|
|
2165
|
+
<InputGroupAddon align="inline-end">
|
|
2166
|
+
<InputGroupButton
|
|
2167
|
+
type="button"
|
|
2168
|
+
variant="ghost"
|
|
2169
|
+
size="icon-xs"
|
|
2170
|
+
onClick={() => field.removeValue(index)}
|
|
2171
|
+
aria-label={`Remove email ${index + 1}`}
|
|
2172
|
+
>
|
|
2173
|
+
<XIcon />
|
|
2174
|
+
</InputGroupButton>
|
|
2175
|
+
</InputGroupAddon>
|
|
2176
|
+
)}
|
|
2177
|
+
</InputGroup>
|
|
2178
|
+
{isSubFieldInvalid && (
|
|
2179
|
+
<FieldError errors={subField.state.meta.errors} />
|
|
2180
|
+
)}
|
|
2181
|
+
</FieldContent>
|
|
2182
|
+
</Field>
|
|
2183
|
+
)
|
|
2184
|
+
}}
|
|
2185
|
+
/>
|
|
2186
|
+
```
|
|
2187
|
+
|
|
2188
|
+
### Adding Items
|
|
2189
|
+
|
|
2190
|
+
Use `field.pushValue(item)` to add items to an array field. You can disable the button when the array reaches its maximum length.
|
|
2191
|
+
|
|
2192
|
+
```tsx showLineNumbers title="form.tsx"
|
|
2193
|
+
<Button
|
|
2194
|
+
type="button"
|
|
2195
|
+
variant="outline"
|
|
2196
|
+
size="sm"
|
|
2197
|
+
onClick={() => field.pushValue({ address: "" })}
|
|
2198
|
+
disabled={field.state.value.length >= 5}
|
|
2199
|
+
>
|
|
2200
|
+
Add Email Address
|
|
2201
|
+
</Button>
|
|
2202
|
+
```
|
|
2203
|
+
|
|
2204
|
+
### Removing Items
|
|
2205
|
+
|
|
2206
|
+
Use `field.removeValue(index)` to remove items from an array field. You can conditionally show the remove button only when there's more than one item.
|
|
2207
|
+
|
|
2208
|
+
```tsx showLineNumbers title="form.tsx"
|
|
2209
|
+
{
|
|
2210
|
+
field.state.value.length > 1 && (
|
|
2211
|
+
<InputGroupButton
|
|
2212
|
+
onClick={() => field.removeValue(index)}
|
|
2213
|
+
aria-label={`Remove email ${index + 1}`}
|
|
2214
|
+
>
|
|
2215
|
+
<XIcon />
|
|
2216
|
+
</InputGroupButton>
|
|
2217
|
+
)
|
|
2218
|
+
}
|
|
2219
|
+
```
|
|
2220
|
+
|
|
2221
|
+
### Array Validation
|
|
2222
|
+
|
|
2223
|
+
Validate array fields using Zod's array methods.
|
|
2224
|
+
|
|
2225
|
+
```tsx showLineNumbers title="form.tsx"
|
|
2226
|
+
const formSchema = z.object({
|
|
2227
|
+
emails: z
|
|
2228
|
+
.array(
|
|
2229
|
+
z.object({
|
|
2230
|
+
address: z.string().email("Enter a valid email address."),
|
|
2231
|
+
})
|
|
2232
|
+
)
|
|
2233
|
+
.min(1, "Add at least one email address.")
|
|
2234
|
+
.max(5, "You can add up to 5 email addresses."),
|
|
2235
|
+
})
|
|
2236
|
+
```
|