{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "form-formisch-checkbox",
  "dependencies": [
    "@formisch/react",
    "valibot"
  ],
  "registryDependencies": [
    "field",
    "checkbox",
    "button",
    "card"
  ],
  "files": [
    {
      "path": "registry/new-york-v4/examples/form-formisch-checkbox.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Form, Field as FormischField, reset, useForm } from \"@formisch/react\"\nimport type { SubmitHandler } from \"@formisch/react\"\nimport { toast } from \"sonner\"\nimport * as v from \"valibot\"\n\nimport { Button } from \"@/registry/new-york-v4/ui/button\"\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardFooter,\n  CardHeader,\n  CardTitle,\n} from \"@/registry/new-york-v4/ui/card\"\nimport { Checkbox } from \"@/registry/new-york-v4/ui/checkbox\"\nimport {\n  Field,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n  FieldLegend,\n  FieldSeparator,\n  FieldSet,\n} from \"@/registry/new-york-v4/ui/field\"\n\nconst tasks = [\n  {\n    id: \"push\",\n    label: \"Push notifications\",\n  },\n  {\n    id: \"email\",\n    label: \"Email notifications\",\n  },\n] as const\n\nconst FormSchema = v.object({\n  responses: v.boolean(),\n  tasks: v.pipe(\n    v.array(v.string()),\n    v.minLength(1, \"Please select at least one notification type.\"),\n    v.check(\n      (value) => value.every((task) => tasks.some((t) => t.id === task)),\n      \"Invalid notification type selected.\"\n    )\n  ),\n})\n\nexport default function FormFormischCheckbox() {\n  const form = useForm({\n    schema: FormSchema,\n    initialInput: {\n      responses: true,\n      tasks: [],\n    },\n  })\n\n  const handleSubmit: SubmitHandler<typeof FormSchema> = (output) => {\n    toast(\"You submitted the following values:\", {\n      description: (\n        <pre className=\"mt-2 w-[320px] overflow-x-auto rounded-md bg-code p-4 text-code-foreground\">\n          <code>{JSON.stringify(output, null, 2)}</code>\n        </pre>\n      ),\n      position: \"bottom-right\",\n      classNames: {\n        content: \"flex flex-col gap-2\",\n      },\n      style: {\n        \"--border-radius\": \"calc(var(--radius)  + 4px)\",\n      } as React.CSSProperties,\n    })\n  }\n\n  return (\n    <Card className=\"w-full sm:max-w-md\">\n      <CardHeader>\n        <CardTitle>Notifications</CardTitle>\n        <CardDescription>Manage your notification preferences.</CardDescription>\n      </CardHeader>\n      <CardContent>\n        <Form of={form} id=\"form-formisch-checkbox\" onSubmit={handleSubmit}>\n          <FieldGroup>\n            <FormischField of={form} path={[\"responses\"]}>\n              {(field) => (\n                <div>\n                  <FieldSet data-invalid={field.errors !== null}>\n                    <FieldLegend variant=\"label\">Responses</FieldLegend>\n                    <FieldDescription>\n                      Get notified for requests that take time, like research or\n                      image generation.\n                    </FieldDescription>\n                    <FieldGroup data-slot=\"checkbox-group\">\n                      <Field orientation=\"horizontal\">\n                        <Checkbox\n                          id=\"form-formisch-checkbox-responses\"\n                          checked={field.input ?? false}\n                          onCheckedChange={(checked) =>\n                            field.onChange(checked === true)\n                          }\n                          disabled\n                        />\n                        <FieldLabel\n                          htmlFor=\"form-formisch-checkbox-responses\"\n                          className=\"font-normal\"\n                        >\n                          Push notifications\n                        </FieldLabel>\n                      </Field>\n                    </FieldGroup>\n                  </FieldSet>\n                  {field.errors && (\n                    <FieldError\n                      errors={field.errors.map((message) => ({ message }))}\n                    />\n                  )}\n                </div>\n              )}\n            </FormischField>\n            <FieldSeparator />\n            <FormischField of={form} path={[\"tasks\"]}>\n              {(field) => (\n                <FieldGroup>\n                  <FieldSet data-invalid={field.errors !== null}>\n                    <FieldLegend variant=\"label\">Tasks</FieldLegend>\n                    <FieldDescription>\n                      Get notified when tasks you&apos;ve created have updates.\n                    </FieldDescription>\n                    <FieldGroup data-slot=\"checkbox-group\">\n                      {tasks.map((task) => {\n                        const current = field.input ?? []\n                        return (\n                          <Field\n                            key={task.id}\n                            orientation=\"horizontal\"\n                            data-invalid={field.errors !== null}\n                          >\n                            <Checkbox\n                              id={`form-formisch-checkbox-${task.id}`}\n                              aria-invalid={field.errors !== null}\n                              checked={current.includes(task.id)}\n                              onCheckedChange={(checked) => {\n                                field.onChange(\n                                  checked === true\n                                    ? [...current, task.id]\n                                    : current.filter(\n                                        (value) => value !== task.id\n                                      )\n                                )\n                              }}\n                            />\n                            <FieldLabel\n                              htmlFor={`form-formisch-checkbox-${task.id}`}\n                              className=\"font-normal\"\n                            >\n                              {task.label}\n                            </FieldLabel>\n                          </Field>\n                        )\n                      })}\n                    </FieldGroup>\n                  </FieldSet>\n                  {field.errors && (\n                    <FieldError\n                      errors={field.errors.map((message) => ({ message }))}\n                    />\n                  )}\n                </FieldGroup>\n              )}\n            </FormischField>\n          </FieldGroup>\n        </Form>\n      </CardContent>\n      <CardFooter>\n        <Field orientation=\"horizontal\">\n          <Button type=\"button\" variant=\"outline\" onClick={() => reset(form)}>\n            Reset\n          </Button>\n          <Button type=\"submit\" form=\"form-formisch-checkbox\">\n            Save\n          </Button>\n        </Field>\n      </CardFooter>\n    </Card>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}