{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "accordion-height",
  "title": "Accordion height",
  "description": "Accordion whose panels spring open to their real height (motion height:auto) with a rotating chevron, in single or multiple mode, with arrow-key, Home and End navigation between headers.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/lists/accordion-height.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { ChevronDown } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\nexport type AccordionHeightItem = {\n  /** Unique id of the item; this is what `value` and `onValueChange` hold. */\n  value: string\n  /** Header text, rendered inside the trigger button. */\n  title: React.ReactNode\n  /** Optional second line under the title. */\n  description?: React.ReactNode\n  /** Icon shown in a tile before the title. */\n  icon?: React.ReactNode\n  /** Panel body, mounted only while the item is open. */\n  content: React.ReactNode\n  /** Disables the trigger and skips it in arrow-key navigation. */\n  disabled?: boolean\n}\n\nexport type AccordionHeightProps = Omit<React.ComponentProps<\"div\">, \"defaultValue\" | \"onChange\"> & {\n  /** The sections, in order. */\n  items: AccordionHeightItem[]\n  /** \"single\" keeps one item open at a time, \"multiple\" lets any number stay open. */\n  type?: \"single\" | \"multiple\"\n  /** Open item values (controlled). */\n  value?: string[]\n  /** Item values open on first render (uncontrolled). */\n  defaultValue?: string[]\n  /** Called with the new list of open item values whenever an item opens or closes. */\n  onValueChange?: (value: string[]) => void\n  /** In single mode, clicking the open item closes it. */\n  collapsible?: boolean\n  /** \"bordered\": one card with dividers. \"separated\": a card per item. \"ghost\": dividers only. */\n  variant?: \"bordered\" | \"separated\" | \"ghost\"\n}\n\nfunction useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (v: T) => void) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const controlled = value !== undefined\n  const current = controlled ? value : inner\n  const set = React.useCallback(\n    (next: T) => {\n      if (!controlled) setInner(next)\n      onChange?.(next)\n    },\n    [controlled, onChange],\n  )\n  return [current, set] as const\n}\n\n/** Accordion whose panels open to their natural height with a spring, never a fixed max-height hack. */\nexport function AccordionHeight({\n  items,\n  type = \"single\",\n  value: valueProp,\n  defaultValue = [],\n  onValueChange,\n  collapsible = true,\n  variant = \"bordered\",\n  className,\n  ...props\n}: AccordionHeightProps) {\n  const reduce = useReducedMotion() ?? false\n  const baseId = React.useId()\n  const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)\n  const triggers = React.useRef<(HTMLButtonElement | null)[]>([])\n\n  const toggle = (v: string) => {\n    const isOpen = value.includes(v)\n    if (type === \"multiple\") setValue(isOpen ? value.filter((x) => x !== v) : [...value, v])\n    else setValue(isOpen ? (collapsible ? [] : value) : [v])\n  }\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {\n    const enabled = triggers.current.filter((el): el is HTMLButtonElement => !!el && !el.disabled)\n    const i = enabled.indexOf(e.currentTarget)\n    let next: HTMLButtonElement | undefined\n    if (e.key === \"ArrowDown\") next = enabled[(i + 1) % enabled.length]\n    else if (e.key === \"ArrowUp\") next = enabled[(i - 1 + enabled.length) % enabled.length]\n    else if (e.key === \"Home\") next = enabled[0]\n    else if (e.key === \"End\") next = enabled[enabled.length - 1]\n    if (next) {\n      e.preventDefault()\n      next.focus()\n    }\n  }\n\n  const height = reduce ? { duration: 0 } : { type: \"spring\" as const, bounce: 0, duration: 0.38 }\n  const fade = reduce ? { duration: 0 } : { duration: 0.22 }\n  const rotate = reduce ? { duration: 0 } : spring.ui\n\n  return (\n    <div\n      data-slot=\"accordion\"\n      className={cn(\n        \"w-full text-sm\",\n        variant === \"bordered\" && \"divide-y rounded-xl border bg-card text-card-foreground\",\n        variant === \"separated\" && \"flex flex-col gap-2\",\n        variant === \"ghost\" && \"divide-y\",\n        className,\n      )}\n      {...props}\n    >\n      <GooduiTokens />\n      {items.map((item, i) => {\n        const open = value.includes(item.value)\n        const triggerId = `${baseId}-trigger-${i}`\n        const panelId = `${baseId}-panel-${i}`\n        const last = i === items.length - 1\n        return (\n          <div\n            key={item.value}\n            data-state={open ? \"open\" : \"closed\"}\n            className={cn(\n              variant === \"separated\" &&\n                \"rounded-xl border bg-card text-card-foreground transition-shadow duration-300 data-[state=open]:shadow-[var(--pc-e2)] data-[state=open]:shadow-black/5\",\n            )}\n          >\n            <h3 className=\"m-0 flex text-sm\">\n              <button\n                ref={(el) => {\n                  triggers.current[i] = el\n                }}\n                id={triggerId}\n                type=\"button\"\n                aria-expanded={open}\n                // Only point at the panel while it is mounted; a closed panel is removed from the DOM.\n                aria-controls={open ? panelId : undefined}\n                disabled={item.disabled}\n                onClick={() => toggle(item.value)}\n                onKeyDown={onKeyDown}\n                className={cn(\n                  \"pc-press pc-press-soft flex w-full items-center gap-3 px-4 py-3.5 text-start font-medium transition-colors outline-none hover:bg-muted/40 focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50\",\n                  variant === \"ghost\" && \"px-1 hover:bg-transparent hover:text-foreground/80\",\n                  variant === \"separated\" && \"rounded-xl\",\n                  variant === \"bordered\" && i === 0 && \"rounded-t-xl\",\n                  variant === \"bordered\" && last && !open && \"rounded-b-xl\",\n                )}\n              >\n                {item.icon && (\n                  <span\n                    className={cn(\n                      \"flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors duration-300 [&_svg]:size-4\",\n                      open && \"bg-primary text-primary-foreground\",\n                    )}\n                    aria-hidden=\"true\"\n                  >\n                    {item.icon}\n                  </span>\n                )}\n                <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                  <span className=\"truncate\">{item.title}</span>\n                  {item.description && (\n                    <span className=\"truncate text-xs font-normal text-muted-foreground\">{item.description}</span>\n                  )}\n                </span>\n                <motion.span\n                  aria-hidden=\"true\"\n                  className=\"flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground\"\n                  initial={false}\n                  animate={{ rotate: open ? 180 : 0 }}\n                  transition={rotate}\n                >\n                  <ChevronDown className=\"size-4\" />\n                </motion.span>\n              </button>\n            </h3>\n            <AnimatePresence initial={false}>\n              {open && (\n                <motion.div\n                  key=\"panel\"\n                  id={panelId}\n                  role=\"region\"\n                  aria-labelledby={triggerId}\n                  className=\"overflow-hidden\"\n                  initial={{ height: 0, opacity: 0 }}\n                  animate={{ height: \"auto\", opacity: 1, transition: { height, opacity: fade } }}\n                  exit={{ height: 0, opacity: 0, transition: { height, opacity: { ...fade, duration: reduce ? 0 : 0.16 } } }}\n                >\n                  <motion.div\n                    className={cn(\n                      \"pb-4 text-muted-foreground\",\n                      variant === \"ghost\" ? \"px-1\" : \"px-4\",\n                      item.icon && variant !== \"ghost\" && \"sm:ps-15\",\n                    )}\n                    initial={reduce ? false : { y: -8 }}\n                    animate={{ y: 0 }}\n                    exit={reduce ? undefined : { y: -6 }}\n                    transition={reduce ? { duration: 0 } : { type: \"spring\", bounce: 0, duration: 0.38 }}\n                  >\n                    {item.content}\n                  </motion.div>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n        )\n      })}\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/accordion-height.tsx"
    }
  ],
  "categories": [
    "components",
    "lists"
  ],
  "type": "registry:component"
}