'use client'; import type { AccordionMultipleProps, AccordionSingleProps, } from '@radix-ui/react-accordion'; import * as AccordionPrimitive from '@radix-ui/react-accordion'; import { Check, ChevronRight, Link as LinkIcon } from 'lucide-react'; import { type ComponentPropsWithoutRef, forwardRef, type ReactNode, useEffect, useRef, useState, } from 'react'; import { cn } from '../lib/cn'; import { useCopyButton } from 'fumadocs-ui/utils/use-copy-button'; import { buttonVariants } from './ui/button'; import { mergeRefs } from '../lib/merge-refs'; export const Accordions = forwardRef< HTMLDivElement, | Omit | Omit >(({ type = 'single', className, defaultValue, ...props }, ref) => { const rootRef = useRef(null); const composedRef = mergeRefs(ref, rootRef); const [value, setValue] = useState(() => type === 'single' ? (defaultValue ?? '') : (defaultValue ?? []), ); useEffect(() => { const id = window.location.hash.substring(1); const element = rootRef.current; if (!element || id.length === 0) return; const selected = document.getElementById(id); if (!selected || !element.contains(selected)) return; const value = selected.getAttribute('data-accordion-value'); if (value) setValue((prev) => (typeof prev === 'string' ? value : [value, ...prev])); }, []); return ( // @ts-expect-error -- Multiple types ); }); Accordions.displayName = 'Accordions'; export const Accordion = forwardRef< HTMLDivElement, Omit< ComponentPropsWithoutRef, 'value' | 'title' > & { title: string | ReactNode; value?: string; } >( ( { title, className, id, value = String(title), children, ...props }, ref, ) => { return ( {title} {id ? : null}
{children}
); }, ); function CopyButton({ id }: { id: string }) { const [checked, onClick] = useCopyButton(() => { const url = new URL(window.location.href); url.hash = id; return navigator.clipboard.writeText(url.toString()); }); return ( ); } Accordion.displayName = 'Accordion';