{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "expandable-row-list",
  "title": "Expandable row list",
  "description": "Appointment rows that open inline into a raised card with notes and working actions, while neighbouring rows smoothly make room.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/lists/expandable-row-list.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 as springs } from \"@/lib/goodui-motion\"\n\nexport type ExpandableRowListProps<T> = Omit<React.ComponentProps<\"ul\">, \"children\" | \"defaultValue\"> & {\n  /** Rows in display order. Adding or removing items animates the row height in or out. */\n  items: T[]\n  /** Stable unique key of a row. Any characters are fine: it is escaped before it goes into element ids. */\n  getKey: (item: T) => string\n  /** The always-visible summary of a row. Keep it free of buttons: the whole row is the toggle. */\n  renderRow: (item: T, state: { expanded: boolean }) => React.ReactNode\n  /** Details shown when the row opens. `collapse` closes it and returns focus to the row. */\n  renderDetails: (item: T, state: { collapse: () => void }) => React.ReactNode\n  /** \"single\" opens one row at a time. */\n  type?: \"single\" | \"multiple\"\n  /** Expanded row keys (controlled). */\n  value?: string[]\n  /** Row keys open on first render (uncontrolled). */\n  defaultValue?: string[]\n  /** Called with the new list of open row keys when a row opens or closes. */\n  onValueChange?: (value: string[]) => void\n  /** Space the open row lifts away from its neighbours, in px. */\n  gap?: number\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/** Turns a row key into a safe id fragment (no spaces or selector characters), keeping distinct keys distinct. */\nfunction idPart(key: string) {\n  return key.replace(/[^A-Za-z0-9-]/g, (c) => `_${c.charCodeAt(0).toString(36)}`)\n}\n\n/** List whose rows open inline into a lifted card with details, while neighbours make room smoothly. */\nexport function ExpandableRowList<T>({\n  items,\n  getKey,\n  renderRow,\n  renderDetails,\n  type = \"single\",\n  value: valueProp,\n  defaultValue = [],\n  onValueChange,\n  gap = 10,\n  className,\n  ...props\n}: ExpandableRowListProps<T>) {\n  const reduce = useReducedMotion() ?? false\n  const baseId = React.useId()\n  const [value, setValue] = useControllable(valueProp, defaultValue, onValueChange)\n  const triggers = React.useRef(new Map<string, HTMLButtonElement>())\n\n  const toggle = (key: string) => {\n    const open = value.includes(key)\n    if (type === \"multiple\") setValue(open ? value.filter((v) => v !== key) : [...value, key])\n    else setValue(open ? [] : [key])\n  }\n  const collapse = (key: string) => {\n    setValue(value.filter((v) => v !== key))\n    triggers.current.get(key)?.focus()\n  }\n\n  const onTriggerKey = (e: React.KeyboardEvent<HTMLButtonElement>, key: string) => {\n    const order = items.map(getKey)\n    const i = order.indexOf(key)\n    let target: string | undefined\n    if (e.key === \"ArrowDown\") target = order[Math.min(i + 1, order.length - 1)]\n    else if (e.key === \"ArrowUp\") target = order[Math.max(i - 1, 0)]\n    else if (e.key === \"Home\") target = order[0]\n    else if (e.key === \"End\") target = order[order.length - 1]\n    if (target) {\n      e.preventDefault()\n      triggers.current.get(target)?.focus()\n    }\n  }\n\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, bounce: 0.12, duration: 0.42 }\n  const quick = reduce ? { duration: 0 } : { duration: 0.18 }\n\n  return (\n    <ul className={cn(\"flex w-full flex-col\", className)} {...props}>\n      <GooduiTokens />\n      <AnimatePresence initial={false}>\n        {items.map((item) => {\n          const key = getKey(item)\n          const open = value.includes(key)\n          const panelId = `${baseId}-${idPart(key)}-panel`\n          const triggerId = `${baseId}-${idPart(key)}-trigger`\n          return (\n            <motion.li\n              key={key}\n              data-state={open ? \"open\" : \"closed\"}\n              initial={{ height: 0, opacity: 0 }}\n              animate={{ height: \"auto\", opacity: 1, marginTop: open ? gap / 2 : 0, marginBottom: open ? gap / 2 : 0 }}\n              exit={{ height: 0, opacity: 0, marginTop: 0, marginBottom: 0, transition: { ...spring, opacity: quick } }}\n              transition={spring}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\" && open) {\n                  e.stopPropagation()\n                  collapse(key)\n                }\n              }}\n              className={cn(\n                \"overflow-hidden rounded-xl border border-transparent transition-[background-color,box-shadow,border-color] duration-300\",\n                open ? \"border-border bg-card shadow-[var(--pc-e2)] shadow-black/5 dark:shadow-black/30\" : \"hover:bg-muted/50\",\n              )}\n            >\n              <button\n                ref={(el) => {\n                  if (el) triggers.current.set(key, el)\n                  else triggers.current.delete(key)\n                }}\n                id={triggerId}\n                type=\"button\"\n                aria-expanded={open}\n                aria-controls={open ? panelId : undefined}\n                onClick={() => toggle(key)}\n                onKeyDown={(e) => onTriggerKey(e, key)}\n                className=\"pc-press pc-press-soft flex w-full items-center gap-3 rounded-xl px-3 py-2.5 text-start outline-none focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset\"\n              >\n                <div className=\"min-w-0 flex-1\">{renderRow(item, { expanded: open })}</div>\n                <motion.span\n                  aria-hidden=\"true\"\n                  initial={false}\n                  animate={{ rotate: open ? 180 : 0 }}\n                  transition={reduce ? { duration: 0 } : springs.ui}\n                  className=\"flex size-6 shrink-0 items-center justify-center text-muted-foreground\"\n                >\n                  <ChevronDown className=\"size-4\" />\n                </motion.span>\n              </button>\n              <AnimatePresence initial={false}>\n                {open && (\n                  <motion.div\n                    key=\"details\"\n                    id={panelId}\n                    role=\"region\"\n                    aria-labelledby={triggerId}\n                    initial={{ height: 0, opacity: 0 }}\n                    animate={{ height: \"auto\", opacity: 1, transition: { height: spring, opacity: { ...quick, delay: reduce ? 0 : 0.06 } } }}\n                    exit={{ height: 0, opacity: 0, transition: { height: spring, opacity: quick } }}\n                  >\n                    <motion.div\n                      initial={reduce ? false : { y: -6 }}\n                      animate={{ y: 0 }}\n                      transition={spring}\n                      className=\"border-t px-3 py-3\"\n                    >\n                      {renderDetails(item, { collapse: () => collapse(key) })}\n                    </motion.div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </motion.li>\n          )\n        })}\n      </AnimatePresence>\n    </ul>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/expandable-row-list.tsx"
    }
  ],
  "categories": [
    "components",
    "lists"
  ],
  "type": "registry:component"
}