{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rhf-rules-03",
  "title": "Number Range",
  "description": "Keep a numeric input within a sensible range.",
  "dependencies": [
    "react-hook-form",
    "@hookform/resolvers",
    "zod",
    "sonner",
    "lucide-react"
  ],
  "registryDependencies": [
    "card",
    "field",
    "input",
    "button"
  ],
  "files": [
    {
      "path": "registry/forms/react-hook-form/rules/rhf-rules-03.tsx",
      "content": "'use client'\n\nimport { Controller, useForm } from 'react-hook-form'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { Hash } from 'lucide-react'\nimport { toast } from 'sonner'\nimport * as z from 'zod'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from '@/components/ui/card'\nimport {\n  Field,\n  FieldDescription,\n  FieldError,\n  FieldGroup,\n  FieldLabel,\n} from '@/components/ui/field'\nimport { Input } from '@/components/ui/input'\n\nconst MIN = 1\nconst MAX = 99\n\nconst formSchema = z.object({\n  quantity: z.coerce\n    .number({ message: 'Enter a number.' })\n    .int('Whole numbers only.')\n    .min(MIN, `Minimum is ${MIN}.`)\n    .max(MAX, `Maximum is ${MAX}.`),\n})\n\ntype FormInput = z.input<typeof formSchema>\ntype FormValues = z.output<typeof formSchema>\n\nexport function RhfRules03() {\n  const form = useForm<FormInput, unknown, FormValues>({\n    resolver: zodResolver(formSchema),\n    defaultValues: { quantity: 1 },\n  })\n\n  function onSubmit(data: FormValues) {\n    toast.success('Quantity confirmed', {\n      description: `${data.quantity} item(s)`,\n    })\n  }\n\n  return (\n    <Card className=\"w-full max-w-sm\">\n      <CardHeader>\n        <CardTitle className=\"flex items-center gap-2\">\n          <Hash className=\"text-muted-foreground size-4\" />\n          Number range\n        </CardTitle>\n        <CardDescription>\n          Tell us how many you&apos;d like to order.\n        </CardDescription>\n      </CardHeader>\n      <CardContent>\n        <form onSubmit={form.handleSubmit(onSubmit)}>\n          <FieldGroup>\n            <Controller\n              control={form.control}\n              name=\"quantity\"\n              render={({ field, fieldState }) => (\n                <Field data-invalid={fieldState.invalid}>\n                  <FieldLabel htmlFor=\"rhf-rules-03-quantity\">\n                    Quantity\n                  </FieldLabel>\n                  <Input\n                    {...field}\n                    value={field.value as number}\n                    id=\"rhf-rules-03-quantity\"\n                    type=\"number\"\n                    inputMode=\"numeric\"\n                    min={MIN}\n                    max={MAX}\n                    aria-invalid={fieldState.invalid}\n                  />\n                  {fieldState.invalid ? (\n                    <FieldError errors={[fieldState.error]} />\n                  ) : (\n                    <FieldDescription>\n                      Pick a whole number between {MIN} and {MAX}.\n                    </FieldDescription>\n                  )}\n                </Field>\n              )}\n            />\n            <Button type=\"submit\" size=\"sm\">\n              Add to cart\n            </Button>\n          </FieldGroup>\n        </form>\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/flx/forms/react-hook-form/rhf-rules-03.tsx"
    }
  ],
  "type": "registry:block"
}