{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"morph-menu","title":"Morph Menu","author":"CoDesign-Spa27","description":"A measured action menu that morphs between compact and expanded states with configurable directional movement.","dependencies":["lucide-react","motion","react-use-measure"],"files":[{"path":"components/ui-components/morph-menu.tsx","content":"\"use client\";\n\nimport { Plus, X } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type ReactNode, useId, useState } from \"react\";\nimport useMeasure from \"react-use-measure\";\n\nexport type MorphMenuDirection =\n  | \"top-left\"\n  | \"top\"\n  | \"top-right\"\n  | \"right\"\n  | \"bottom-right\"\n  | \"bottom\"\n  | \"bottom-left\"\n  | \"left\"\n  | \"center\";\n\nexport type MorphMenuItem = {\n  id: string;\n  title: string;\n  description: string;\n};\n\nexport type MorphMenuProps = {\n  direction?: MorphMenuDirection;\n  eyebrow?: string;\n  title?: string;\n  items?: readonly MorphMenuItem[];\n  menuWidth?: number;\n  triggerIcon?: ReactNode;\n  closeIcon?: ReactNode;\n  triggerLabel?: string;\n  closeLabel?: string;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  onItemSelect?: (item: MorphMenuItem) => void;\n  className?: string;\n};\n\nconst DEFAULT_ITEMS: readonly MorphMenuItem[] = [\n  {\n    id: \"project\",\n    title: \"New project\",\n    description: \"Start something from scratch\",\n  },\n  {\n    id: \"document\",\n    title: \"New document\",\n    description: \"Create a blank document\",\n  },\n  {\n    id: \"import\",\n    title: \"Import\",\n    description: \"Bring something into your workspace\",\n  },\n];\n\nconst TRIGGER_SIZE = 56;\n\nconst DIRECTION_OFFSETS: Record<MorphMenuDirection, readonly [number, number]> = {\n  \"top-left\": [-1, -1],\n  top: [-0.5, -1],\n  \"top-right\": [0, -1],\n  right: [0, -0.5],\n  \"bottom-right\": [0, 0],\n  bottom: [-0.5, 0],\n  \"bottom-left\": [-1, 0],\n  left: [-1, -0.5],\n  center: [-0.5, -0.5],\n};\n\nconst MORPH_SPRING = {\n  type: \"spring\",\n  duration: 0.3,\n  bounce: 0,\n} as const;\n\nconst REDUCED_MORPH_TRANSITION = { duration: 0 } as const;\n\nconst CONTENT_TRANSITION = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n} as const;\n\nconst PRESS_CLASSES =\n  \"transition-[background-color,transform] duration-[160ms] ease-[cubic-bezier(0.23,1,0.32,1)] active:scale-[0.97] motion-reduce:transform-none\";\n\nexport function MorphMenu({\n  direction = \"center\",\n  eyebrow = \"Create new\",\n  title = \"What would you like to add?\",\n  items = DEFAULT_ITEMS,\n  menuWidth = 360,\n  triggerIcon = <Plus className=\"size-5\" />,\n  closeIcon = <X className=\"size-4\" />,\n  triggerLabel = \"Open create menu\",\n  closeLabel = \"Close create menu\",\n  open: controlledOpen,\n  defaultOpen = false,\n  onOpenChange,\n  onItemSelect,\n  className,\n}: MorphMenuProps) {\n  const instanceId = useId();\n  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n  const [measureRef, bounds] = useMeasure();\n  const shouldReduceMotion = Boolean(useReducedMotion());\n  const open = controlledOpen ?? uncontrolledOpen;\n  const morphTransition = shouldReduceMotion ? REDUCED_MORPH_TRANSITION : MORPH_SPRING;\n  const contentTransform = shouldReduceMotion ? \"none\" : \"translateY(4px)\";\n  const iconLayoutId = `${instanceId}-bloom-icon`;\n  const contentId = `${instanceId}-bloom-menu-content`;\n\n  const width = bounds.width || TRIGGER_SIZE;\n  const height = bounds.height || TRIGGER_SIZE;\n  const [horizontalOffset, verticalOffset] = DIRECTION_OFFSETS[direction];\n  const x = (width - TRIGGER_SIZE) * horizontalOffset;\n  const y = (height - TRIGGER_SIZE) * verticalOffset;\n\n  function setOpen(nextOpen: boolean) {\n    if (controlledOpen === undefined) {\n      setUncontrolledOpen(nextOpen);\n    }\n\n    onOpenChange?.(nextOpen);\n  }\n\n  function selectItem(item: MorphMenuItem) {\n    onItemSelect?.(item);\n    setOpen(false);\n  }\n\n  return (\n    <div className={`relative size-14 shrink-0 ${className ?? \"\"}`}>\n      <motion.div\n        initial={false}\n        animate={{\n          width,\n          height,\n          transform: `translate3d(${x}px, ${y}px, 0)`,\n        }}\n        transition={morphTransition}\n        className=\"absolute left-0 top-0 overflow-hidden rounded-2xl bg-background text-foreground border\"\n      >\n        <div\n          ref={measureRef}\n          style={{ width: open ? menuWidth : TRIGGER_SIZE }}\n          className={`relative ${open ? \"\" : \"h-14\"}`}\n        >\n          <AnimatePresence initial={false} mode=\"popLayout\">\n            {!open ? (\n              <motion.div\n                key=\"trigger\"\n                initial={{ opacity: 0 }}\n                animate={{ opacity: 1 }}\n                exit={{ opacity: 0 }}\n                transition={CONTENT_TRANSITION}\n                className=\"size-14\"\n              >\n                <button\n                  type=\"button\"\n                  aria-expanded={false}\n                  aria-controls={contentId}\n                  aria-label={triggerLabel}\n                  onClick={() => setOpen(true)}\n                  className={`flex size-full items-center justify-center ${PRESS_CLASSES}`}\n                >\n                  <motion.span\n                    layoutId={iconLayoutId}\n                    transition={morphTransition}\n                    className=\"block\"\n                  >\n                    {triggerIcon}\n                  </motion.span>\n                </button>\n              </motion.div>\n            ) : (\n              <motion.div\n                key=\"menu\"\n                id={contentId}\n                initial={{ opacity: 0, transform: contentTransform, filter: \"blur(8px)\" }}\n                animate={{ opacity: 1, transform: \"none\", filter: \"blur(0px)\" }}\n                exit={{ opacity: 0, transform: contentTransform, filter: \"blur(8px)\" }}\n                transition={CONTENT_TRANSITION}\n                className=\"w-full px-2 py-2\"\n              >\n                <div className=\"flex items-start justify-between px-2 pt-2\">\n                  <div>\n                    <p className=\"text-sm text-neutral-400\">{eyebrow}</p>\n\n                    <h2 className=\"mt-1 text-xl font-medium\">{title}</h2>\n                  </div>\n\n                  <button\n                    type=\"button\"\n                    aria-label={closeLabel}\n                    onClick={() => setOpen(false)}\n                    className={`flex size-9 shrink-0 items-center justify-center rounded-xl bg-white/10 hover:bg-white/15 ${PRESS_CLASSES}`}\n                  >\n                    <motion.span\n                      layoutId={iconLayoutId}\n                      transition={morphTransition}\n                      className=\"block\"\n                    >\n                      {closeIcon}\n                    </motion.span>\n                  </button>\n                </div>\n\n                <div className=\"mt-6 space-y-2\">\n                  {items.map((item) => (\n                    <BloomItem key={item.id} item={item} onSelect={selectItem} />\n                  ))}\n                </div>\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n      </motion.div>\n    </div>\n  );\n}\n\nexport default MorphMenu;\n\nfunction BloomItem({\n  item,\n  onSelect,\n}: {\n  item: MorphMenuItem;\n  onSelect: (item: MorphMenuItem) => void;\n}) {\n  return (\n    <button\n      type=\"button\"\n      onClick={() => onSelect(item)}\n      className={`block w-full rounded-2xl bg-accent border px-4 py-3 text-left hover:bg-white/[0.1] ${PRESS_CLASSES}`}\n    >\n      <div className=\"text-sm font-medium\">{item.title}</div>\n\n      <div className=\"mt-0.5 text-xs text-neutral-400\">{item.description}</div>\n    </button>\n  );\n}\n","type":"registry:ui"}],"categories":["menu","interaction","animation"],"type":"registry:ui"}