{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contact-form",
  "type": "registry:block",
  "title": "Contact, form",
  "description": "Heading and contact details beside a simple message form. Presentation only: the page wires the submit.",
  "categories": [
    "contact"
  ],
  "dependencies": [
    "lucide-react@^1.49.0",
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/kit-form.json",
    "https://ui.klarhimmel.com/r/native-select.json"
  ],
  "files": [
    {
      "path": "src/blocks/contact-form/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/contact-form/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, formErrors, formFields, formStatus, link, t, req } from '../_shared/schema';\n\n/** One extra field (or a group heading) between the phone and the message. Options are the choices of a select, a radio group or a checkbox group; checkbox answers post once per ticked option under the same name. */\nconst extraField = z.object({\n  kind: z.enum(['heading', 'text', 'select', 'radio', 'checkboxes', 'date', 'number']),\n  label: t(80),\n  /** The form name; without one it is made from the label. */\n  name: t(40).optional(),\n  options: z.array(t(80)).max(40).optional(),\n  required: z.boolean().optional(),\n  /** Shown inside an empty text or number field. */\n  placeholder: t(60).optional(),\n  hint: t(160).optional(),\n});\n\nconst schema = z.object({\n  eyebrow: t(60),\n  title: t(120),\n  description: t(300),\n  /** href (tel:, mailto:, https:) makes the value a link, so a phone or e-mail can be tapped; without it the value is plain text. */\n  /** Up to six details (was four: Allakando and Levande Tak list six), each with an optional second line (opening hours under an address). */\n  details: z.array(z.object({ label: t(40), value: t(120), href: t(300).optional(), note: t(120).optional() })).max(6),\n  /** Omit to drop the name field (email and message only). */\n  nameLabel: t(40).optional(),\n  emailLabel: req(40),\n  /** With a label, a phone field (type tel, optional to fill) follows the email: for a page that promises to ring or text back. */\n  phoneLabel: t(40).optional(),\n  /** A street, postcode and city field (named street, postcode and city, with the browser's address autocomplete) after the phone; the labels are theirs. */\n  address: z.object({ street: req(40), postcode: req(40), city: req(40) }).partial().optional(),\n  /** Extra fields and group headings in order (Rullande Greken has about 17 fields in four groups). Text, select, radio, checkbox group, date and number; max 30 entries. */\n  fields: z.array(extraField).max(30).optional(),\n  /** Up to 80: a label that asks for the trip, the dates and the group size is real copy (Builder rejected 20 of 21 contact-form fills at 40, 15 Nov). */\n  messageLabel: req(80),\n  /** What the last field is. textarea (default, absent means this) is a long message named `message`; url, email and text make it a single line, with the right keyboard, autocomplete and validation. url needs a scheme (https://…); domain takes what owners type: a bare domain or a full address (yourcompany.se, www.x.se, https://x.se/page). */\n  messageType: z.enum(['textarea', 'url', 'domain', 'email', 'text']).optional(),\n  /** The last field's form name. Default \"message\" for every type, so a backend that stores email + message keeps working. */\n  messageName: t(40).optional(),\n  /** What each field says under itself when the browser's own validation fails (see formErrors). Optional: English defaults. */\n  errors: formErrors,\n  submit: req(40),\n  consent: t(160),\n  /** A link after the consent text (the privacy policy). */\n  consentLink: link.partial().optional(),\n  /** Turns the consent text into a tick box that must be ticked (posted as `consent`). */\n  consentRequired: z.boolean().optional(),\n  /** The name of a hidden trap field that people never fill (spam bots do): the host drops a post where it has a value. Not drawn, not tabbable. */\n  honeypot: t(40).optional(),\n  /** Form wiring: `action` is where the form goes (and a flow edge in Canvas); with `method` it submits natively. See formFields. */\n  ...formFields,\n  ...formStatus,\n});\n\nexport const spec = defineSpec({\n  type: 'contact-form',\n  aliases: ['contact/form'],\n  name: 'Contact, form',\n  category: 'contact',\n  role: 'body',\n  description: 'Heading and contact details beside a simple message form. Presentation only: the page wires the submit.',\n  schema,\n  defaults: {\n    eyebrow: 'Name the topic',\n    title: 'Ask what they want to tell you',\n    description: 'Say in one sentence who reads the message and when they get a reply.',\n    details: [\n      { label: 'First detail', value: 'hello@yourcompany.example', href: 'mailto:hello@yourcompany.example' },\n      { label: 'Second detail', value: 'Give the street address and town' },\n      { label: 'Third detail', value: 'Give the days and opening hours' },\n    ],\n    nameLabel: 'Full name',\n    emailLabel: 'Your email',\n    messageLabel: 'Your message',\n    submit: 'Send',\n    consent: 'Say in one line what the details are used for.',\n    messages: { sent: 'Thank them and say when they can expect a reply.', error: 'Say it failed and what they can do instead.' },\n    errors: { required: 'Say this field is needed.', email: 'Say what a valid email address looks like.', url: 'Say what a valid web address looks like, with an example.', domain: 'Say what a site address looks like, with one.' },\n  },\n});\n"
    },
    {
      "path": "src/blocks/contact-form/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/contact-form/index.tsx",
      "content": "import { useId } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Button, safeHref } from '../../ui/button';\nimport { NativeSelect } from '../../ui/native-select';\nimport { Check } from 'lucide-react';\nimport { DOMAIN_PATTERN, EMAIL_PATTERN, ERROR_WORDS, FieldError, FormExtras, FormStatus, URL_PATTERN, useFieldErrors, useFormProps } from '../_shared/form-kit';\nimport { Input, Textarea } from '../../ui/input';\nimport { Container, Gate, LinkedValue, Opt, Section, SectionHeader, useEditing, useNamed } from '../_shared/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 Label({ htmlFor, path, value }: { htmlFor: string; path: (string | number)[]; value: string }) {\n  return (\n    <label htmlFor={htmlFor} className=\"mb-1.5 block text-kh-small font-medium\">\n      <Text path={path} value={value} as=\"span\" />\n    </label>\n  );\n}\n\nexport { DOMAIN_PATTERN };\n\ntype Extra = NonNullable<Props['fields']>[number];\n\n/** A name for a field with none: its label in ascii, or its place in the list. */\nconst slug = (e: Extra, i: number) => e.name || e.label.normalize('NFKD').replace(/[\\u0300-\\u036f]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || `field-${i}`;\n\n/** A choice drawn as a row with a real input (required and name work without script) and a box or a dot that follows its state. */\nfunction Choice({ type, name, value, required, path }: { type: 'radio' | 'checkbox'; name: string; value: string; required?: boolean; path: (string | number)[] }) {\n  return (\n    <label className=\"flex min-h-11 cursor-pointer items-start gap-3 py-2.5 text-kh-body has-focus-visible:outline-2 has-focus-visible:outline-offset-0 has-focus-visible:outline-(--kh-focus)\">\n      <input type={type} name={name} value={value} required={required} className=\"peer sr-only\" />\n      <span aria-hidden className={`mt-[calc((1lh-1.25rem)/2)] flex size-5 shrink-0 items-center justify-center border border-kh-line-strong bg-kh-surface text-transparent peer-checked:border-kh-ink peer-checked:bg-kh-ink peer-checked:text-kh-on-ink ${type === 'radio' ? 'rounded-full' : 'rounded-kh-sm'}`}>\n        {type === 'checkbox' ? <Check className=\"size-3.5\" strokeWidth={3} /> : <span className=\"size-2 rounded-full bg-current\" />}\n      </span>\n      <Text path={path} value={value} as=\"span\" className=\"min-w-0\" />\n    </label>\n  );\n}\n\nfunction ContactForm({ props }: BlockProps<Props>) {\n  const messageNamed = useNamed(props.messageLabel);\n  const id = useId();\n  const f = (n: string) => `${id}-${n}`;\n  const formProps = useFormProps(props);\n  const kind = props.messageType ?? 'textarea';\n  const editing = useEditing();\n  const words = { ...ERROR_WORDS, ...props.errors };\n  const { errs, fieldProps } = useFieldErrors(words, f);\n  const sent = props.status === 'sent' && !editing;\n  return (\n    <Section labelledBy={id}>\n      <Container className=\"grid gap-14 @4xl:grid-cols-[1fr_1.1fr] @4xl:gap-20\">\n        <div>\n          <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n          <dl className=\"mt-10 space-y-6\">\n            {props.details.map((d, i) => (\n              <div key={i}>\n                <dt className=\"text-kh-small text-kh-muted\">\n                  <Text path={['details', i, 'label']} value={d.label} as=\"span\" />\n                </dt>\n                <dd className=\"mt-1 text-kh-body\">\n                  <LinkedValue path={['details', i, 'value']} value={d.value} href={d.href} />\n                  <Opt path={['details', i, 'note']} value={d.note} as=\"span\" className=\"block text-kh-small text-kh-muted\" placeholder=\"A second line\" />\n                </dd>\n              </div>\n            ))}\n          </dl>\n        </div>\n        <form {...formProps} className=\"space-y-5 rounded-kh-xl border border-kh-line bg-kh-surface p-6 shadow-kh-1 @xl:p-8\">\n          <FormStatus status={props.status} messages={props.messages} />\n          <div hidden={sent} className=\"space-y-5\">\n          <div className={props.nameLabel ? 'grid gap-5 @xl:grid-cols-2' : undefined}>\n            {props.nameLabel && (\n              <div>\n                <Label htmlFor={f('name')} path={['nameLabel']} value={props.nameLabel} />\n                <Input id={f('name')} name=\"name\" autoComplete=\"name\" required {...fieldProps('name', 'text')} />\n                <FieldError id={f('name')} text={errs.name} />\n              </div>\n            )}\n            <div>\n              <Label htmlFor={f('email')} path={['emailLabel']} value={props.emailLabel} />\n              <Input id={f('email')} name=\"email\" type=\"email\" autoComplete=\"email\" required pattern={EMAIL_PATTERN} title={words.email} {...fieldProps('email', 'email')} />\n              <FieldError id={f('email')} text={errs.email} />\n            </div>\n          </div>\n          {props.phoneLabel && (\n            <div>\n              <Label htmlFor={f('phone')} path={['phoneLabel']} value={props.phoneLabel} />\n              <Input id={f('phone')} name=\"phone\" type=\"tel\" autoComplete=\"tel\" inputMode=\"tel\" />\n            </div>\n          )}\n          {props.address && (\n            <div className=\"grid gap-5 @xl:grid-cols-2\">\n              <div className=\"@xl:col-span-2\">\n                <Label htmlFor={f('street')} path={['address', 'street']} value={props.address.street ?? ''} />\n                <Input id={f('street')} name=\"street\" autoComplete=\"street-address\" />\n              </div>\n              <div>\n                <Label htmlFor={f('postcode')} path={['address', 'postcode']} value={props.address.postcode ?? ''} />\n                <Input id={f('postcode')} name=\"postcode\" autoComplete=\"postal-code\" />\n              </div>\n              <div>\n                <Label htmlFor={f('city')} path={['address', 'city']} value={props.address.city ?? ''} />\n                <Input id={f('city')} name=\"city\" autoComplete=\"address-level2\" />\n              </div>\n            </div>\n          )}\n          {(props.fields?.length ?? 0) > 0 && (\n            <div className=\"grid gap-x-5 gap-y-5 @xl:grid-cols-2\">\n              {props.fields!.map((e, i) => {\n                const fid = f(`x${i}`);\n                const name = slug(e, i);\n                const path = ['fields', i];\n                const options = e.options ?? [];\n                if (e.kind === 'heading') {\n                  return <Gate key={i} label={e.label}><Text path={[...path, 'label']} value={e.label} as=\"h3\" className=\"@xl:col-span-2 border-b border-kh-line pb-2 pt-3 text-kh-body font-semibold\" /></Gate>;\n                }\n                const group = e.kind === 'radio' || e.kind === 'checkboxes';\n                return (\n                  <Gate key={i} label={e.label}>\n                    {group ? (\n                      <fieldset className=\"@xl:col-span-2\">\n                        <legend className=\"mb-1 text-kh-small font-medium\"><Text path={[...path, 'label']} value={e.label} as=\"span\" />{e.required && <span aria-hidden className=\"ml-0.5\">*</span>}</legend>\n                        <div className=\"grid @md:grid-cols-2 @md:gap-x-6\">\n                          {options.map((o, j) => <Choice key={j} type={e.kind === 'radio' ? 'radio' : 'checkbox'} name={name} value={o} required={e.required && e.kind === 'radio'} path={[...path, 'options', j]} />)}\n                        </div>\n                        <Opt path={[...path, 'hint']} value={e.hint} className=\"mt-1 text-kh-caption text-kh-muted\" placeholder=\"Hint\" />\n                      </fieldset>\n                    ) : (\n                      <div>\n                        <Label htmlFor={fid} path={[...path, 'label']} value={e.label} />\n                        {e.kind === 'select' ? (\n                          <NativeSelect id={fid} name={name} required={e.required} defaultValue=\"\" className=\"w-full\">\n                            <option value=\"\">{e.placeholder || '\\u2014'}</option>\n                            {options.map((o, j) => <option key={j} value={o}>{o}</option>)}\n                          </NativeSelect>\n                        ) : (\n                          <Input id={fid} name={name} type={e.kind === 'date' ? 'date' : e.kind === 'number' ? 'number' : 'text'} inputMode={e.kind === 'number' ? 'decimal' : undefined} placeholder={e.placeholder || undefined} required={e.required} {...(e.required ? fieldProps(`x${i}`, 'text') : {})} />\n                        )}\n                        <Opt path={[...path, 'hint']} value={e.hint} className=\"mt-1 text-kh-caption text-kh-muted\" placeholder=\"Hint\" />\n                        {e.required && e.kind !== 'select' && <FieldError id={fid} text={errs[`x${i}`]} />}\n                      </div>\n                    )}\n                  </Gate>\n                );\n              })}\n            </div>\n          )}\n          {messageNamed && (\n          <div>\n            <Label htmlFor={f('message')} path={['messageLabel']} value={props.messageLabel} />\n            {kind === 'textarea' ? (\n              <Textarea id={f('message')} name={props.messageName || 'message'} rows={6} required {...fieldProps('message', 'text')} />\n            ) : (\n              <Input\n                id={f('message')}\n                name={props.messageName || 'message'}\n                type={kind === 'domain' ? 'text' : kind}\n                required\n                {...(kind === 'url' || kind === 'domain' ? { inputMode: 'url' as const, autoComplete: 'url', autoCapitalize: 'none', spellCheck: false } : kind === 'email' ? { autoComplete: 'email', autoCapitalize: 'none', spellCheck: false } : {})}\n                {...(kind === 'domain' ? { pattern: DOMAIN_PATTERN, title: words.domain } : kind === 'url' ? { pattern: URL_PATTERN, title: words.url } : kind === 'email' ? { pattern: EMAIL_PATTERN, title: words.email } : {})}\n                {...fieldProps('message', kind)}\n              />\n            )}\n            <FieldError id={f('message')} text={errs.message} />\n          </div>\n          )}\n          {editing && (\n            <p className=\"text-kh-caption text-kh-muted\">\n              <Text path={['errors', 'required']} value={words.required} as=\"span\" /> · <Text path={['errors', 'email']} value={words.email} as=\"span\" /> · <Text path={['errors', 'url']} value={words.url} as=\"span\" /> · <Text path={['errors', 'domain']} value={words.domain} as=\"span\" />\n            </p>\n          )}\n          {props.honeypot && <div aria-hidden className=\"sr-only\"><input type=\"text\" name={props.honeypot} tabIndex={-1} autoComplete=\"off\" /></div>}\n          <FormExtras {...props} />\n          <div className=\"flex flex-col gap-4 @xl:flex-row @xl:items-center @xl:justify-between\">\n            {props.consentRequired ? (\n              <label className=\"flex max-w-sm cursor-pointer items-start gap-3 text-kh-caption text-kh-muted has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-(--kh-focus)\">\n                <input type=\"checkbox\" name=\"consent\" required className=\"peer sr-only\" />\n                <span aria-hidden className=\"flex size-5 shrink-0 items-center justify-center rounded-kh-sm border border-kh-line-strong bg-kh-surface text-transparent peer-checked:border-kh-ink peer-checked:bg-kh-ink peer-checked:text-kh-on-ink\"><Check className=\"size-3.5\" strokeWidth={3} /></span>\n                <span className=\"min-w-0\">\n                  <Text path={['consent']} value={props.consent} as=\"span\" />\n                  {props.consentLink?.label && <> <a href={safeHref(props.consentLink.href)} className=\"underline underline-offset-2 hover:text-kh-ink\"><Text path={['consentLink', 'label']} value={props.consentLink.label} as=\"span\" /></a></>}\n                </span>\n              </label>\n            ) : (\n              props.consentLink?.label ? (\n                <p className=\"max-w-xs text-kh-caption text-kh-muted\">\n                  <Text path={['consent']} value={props.consent} as=\"span\" /> <a href={safeHref(props.consentLink.href)} className=\"underline underline-offset-2 hover:text-kh-ink\"><Text path={['consentLink', 'label']} value={props.consentLink.label} as=\"span\" /></a>\n                </p>\n              ) : (\n                <Text path={['consent']} value={props.consent} as=\"p\" className=\"max-w-xs text-kh-caption text-kh-muted\" />\n              )\n            )}\n            <Button type=\"submit\" size=\"lg\">\n              <Text path={['submit']} value={props.submit} as=\"span\" />\n            </Button>\n          </div>\n          </div>\n        </form>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(ContactForm);\n"
    }
  ]
}
