"use client"; import { useId, useState, type ReactNode } from "react"; import "./index-faq.css"; /** * Index FAQ * An accordion set like the index of a book. Each entry has a mono index * number, a serif question and a plus that rotates into a dash. Opening an * entry slides the answer open on a grid-rows reveal while a rule draws * under the question. One entry open at a time; arrows move between them. */ export type Faq = { q: string; a: ReactNode }; export function IndexFaq({ items, defaultOpen = 0 }: { items: Faq[]; defaultOpen?: number | null }) { const uid = useId(); const [open, setOpen] = useState(defaultOpen); const onKey = (e: React.KeyboardEvent, i: number) => { const btns = [...(e.currentTarget.closest("ol")?.querySelectorAll(".ifaq__q") ?? [])]; const to = e.key === "ArrowDown" ? (i + 1) % btns.length : e.key === "ArrowUp" ? (i - 1 + btns.length) % btns.length : e.key === "Home" ? 0 : e.key === "End" ? btns.length - 1 : null; if (to === null) return; e.preventDefault(); btns[to]?.focus(); }; return (
    {items.map((it, i) => { const isOpen = open === i; return (
  1. {it.a}
  2. ); })}
); }