"use client" import * as React from "react" import { Form, Field as FormischField, reset, useForm } from "@formisch/react" import type { SubmitHandler } from "@formisch/react" import { toast } from "sonner" import * as v from "valibot" import { Button } from "@/registry/new-york-v4/ui/button" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/registry/new-york-v4/ui/card" import { Checkbox } from "@/registry/new-york-v4/ui/checkbox" import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet, } from "@/registry/new-york-v4/ui/field" const tasks = [ { id: "push", label: "Push notifications", }, { id: "email", label: "Email notifications", }, ] as const const FormSchema = v.object({ responses: v.boolean(), tasks: v.pipe( v.array(v.string()), v.minLength(1, "Please select at least one notification type."), v.check( (value) => value.every((task) => tasks.some((t) => t.id === task)), "Invalid notification type selected." ) ), }) export default function FormFormischCheckbox() { const form = useForm({ schema: FormSchema, initialInput: { responses: true, tasks: [], }, }) const handleSubmit: SubmitHandler = (output) => { toast("You submitted the following values:", { description: (
          {JSON.stringify(output, null, 2)}
        
), position: "bottom-right", classNames: { content: "flex flex-col gap-2", }, style: { "--border-radius": "calc(var(--radius) + 4px)", } as React.CSSProperties, }) } return ( Notifications Manage your notification preferences.
{(field) => (
Responses Get notified for requests that take time, like research or image generation. field.onChange(checked === true) } disabled /> Push notifications
{field.errors && ( ({ message }))} /> )}
)}
{(field) => (
Tasks Get notified when tasks you've created have updates. {tasks.map((task) => { const current = field.input ?? [] return ( { field.onChange( checked === true ? [...current, task.id] : current.filter( (value) => value !== task.id ) ) }} /> {task.label} ) })}
{field.errors && ( ({ message }))} /> )}
)}
) }