{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"faq-section","type":"registry:block","title":"FAQ Section","description":"A two-column FAQ with topic chips, questions that expand in place with a plus-to-minus toggle, inline code answers, and an empty-state route back to all questions.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/faq-section/faq-section.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useId, useRef, useState } from \"react\";\nimport {\n  AnimatePresence,\n  MotionConfig,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { ArrowUpRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type FaqSectionItem = {\n  /** Stable id used for ARIA wiring and the open state. */\n  id: string;\n  /** Topic matched by the filter chips, e.g. \"Install\". */\n  topic: string;\n  question: string;\n  /** Plain text; wrap commands or code in backticks. */\n  answer: string;\n};\n\nexport type FaqSectionProps = {\n  className?: string;\n  title?: string;\n  intro?: string;\n  contactText?: string;\n  contactLabel?: string;\n  contactHref?: string;\n  items?: FaqSectionItem[];\n  /** Topics rendered as filter chips. Defaults to Billing, Install, Licence. */\n  topics?: string[];\n  /** Show the topic filter. Defaults to true. */\n  showFilter?: boolean;\n  /** Allow more than one panel open at a time. Defaults to false. */\n  allowMultiple?: boolean;\n  /** Ids open on first render. Defaults to the first question. */\n  defaultOpenIds?: string[];\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo content                                          */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_TITLE = \"Questions, answered plainly.\";\nconst DEFAULT_INTRO =\n  \"PrequelUI is MIT-licensed, installs with one command, and copies code you can read. Here is what people ask before adding their first block.\";\nconst DEFAULT_CONTACT_TEXT =\n  \"Can't find your answer? Ask on GitHub — the same place the source lives.\";\nconst DEFAULT_CONTACT_LABEL = \"Ask on GitHub\";\nconst DEFAULT_CONTACT_HREF = \"https://github.com/prequelui/prequelui\";\n\nconst DEFAULT_TOPICS = [\"Billing\", \"Install\", \"Licence\"];\n\nconst DEFAULT_ITEMS: FaqSectionItem[] = [\n  {\n    id: \"first-block\",\n    topic: \"Install\",\n    question: \"How do I add my first block?\",\n    answer:\n      \"Run `npx shadcn@latest add https://prequelui.terravidhal.me/r/area-chart.json`. The CLI copies the component into your project, so you can edit it, rename it, or remove the parts you don't need. It expects React 19, Tailwind CSS 4, and motion.\",\n  },\n  {\n    id: \"updates\",\n    topic: \"Install\",\n    question: \"What happens when I update a block?\",\n    answer:\n      \"Re-run the add command with `--overwrite` to pull the latest version. If you have already edited the file, the CLI asks before replacing it — diff your changes first and merge by hand where it matters.\",\n  },\n  {\n    id: \"app-router\",\n    topic: \"Install\",\n    question: \"Do the blocks work in the App Router?\",\n    answer:\n      \"Yes. Every block starts with `\\\"use client\\\"`, so it drops into a server-rendered page without a wrapper. Keep data fetching on the server and pass plain props down to the block.\",\n  },\n  {\n    id: \"client-work\",\n    topic: \"Licence\",\n    question: \"Can I use the blocks in paid client work?\",\n    answer:\n      \"Yes. PrequelUI ships under the MIT licence, which covers commercial and client projects. Keep the licence notice in the repository and you are free to ship, rebrand, and extend the components.\",\n  },\n  {\n    id: \"attribution\",\n    topic: \"Licence\",\n    question: \"Do I have to show attribution?\",\n    answer:\n      \"No visible credit is required. The MIT notice in the source files is enough, and you can move components into any folder structure your project already uses.\",\n  },\n  {\n    id: \"pro-plan\",\n    topic: \"Billing\",\n    question: \"If the blocks are MIT, why is there a Pro plan?\",\n    answer:\n      \"Pro is a separate paid product for complete dashboards: every page, plus notifications, a command menu, export and colour themes. The free blocks stay free and complete — Pro never gates the code you already have.\",\n  },\n  {\n    id: \"cancel\",\n    topic: \"Billing\",\n    question: \"What happens to my blocks if I stop paying for Pro?\",\n    answer:\n      \"Nothing. Free blocks are copied into your project and stay yours under the MIT licence. Cancelling Pro only ends access to Pro dashboards and their updates, with no export lock-in.\",\n  },\n];\n\n/* ------------------------------------------------------------------ */\n/* small helpers                                                       */\n/* ------------------------------------------------------------------ */\n\n/** Renders `inline code` spans inside an answer string. */\nfunction AnswerText({ text }: { text: string }) {\n  return (\n    <>\n      {text.split(\"`\").map((part, index) =>\n        index % 2 === 1 ? (\n          <code\n            key={index}\n            className=\"rounded bg-muted px-1 py-0.5 font-mono text-[12px] text-foreground [overflow-wrap:anywhere]\"\n          >\n            {part}\n          </code>\n        ) : (\n          <span key={index}>{part}</span>\n        )\n      )}\n    </>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* plus that turns into a minus                                        */\n/* ------------------------------------------------------------------ */\n\nfunction PlusMinus({ open, reduce }: { open: boolean; reduce: boolean }) {\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"relative mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center\"\n    >\n      <motion.span\n        className=\"relative flex h-4 w-4 items-center justify-center\"\n        initial={false}\n        animate={{ rotate: open ? 90 : 0 }}\n        transition={{ duration: reduce ? 0 : 0.3, ease: EASE }}\n      >\n        <motion.span\n          className=\"absolute left-0 top-1/2 h-px w-4 -translate-y-1/2 bg-current\"\n          initial={false}\n          animate={{ scaleX: open ? 0 : 1 }}\n          transition={{ duration: reduce ? 0 : 0.3, ease: EASE }}\n        />\n        <span className=\"absolute left-1/2 top-0 h-4 w-px -translate-x-1/2 bg-current\" />\n      </motion.span>\n    </span>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* one question                                                        */\n/* ------------------------------------------------------------------ */\n\ntype FaqRowProps = {\n  item: FaqSectionItem;\n  index: number;\n  open: boolean;\n  show: boolean;\n  reduce: boolean;\n  onToggle: (id: string) => void;\n  idPrefix: string;\n};\n\nfunction FaqRow({\n  item,\n  index,\n  open,\n  show,\n  reduce,\n  onToggle,\n  idPrefix,\n}: FaqRowProps) {\n  const buttonId = `${idPrefix}-question-${item.id}`;\n  const panelId = `${idPrefix}-answer-${item.id}`;\n  const number = String(index + 1).padStart(2, \"0\");\n\n  return (\n    <motion.li\n      initial={reduce ? false : { opacity: 0, y: 8 }}\n      animate={{\n        opacity: show ? 1 : 0,\n        y: show ? 0 : 8,\n      }}\n      exit={reduce ? { opacity: 0 } : { opacity: 0, y: -6 }}\n      transition={{\n        duration: reduce ? 0 : 0.28,\n        ease: EASE,\n        delay: reduce ? 0 : Math.min(index, 6) * 0.04,\n      }}\n      className=\"border-b border-border last:border-b-0\"\n    >\n      <h3>\n        <button\n          type=\"button\"\n          id={buttonId}\n          aria-expanded={open}\n          aria-controls={panelId}\n          onClick={() => onToggle(item.id)}\n          className=\"group flex w-full items-start gap-3 rounded-lg py-4 pr-1 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background sm:gap-4 sm:py-5\"\n        >\n          <span\n            className={cn(\n              \"w-5 shrink-0 pt-0.5 text-[11px] font-medium tabular-nums transition-colors\",\n              open\n                ? \"text-foreground\"\n                : \"text-muted-foreground group-hover:text-foreground\"\n            )}\n          >\n            {number}\n          </span>\n          <span\n            className={cn(\n              \"min-w-0 flex-1 break-words text-[14.5px] font-medium leading-6 tracking-[-0.01em] transition-colors\",\n              open\n                ? \"text-foreground\"\n                : \"text-foreground/85 group-hover:text-foreground\"\n            )}\n          >\n            {item.question}\n          </span>\n          <span\n            className={cn(\n              \"flex h-5 w-5 shrink-0 items-center justify-center transition-colors\",\n              open\n                ? \"text-foreground\"\n                : \"text-muted-foreground group-hover:text-foreground\"\n            )}\n          >\n            <PlusMinus open={open} reduce={reduce} />\n          </span>\n        </button>\n      </h3>\n\n      <motion.div\n        id={panelId}\n        role=\"region\"\n        aria-labelledby={buttonId}\n        aria-hidden={!open}\n        initial={false}\n        animate={{\n          height: open ? \"auto\" : 0,\n          opacity: open ? 1 : 0,\n        }}\n        transition={{ duration: reduce ? 0 : 0.32, ease: EASE }}\n        className=\"overflow-hidden\"\n      >\n        <div className=\"break-words pb-4 pl-8 pr-6 text-[13.5px] leading-6 text-muted-foreground sm:pb-5 sm:pl-9\">\n          <AnswerText text={item.answer} />\n        </div>\n      </motion.div>\n    </motion.li>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function FaqSection({\n  className,\n  title = DEFAULT_TITLE,\n  intro = DEFAULT_INTRO,\n  contactText = DEFAULT_CONTACT_TEXT,\n  contactLabel = DEFAULT_CONTACT_LABEL,\n  contactHref = DEFAULT_CONTACT_HREF,\n  items = DEFAULT_ITEMS,\n  topics = DEFAULT_TOPICS,\n  showFilter = true,\n  allowMultiple = false,\n  defaultOpenIds,\n}: FaqSectionProps) {\n  const ref = useRef<HTMLElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n  const show = reduce || inView;\n\n  const uid = useId().replace(/:/g, \"\");\n  const headingId = `${uid}-heading`;\n  const pillId = `${uid}-filter-pill`;\n\n  const [activeTopic, setActiveTopic] = useState<string | null>(null);\n  const [openIds, setOpenIds] = useState<string[]>(() => {\n    const initial =\n      defaultOpenIds ?? (items.length > 0 ? [items[0].id] : []);\n    return allowMultiple ? initial : initial.slice(0, 1);\n  });\n\n  const toggle = (id: string) => {\n    setOpenIds((current) => {\n      if (current.includes(id)) {\n        return current.filter((openId) => openId !== id);\n      }\n      return allowMultiple ? [...current, id] : [id];\n    });\n  };\n\n  const entries = items.map((item, index) => ({ item, index }));\n  const filtered =\n    activeTopic === null\n      ? entries\n      : entries.filter(({ item }) => item.topic === activeTopic);\n\n  const filtersVisible = showFilter && topics.length > 0;\n\n  const countFor = (topic: string) =>\n    items.filter((item) => item.topic === topic).length;\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.section\n        ref={ref}\n        aria-labelledby={title ? headingId : undefined}\n        aria-label={title ? undefined : \"Frequently asked questions\"}\n        initial={reduce ? false : { opacity: 0, y: 14 }}\n        animate={\n          show ? { opacity: 1, y: 0 } : { opacity: 0, y: reduce ? 0 : 14 }\n        }\n        transition={{ duration: reduce ? 0 : 0.6, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card p-5 text-card-foreground sm:p-8 lg:p-10\",\n          className\n        )}\n      >\n        <div className=\"grid gap-8 lg:grid-cols-[minmax(0,0.85fr)_minmax(0,1.15fr)] lg:gap-14\">\n          <div className=\"lg:sticky lg:top-10 lg:self-start\">\n            {title ? (\n              <h2\n                id={headingId}\n                className=\"text-balance text-2xl font-semibold tracking-tight sm:text-[28px] sm:leading-[1.15]\"\n              >\n                {title}\n              </h2>\n            ) : null}\n            {intro ? (\n              <p className=\"mt-3 max-w-sm text-pretty text-[13.5px] leading-6 text-muted-foreground\">\n                {intro}\n              </p>\n            ) : null}\n\n            <div className=\"mt-7 border-t border-border pt-5\">\n              <div className=\"flex items-start gap-3\">\n                <span\n                  aria-hidden=\"true\"\n                  className=\"relative mt-0.5 grid h-7 w-7 shrink-0 place-items-center rounded-full border border-border bg-background\"\n                >\n                  <span className=\"absolute right-[5px] top-[5px] h-1 w-1 rounded-full bg-foreground/70\" />\n                </span>\n                <div className=\"min-w-0\">\n                  <p className=\"text-[13px] leading-5 text-muted-foreground\">\n                    {contactText}\n                  </p>\n                  <a\n                    href={contactHref}\n                    className=\"mt-1.5 inline-flex items-center gap-1 rounded-sm text-[13px] font-medium text-foreground underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                  >\n                    {contactLabel}\n                    <ArrowUpRight className=\"h-3.5 w-3.5\" />\n                  </a>\n                  <p className=\"mt-2 text-[12px] text-muted-foreground\">\n                    Replies within two working days.\n                  </p>\n                </div>\n              </div>\n            </div>\n          </div>\n\n          <div className=\"min-w-0\">\n            {filtersVisible ? (\n              <div\n                role=\"group\"\n                aria-label=\"Filter questions by topic\"\n                className=\"mb-4 flex flex-wrap items-center gap-1.5\"\n              >\n                <FilterChip\n                  label=\"All\"\n                  count={items.length}\n                  active={activeTopic === null}\n                  pillId={pillId}\n                  reduce={reduce}\n                  onClick={() => setActiveTopic(null)}\n                />\n                {topics.map((topic) => (\n                  <FilterChip\n                    key={topic}\n                    label={topic}\n                    count={countFor(topic)}\n                    active={activeTopic === topic}\n                    pillId={pillId}\n                    reduce={reduce}\n                    onClick={() => setActiveTopic(topic)}\n                  />\n                ))}\n              </div>\n            ) : null}\n\n            {filtered.length > 0 ? (\n              <ul className=\"relative border-t border-border\">\n                <AnimatePresence mode=\"popLayout\">\n                  {filtered.map(({ item, index }) => (\n                    <FaqRow\n                      key={item.id}\n                      item={item}\n                      index={index}\n                      open={openIds.includes(item.id)}\n                      show={show}\n                      reduce={reduce}\n                      onToggle={toggle}\n                      idPrefix={uid}\n                    />\n                  ))}\n                </AnimatePresence>\n              </ul>\n            ) : (\n              <div className=\"border-t border-border py-6\">\n                <p className=\"text-[13px] leading-5 text-muted-foreground\">\n                  {activeTopic\n                    ? `Nothing filed under ${activeTopic} yet.`\n                    : \"No questions here yet.\"}\n                </p>\n                {activeTopic ? (\n                  <button\n                    type=\"button\"\n                    onClick={() => setActiveTopic(null)}\n                    className=\"mt-2 rounded-sm text-[13px] font-medium text-foreground underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                  >\n                    Show all topics\n                  </button>\n                ) : null}\n              </div>\n            )}\n          </div>\n        </div>\n      </motion.section>\n    </MotionConfig>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* filter chip                                                         */\n/* ------------------------------------------------------------------ */\n\ntype FilterChipProps = {\n  label: string;\n  count: number;\n  active: boolean;\n  pillId: string;\n  reduce: boolean;\n  onClick: () => void;\n};\n\nfunction FilterChip({\n  label,\n  count,\n  active,\n  pillId,\n  reduce,\n  onClick,\n}: FilterChipProps) {\n  return (\n    <button\n      type=\"button\"\n      aria-pressed={active}\n      onClick={onClick}\n      className={cn(\n        \"relative inline-flex max-w-full items-center gap-1.5 rounded-full border px-3 py-1.5 text-[12.5px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n        active\n          ? \"border-transparent text-background\"\n          : \"border-border text-muted-foreground hover:border-muted-foreground/40 hover:text-foreground\"\n      )}\n    >\n      {active ? (\n        <motion.span\n          layoutId={pillId}\n          className=\"absolute inset-0 rounded-full bg-foreground\"\n          transition={\n            reduce ? { duration: 0 } : { type: \"tween\", duration: 0.28, ease: EASE }\n          }\n        />\n      ) : null}\n      <span className=\"relative z-10 break-words\">{label}</span>\n      <span\n        className={cn(\n          \"relative z-10 text-[11px] tabular-nums\",\n          active && \"opacity-80\"\n        )}\n      >\n        {count}\n      </span>\n    </button>\n  );\n}\n\nexport default FaqSection;\n"}]}