{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "newsletter-topics",
  "type": "registry:block",
  "title": "Newsletter, choose topics",
  "description": "A sign-up where readers tick the topics they want (two to six checkbox cards) before giving an email address. Fewer unsubscribes, better targeting.",
  "categories": [
    "newsletter"
  ],
  "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"
  ],
  "files": [
    {
      "path": "src/blocks/newsletter-topics/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/newsletter-topics/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, formFields, t, req } from '../_shared/schema';\n\nconst schema = z.object({\n  eyebrow: t(60),\n  title: t(100),\n  description: t(240),\n  topicsLabel: t(60),\n  /** `checked` pre-ticks a topic. Off unless set: a pre-ticked box is not consent. */\n  topics: z.array(z.object({ label: req(40), description: t(100), checked: z.boolean().optional() })).min(2).max(6),\n  emailLabel: req(40),\n  placeholder: t(60),\n  submit: req(24),\n  consent: t(160),\n  /** Form wiring: `action` is where the form goes; with `method` it submits natively. See formFields. */\n  ...formFields,\n});\n\nexport const spec = defineSpec({\n  type: 'newsletter-topics',\n  aliases: ['newsletter/topics'],\n  name: 'Newsletter, choose topics',\n  category: 'newsletter',\n  role: 'body',\n  description: 'A sign-up where readers tick the topics they want (two to six checkbox cards) before giving an email address. Fewer unsubscribes, better targeting.',\n  schema,\n  defaults: {\n    eyebrow: 'Name the section',\n    title: 'Say what subscribers get by email',\n    description: 'Say in one or two sentences how to pick topics and how to change the choice later.',\n    topicsLabel: 'Topic list',\n    topics: [\n      { label: 'Name a topic', description: 'Say what the topic brings' },\n      { label: 'Name a topic', description: 'Say what the topic brings' },\n      { label: 'Name a topic', description: 'Say what the topic brings' },\n      { label: 'Name a topic', description: 'Say what the topic brings' },\n    ],\n    emailLabel: 'Email address',\n    placeholder: 'Your email address',\n    submit: 'Subscribe',\n    consent: 'Say how the address is kept and how to leave',\n  },\n});\n"
    },
    {
      "path": "src/blocks/newsletter-topics/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/newsletter-topics/index.tsx",
      "content": "import { useId } from 'react';\nimport { FormExtras, useFormProps } from '../_shared/form-kit';\nimport { Check } from 'lucide-react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Button } from '../../ui/button';\nimport { Input } from '../../ui/input';\nimport { Container, 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 NewsletterTopics({ props }: BlockProps<Props>) {\n  const emailNamed = useNamed(props.emailLabel);\n  const id = useId();\n  const emailId = useId();\n  const editing = useEditing();\n  const formProps = useFormProps(props);\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} align=\"center\" />\n        <form {...formProps} className=\"mt-10\">\n          <fieldset>\n            <legend className=\"mb-3 text-kh-small font-medium text-kh-muted\">\n              <Text path={['topicsLabel']} value={props.topicsLabel} as=\"span\" />\n            </legend>\n            <div className=\"grid gap-3 @md:grid-cols-2\">\n              {props.topics.map((topic, i) => (\n                <label key={i} className=\"group relative flex min-h-16 cursor-pointer items-start gap-3 rounded-kh-lg border border-kh-line bg-kh-surface p-4 transition-colors hover:border-kh-muted has-checked:border-kh-ink has-checked:bg-kh-accent-soft has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-(--kh-focus)\">\n                  <input type=\"checkbox\" name=\"topics\" value={topic.label} defaultChecked={!!topic.checked} className=\"peer sr-only\" />\n                  <span aria-hidden className=\"mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-kh-sm border border-kh-line-strong bg-kh-canvas text-transparent peer-checked:border-kh-ink peer-checked:bg-kh-ink peer-checked:text-kh-canvas\">\n                    <Check className=\"size-3.5\" strokeWidth={3} />\n                  </span>\n                  <span className=\"min-w-0\">\n                    <Text path={['topics', i, 'label']} value={topic.label} as=\"span\" className=\"block text-kh-body font-medium\" />\n                    <Text path={['topics', i, 'description']} value={topic.description} as=\"span\" className=\"block text-kh-small text-kh-muted\" />\n                  </span>\n                </label>\n              ))}\n            </div>\n          </fieldset>\n          {emailNamed && (\n            <>\n          <label htmlFor={emailId} className=\"mt-8 block text-kh-small font-medium\">\n            <Text path={['emailLabel']} value={props.emailLabel} as=\"span\" />\n          </label>\n          <FormExtras {...props} />\n          <div className=\"mt-2 flex flex-col gap-2 @md:flex-row\">\n            <Input id={emailId} name=\"email\" type=\"email\" autoComplete=\"email\" required placeholder={props.placeholder} className=\"min-w-0 @md:flex-1\" />\n            <Button type=\"submit\" size=\"lg\" className=\"@md:shrink-0\">\n              <Text path={['submit']} value={props.submit} as=\"span\" />\n            </Button>\n          </div>\n            </>\n          )}\n          {editing && (\n            <Text path={['placeholder']} value={props.placeholder} as=\"p\" className=\"mt-1 text-kh-caption text-kh-muted\" />\n          )}\n          <Opt path={['consent']} value={props.consent} className=\"mt-3 text-center text-kh-caption text-kh-muted\" placeholder=\"Consent\" />\n        </form>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(NewsletterTopics);\n"
    }
  ]
}
