{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"gooey-toolbar","title":"Gooey Toolbar","author":"CoDesign-Spa27","description":"A compact action toolbar with configurable liquid merging effects and accessible controls.","dependencies":["clsx","motion","nucleo-ui-essential-fill-duo-18","tailwind-merge"],"files":[{"path":"components/ui-components/gooey-toolbar.tsx","content":"\"use client\";\n\nimport { type ClassValue, clsx } from \"clsx\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport {\n  IconAlarmClockFillDuo18,\n  IconBellFillDuo18,\n  IconClipboardFillDuo18,\n  IconFacialRecognitionFillDuo18,\n  IconGamepadButtonsFillDuo18,\n  IconImages2FillDuo18,\n  IconPenNib3FillDuo18,\n  IconShapesFillDuo18,\n  IconShopFillDuo18,\n  IconTrashFillDuo18,\n} from \"nucleo-ui-essential-fill-duo-18\";\nimport { type CSSProperties, useEffect, useRef, useState } from \"react\";\n\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype GooeyToolbarVariant = \"peel\" | \"amoeba\";\n\ntype GooeyItem = {\n  id: string;\n  label: string;\n  icon: React.ComponentType<{ className?: string }>;\n};\n\ntype GooeyToolbarProps = {\n  variant?: GooeyToolbarVariant;\n  defaultVariant?: GooeyToolbarVariant;\n  showVariantToggle?: boolean;\n  className?: string;\n};\n\nconst filterId = \"gooey-toolbar-filter\";\n\nconst spring = {\n  type: \"spring\" as const,\n  stiffness: 300,\n  damping: 34,\n  mass: 0.8,\n};\n\nconst gooStyle = {\n  filter: `url(#${filterId})`,\n} satisfies CSSProperties;\n\nconst blobClass =\n  \"rounded-full bg-foreground text-background shadow-[0_12px_30px_-18px_rgb(0_0_0/0.7)] transition-colors hover:bg-foreground/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\";\n\nconst peelActions: GooeyItem[] = [\n  { id: \"edit\", label: \"Edit\", icon: IconPenNib3FillDuo18 },\n  { id: \"copy\", label: \"Copy\", icon: IconClipboardFillDuo18 },\n  { id: \"share\", label: \"Share\", icon: IconBellFillDuo18 },\n  { id: \"delete\", label: \"Delete\", icon: IconTrashFillDuo18 },\n];\n\nconst amoebaTools: GooeyItem[] = [\n  { id: \"shop\", label: \"Shop\", icon: IconShopFillDuo18 },\n  { id: \"images\", label: \"Images\", icon: IconImages2FillDuo18 },\n  { id: \"face\", label: \"Face\", icon: IconFacialRecognitionFillDuo18 },\n  { id: \"clock\", label: \"Clock\", icon: IconAlarmClockFillDuo18 },\n];\n\nfunction getArcPoint(\n  index: number,\n  total: number,\n  radius: number,\n  startAngle: number,\n  endAngle: number,\n) {\n  const angle =\n    total === 1\n      ? (startAngle + endAngle) / 2\n      : startAngle + ((endAngle - startAngle) / (total - 1)) * index;\n  const radians = (angle * Math.PI) / 180;\n\n  return {\n    x: Math.cos(radians) * radius,\n    y: Math.sin(radians) * radius,\n  };\n}\n\n// Simple minimalist toggle group instead of library toggle group\nfunction VariantToggle({\n  value,\n  onValueChange,\n}: {\n  value: GooeyToolbarVariant;\n  onValueChange: (value: GooeyToolbarVariant) => void;\n}) {\n  return (\n    <div\n      role=\"radiogroup\"\n      aria-label=\"Select gooey toolbar variant\"\n      className=\"inline-flex rounded-lg border bg-background p-0.5 gap-0.5 shadow-xs\"\n    >\n      <button\n        type=\"button\"\n        role=\"radio\"\n        aria-checked={value === \"peel\"}\n        aria-label=\"Use peel toolbar\"\n        className={cn(\n          \"h-7 rounded-md px-3 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n          value === \"peel\"\n            ? \"bg-accent text-foreground\"\n            : \"bg-transparent text-foreground/60 hover:bg-foreground/10\",\n        )}\n        onClick={() => onValueChange(\"peel\")}\n        tabIndex={0}\n      >\n        Peel\n      </button>\n      <button\n        type=\"button\"\n        role=\"radio\"\n        aria-checked={value === \"amoeba\"}\n        aria-label=\"Use amoeba toolbar\"\n        className={cn(\n          \"h-7 rounded-md px-3 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\",\n          value === \"amoeba\"\n            ? \"bg-accent text-foreground\"\n            : \"bg-transparent text-foreground/60 hover:bg-foreground/10\",\n        )}\n        onClick={() => onValueChange(\"amoeba\")}\n        tabIndex={0}\n      >\n        Amoeba\n      </button>\n    </div>\n  );\n}\n\nfunction PeelToolbar() {\n  const [isOpen, setIsOpen] = useState(false);\n  const [activeId, setActiveId] = useState<string | null>(null);\n\n  return (\n    <div className=\"relative h-48 w-72\">\n      <div className=\"absolute inset-0\" style={gooStyle}>\n        <div className=\"absolute right-2 top-1/2 z-10 -translate-y-1/2\">\n          <motion.button\n            aria-expanded={isOpen}\n            aria-label={isOpen ? \"Close peel toolbar\" : \"Open peel toolbar\"}\n            animate={{ scale: 1 }}\n            className={cn(blobClass, \"flex size-12 items-center justify-center\")}\n            onClick={() => {\n              setIsOpen((current) => !current);\n              if (isOpen) setActiveId(null);\n            }}\n            transition={spring}\n            type=\"button\"\n          >\n            <motion.span\n              animate={{ rotate: isOpen ? 90 : 0 }}\n              className=\"font-satoshi text-xs font-semibold tracking-tight\"\n              transition={{\n                type: \"spring\",\n                bounce: 0.15,\n                duration: 0.3,\n              }}\n            >\n              <IconShapesFillDuo18 className=\"size-6\" />\n            </motion.span>\n          </motion.button>\n        </div>\n\n        <AnimatePresence>\n          {isOpen ? (\n            <motion.div\n              animate={{ x: 0, y: \"-50%\", opacity: 1 }}\n              className=\"absolute right-16 top-1/2 flex flex-row-reverse items-center\"\n              exit={{ x: 18, y: \"-50%\", opacity: 0 }}\n              initial={{ x: 18, y: \"-50%\", opacity: 0 }}\n              transition={spring}\n            >\n              {peelActions.map((action, index) => {\n                const Icon = action.icon;\n                const isActive = activeId === action.id;\n\n                return (\n                  <motion.button\n                    aria-label={action.label}\n                    aria-pressed={isActive}\n                    animate={{\n                      x: 0,\n                      scale: isActive ? 1.06 : 1,\n                      opacity: 1,\n                    }}\n                    className={cn(blobClass, \"flex size-11 items-center justify-center\")}\n                    exit={{ x: 12, scale: 0.4, opacity: 0 }}\n                    initial={{ x: 12, scale: 0.4, opacity: 0 }}\n                    key={action.id}\n                    onClick={() =>\n                      setActiveId((current) => (current === action.id ? null : action.id))\n                    }\n                    transition={{\n                      ...spring,\n                      delay: index * 0.025,\n                    }}\n                    type=\"button\"\n                  >\n                    <Icon className=\"size-4\" />\n                  </motion.button>\n                );\n              })}\n            </motion.div>\n          ) : null}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nfunction AmoebaToolbar() {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const [isOpen, setIsOpen] = useState(false);\n  const [activeId, setActiveId] = useState<string | null>(null);\n\n  useEffect(() => {\n    const handlePointerDown = (event: MouseEvent) => {\n      if (!containerRef.current?.contains(event.target as Node)) {\n        setIsOpen(false);\n        setActiveId(null);\n      }\n    };\n\n    document.addEventListener(\"mousedown\", handlePointerDown);\n    return () => document.removeEventListener(\"mousedown\", handlePointerDown);\n  }, []);\n\n  return (\n    <div ref={containerRef} className=\"relative flex h-52 w-full items-center justify-center\">\n      <div className=\"relative flex size-44 items-center justify-center\" style={gooStyle}>\n        <motion.button\n          aria-expanded={isOpen}\n          aria-label={isOpen ? \"Close amoeba toolbar\" : \"Open amoeba toolbar\"}\n          animate={{ scale: isOpen ? 0.82 : 1 }}\n          className={cn(blobClass, \"relative z-10 flex size-14 items-center justify-center\")}\n          onClick={() => {\n            if (isOpen) {\n              setIsOpen(false);\n              setActiveId(null);\n              return;\n            }\n\n            setIsOpen(true);\n          }}\n          transition={spring}\n          type=\"button\"\n        >\n          <IconGamepadButtonsFillDuo18 className=\"size-6\" />\n        </motion.button>\n\n        <AnimatePresence>\n          {isOpen\n            ? amoebaTools.map((tool, index) => {\n                const point = getArcPoint(index, amoebaTools.length, 72, 210, -30);\n                const Icon = tool.icon;\n                const isActive = activeId === tool.id;\n\n                return (\n                  <motion.button\n                    aria-label={tool.label}\n                    aria-pressed={isActive}\n                    animate={{\n                      x: point.x,\n                      y: point.y,\n                      scale: isActive ? 1.12 : 1,\n                      opacity: 1,\n                    }}\n                    className={cn(blobClass, \"absolute flex size-11 items-center justify-center\")}\n                    exit={{ x: 0, y: 0, scale: 0.2, opacity: 0 }}\n                    initial={{ x: 0, y: 0, scale: 0.2, opacity: 0 }}\n                    key={tool.id}\n                    onClick={(event) => {\n                      event.stopPropagation();\n                      setActiveId((current) => (current === tool.id ? null : tool.id));\n                    }}\n                    transition={{\n                      ...spring,\n                      delay: index * 0.04,\n                    }}\n                    type=\"button\"\n                  >\n                    <Icon className=\"size-4\" />\n                  </motion.button>\n                );\n              })\n            : null}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nexport function GooeyFilter() {\n  return (\n    <svg aria-hidden=\"true\" className=\"pointer-events-none absolute h-0 w-0\">\n      <defs>\n        <filter id={filterId} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n          <feGaussianBlur in=\"SourceGraphic\" result=\"blur\" stdDeviation=\"6\" />\n          <feColorMatrix\n            in=\"blur\"\n            result=\"goo\"\n            type=\"matrix\"\n            values=\"1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 24 -16\"\n          />\n          <feComposite in=\"SourceGraphic\" in2=\"goo\" operator=\"atop\" />\n        </filter>\n      </defs>\n    </svg>\n  );\n}\n\nexport function GooeyToolbar({\n  className,\n  defaultVariant = \"peel\",\n  showVariantToggle = true,\n  variant,\n}: GooeyToolbarProps) {\n  const [selectedVariant, setSelectedVariant] = useState<GooeyToolbarVariant>(defaultVariant);\n  const currentVariant = variant ?? selectedVariant;\n\n  return (\n    <div className={cn(\"relative w-full items-center justify-center flex h-full\", className)}>\n      <GooeyFilter />\n      {showVariantToggle ? (\n        <div className=\"absolute -top-20 right-1/3 mb-4 flex justify-center\">\n          <VariantToggle value={currentVariant} onValueChange={setSelectedVariant} />\n        </div>\n      ) : null}\n\n      <AnimatePresence mode=\"wait\">\n        <motion.div\n          animate={{ opacity: 1, y: 0 }}\n          exit={{ opacity: 0, y: 8 }}\n          initial={{ opacity: 0, y: 8 }}\n          key={currentVariant}\n          transition={{ duration: 0.18 }}\n        >\n          {currentVariant === \"peel\" ? <PeelToolbar /> : <AmoebaToolbar />}\n        </motion.div>\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport const PeelTab = PeelToolbar;\nexport const AmoebaFab = AmoebaToolbar;\n\nexport default GooeyToolbar;\n","type":"registry:ui"}],"categories":["toolbar","navigation"],"type":"registry:ui"}