{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"spring-accordion","type":"registry:block","title":"Spring accordion","description":"A settings accordion whose rows open on a spring, the chevron turning as the panel unfolds.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/spring-accordion/spring-accordion.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useId, useRef, useState } from \"react\";\nimport {\n  MotionConfig,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\nconst SPRING = { type: \"spring\", stiffness: 320, damping: 33 } as const;\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type SpringAccordionItem = {\n  id: string;\n  title: string;\n  /** Short value shown at the right of the row, e.g. \"Admins\". */\n  meta?: string;\n  /** Main explanation, one or two sentences. */\n  body: string;\n  /** Optional smaller line under the body. */\n  footnote?: string;\n};\n\nexport type SpringAccordionProps = {\n  className?: string;\n  title?: string;\n  subtitle?: string;\n  items?: SpringAccordionItem[];\n  /** Id open on first render. Defaults to the first item. */\n  defaultOpen?: string;\n  /** Keep several rows open at once. Defaults to false. */\n  allowMultiple?: boolean;\n};\n\n/* ------------------------------------------------------------------ */\n/* deterministic demo data                                             */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_ITEMS: SpringAccordionItem[] = [\n  {\n    id: \"invites\",\n    title: \"Who can invite members\",\n    meta: \"Admins\",\n    body: \"Owners and admins can send invites directly. Members can request one, and the request lands in the admin queue with a short note from them.\",\n    footnote: \"Changed by Ama Mensah on 4 November.\",\n  },\n  {\n    id: \"sessions\",\n    title: \"Session lifetime\",\n    meta: \"12 hours\",\n    body: \"Every device is signed out after 12 hours of inactivity. Active sessions renew quietly while the tab stays open.\",\n    footnote: \"Shorter lifetimes also apply to shared devices.\",\n  },\n  {\n    id: \"retention\",\n    title: \"Data retention\",\n    meta: \"180 days\",\n    body: \"Events and request logs are kept for 180 days, then removed on the next nightly pass. Exports are not affected.\",\n  },\n  {\n    id: \"exports\",\n    title: \"Export permissions\",\n    meta: \"Owners\",\n    body: \"Only owners can export member data. Admins can download reports, but the raw customer table stays restricted.\",\n    footnote: \"Every export is written to the audit log.\",\n  },\n];\n\n/* ------------------------------------------------------------------ */\n/* row                                                                 */\n/* ------------------------------------------------------------------ */\n\ntype RowProps = {\n  item: SpringAccordionItem;\n  index: number;\n  open: boolean;\n  show: boolean;\n  reduce: boolean;\n  idBase: string;\n  onToggle: (id: string) => void;\n};\n\nfunction AccordionRow({\n  item,\n  index,\n  open,\n  show,\n  reduce,\n  idBase,\n  onToggle,\n}: RowProps) {\n  const buttonId = `${idBase}-button-${item.id}`;\n  const panelId = `${idBase}-panel-${item.id}`;\n\n  return (\n    <motion.li\n      initial={reduce ? false : { opacity: 0, y: 8 }}\n      animate={show ? { opacity: 1, y: 0 } : { opacity: 0, y: reduce ? 0 : 8 }}\n      transition={{\n        duration: reduce ? 0 : 0.45,\n        ease: EASE,\n        delay: reduce ? 0 : index * 0.05,\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-center gap-3 rounded-lg py-4 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\"\n        >\n          <span\n            className={cn(\n              \"min-w-0 flex-1 break-words text-[14px] font-medium leading-5 tracking-[-0.01em] transition-colors\",\n              open\n                ? \"text-foreground\"\n                : \"text-foreground/85 group-hover:text-foreground\"\n            )}\n          >\n            {item.title}\n          </span>\n\n          {item.meta ? (\n            <span className=\"hidden shrink-0 text-[12px] tabular-nums text-muted-foreground sm:inline\">\n              {item.meta}\n            </span>\n          ) : null}\n\n          <motion.span\n            aria-hidden=\"true\"\n            initial={false}\n            animate={{ rotate: open ? 180 : 0 }}\n            transition={reduce ? { duration: 0 } : SPRING}\n            className={cn(\n              \"grid h-6 w-6 shrink-0 place-items-center rounded-full border transition-colors\",\n              open\n                ? \"border-foreground/25 text-foreground\"\n                : \"border-border text-muted-foreground group-hover:border-muted-foreground/40 group-hover:text-foreground\"\n            )}\n          >\n            <ChevronDown className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n          </motion.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={{ height: open ? \"auto\" : 0, opacity: open ? 1 : 0 }}\n        transition={reduce ? { duration: 0 } : SPRING}\n        className=\"overflow-hidden\"\n      >\n        <div className=\"pb-4 pr-8 sm:pb-5 sm:pr-10\">\n          <p className=\"break-words text-[13px] leading-6 text-muted-foreground\">\n            {item.body}\n          </p>\n          {item.meta ? (\n            <p className=\"mt-1.5 text-[12px] tabular-nums text-muted-foreground sm:hidden\">\n              {item.meta}\n            </p>\n          ) : null}\n          {item.footnote ? (\n            <p className=\"mt-2 break-words text-[12px] leading-5 text-muted-foreground/80\">\n              {item.footnote}\n            </p>\n          ) : null}\n        </div>\n      </motion.div>\n    </motion.li>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function SpringAccordion({\n  className,\n  title = \"Workspace policies\",\n  subtitle = \"Changes apply to all 27 members.\",\n  items = DEFAULT_ITEMS,\n  defaultOpen,\n  allowMultiple = false,\n}: SpringAccordionProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const inView = useInView(rootRef, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n  const show = reduce || inView;\n\n  const uid = useId().replace(/:/g, \"\");\n  const idBase = `spring-accordion-${uid}`;\n\n  const [openIds, setOpenIds] = useState<string[]>(() => {\n    const initial =\n      defaultOpen && items.some((item) => item.id === defaultOpen)\n        ? [defaultOpen]\n        : items.length > 0\n          ? [items[0].id]\n          : [];\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  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={rootRef}\n        initial={reduce ? false : { opacity: 0, y: 16 }}\n        animate={\n          show ? { opacity: 1, y: 0 } : { opacity: 0, y: reduce ? 0 : 16 }\n        }\n        transition={{ duration: reduce ? 0 : 0.55, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card text-card-foreground shadow-sm\",\n          className\n        )}\n      >\n        <div className=\"p-5 sm:p-6\">\n          <div className=\"flex flex-wrap items-start justify-between gap-3\">\n            <div className=\"min-w-0\">\n              <h2 className=\"text-[15px] font-semibold tracking-tight\">\n                {title}\n              </h2>\n              <p className=\"mt-0.5 text-[13px] text-muted-foreground\">\n                {subtitle}\n              </p>\n            </div>\n            <span className=\"shrink-0 text-[12px] tabular-nums text-muted-foreground\">\n              {items.length} {items.length === 1 ? \"policy\" : \"policies\"}\n            </span>\n          </div>\n\n          {items.length > 0 ? (\n            <ul className=\"mt-4 border-t border-border\">\n              {items.map((item, index) => (\n                <AccordionRow\n                  key={item.id}\n                  item={item}\n                  index={index}\n                  open={openIds.includes(item.id)}\n                  show={show}\n                  reduce={reduce}\n                  idBase={idBase}\n                  onToggle={toggle}\n                />\n              ))}\n            </ul>\n          ) : (\n            <p className=\"mt-5 text-[13px] text-muted-foreground\">\n              No policies defined yet.\n            </p>\n          )}\n        </div>\n      </motion.div>\n    </MotionConfig>\n  );\n}\n\nexport default SpringAccordion;\n"}]}