{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "faq-topics",
  "title": "FAQ topics",
  "description": "A landing page’s questions sorted into topics under a centred heading: tabs pick a topic, its questions sit in cards with one answer open at a time, and the list’s height follows the topic.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/accordion.json",
    "https://kinoui.com/r/avatar.json",
    "https://kinoui.com/r/controllable.json",
    "https://kinoui.com/r/faq-parts.json",
    "https://kinoui.com/r/link-target.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/section-heading.json",
    "https://kinoui.com/r/tabs.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/faq-topics/faq-topics.tsx",
      "content": "'use client'\n\nimport {\n  Accordion,\n  AccordionPanel,\n  AccordionItem,\n  AccordionTrigger,\n} from '@/registry/components/kino/accordion'\nimport { Tabs, TabsPanel, TabsList, TabsTab } from '@/registry/components/kino/tabs'\nimport { useControllable } from '@/registry/lib/controllable'\nimport {\n  faqAnswerClassName,\n  faqColumnClassName,\n  type FaqSectionProps,\n  type FaqQuestion,\n  faqQuestionClassName,\n  faqSectionClassName,\n} from '@/registry/lib/faq-parts'\nimport { linkTargetClassName, useLinkTarget } from '@/registry/lib/link-target'\nimport { followHeight, runningTransitions } from '@/registry/lib/resize'\nimport { HEADING_BELOW, SectionHeading } from '@/registry/lib/section-heading'\nimport { type ReactNode, useCallback, useEffect, useId, useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A landing page's questions sorted into topics: the heading, the topics as\n * tabs under it, and the picked topic's questions as cards, one open at a\n * time. The list moves to the height of the topic picked, so what sits under\n * it glides rather than jumps. A link to a question opens its topic first.\n *\n *   <FaqTopics\n *     title='Questions, answered.'\n *     topics={[{ value: 'billing', label: 'Billing', questions: [{ value: 'cancel', question: 'Can we cancel at any time?', answer: '…' }] }]}\n *   />\n */\n\n/** A group of questions under a name, such as Billing. */\ninterface FaqTopic {\n  /** Tells the topics apart, and names a picked one. */\n  value: string\n  label: string\n  /** Before the label. */\n  icon?: ReactNode\n  questions: FaqQuestion[]\n}\n\ninterface FaqTopicsProps extends FaqSectionProps {\n  topics: FaqTopic[]\n  /** The topic shown, by its `value`. */\n  topic?: string\n  /** The topic shown at first: the first, unless you give another. */\n  defaultTopic?: string\n  onTopicChange?: (topic: string) => void\n  /** The open question, by its `value`: one at most. */\n  value?: string[]\n  /** The question open at first: none, unless you give one. */\n  defaultValue?: string[]\n  onValueChange?: (value: string[]) => void\n}\n\nfunction FaqTopics({\n  title,\n  description,\n  eyebrow,\n  heading = 'h2',\n  contact,\n  topics,\n  topic: topicProp,\n  defaultTopic,\n  onTopicChange,\n  value: valueProp,\n  defaultValue,\n  onValueChange,\n  className,\n  ...props\n}: FaqTopicsProps) {\n  const titleId = useId()\n  const ref = useRef<HTMLElement>(null)\n  const [topic, setTopic] = useControllable(\n    topicProp,\n    defaultTopic ?? topics[0]?.value ?? '',\n    onTopicChange,\n  )\n  const [open, setOpen] = useControllable(valueProp, defaultValue ?? [], onValueChange)\n  const topicOf = useCallback(\n    (value: string) =>\n      topics.find((each) => each.questions.some((question) => question.value === value)),\n    [topics],\n  )\n  useLinkTarget(\n    ref,\n    useCallback((value: string) => topicOf(value) !== undefined, [topicOf]),\n    useCallback(\n      (value: string) => {\n        const linked = topicOf(value)\n        if (linked) setTopic(linked.value)\n        setOpen([value])\n      },\n      [topicOf, setTopic, setOpen],\n    ),\n  )\n\n  // The list moves to the height of the topic picked. While an answer opens\n  // or closes, the Accordion moves it already, so the list takes its height\n  // as it goes.\n  const frameRef = useRef<HTMLDivElement>(null)\n  const innerRef = useRef<HTMLDivElement>(null)\n  useEffect(() => {\n    const frame = frameRef.current\n    const inner = innerRef.current\n    if (!frame || !inner) return\n    return followHeight(frame, inner, {\n      // A glide under way goes on from where it is, to the new height.\n      instant: () =>\n        runningTransitions(frame, { property: 'height' }).length === 0 &&\n        runningTransitions(inner, { property: 'height', subtree: true }).length > 0,\n    })\n  }, [])\n\n  return (\n    <section\n      ref={ref}\n      data-slot='faq-topics'\n      aria-labelledby={titleId}\n      className={cn(faqSectionClassName, className)}\n      {...props}\n    >\n      <div className={cn(faqColumnClassName, 'flex flex-col items-center gap-10')}>\n        <SectionHeading\n          id={titleId}\n          eyebrow={eyebrow}\n          title={title}\n          description={description}\n          heading={heading}\n        />\n        <Tabs\n          value={topic}\n          onValueChange={(next) => setTopic(String(next))}\n          // Every topic's questions stay in the page, for the browser's find.\n          hiddenUntilFound\n          className='flex w-full max-w-3xl min-w-0 flex-col items-center gap-6'\n        >\n          {/* One topic needs no tabs. */}\n          {topics.length > 1 ? (\n            <TabsList aria-labelledby={titleId} className='self-center'>\n              {topics.map((each) => (\n                <TabsTab key={each.value} value={each.value}>\n                  {each.icon}\n                  <bdi>{each.label}</bdi>\n                </TabsTab>\n              ))}\n            </TabsList>\n          ) : null}\n          {/* Clipped down the page only, so the cards' shadows keep their sides, with a ring's room above. */}\n          <div\n            ref={frameRef}\n            className='-mt-0.75 -mb-4 w-full min-w-0 overflow-y-clip pt-0.75 pb-4 transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none'\n          >\n            <div ref={innerRef} className='flex min-w-0 flex-col'>\n              {topics.map((each) => (\n                <TabsPanel\n                  key={each.value}\n                  value={each.value}\n                  // Its ring inside, where the list's clip can't cut it.\n                  className='focus-visible:ring-inset'\n                >\n                  <Accordion\n                    variant='card'\n                    hiddenUntilFound\n                    heading={HEADING_BELOW[heading]}\n                    value={open}\n                    onValueChange={(next) => setOpen(next.map(String))}\n                  >\n                    {each.questions.map((question) => (\n                      <AccordionItem\n                        key={question.value}\n                        value={question.value}\n                        data-link-target={question.value}\n                        className={linkTargetClassName}\n                      >\n                        <AccordionTrigger\n                          data-link-focus=''\n                          className='py-4 [&>svg]:mt-1'\n                        >\n                          <span className={cn(faqQuestionClassName, 'min-w-0 flex-1')}>\n                            <bdi>{question.question}</bdi>\n                          </span>\n                        </AccordionTrigger>\n                        <AccordionPanel className={cn(faqAnswerClassName, 'pe-10')}>\n                          {question.answer}\n                        </AccordionPanel>\n                      </AccordionItem>\n                    ))}\n                  </Accordion>\n                </TabsPanel>\n              ))}\n            </div>\n          </div>\n        </Tabs>\n        {contact ? (\n          <div className='flex w-full max-w-3xl min-w-0 justify-center'>{contact}</div>\n        ) : null}\n      </div>\n    </section>\n  )\n}\n\nexport { type FaqTopic, FaqTopics, type FaqTopicsProps }\n",
      "type": "registry:component",
      "target": "@components/kino/faq-topics/faq-topics.tsx"
    }
  ],
  "type": "registry:block"
}