form-rhf-switch.tsx — ui Source File
Architecture documentation for form-rhf-switch.tsx, a tsx file in the ui codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 0ce478d4_85e2_8edb_f864_1ffde814087f["form-rhf-switch.tsx"] 1d141819_425e_b5fd_4c8e_32f7c6a42cf2["react"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 1d141819_425e_b5fd_4c8e_32f7c6a42cf2 3d40a3bf_c062_4304_329a_00b1b72e8523["zod"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 3d40a3bf_c062_4304_329a_00b1b72e8523 6d65354d_8f59_2cfc_4783_24b2eb870bc4["react-hook-form"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 6d65354d_8f59_2cfc_4783_24b2eb870bc4 e750d152_1191_1793_7244_99c7f9c595f4["sonner"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> e750d152_1191_1793_7244_99c7f9c595f4 6802ce19_522d_e5fb_e458_8826d9f6952e["zod"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 6802ce19_522d_e5fb_e458_8826d9f6952e 57e86e45_ac6e_7278_be08_9092724e8401["button"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 57e86e45_ac6e_7278_be08_9092724e8401 c6d6139d_ea69_3d79_5004_68419bae2ac0["card"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> c6d6139d_ea69_3d79_5004_68419bae2ac0 169af77a_46c3_8fec_4801_f34a0f1a3471["field"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 169af77a_46c3_8fec_4801_f34a0f1a3471 38ebb3c2_9638_6c9d_8ced_a16ec1ff06c9["switch"] 0ce478d4_85e2_8edb_f864_1ffde814087f --> 38ebb3c2_9638_6c9d_8ced_a16ec1ff06c9 style 0ce478d4_85e2_8edb_f864_1ffde814087f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"use client"
import * as React from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { Controller, useForm } from "react-hook-form"
import { toast } from "sonner"
import * as z from "zod"
import { Button } from "@/registry/new-york-v4/ui/button"
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/registry/new-york-v4/ui/card"
import {
Field,
FieldContent,
FieldDescription,
FieldError,
FieldGroup,
FieldLabel,
} from "@/registry/new-york-v4/ui/field"
import { Switch } from "@/registry/new-york-v4/ui/switch"
const formSchema = z.object({
twoFactor: z.boolean().refine((val) => val === true, {
message: "It is highly recommended to enable two-factor authentication.",
}),
})
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>
)
}
Domain
Subdomains
Functions
Dependencies
- button
- card
- field
- react
- react-hook-form
- sonner
- switch
- zod
- zod
Source
Frequently Asked Questions
What does form-rhf-switch.tsx do?
form-rhf-switch.tsx is a source file in the ui codebase, written in tsx. It belongs to the ComponentRegistry domain, ChartRegistry subdomain.
What functions are defined in form-rhf-switch.tsx?
form-rhf-switch.tsx defines 1 function(s): FormRhfSwitch.
What does form-rhf-switch.tsx depend on?
form-rhf-switch.tsx imports 9 module(s): button, card, field, react, react-hook-form, sonner, switch, zod, and 1 more.
Where is form-rhf-switch.tsx in the architecture?
form-rhf-switch.tsx is located at apps/v4/registry/new-york-v4/examples/form-rhf-switch.tsx (domain: ComponentRegistry, subdomain: ChartRegistry, directory: apps/v4/registry/new-york-v4/examples).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free