/* eslint-disable react/no-children-prop */ "use client" import { useForm } from "@tanstack/react-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 FormTanstackSwitch() { const form = useForm({ defaultValues: { twoFactor: false, }, validators: { onSubmit: formSchema, }, onSubmit: async ({ value }) => { toast("You submitted the following values:", { description: (
{JSON.stringify(value, null, 2)}
),
position: "bottom-right",
classNames: {
content: "flex flex-col gap-2",
},
style: {
"--border-radius": "calc(var(--radius) + 4px)",
} as React.CSSProperties,
})
},
})
return (