{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-auth-signup",
  "type": "registry:block",
  "title": "App, sign up",
  "description": "Create an account: name, email and a password with its rules, a required consent checkbox that names the terms and privacy links, and idle, sending, error and consent-missing states. The sentence a person agrees to is never replaced by a default.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/banner.json",
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/checkbox.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/kit-auth.json",
    "https://ui.klarhimmel.com/r/kit-form.json",
    "https://ui.klarhimmel.com/r/kit-invalid.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-auth-signup/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-auth-signup/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, formFields, link, req, t } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  nameLabel: req(40),\n  emailLabel: req(40),\n  passwordLabel: req(40),\n  passwordHint: t(120),\n  showLabel: t(30),\n  hideLabel: t(30),\n  /** The consent sentence, in three parts around two links: \"I agree to the\" [Terms of service] \"and\" [Privacy policy]. */\n  consent: z.object({ before: req(60), terms: z.object({ label: req(40), href: t(300) }), and: req(20), privacy: z.object({ label: req(40), href: t(300) }) }),\n  submit: t(30),\n  sending: t(30),\n  alternative: z.object({ text: t(80), link }),\n  /** idle, sending, error (a banner), consent (the box is marked and described: the person has not agreed yet). */\n  state: z.enum(['idle', 'sending', 'error', 'consent']),\n  messages: z.object({ error: t(160), consent: t(120) }),\n  ...formFields,\n});\n\nexport const spec = defineSpec({\n  type: 'app-auth-signup',\n  aliases: ['app/auth-signup'],\n  name: 'App, sign up',\n  category: 'app',\n  role: 'body',\n  // Strict: the consent sentence and its two links are what a person agrees to. They are never replaced by defaults.\n  strict: true,\n  description: 'Create an account: name, email and a password with its rules, a required consent checkbox that names the terms and privacy links, and idle, sending, error and consent-missing states. The sentence a person agrees to is never replaced by a default.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Name the section\",\n    \"title\": \"Say what this page creates\",\n    \"description\": \"Say in one line what a person gets with an account.\",\n    \"nameLabel\": \"Full name\",\n    \"emailLabel\": \"Work email\",\n    \"passwordLabel\": \"Password\",\n    \"passwordHint\": \"Say how long and what kind of secret is accepted.\",\n    \"showLabel\": \"Show password\",\n    \"hideLabel\": \"Hide password\",\n    \"consent\": {\n      \"before\": \"I agree to the\",\n      \"terms\": {\n        \"label\": \"Terms of service\",\n        \"href\": \"#terms\"\n      },\n      \"and\": \"and\",\n      \"privacy\": {\n        \"label\": \"Privacy policy\",\n        \"href\": \"#privacy\"\n      }\n    },\n    \"submit\": \"Create account\",\n    \"sending\": \"Creating it…\",\n    \"alternative\": {\n      \"text\": \"Ask if they have one already\",\n      \"link\": {\n        \"label\": \"Sign in\",\n        \"href\": \"#sign-in\"\n      }\n    },\n    \"state\": \"idle\",\n    \"messages\": {\n      \"error\": \"Say that the account was not created and to check the details.\",\n      \"consent\": \"Say that they must agree to continue.\"\n    }\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-auth-signup/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-auth-signup/index.tsx",
      "content": "import { useId, useRef, useState } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Banner } from '../../ui/banner';\nimport { Button } from '../../ui/button';\nimport { Checkbox } from '../../ui/checkbox';\nimport { Input } from '../../ui/input';\nimport { Container, Section, SectionHeader } from '../_shared/kit';\nimport { AppPanel, StateSlot, Swap } from '../_shared/app-kit';\nimport { FieldRow, LabelLink, PasswordInput, describedBy } from '../_shared/auth-kit';\nimport { FormExtras, useFormProps } from '../_shared/form-kit';\nimport { InvalidNotice } from '../_shared/invalid-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppAuthSignup(p: BlockProps<Props>) {\n  // A strict block: the consent sentence and its links are never replaced by default text.\n  if (!spec.schema.safeParse(p.props).success) return <InvalidNotice title=\"This sign-up form could not be shown\" />;\n  return <SignUp {...p} />;\n}\n\nfunction SignUp({ props }: BlockProps<Props>) {\n  const id = useId();\n  const form = useFormProps(props);\n  const box = useRef<HTMLButtonElement>(null);\n  const [agreed, setAgreed] = useState(false);\n  const [tried, setTried] = useState(false);\n  const { state } = props;\n  const missing = state === 'consent' || (tried && !agreed);\n  const failed = state === 'error';\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\" className=\"max-w-md\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <AppPanel className=\"mt-8\">\n          <form\n            {...form}\n            aria-busy={state === 'sending' || undefined}\n            onSubmit={(e) => {\n              if (!agreed) {\n                e.preventDefault();\n                setTried(true);\n                box.current?.focus();\n                return;\n              }\n              form.onSubmit?.(e);\n            }}\n            className=\"p-6 @xl:p-8\"\n          >\n            <fieldset disabled={state === 'sending'} className=\"m-0 flex min-w-0 flex-col gap-5 border-0 p-0\">\n            <StateSlot show={failed}>\n              <Banner tone=\"error\">\n                <Text path={['messages', 'error']} value={props.messages.error} as=\"span\" />\n              </Banner>\n            </StateSlot>\n            <FieldRow id={`${id}-n`} label={<Text path={['nameLabel']} value={props.nameLabel} as=\"span\" />}>\n              <Input id={`${id}-n`} name=\"name\" autoComplete=\"name\" required />\n            </FieldRow>\n            <FieldRow id={`${id}-m`} label={<Text path={['emailLabel']} value={props.emailLabel} as=\"span\" />}>\n              <Input id={`${id}-m`} name=\"email\" type=\"email\" autoComplete=\"email\" autoCapitalize=\"none\" spellCheck={false} required />\n            </FieldRow>\n            <FieldRow id={`${id}-p`} label={<Text path={['passwordLabel']} value={props.passwordLabel} as=\"span\" />} hint={<Text path={['passwordHint']} value={props.passwordHint} as=\"span\" />}>\n              <PasswordInput id={`${id}-p`} name=\"password\" autoComplete=\"new-password\" showLabel={props.showLabel} hideLabel={props.hideLabel} showPath={['showLabel']} hidePath={['hideLabel']} describedby={describedBy(`${id}-p`, true, false)} required minLength={12} />\n            </FieldRow>\n            <div className=\"flex flex-col gap-1.5\">\n              <Checkbox\n                ref={box}\n                name=\"consent\"\n                value=\"yes\"\n                required\n                invalid={missing}\n                checked={agreed}\n                onCheckedChange={setAgreed}\n                aria-describedby={missing ? `${id}-c` : undefined}\n                label={\n                  <span>\n                    <Text path={['consent', 'before']} value={props.consent.before} as=\"span\" />{' '}\n                    <LabelLink path={['consent', 'terms']} link={props.consent.terms} />{' '}\n                    <Text path={['consent', 'and']} value={props.consent.and} as=\"span\" />{' '}\n                    <LabelLink path={['consent', 'privacy']} link={props.consent.privacy} />\n                  </span>\n                }\n              />\n              <StateSlot show={missing}>\n                <p id={`${id}-c`} className=\"text-kh-small text-kh-ink\">\n                  <Text path={['messages', 'consent']} value={props.messages.consent} as=\"span\" />\n                </p>\n              </StateSlot>\n            </div>\n            <FormExtras {...props} />\n            <Button type=\"submit\" full disabled={state === 'sending'}>\n              <Swap show={state !== 'sending'}>\n                <Text path={['submit']} value={props.submit} as=\"span\" />\n              </Swap>\n              <Swap show={state === 'sending'}>\n                <Text path={['sending']} value={props.sending} as=\"span\" />\n              </Swap>\n            </Button>\n            </fieldset>\n          </form>\n        </AppPanel>\n        <p className=\"mt-6 text-center text-kh-small text-kh-muted\">\n          <Text path={['alternative', 'text']} value={props.alternative.text} as=\"span\" />{' '}\n          <LabelLink path={['alternative', 'link']} link={props.alternative.link} />\n        </p>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppAuthSignup);\n"
    }
  ]
}
