Home / Function/ FormRhfSwitch() — ui Function Reference

FormRhfSwitch() — ui Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  ecab65ad_2193_87a0_804e_73cd64533ac4["FormRhfSwitch()"]
  0ce478d4_85e2_8edb_f864_1ffde814087f["form-rhf-switch.tsx"]
  ecab65ad_2193_87a0_804e_73cd64533ac4 -->|defined in| 0ce478d4_85e2_8edb_f864_1ffde814087f
  style ecab65ad_2193_87a0_804e_73cd64533ac4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/registry/new-york-v4/examples/form-rhf-switch.tsx lines 34–114

export default function FormRhfSwitch() {
  const form = useForm<z.infer<typeof formSchema>>({
    resolver: zodResolver(formSchema),
    defaultValues: {
      twoFactor: false,
    },
  })

  function onSubmit(data: z.infer<typeof formSchema>) {
    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(data, 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-rhf-switch" onSubmit={form.handleSubmit(onSubmit)}>
          <FieldGroup>
            <Controller
              name="twoFactor"
              control={form.control}
              render={({ field, fieldState }) => (
                <Field
                  orientation="horizontal"
                  data-invalid={fieldState.invalid}
                >
                  <FieldContent>
                    <FieldLabel htmlFor="form-rhf-switch-twoFactor">
                      Multi-factor authentication
                    </FieldLabel>
                    <FieldDescription>
                      Enable multi-factor authentication to secure your account.
                    </FieldDescription>
                    {fieldState.invalid && (
                      <FieldError errors={[fieldState.error]} />
                    )}
                  </FieldContent>
                  <Switch
                    id="form-rhf-switch-twoFactor"
                    name={field.name}
                    checked={field.value}
                    onCheckedChange={field.onChange}
                    aria-invalid={fieldState.invalid}
                  />
                </Field>
              )}
            />
          </FieldGroup>
        </form>
      </CardContent>
      <CardFooter>
        <Field orientation="horizontal">
          <Button type="button" variant="outline" onClick={() => form.reset()}>
            Reset
          </Button>
          <Button type="submit" form="form-rhf-switch">
            Save
          </Button>
        </Field>
      </CardFooter>
    </Card>
  )
}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free