Try 'magnetic button'
View code

Number 101: Drops that merge like goo

Specification

Catalogue
No. 101 of 110
Interaction
Press, Layout Animation
Element
Button
Preview
Live component
Imports
react 19.3.1
Added

Notes

Round shapes that touch join with a neck of liquid and pull apart like drops. On the entry page a plus button oozes out two actions and draws them back in.

A small menu that grows out of its button makes it obvious where the actions came from and where they go.

An SVG filter blurs the drops 7px and then sharpens their alpha (multiply by 20, minus 8), so overlapping blurs join into one edge. The buttons and icons sit on top of the drops, outside the filter, so text and icons stay crisp. Actions move out 550ms on cubic-bezier(.34, 1.56, .64, 1), 40ms apart, and come back in reverse order. On a card the two drops join, part and settle back over 3.6s while hovered. Under reduced motion the actions appear in place.

Changed from the library: two actions and a plus, drops in a mix of the site's ink and stage colours.

Code

React and plain CSS
"use client";

import { useId, useState, type CSSProperties, type ReactNode } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import styles from "./gooey-blobs.module.css";

/**
 * The goo: blur the shapes, then sharpen their alpha again. Where two blurred
 * shapes overlap the sum crosses the threshold, so they join with a neck of
 * liquid instead of just touching.
 */
function GooFilter({ id }: { id: string }) {
  return (
    <filter id={id} x="-50%" y="-50%" width="200%" height="200%" colorInterpolationFilters="sRGB">
      <feGaussianBlur in="SourceGraphic" stdDeviation="7" />
      <feColorMatrix mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 20 -8" />
    </filter>
  );
}

const useFilterId = () => `goo-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;

/**
 * On a card: two drops that pull apart and run back together. When the card
 * stops playing, the drops finish the cycle they are in, so they always come
 * to rest holding each other.
 */
function Blobs({ playing }: { playing: boolean }) {
  const filterId = useFilterId();
  const [settling, setSettling] = useState(false);
  const [wasPlaying, setWasPlaying] = useState(playing);
  if (wasPlaying !== playing) {
    setWasPlaying(playing);
    setSettling(!playing);
  }
  const moving = playing || settling;

  return (
    <svg className={styles.blobs} viewBox="0 0 220 140" width="220" height="140" role="img" aria-label="Two drops joined by a neck of liquid">
      <defs>
        <GooFilter id={filterId} />
      </defs>
      <g filter={`url(#${filterId})`} data-running={moving || undefined}>
        <circle
          className={styles.left}
          cx="110"
          cy="70"
          r="29"
          onAnimationIteration={() => {
            if (!playing) setSettling(false);
          }}
        />
        <circle className={styles.right} cx="110" cy="70" r="29" />
      </g>
    </svg>
  );
}

type Action = { id: string; label: string; done: string; x: number; y: number; icon: ReactNode };

const ACTIONS: Action[] = [
  {
    id: "share",
    label: "Share",
    done: "Link copied",
    x: -62,
    y: -46,
    icon: <path d="M12 15V4M7.5 8.5 12 4l4.5 4.5M5 13v5a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-5" />,
  },
  {
    id: "save",
    label: "Save",
    done: "Saved",
    x: 62,
    y: -46,
    icon: <path d="M7 4h10a1 1 0 0 1 1 1v15l-6-4-6 4V5a1 1 0 0 1 1-1Z" />,
  },
];

const Icon = ({ children }: { children: ReactNode }) => (
  <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
    {children}
  </svg>
);

/** On the entry page: a plus button whose actions ooze out of it and run back in. */
function GooeyMenu() {
  const filterId = useFilterId();
  const [open, setOpen] = useState(false);
  const [status, setStatus] = useState("");

  const place = (a: Action, i: number) =>
    ({
      "--x": open ? `${a.x}px` : "0px",
      "--y": open ? `${a.y}px` : "0px",
      "--delay": `${open ? i * 40 : (ACTIONS.length - 1 - i) * 40}ms`,
    }) as CSSProperties;

  return (
    <div className={styles.menu}>
      <svg className={styles.goo} viewBox="-110 -110 220 220" width="220" height="220" aria-hidden="true">
        <defs>
          <GooFilter id={filterId} />
        </defs>
        <g filter={`url(#${filterId})`}>
          {ACTIONS.map((a, i) => (
            <circle key={a.id} className={styles.drop} r="24" style={place(a, i)} />
          ))}
          <circle className={styles.drop} r="30" />
        </g>
      </svg>
      {ACTIONS.map((a, i) => (
        <button
          key={a.id}
          type="button"
          className={styles.action}
          style={place(a, i)}
          aria-label={a.label}
          tabIndex={open ? 0 : -1}
          aria-hidden={!open || undefined}
          onClick={() => {
            setStatus(a.done);
            setOpen(false);
          }}
        >
          <Icon>{a.icon}</Icon>
        </button>
      ))}
      <button
        type="button"
        className={styles.main}
        aria-expanded={open}
        aria-label={open ? "Close actions" : "Open actions"}
        onClick={() => {
          setStatus("");
          setOpen((o) => !o);
        }}
      >
        <span className={styles.plus} data-open={open || undefined}>
          <Icon>
            <path d="M12 5v14M5 12h14" />
          </Icon>
        </span>
      </button>
      <p className={styles.status} aria-live="polite">
        {status || "Press the plus"}
      </p>
    </div>
  );
}

export default function GooeyBlobs({ active, context }: LivePreviewProps) {
  if (context === "detail") return <GooeyMenu />;
  return <Blobs playing={active} />;
}

More like this

Slingshot button

Press, DragButtons and toggles

Currency swap that trades places

Press, Layout AnimationForms and inputs

Magnetic button

Hover, PressButtons and toggles

Button that grows into its form

Press, TypeButtons and toggles

Liquid metal ring

Hover, PressButtons and toggles

Huddle you can join

Press, FeedbackCards and accordions