{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "docs-accordion",
  "title": "Accordion",
  "description": "Accordions and Accordion: collapsible sections that open from the URL hash and have a copy-link button.",
  "dependencies": [
    "cn",
    "@fuma-translate/react@^1.0.2",
    "lucide-react"
  ],
  "registryDependencies": [
    "accordion",
    "button",
    "@docscn/docs-utils"
  ],
  "files": [
    {
      "path": "registry/base/docs/components/accordion.tsx",
      "content": "// Adapted from Fumadocs UI (https://github.com/fuma-nama/fumadocs)\n// Copyright (c) 2023 Fuma, MIT License\n\"use client\";\n\nimport { useTranslations } from \"@fuma-translate/react\";\nimport { cn } from \"cn\";\nimport { Check, LinkIcon } from \"lucide-react\";\nimport {\n  type ComponentProps,\n  type ReactNode,\n  useEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport {\n  AccordionContent,\n  AccordionItem,\n  Accordion as AccordionRoot,\n  AccordionTrigger,\n} from \"@/components/ui/accordion\";\nimport { Button } from \"@/components/ui/button\";\nimport { mergeRefs } from \"../utils/merge-refs\";\nimport { useCopyButton } from \"../utils/use-copy-button\";\n\ntype WithStringClassName<T> = Omit<T, \"className\"> & { className?: string };\n\nexport function Accordions({\n  ref,\n  className,\n  defaultValue,\n  ...props\n}: WithStringClassName<ComponentProps<typeof AccordionRoot>>) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const [value, setValue] = useState<unknown[]>(defaultValue ?? []);\n\n  // open the item the URL hash points to\n  useEffect(() => {\n    function openFromHash() {\n      const id = decodeURIComponent(window.location.hash.slice(1));\n      const element = rootRef.current;\n      if (!element || id.length === 0) return;\n\n      const selected = document.getElementById(id);\n      if (!selected || !element.contains(selected)) return;\n      const itemValue = selected.getAttribute(\"data-accordion-value\");\n      if (itemValue)\n        setValue((prev) =>\n          prev.includes(itemValue) ? prev : [itemValue, ...prev],\n        );\n    }\n\n    const frame = requestAnimationFrame(openFromHash);\n    window.addEventListener(\"hashchange\", openFromHash);\n    return () => {\n      cancelAnimationFrame(frame);\n      window.removeEventListener(\"hashchange\", openFromHash);\n    };\n  }, []);\n\n  return (\n    <AccordionRoot\n      ref={mergeRefs(ref, rootRef)}\n      value={value}\n      onValueChange={setValue}\n      className={cn(\n        \"my-4 overflow-hidden rounded-xl border bg-card\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport function Accordion({\n  title,\n  id,\n  value = String(title),\n  children,\n  className,\n  ...props\n}: Omit<\n  WithStringClassName<ComponentProps<typeof AccordionItem>>,\n  \"value\" | \"title\"\n> & {\n  title: string | ReactNode;\n  value?: string;\n}) {\n  return (\n    <AccordionItem\n      value={value}\n      id={id}\n      data-accordion-value={value}\n      // the header is an <h3>; keep docs-typeset heading styles off it\n      className={cn(\n        \"relative scroll-m-28 [&>h3]:m-0 [&>h3]:tracking-normal\",\n        className,\n      )}\n      {...props}\n    >\n      <AccordionTrigger className=\"px-4 py-3\">\n        {/* leave room for the copy button beside the chevron */}\n        <span className={cn(id && \"pe-8\")}>{title}</span>\n      </AccordionTrigger>\n      {id ? <CopyButton id={id} /> : null}\n      <AccordionContent hiddenUntilFound>\n        <div className=\"px-4 pb-2 text-[0.9375rem] *:first:mt-0 *:last:mb-0\">\n          {children}\n        </div>\n      </AccordionContent>\n    </AccordionItem>\n  );\n}\n\nfunction CopyButton({ id }: { id: string }) {\n  const t = useTranslations({ note: \"accordion\" });\n  const [checked, onClick] = useCopyButton(() => {\n    const url = new URL(window.location.href);\n    url.hash = id;\n\n    return navigator.clipboard.writeText(url.toString());\n  });\n\n  return (\n    <Button\n      type=\"button\"\n      variant=\"ghost\"\n      size=\"icon-xs\"\n      aria-live=\"polite\"\n      className=\"absolute end-10 top-2.5 text-muted-foreground\"\n      onClick={onClick}\n    >\n      {checked ? <Check /> : <LinkIcon />}\n      <span className=\"sr-only\">\n        {checked\n          ? t(\"Copied Link\", { note: \"aria-label\" })\n          : t(\"Copy Link\", { note: \"aria-label\" })}\n      </span>\n    </Button>\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/docs/components/accordion.tsx"
    }
  ],
  "type": "registry:component"
}