{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "faq-section",
  "title": "FAQ Section",
  "description": "Searchable questions with accessible disclosure answers.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "collapsible",
    "https://uaiblocks.dev/r/uai-theme.json",
    "https://uaiblocks.dev/r/search-field.json",
    "https://uaiblocks.dev/r/uai-utils.json"
  ],
  "files": [
    {
      "path": "src/registry/uai/blocks/faq-section.tsx",
      "content": "\"use client\";\n\nimport { cva } from \"class-variance-authority\";\nimport { ChevronDown } from \"lucide-react\";\nimport {\n  type ComponentProps,\n  createContext,\n  useCallback,\n  useContext,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { Collapsible, CollapsibleTrigger } from \"@/components/ui/collapsible\";\nimport {\n  SearchField,\n  type SearchFieldProps,\n  type SearchFieldVariant,\n} from \"@/components/ui/uai/search-field\";\nimport { cn } from \"@/lib/uai-utils\";\n\nexport const FAQ_SECTION_VARIANTS = [\"list\", \"cards\", \"split\"] as const;\nexport type FaqSectionVariant = (typeof FAQ_SECTION_VARIANTS)[number];\nexport type FaqSectionProps = ComponentProps<\"section\"> & { variant?: FaqSectionVariant };\n\ntype SectionContext = {\n  id: string;\n  variant: FaqSectionVariant;\n  query: string;\n  setQuery: (query: string) => void;\n  visible: number;\n  report: (id: string, matches: boolean | null) => void;\n};\nconst Context = createContext<SectionContext | null>(null);\nfunction useSection(part: string) {\n  const context = useContext(Context);\n  if (!context) throw new Error(`${part} must be used within FaqSection`);\n  return context;\n}\ntype ItemContext = { id: string; open: boolean };\nconst ItemContext = createContext<ItemContext | null>(null);\nfunction useItem(part: string) {\n  const context = useContext(ItemContext);\n  if (!context) throw new Error(`${part} must be used within FaqSectionItem`);\n  return context;\n}\nconst useIsomorphicLayoutEffect = typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nconst faqSectionLayoutVariants = cva(\"grid min-w-0 items-start gap-5\", {\n  variants: {\n    variant: {\n      list: \"\",\n      cards: \"\",\n      split:\n        \"@min-[720px]:grid-cols-[minmax(0,1fr)_minmax(0,1.7fr)] @min-[720px]:gap-x-12 @min-[720px]:[&>:not([data-slot=faq-section-header])]:col-start-2\",\n    },\n  },\n});\n\nconst faqSectionItemVariants = cva(\"min-w-0 border-solid motion-reduce:transition-none\", {\n  variants: {\n    variant: {\n      list: \"rounded-none border-b bg-transparent p-0 last:border-b\",\n      cards:\n        \"rounded-[14px] border bg-card px-4 shadow-[0_1px_2px_oklch(0_0_0/0.04)] transition-[border-color] duration-120 ease-out last:border-b hover:border-border-strong\",\n      split: \"rounded-none border-b bg-transparent p-0 last:border-b\",\n    },\n  },\n});\n\nfunction normalize(text: string) {\n  return text.toLowerCase().replace(/\\s+/g, \" \").trim();\n}\n\n/** Searchable questions with disclosure answers. Split moves the header beside the list from 720px. */\nexport function FaqSection({ variant = \"list\", children, className, ...props }: FaqSectionProps) {\n  const id = useId();\n  const [query, setQuery] = useState(\"\");\n  const [matches, setMatches] = useState<Readonly<Record<string, boolean>>>({});\n  const report = useCallback((itemId: string, match: boolean | null) => {\n    setMatches((current) => {\n      if (match === null) {\n        if (!(itemId in current)) return current;\n        const { [itemId]: _removed, ...rest } = current;\n        return rest;\n      }\n      return current[itemId] === match ? current : { ...current, [itemId]: match };\n    });\n  }, []);\n  const visible = Object.values(matches).filter(Boolean).length;\n  return (\n    <Context.Provider value={{ id, variant, query, setQuery, visible, report }}>\n      <section\n        aria-labelledby={`${id}-title`}\n        data-slot=\"faq-section\"\n        data-variant={variant}\n        className={cn(\n          \"@container box-border min-w-0 text-[13px]/[18px] text-foreground\",\n          className,\n        )}\n        {...props}\n      >\n        <div className={faqSectionLayoutVariants({ variant })}>{children}</div>\n      </section>\n    </Context.Provider>\n  );\n}\n\nexport function FaqSectionHeader({ className, ...props }: ComponentProps<\"header\">) {\n  const { variant } = useSection(\"FaqSectionHeader\");\n  return (\n    <header\n      data-slot=\"faq-section-header\"\n      className={cn(\n        \"grid min-w-0 gap-2\",\n        variant === \"split\" && \"@min-[720px]:sticky @min-[720px]:top-4 @min-[720px]:row-[1/span_4]\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport function FaqSectionTitle({ className, ...props }: ComponentProps<\"h2\">) {\n  const { id } = useSection(\"FaqSectionTitle\");\n  return (\n    <h2\n      data-slot=\"faq-section-title\"\n      className={cn(\n        \"m-0 text-[length:clamp(22px,2.5cqi_+_12px,30px)] leading-[1.15] font-medium tracking-[-0.025em] text-balance\",\n        className,\n      )}\n      {...props}\n      id={`${id}-title`}\n    />\n  );\n}\n\nexport function FaqSectionDescription({ className, ...props }: ComponentProps<\"p\">) {\n  return (\n    <p\n      data-slot=\"faq-section-description\"\n      className={cn(\"m-0 text-[15px]/[23px] text-pretty text-muted-foreground\", className)}\n      {...props}\n    />\n  );\n}\n\nexport type FaqSectionSearchProps = Omit<\n  SearchFieldProps,\n  \"value\" | \"defaultValue\" | \"onValueChange\" | \"status\"\n>;\n\n/** A Search Field bound to the question filter. Compose the label, control, input, clear, and message inside. */\nexport function FaqSectionSearch({ variant, ...props }: FaqSectionSearchProps) {\n  const section = useSection(\"FaqSectionSearch\");\n  const fieldVariant: SearchFieldVariant =\n    variant ?? (section.variant === \"cards\" ? \"pill\" : \"rounded\");\n  return (\n    <SearchField\n      {...props}\n      variant={fieldVariant}\n      value={section.query}\n      onValueChange={section.setQuery}\n      status={section.query.trim() && section.visible === 0 ? \"empty\" : \"idle\"}\n    />\n  );\n}\n\nexport function FaqSectionList({ className, ...props }: ComponentProps<\"ul\">) {\n  const { variant } = useSection(\"FaqSectionList\");\n  return (\n    <ul\n      data-slot=\"faq-section-list\"\n      className={cn(\n        \"m-0 grid min-w-0 list-none p-0\",\n        variant === \"cards\" ? \"mt-0 gap-2 border-t-0\" : \"mt-1 gap-0 border-t\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type FaqSectionItemProps = ComponentProps<\"li\"> & {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n};\n\n/** One question. It hides itself when neither the question nor the answer matches the search. */\nexport function FaqSectionItem({\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  className,\n  ...props\n}: FaqSectionItemProps) {\n  const section = useSection(\"FaqSectionItem\");\n  const { report } = section;\n  const id = useId();\n  const ref = useRef<HTMLLIElement>(null);\n  const [internal, setInternal] = useState(defaultOpen);\n  const [hidden, setHidden] = useState(false);\n  const current = open ?? internal;\n  const query = normalize(section.query);\n  useIsomorphicLayoutEffect(() => {\n    const match = !query || normalize(ref.current?.textContent ?? \"\").includes(query);\n    setHidden(!match);\n    report(id, match);\n  }, [id, query, report]);\n  useEffect(() => () => report(id, null), [id, report]);\n  return (\n    <ItemContext.Provider value={{ id, open: current }}>\n      {/* Each question is its own disclosure. Collapsible's open/onOpenChange API is the same on\n          Radix and Base UI, where a single-item Accordion's value is a string on one and an array\n          on the other. */}\n      <Collapsible\n        asChild\n        open={current}\n        onOpenChange={(next) => {\n          if (open === undefined) setInternal(next);\n          onOpenChange?.(next);\n        }}\n      >\n        <li\n          data-slot=\"faq-section-item\"\n          data-variant={section.variant}\n          className={cn(\n            \"border-b last:border-b-0\",\n            faqSectionItemVariants({ variant: section.variant }),\n            className,\n          )}\n          {...props}\n          ref={ref}\n          hidden={hidden}\n        />\n      </Collapsible>\n    </ItemContext.Provider>\n  );\n}\n\nexport function FaqSectionQuestion({ children, className, ...props }: ComponentProps<\"button\">) {\n  const item = useItem(\"FaqSectionQuestion\");\n  return (\n    <h3 className=\"m-0 flex\">\n      <CollapsibleTrigger\n        data-slot=\"faq-section-question\"\n        className={cn(\n          \"flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium outline-none hover:underline focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-expanded:[&>svg]:rotate-180\",\n          \"group/faq-question min-h-13 w-full cursor-pointer items-center gap-3 rounded-[6px] border-0 bg-transparent py-3.5 text-start text-sm/5 font-medium text-foreground hover:no-underline focus-visible:ring-0 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring\",\n          \"[&>svg]:translate-y-0 [&>svg]:stroke-[1.75] [&>svg]:text-subtle-foreground [&>svg]:[transition:rotate_180ms_cubic-bezier(0.23,1,0.32,1),color_120ms_ease-out] hover:[&>svg]:text-foreground motion-reduce:[&>svg]:transition-none\",\n          className,\n        )}\n        {...props}\n        aria-controls={`${item.id}-answer`}\n      >\n        <span className=\"min-w-0\">{children}</span>\n        <ChevronDown\n          aria-hidden=\"true\"\n          className=\"pointer-events-none size-4 shrink-0 translate-y-0.5 text-muted-foreground\"\n        />\n      </CollapsibleTrigger>\n    </h3>\n  );\n}\n\n/**\n * The answer stays mounted while collapsed so the search can match its text. Its height eases\n * between 0fr and 1fr rows, `inert` takes the collapsing text out of focus and the a11y tree, and\n * `hidden` lands once the transition ends.\n */\nexport function FaqSectionAnswer({ className, children, ...props }: ComponentProps<\"div\">) {\n  const item = useItem(\"FaqSectionAnswer\");\n  const state = item.open ? \"open\" : \"closed\";\n  const ref = useRef<HTMLDivElement>(null);\n  const [rendered, setRendered] = useState(item.open);\n  useEffect(() => {\n    if (item.open) {\n      setRendered(true);\n      return;\n    }\n    // Without a running height transition (reduced motion, no CSS) the answer hides right away.\n    const node = ref.current;\n    const duration = node ? window.getComputedStyle(node).transitionDuration : \"\";\n    if (!duration || duration.split(\",\").every((value) => Number.parseFloat(value) === 0)) {\n      setRendered(false);\n    }\n  }, [item.open]);\n  return (\n    <div\n      ref={ref}\n      inert={!item.open}\n      onTransitionEnd={(event) => {\n        if (event.target === event.currentTarget && !item.open) setRendered(false);\n      }}\n      className={cn(\n        \"grid overflow-hidden text-sm transition-[grid-template-rows] duration-200 ease-out motion-reduce:transition-none\",\n        item.open ? \"grid-rows-[1fr]\" : \"grid-rows-[0fr]\",\n      )}\n    >\n      <div data-state={state} className=\"min-h-0\">\n        <div\n          data-slot=\"faq-section-answer\"\n          data-state={state}\n          className={cn(\n            \"grid max-w-[64ch] gap-2 pt-0 pb-4 text-[13px]/5 text-pretty text-muted-foreground\",\n            // The text fades with the height transition on its parent.\n            \"[[data-state=open]>&]:animate-in [[data-state=open]>&]:fade-in-0 [[data-state=open]>&]:duration-200 [[data-state=closed]>&]:animate-out [[data-state=closed]>&]:fade-out-0 [[data-state=closed]>&]:duration-150 motion-reduce:animate-none\",\n            className,\n          )}\n          {...props}\n          id={`${item.id}-answer`}\n          hidden={!item.open && !rendered}\n        >\n          {children}\n        </div>\n      </div>\n    </div>\n  );\n}\n\n/** Shown only while a search matches no questions. */\nexport function FaqSectionEmpty({ className, ...props }: ComponentProps<\"div\">) {\n  const section = useSection(\"FaqSectionEmpty\");\n  if (!section.query.trim() || section.visible > 0) return null;\n  return (\n    <div\n      data-slot=\"faq-section-empty\"\n      className={cn(\n        \"grid justify-items-start gap-2 rounded-[14px] bg-muted/60 p-4 text-muted-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "@components/uai/faq-section.tsx"
    }
  ],
  "categories": [
    "marketing",
    "faq"
  ],
  "type": "registry:block"
}