Home / Function/ FormTanstackSwitch() — ui Function Reference

FormTanstackSwitch() — ui Function Reference

Architecture documentation for the FormTanstackSwitch() function in form-tanstack-switch.tsx from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  c69935e1_31fe_40ba_fcaa_f1ff0ef364b9["FormTanstackSwitch()"]
  9f40313d_e5b8_002a_e78a_1ace7381f3a4["form-tanstack-switch.tsx"]
  c69935e1_31fe_40ba_fcaa_f1ff0ef364b9 -->|defined in| 9f40313d_e5b8_002a_e78a_1ace7381f3a4
  style c69935e1_31fe_40ba_fcaa_f1ff0ef364b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/registry/new-york-v4/examples/form-tanstack-switch.tsx lines 33–121

export default function FormTanstackSwitch() {
  const form = useForm({
    defaultValues: {
      twoFactor: false,
    },
    validators: {
      onSubmit: formSchema,
    },
    onSubmit: async ({ value }) => {
      toast("You submitted the following values:", {
        description: (
          <pre className="bg-code text-code-foreground mt-2 w-[320px] overflow-x-auto rounded-md p-4">
            <code>{JSON.stringify(value, null, 2)}</code>
          </pre>
        ),
        position: "bottom-right",
        classNames: {
          content: "flex flex-col gap-2",
        },
        style: {
          "--border-radius": "calc(var(--radius)  + 4px)",
        } as React.CSSProperties,
      })
    },
  })

  return (
    <Card className="w-full sm:max-w-md">
      <CardHeader>
        <CardTitle>Security Settings</CardTitle>
        <CardDescription>
          Manage your account security preferences.
        </CardDescription>
      </CardHeader>
      <CardContent>
        <form
          id="form-tanstack-switch"
          onSubmit={(e) => {
            e.preventDefault()
            form.handleSubmit()
          }}
        >
          <FieldGroup>
            <form.Field
              name="twoFactor"
              children={(field) => {
                const isInvalid =
                  field.state.meta.isTouched && !field.state.meta.isValid
                return (
                  <Field orientation="horizontal" data-invalid={isInvalid}>
                    <FieldContent>
                      <FieldLabel htmlFor="form-tanstack-switch-twoFactor">
                        Multi-factor authentication
                      </FieldLabel>
                      <FieldDescription>
                        Enable multi-factor authentication to secure your
                        account.
                      </FieldDescription>
                      {isInvalid && (
                        <FieldError errors={field.state.meta.errors} />
                      )}
                    </FieldContent>
                    <Switch
                      id="form-tanstack-switch-twoFactor"
                      name={field.name}
                      checked={field.state.value}
                      onCheckedChange={field.handleChange}
                      aria-invalid={isInvalid}
                    />
                  </Field>
                )
              }}
            />
          </FieldGroup>
        </form>
      </CardContent>
      <CardFooter>
        <Field orientation="horizontal">
          <Button type="button" variant="outline" onClick={() => form.reset()}>
            Reset
          </Button>

Subdomains

Frequently Asked Questions

What does FormTanstackSwitch() do?
FormTanstackSwitch() is a function in the ui codebase, defined in apps/v4/registry/new-york-v4/examples/form-tanstack-switch.tsx.
Where is FormTanstackSwitch() defined?
FormTanstackSwitch() is defined in apps/v4/registry/new-york-v4/examples/form-tanstack-switch.tsx at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free