{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fold",
  "type": "registry:block",
  "title": "Fold",
  "description": "A neutral-elegant FAQ accordion of soft stacked cards: the open row lifts a hair off the stack, its chevron spins up in one accent hue, and the answer unfolds by hinging down from the top edge over a measured height animation. Full disclosure semantics with aria-expanded/aria-controls, labelled region panels, and Up/Down/Home/End focus movement; single-open by default with a singleOpen knob; instant open/close with the open row resting lifted under reduced motion.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/sections/fold/fold.tsx",
      "type": "registry:block",
      "target": "components/crucible/fold.tsx",
      "content": "\"use client\";\n\nimport { AnimatePresence, motion, type Transition } from \"motion/react\";\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\n\n/** A single question/answer pair in a {@link Fold}. */\nexport interface FoldItem {\n  /** The question shown on the disclosure trigger. */\n  question: string;\n  /** The answer revealed when the row unfolds. Plain text or rich nodes. */\n  answer: React.ReactNode;\n}\n\n/** Accent tokens for {@link Fold}. Everything defaults to a cool, elegant blue. */\nexport interface FoldColors {\n  /** Hue of the active chevron, focus ring, and the open row's hairline. @default \"#93c5fd\" */\n  accent?: string;\n}\n\nexport interface FoldProps extends Omit<React.ComponentPropsWithoutRef<\"section\">, \"color\"> {\n  /** Question/answer pairs, rendered in order. @default five generic FAQs */\n  items?: FoldItem[];\n  /** Optional heading rendered as an h2 above the stack. Pass `null` to omit. @default \"Frequently asked questions\" */\n  heading?: React.ReactNode;\n  /**\n   * When true (default), opening a row folds the previously open one shut so\n   * only one answer shows at a time. When false, rows open independently.\n   * @default true\n   */\n  singleOpen?: boolean;\n  /** Index open on mount (changing it later re-seeds the open row). Pass -1 to start fully folded. @default 0 */\n  defaultOpenIndex?: number;\n  /** Accent tokens — the single cool hue on the active chevron and ring. @default `{ accent: \"#93c5fd\" }` */\n  colors?: FoldColors;\n}\n\nconst DEFAULT_ITEMS: FoldItem[] = [\n  {\n    question: \"How does the free plan work?\",\n    answer:\n      \"Everything you need to evaluate the product, with no time limit and no card required. Upgrade only when you outgrow the free limits.\",\n  },\n  {\n    question: \"Can I change plans at any time?\",\n    answer:\n      \"Yes. Switch up or down whenever you like — changes take effect immediately and we prorate the difference to the cent.\",\n  },\n  {\n    question: \"Do you offer refunds?\",\n    answer:\n      \"If something isn't right within the first 30 days, reach out and we'll issue a full refund. No forms, no friction.\",\n  },\n  {\n    question: \"Where is my data stored?\",\n    answer:\n      \"In the region you choose, encrypted at rest and in transit. You can export or delete everything at any time.\",\n  },\n  {\n    question: \"How do I get support?\",\n    answer:\n      \"Every plan includes email support with a same-business-day response. Paid plans add priority chat and a shared channel.\",\n  },\n];\n\nconst DEFAULT_ACCENT = \"#93c5fd\";\n\n/**\n * Fold — a neutral-elegant FAQ accordion where each row is a self-contained card\n * in a soft stack. Opening a row lifts it a hair off the stack (a whisper of\n * shadow and scale), spins its chevron to point up in one accent hue, and the\n * answer physically unfolds: the panel measures its own height while the copy\n * hinges down from the top edge like paper opening. Full disclosure semantics —\n * every trigger is a real button with aria-expanded/aria-controls, the panel is a\n * labelled region, Enter/Space toggle, and Up/Down/Home/End roam between\n * questions. Single-open by default; `singleOpen={false}` lets rows open\n * independently. Reduced motion swaps to an instant open/close with the open row\n * resting lifted and the chevron already turned — no height tween, no hinge.\n */\nexport function Fold({\n  items = DEFAULT_ITEMS,\n  heading = \"Frequently asked questions\",\n  singleOpen = true,\n  defaultOpenIndex = 0,\n  colors,\n  className,\n  ...props\n}: FoldProps) {\n  const reducedMotion = useReducedMotion();\n  const baseId = React.useId();\n  const headingId = `${baseId}-heading`;\n  const accent = colors?.accent ?? DEFAULT_ACCENT;\n\n  const triggerRefs = React.useRef<Array<HTMLButtonElement | null>>([]);\n\n  const [openIndexes, setOpenIndexes] = React.useState<number[]>(() =>\n    defaultOpenIndex >= 0 && defaultOpenIndex < items.length ? [defaultOpenIndex] : []\n  );\n\n  // Re-seed the open row when `defaultOpenIndex` itself changes after mount\n  // (e.g. a live customizer knob), using the adjust-state-during-render pattern.\n  const [seededIndex, setSeededIndex] = React.useState(defaultOpenIndex);\n  if (seededIndex !== defaultOpenIndex) {\n    setSeededIndex(defaultOpenIndex);\n    setOpenIndexes(\n      defaultOpenIndex >= 0 && defaultOpenIndex < items.length ? [defaultOpenIndex] : []\n    );\n  }\n\n  const toggle = React.useCallback(\n    (index: number) => {\n      setOpenIndexes((current) => {\n        const isOpen = current.includes(index);\n        if (singleOpen) return isOpen ? [] : [index];\n        return isOpen ? current.filter((i) => i !== index) : [...current, index];\n      });\n    },\n    [singleOpen]\n  );\n\n  const handleKeyDown = React.useCallback(\n    (event: React.KeyboardEvent<HTMLButtonElement>, index: number) => {\n      let next: number | null = null;\n      if (event.key === \"ArrowDown\") next = (index + 1) % items.length;\n      else if (event.key === \"ArrowUp\") next = (index - 1 + items.length) % items.length;\n      else if (event.key === \"Home\") next = 0;\n      else if (event.key === \"End\") next = items.length - 1;\n      if (next === null) return;\n      event.preventDefault();\n      triggerRefs.current[next]?.focus();\n    },\n    [items.length]\n  );\n\n  // Height/hinge tween for the panel; snaps instantly under reduced motion.\n  const panelTransition: Transition = reducedMotion\n    ? { duration: 0 }\n    : {\n        height: { duration: 0.36, ease: [0.16, 1, 0.3, 1] },\n        opacity: { duration: 0.26, ease: \"easeOut\" },\n      };\n\n  const liftTransition: Transition = reducedMotion\n    ? { duration: 0 }\n    : { type: \"spring\", stiffness: 420, damping: 34, mass: 0.7 };\n\n  const chevronTransition: Transition = reducedMotion\n    ? { duration: 0 }\n    : { type: \"spring\", stiffness: 460, damping: 30 };\n\n  return (\n    <section\n      aria-labelledby={heading == null ? undefined : headingId}\n      style={{ [\"--fold-accent\" as string]: accent }}\n      className={cn(\"w-full\", className)}\n      {...props}\n    >\n      {heading != null ? (\n        <h2\n          id={headingId}\n          className=\"text-balance text-2xl font-semibold tracking-tight text-white sm:text-3xl\"\n        >\n          {heading}\n        </h2>\n      ) : null}\n\n      <div className={cn(\"flex flex-col gap-2.5\", heading != null && \"mt-8\")}>\n        {items.map((item, index) => {\n          const open = openIndexes.includes(index);\n          const triggerId = `${baseId}-trigger-${index}`;\n          const panelId = `${baseId}-panel-${index}`;\n\n          return (\n            <motion.div\n              key={index}\n              initial={false}\n              animate={{\n                y: open ? -2 : 0,\n                scale: open ? 1.006 : 1,\n                borderColor: open ? \"rgba(255,255,255,0.16)\" : \"rgba(255,255,255,0.08)\",\n                backgroundColor: open ? \"rgba(255,255,255,0.05)\" : \"rgba(255,255,255,0.02)\",\n                boxShadow: open\n                  ? \"0 12px 30px -14px rgba(0,0,0,0.7)\"\n                  : \"0 0 0 0 rgba(0,0,0,0)\",\n              }}\n              transition={liftTransition}\n              className=\"relative overflow-hidden rounded-xl border\"\n            >\n              {/* Hairline accent seam down the open row's left edge. */}\n              <motion.span\n                aria-hidden\n                initial={false}\n                animate={{ opacity: open ? 1 : 0 }}\n                transition={{ duration: reducedMotion ? 0 : 0.4, ease: \"easeOut\" }}\n                className=\"pointer-events-none absolute inset-y-2.5 left-0 w-px\"\n                style={{\n                  background:\n                    \"linear-gradient(to bottom, transparent, var(--fold-accent) 28%, var(--fold-accent) 72%, transparent)\",\n                }}\n              />\n\n              <h3 className=\"m-0\">\n                <button\n                  ref={(el) => {\n                    triggerRefs.current[index] = el;\n                  }}\n                  type=\"button\"\n                  id={triggerId}\n                  aria-expanded={open}\n                  aria-controls={panelId}\n                  onClick={() => toggle(index)}\n                  onKeyDown={(event) => handleKeyDown(event, index)}\n                  className={cn(\n                    \"flex w-full items-center justify-between gap-4 px-5 py-4 text-left\",\n                    \"text-[15px] font-medium text-white/90 transition-colors hover:text-white\",\n                    \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--fold-accent)] focus-visible:ring-inset\"\n                  )}\n                >\n                  <span className=\"min-w-0\">{item.question}</span>\n\n                  <motion.svg\n                    viewBox=\"0 0 16 16\"\n                    aria-hidden=\"true\"\n                    className=\"h-4 w-4 shrink-0\"\n                    initial={false}\n                    animate={{\n                      rotate: open ? 180 : 0,\n                      color: open ? \"var(--fold-accent)\" : \"#8a8a8a\",\n                    }}\n                    transition={chevronTransition}\n                  >\n                    <path\n                      d=\"M4 6l4 4 4-4\"\n                      fill=\"none\"\n                      stroke=\"currentColor\"\n                      strokeWidth=\"1.6\"\n                      strokeLinecap=\"round\"\n                      strokeLinejoin=\"round\"\n                    />\n                  </motion.svg>\n                </button>\n              </h3>\n\n              <AnimatePresence initial={false}>\n                {open ? (\n                  <motion.div\n                    key=\"panel\"\n                    id={panelId}\n                    role=\"region\"\n                    aria-labelledby={triggerId}\n                    initial={{ height: 0, opacity: 0 }}\n                    animate={{ height: \"auto\", opacity: 1 }}\n                    exit={{ height: 0, opacity: 0 }}\n                    transition={panelTransition}\n                    className=\"overflow-hidden\"\n                    style={{ perspective: 900 }}\n                  >\n                    <motion.div\n                      initial={reducedMotion ? false : { rotateX: -14, opacity: 0 }}\n                      animate={{ rotateX: 0, opacity: 1 }}\n                      exit={reducedMotion ? undefined : { rotateX: -8, opacity: 0 }}\n                      transition={\n                        reducedMotion\n                          ? { duration: 0 }\n                          : { duration: 0.34, ease: [0.16, 1, 0.3, 1] }\n                      }\n                      style={{ transformOrigin: \"top center\" }}\n                      className=\"px-5 pb-4.5 pt-0 text-sm leading-relaxed text-neutral-400\"\n                    >\n                      {item.answer}\n                    </motion.div>\n                  </motion.div>\n                ) : null}\n              </AnimatePresence>\n            </motion.div>\n          );\n        })}\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}