{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"accordion","type":"registry:ui","title":"Accordion","description":"Sections that open with an animated height, one at a time or several together.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/accordion.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { useId, useRef, useState, type KeyboardEvent, type ReactNode } from \"react\";\n\nexport type AccordionItem = {\n  id: string;\n  title: ReactNode;\n  content: ReactNode;\n  disabled?: boolean;\n};\n\ntype AccordionProps = {\n  items: AccordionItem[];\n  /** \"single\" keeps one section open at a time, \"multiple\" lets any number open. */\n  type?: \"single\" | \"multiple\";\n  /** Section ids open on first render, when uncontrolled. */\n  defaultOpen?: string | string[];\n  /** Open section ids, for controlled use. */\n  value?: string[];\n  onValueChange?: (open: string[]) => void;\n  /** In single mode, whether the open section can be closed again. */\n  collapsible?: boolean;\n  className?: string;\n};\n\nconst toList = (v: string | string[] | undefined) => (v === undefined ? [] : Array.isArray(v) ? v : [v]);\n\n/** Sections that open with an animated height and a rotating chevron. */\nexport function Accordion({\n  items,\n  type = \"single\",\n  defaultOpen,\n  value,\n  onValueChange,\n  collapsible = true,\n  className = \"\",\n}: AccordionProps) {\n  const uid = useId();\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLDivElement>(null);\n  const [internal, setInternal] = useState<string[]>(() => {\n    const list = toList(defaultOpen);\n    return type === \"single\" ? list.slice(0, 1) : list;\n  });\n  const open = value ?? internal;\n\n  function toggle(id: string) {\n    let next: string[];\n    if (open.includes(id)) {\n      if (type === \"single\" && !collapsible) return;\n      next = open.filter((x) => x !== id);\n    } else {\n      next = type === \"single\" ? [id] : [...open, id];\n    }\n    if (value === undefined) setInternal(next);\n    onValueChange?.(next);\n  }\n\n  // Arrow keys, Home and End move between section headers.\n  function onKeyDown(e: KeyboardEvent<HTMLButtonElement>) {\n    const keys = [\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"];\n    if (!keys.includes(e.key)) return;\n    const triggers = Array.from(rootRef.current?.querySelectorAll<HTMLButtonElement>(\"[data-accordion-trigger]:not([disabled])\") ?? []);\n    const current = triggers.indexOf(e.currentTarget);\n    const next =\n      e.key === \"ArrowDown\"\n        ? triggers[(current + 1) % triggers.length]\n        : e.key === \"ArrowUp\"\n          ? triggers[(current - 1 + triggers.length) % triggers.length]\n          : e.key === \"Home\"\n            ? triggers[0]\n            : triggers[triggers.length - 1];\n    e.preventDefault();\n    next?.focus();\n  }\n\n  const height = reduce\n    ? { duration: 0 }\n    : { height: { type: \"spring\" as const, stiffness: 320, damping: 36 }, opacity: { duration: 0.2 } };\n\n  return (\n    <div\n      ref={rootRef}\n      className={`divide-y divide-ink-700 overflow-hidden rounded-3xl border border-ink-600 bg-ink-900 ${className}`}\n    >\n      {items.map((item) => {\n        const isOpen = open.includes(item.id);\n        const triggerId = `${uid}-trigger-${item.id}`;\n        const panelId = `${uid}-panel-${item.id}`;\n        return (\n          <div key={item.id}>\n            <h3>\n              <button\n                id={triggerId}\n                type=\"button\"\n                data-accordion-trigger=\"\"\n                aria-expanded={isOpen}\n                aria-controls={panelId}\n                disabled={item.disabled}\n                onClick={() => toggle(item.id)}\n                onKeyDown={onKeyDown}\n                className={`flex w-full items-center gap-4 px-5 py-4 text-left font-display text-[15px] font-bold transition-colors focus-visible:-outline-offset-2 disabled:cursor-not-allowed disabled:opacity-40 ${\n                  isOpen ? \"text-bone\" : \"text-bone-muted hover:text-bone\"\n                }`}\n              >\n                <span className=\"flex-1\">{item.title}</span>\n                <motion.span\n                  aria-hidden=\"true\"\n                  initial={false}\n                  animate={{ rotate: isOpen ? 180 : 0 }}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 380, damping: 24 }}\n                  className={`grid size-7 shrink-0 place-items-center rounded-full border transition-colors ${\n                    isOpen ? \"border-ember/50 bg-ember/10 text-ember\" : \"border-ink-600 text-bone-dim\"\n                  }`}\n                >\n                  <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" className=\"size-3.5\">\n                    <path d=\"m4 6 4 4 4-4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                  </svg>\n                </motion.span>\n              </button>\n            </h3>\n            <AnimatePresence initial={false}>\n              {isOpen ? (\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={height}\n                  className=\"overflow-hidden\"\n                >\n                  <motion.div\n                    initial={reduce ? false : { y: -6 }}\n                    animate={{ y: 0 }}\n                    transition={{ duration: 0.25, ease: [0.22, 1, 0.36, 1] }}\n                    className=\"px-5 pb-5 text-sm leading-relaxed text-bone-muted\"\n                  >\n                    {item.content}\n                  </motion.div>\n                </motion.div>\n              ) : null}\n            </AnimatePresence>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n"}]}