{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "expandable-card",
  "title": "Expandable card",
  "description": "A card expands in place on a spring to reveal details, such as a staff profile with bookable slots or a plan's full feature list.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/cards/expandable-card.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, ease, spring } from \"@/lib/goodui-motion\"\n\ntype Ctx = {\n  open: boolean\n  setOpen: (open: boolean) => void\n  contentId: string\n  triggerId: string\n  setTriggerId: (id: string) => void\n  triggerRef: React.RefObject<HTMLButtonElement | null>\n  reduce: boolean\n}\nconst ExpandableContext = React.createContext<Ctx | null>(null)\n\nfunction useExpandable(name: string) {\n  const ctx = React.useContext(ExpandableContext)\n  if (!ctx) throw new Error(`${name} must be used inside <ExpandableCard>`)\n  return ctx\n}\n\nexport type ExpandableCardProps = React.HTMLAttributes<HTMLDivElement> & {\n  /** Controlled open state. */\n  open?: boolean\n  /** Initial open state when uncontrolled. */\n  defaultOpen?: boolean\n  /** Called when the trigger or Esc opens or closes the card. */\n  onOpenChange?: (open: boolean) => void\n}\n\n/**\n * A card that expands in place: the content grows to its natural height on a spring and fades up, and the card\n * lifts slightly. Esc collapses it while focus is inside. Use with ExpandableCardTrigger and ExpandableCardContent.\n */\nexport function ExpandableCard({ open, defaultOpen = false, onOpenChange, className, onKeyDown, children, ...props }: ExpandableCardProps) {\n  const reduce = useReducedMotion() ?? false\n  const [inner, setInner] = React.useState(defaultOpen)\n  const isOpen = open ?? inner\n  const contentId = React.useId()\n  const [triggerId, setTriggerId] = React.useState(`${contentId}-trigger`)\n  const triggerRef = React.useRef<HTMLButtonElement | null>(null)\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (open === undefined) setInner(next)\n      onOpenChange?.(next)\n    },\n    [open, onOpenChange],\n  )\n\n  return (\n    <ExpandableContext.Provider value={{ open: isOpen, setOpen, contentId, triggerId, setTriggerId, triggerRef, reduce }}>\n      <GooduiTokens />\n      <div\n        data-state={isOpen ? \"open\" : \"closed\"}\n        className={cn(\n          \"rounded-[14px] bg-card text-card-foreground shadow-[var(--pc-e1)] transition-shadow duration-300 data-[state=open]:shadow-[var(--pc-e2)]\",\n          className,\n        )}\n        onKeyDown={(e) => {\n          if (e.key === \"Escape\" && isOpen) {\n            e.stopPropagation()\n            setOpen(false)\n            // The content unmounts, so focus inside it would be lost: return it to the trigger.\n            if (triggerRef.current && document.activeElement !== triggerRef.current) triggerRef.current.focus()\n          }\n          onKeyDown?.(e)\n        }}\n        {...props}\n      >\n        {children}\n      </div>\n    </ExpandableContext.Provider>\n  )\n}\n\nexport type ExpandableCardTriggerProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {\n  /** Show the rotating chevron on the right. */\n  chevron?: boolean\n}\n\n/** The always-visible header; a real button that toggles the card. */\nexport function ExpandableCardTrigger({ chevron = true, className, children, onClick, id, ...props }: ExpandableCardTriggerProps) {\n  const { open, setOpen, contentId, triggerId, setTriggerId, triggerRef, reduce } = useExpandable(\"ExpandableCardTrigger\")\n  // A custom id still names the content region (aria-labelledby).\n  React.useEffect(() => {\n    if (id) setTriggerId(id)\n  }, [id, setTriggerId])\n  return (\n    <button\n      ref={triggerRef}\n      id={id ?? triggerId}\n      type=\"button\"\n      aria-expanded={open}\n      aria-controls={contentId}\n      onClick={(e) => {\n        setOpen(!open)\n        onClick?.(e)\n      }}\n      className={cn(\n        \"pc-press pc-press-soft flex w-full items-center gap-3 rounded-[inherit] p-4 text-start outline-none focus-visible:ring-3 focus-visible:ring-ring/50\",\n        className,\n      )}\n      {...props}\n    >\n      <GooduiTokens />\n      <span className=\"min-w-0 flex-1\">{children}</span>\n      {chevron && (\n        <motion.span\n          aria-hidden=\"true\"\n          className=\"flex size-7 shrink-0 items-center justify-center rounded-full text-muted-foreground shadow-[var(--pc-e1)]\"\n          animate={{ rotate: open ? 180 : 0 }}\n          transition={reduce ? { duration: 0 } : spring.morph}\n        >\n          <ChevronDown className=\"size-4\" />\n        </motion.span>\n      )}\n    </button>\n  )\n}\n\nexport type ExpandableCardContentProps = React.HTMLAttributes<HTMLDivElement>\n\n/** The part that expands. Grows to its natural height (motion height: \"auto\"), then the inner content fades up. */\nexport function ExpandableCardContent({ className, children, ...props }: ExpandableCardContentProps) {\n  const { open, contentId, triggerId, reduce } = useExpandable(\"ExpandableCardContent\")\n  return (\n    <AnimatePresence initial={false}>\n      {open && (\n        <motion.div\n          key=\"content\"\n          id={contentId}\n          role=\"region\"\n          aria-labelledby={triggerId}\n          initial={{ height: 0, opacity: 0 }}\n          animate={{ height: \"auto\", opacity: 1 }}\n          exit={{ height: 0, opacity: 0 }}\n          transition={\n            reduce\n              ? { duration: 0 }\n              : { height: spring.morph, opacity: { duration: 0.14 } }\n          }\n          className=\"overflow-hidden\"\n        >\n          <motion.div\n            initial={reduce ? false : { y: -6, opacity: 0, filter: \"blur(4px)\" }}\n            animate={{ y: 0, opacity: 1, filter: \"blur(0px)\" }}\n            exit={reduce ? undefined : { y: -4, opacity: 0, filter: \"blur(4px)\", transition: { duration: 0.14 } }}\n            transition={reduce ? { duration: 0 } : { duration: 0.26, delay: 0.06, ease: ease.out }}\n            className={cn(\"px-4 pb-4\", className)}\n            {...(props as React.ComponentProps<typeof motion.div>)}\n          >\n            {children}\n          </motion.div>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/expandable-card.tsx"
    }
  ],
  "categories": [
    "components",
    "cards"
  ],
  "type": "registry:component"
}