{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"signup-form-with-inline-validation-messages","type":"registry:component","title":"Signup Form With Inline Validation Messages","description":"","dependencies":[],"files":[{"path":"components/we-inc/signup-form-with-inline-validation-messages.tsx","type":"registry:component","content":"import { useState, type FormEvent } from \"react\";\n\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\n// Password rules shown as a live checklist under the field.\nconst RULES = [\n  { id: \"len\", text: \"At least 10 characters\", test: (p: string) => p.length >= 10 },\n  { id: \"num\", text: \"Contains a number\", test: (p: string) => /\\d/.test(p) },\n  { id: \"case\", text: \"Upper and lower case letters\", test: (p: string) => /[a-z]/.test(p) && /[A-Z]/.test(p) },\n];\n\nexport default function SignupFormWithInlineValidation() {\n  const [email, setEmail] = useState(\"dev@ortolan\");\n  const [pass, setPass] = useState(\"orchard7\");\n  const [agree, setAgree] = useState(false);\n  const [left, setLeft] = useState<Record<string, boolean>>({ email: true, pass: true });\n  const [done, setDone] = useState(false);\n\n  const emailErr = left.email && !EMAIL.test(email) ? \"That address is missing its ending, such as .com or .io.\" : \"\";\n  const passOk = RULES.every((r) => r.test(pass));\n  const agreeErr = left.agree && !agree ? \"Please accept the terms to continue.\" : \"\";\n\n  const submit = (e: FormEvent) => {\n    e.preventDefault();\n    setLeft({ email: true, pass: true, agree: true });\n    if (EMAIL.test(email) && passOk && agree) setDone(true);\n  };\n\n  const field = (err: boolean) => `mt-1.5 block h-11 w-full rounded-lg border bg-white px-3 text-sm text-slate-900 focus:outline-none focus:ring-2 ${err ? \"border-rose-500 focus:ring-rose-200\" : \"border-slate-300 focus:border-violet-600 focus:ring-violet-200\"}`;\n\n  return (\n    <section className=\"bg-violet-50 px-4 py-16\">\n      <form noValidate onSubmit={submit} className=\"mx-auto max-w-md rounded-2xl bg-white p-6 shadow-[0_24px_48px_-28px_rgba(76,29,149,0.45)] ring-1 ring-violet-100 sm:p-8\">\n        <h2 className=\"text-xl font-semibold tracking-tight text-slate-900\">Create your Ortolan account</h2>\n        <p className=\"mt-1 text-sm text-slate-600\">Free for teams of up to five. No card needed.</p>\n\n        <div className=\"mt-6\">\n          <label htmlFor=\"sfiv-email\" className=\"text-sm font-medium text-slate-800\">Work email</label>\n          <input id=\"sfiv-email\" type=\"email\" autoComplete=\"email\" value={email} onChange={(e) => setEmail(e.target.value)} onBlur={() => setLeft({ ...left, email: true })} aria-invalid={!!emailErr || undefined} aria-describedby=\"sfiv-email-msg\" className={field(!!emailErr)} />\n          <p id=\"sfiv-email-msg\" className=\"mt-1.5 min-h-[1.25rem] text-sm text-rose-700\">{emailErr}</p>\n        </div>\n\n        <div className=\"mt-2\">\n          <label htmlFor=\"sfiv-pass\" className=\"text-sm font-medium text-slate-800\">Password</label>\n          <input id=\"sfiv-pass\" type=\"password\" autoComplete=\"new-password\" value={pass} onChange={(e) => setPass(e.target.value)} onBlur={() => setLeft({ ...left, pass: true })} aria-invalid={(left.pass && !passOk) || undefined} aria-describedby=\"sfiv-rules\" className={field(left.pass && !passOk)} />\n          <ul id=\"sfiv-rules\" className=\"mt-2.5 space-y-1.5\" aria-label=\"Password rules\">\n            {RULES.map((r) => {\n              const ok = r.test(pass);\n              return (\n                <li key={r.id} className={`flex items-center gap-2 text-sm ${ok ? \"text-emerald-700\" : \"text-slate-600\"}`}>\n                  <span className={`grid h-4 w-4 place-items-center rounded-full ${ok ? \"bg-emerald-600\" : \"border border-slate-400\"}`} aria-hidden=\"true\">\n                    {ok && <svg viewBox=\"0 0 12 12\" width=\"10\" height=\"10\"><path d=\"M2.5 6.2l2.2 2.2 4.8-4.9\" fill=\"none\" stroke=\"#fff\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" /></svg>}\n                  </span>\n                  {r.text}<span className=\"sr-only\">{ok ? \", done\" : \", not yet\"}</span>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n\n        <div className=\"mt-5\">\n          <div className=\"flex items-start gap-3\">\n            <input id=\"sfiv-agree\" type=\"checkbox\" checked={agree} onChange={(e) => setAgree(e.target.checked)} aria-invalid={!!agreeErr || undefined} aria-describedby=\"sfiv-agree-msg\" className=\"mt-0.5 h-5 w-5 rounded border-slate-400 accent-violet-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-violet-600\" />\n            <label htmlFor=\"sfiv-agree\" className=\"text-sm text-slate-700\">I agree to the <a href=\"#\" className=\"font-medium text-violet-800 underline underline-offset-2\">terms</a> and <a href=\"#\" className=\"font-medium text-violet-800 underline underline-offset-2\">privacy notice</a>.</label>\n          </div>\n          <p id=\"sfiv-agree-msg\" className=\"mt-1 min-h-[1.25rem] text-sm text-rose-700\">{agreeErr}</p>\n        </div>\n\n        <button type=\"submit\" className=\"mt-2 h-11 w-full rounded-lg bg-violet-700 text-sm font-semibold text-white hover:bg-violet-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-700 focus-visible:ring-offset-2\">Create account</button>\n        <p role=\"status\" className=\"mt-3 text-center text-sm font-medium text-emerald-700\">{done ? \"Account created. Check your inbox to confirm.\" : \"\"}</p>\n      </form>\n    </section>\n  );\n}\n"}]}
