Components102 / 118
Liquid Buttons
Three call-to-action buttons filled with living pictures. A picture floods the pill from exactly where your cursor enters and drains toward where it leaves, drifting against your cursor; an arc of picture races round a hairline border until the whole outline is lit; a disc blooms with a picture as its arrow shoots through. Every one pulls toward you and squashes as you press.
GSAPGSAPImage fillsImage fillsMagneticMagneticKeyboard friendlyKeyboard friendly60fps60fpsReduced-motion safeReduced-motion safe
Hover from different sides, then press
Tweak
LIVELIVELabels
Pictures
Bloom
Orbit
Arrow
Feel
4.0s
1.00
Usage
Follows your tweaks.
usage.tsx
import { ArrowButton, BloomButton, OrbitButton } from "@/components/inreact/liquid-buttons";
export function Actions() {
return (
<div className="flex items-center gap-3">
<BloomButton href="/start" image="/images/liquid.jpg">Get started</BloomButton>
<ArrowButton href="/next" label="Continue" image="/images/foil.jpg" />
<OrbitButton href="/demo" image="/images/silk.jpg">Book a demo</OrbitButton>
</div>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/liquid-buttons.jsonOr copy the source
Install the dependencies, then save this as components/inreact/liquid-buttons.tsx.
terminal
npm install gsapcomponents/inreact/liquid-buttons.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef, type CSSProperties, type MouseEventHandler, type ReactNode, type RefObject } from "react";
/**
* Liquid Buttons: three call-to-action buttons filled with living pictures.
*
* - BloomButton: a picture floods in from exactly where the cursor enters,
* through a soft liquid edge, drifting against your cursor inside the pill,
* and drains toward wherever you leave; the label rolls over.
* - OrbitButton: an arc of a picture travels round the border; on hover it
* races and stretches until the whole outline is lit, and the picture
* glows faintly through the body.
* - ArrowButton: a magnetic disc that blooms with a picture from your entry
* point while its arrow shoots out and a new one slides in.
*
* All three pull toward the cursor, squash wide and low as you press and
* spring back, render a real <a> when given href (otherwise a <button>),
* treat keyboard focus like hover, and keep only the fades under reduced
* motion. Without a picture (or before it loads) the colour fallback shows.
*
* <BloomButton href="/start" image="/cta.jpg">Get started</BloomButton>
* <OrbitButton onClick={book} image="/ring.jpg">Book a demo</OrbitButton>
* <ArrowButton href="/next" label="Next" image="/disc.jpg" />
*/
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const finePointer = () => typeof window !== "undefined" && window.matchMedia("(pointer: fine)").matches;
interface BaseProps {
href?: string;
onClick?: MouseEventHandler<HTMLElement>;
/** How strongly the button is pulled toward the cursor (0 = off). */
magnetic?: number;
/** Font of the label (inherits by default). */
font?: string;
className?: string;
style?: CSSProperties;
}
/* ------------------------------------------------------------------ */
/* shared behaviour */
/* ------------------------------------------------------------------ */
type Hook = (e: PointerEvent | FocusEvent) => void;
/** Magnetic pull, press squash, and enter / leave / move hooks on one element. */
function useLiving(ref: RefObject<HTMLElement | null>, magnetic: number, hooks: { enter?: Hook; leave?: Hook; move?: (e: PointerEvent) => void }) {
const hooksRef = useRef(hooks);
useEffect(() => {
hooksRef.current = hooks;
});
useEffect(() => {
const el = ref.current;
if (!el) return;
const still = reduced();
const pull = !still && finePointer() && magnetic > 0;
const inner = el.querySelector<HTMLElement>("[data-inner]");
const xTo = gsap.quickTo(el, "x", { duration: 0.6, ease: "power3" });
const yTo = gsap.quickTo(el, "y", { duration: 0.6, ease: "power3" });
const ixTo = inner ? gsap.quickTo(inner, "x", { duration: 0.6, ease: "power3" }) : null;
const iyTo = inner ? gsap.quickTo(inner, "y", { duration: 0.6, ease: "power3" }) : null;
let hovered = false;
const move = (e: PointerEvent) => {
hooksRef.current.move?.(e);
if (!pull) return;
const r = el.getBoundingClientRect();
const x = e.clientX - (r.left + r.width / 2);
const y = e.clientY - (r.top + r.height / 2);
xTo(x * magnetic);
yTo(y * magnetic);
ixTo?.(x * magnetic * 0.4);
iyTo?.(y * magnetic * 0.4);
};
const enter = (e: PointerEvent | FocusEvent) => {
if (hovered) return;
hovered = true;
hooksRef.current.enter?.(e);
};
const leave = (e: PointerEvent | FocusEvent) => {
if (!hovered) return;
hovered = false;
if (pull) {
gsap.to(el, { x: 0, y: 0, duration: 1, ease: "elastic.out(1, 0.4)", overwrite: "auto" });
if (inner) gsap.to(inner, { x: 0, y: 0, duration: 1, ease: "elastic.out(1, 0.4)", overwrite: "auto" });
}
hooksRef.current.leave?.(e);
};
// squash and stretch: wide and low as you press, a springy rebound on release
const down = () => {
if (!still) gsap.to(el, { scaleX: 1.06, scaleY: 0.88, duration: 0.12, ease: "power2.out", overwrite: "auto" });
};
const up = () => {
if (!still) gsap.to(el, { scaleX: 1, scaleY: 1, duration: 0.75, ease: "elastic.out(1, 0.32)", overwrite: "auto" });
};
el.addEventListener("pointerenter", enter);
el.addEventListener("pointermove", move);
el.addEventListener("pointerleave", leave);
el.addEventListener("focus", enter);
el.addEventListener("blur", leave);
el.addEventListener("pointerdown", down);
el.addEventListener("pointerup", up);
el.addEventListener("pointercancel", up);
el.addEventListener("pointerleave", up);
return () => {
el.removeEventListener("pointerenter", enter);
el.removeEventListener("pointermove", move);
el.removeEventListener("pointerleave", leave);
el.removeEventListener("focus", enter);
el.removeEventListener("blur", leave);
el.removeEventListener("pointerdown", down);
el.removeEventListener("pointerup", up);
el.removeEventListener("pointercancel", up);
el.removeEventListener("pointerleave", up);
gsap.killTweensOf(el);
if (inner) gsap.killTweensOf(inner);
};
}, [ref, magnetic]);
}
/** Where a pointer (or a focus, from the centre) meets the element, in its own px. */
function pointIn(el: HTMLElement, e: PointerEvent | FocusEvent) {
const r = el.getBoundingClientRect();
const sx = r.width / Math.max(1, el.offsetWidth), sy = r.height / Math.max(1, el.offsetHeight); // the element may be scaled
const has = "clientX" in e && (e.clientX !== 0 || e.clientY !== 0);
return {
x: has ? ((e as PointerEvent).clientX - r.left) / sx : el.offsetWidth / 2,
y: has ? ((e as PointerEvent).clientY - r.top) / sy : el.offsetHeight / 2,
reach: Math.hypot(el.offsetWidth, el.offsetHeight),
};
}
/**
* A picture revealed through a soft-edged circle (a CSS mask driven by GSAP):
* it floods in from a point and drains toward another, and drifts against the cursor.
*/
function useBloom(maskRef: RefObject<HTMLSpanElement | null>, picRef: RefObject<HTMLSpanElement | null>) {
const st = useRef({ x: 0, y: 0, r: 0, soft: 14 });
const paint = () => {
const m = maskRef.current;
if (!m) return;
const { x, y, r, soft } = st.current;
const g = `radial-gradient(circle at ${x.toFixed(1)}px ${y.toFixed(1)}px, #000 ${Math.max(0, r - soft).toFixed(1)}px, transparent ${r.toFixed(1)}px)`;
m.style.maskImage = g;
m.style.webkitMaskImage = g;
};
useEffect(() => {
paint();
const s = st.current;
return () => void gsap.killTweensOf(s);
}, []); // eslint-disable-line react-hooks/exhaustive-deps
return {
open(p: { x: number; y: number; reach: number }) {
const s = st.current;
gsap.killTweensOf(s);
if (s.r < 1) (s.x = p.x), (s.y = p.y);
if (reduced()) return void (Object.assign(s, { x: p.x, y: p.y, r: p.reach * 1.2 }), paint());
// the flood: quick at first, settling as it reaches the far edge
gsap.to(s, { x: p.x, y: p.y, r: p.reach * 1.15, duration: 0.85, ease: "power3.out", onUpdate: paint });
gsap.fromTo(picRef.current, { scale: 1.3 }, { scale: 1.12, duration: 1.1, ease: "expo.out", overwrite: "auto" });
},
close(p: { x: number; y: number }) {
const s = st.current;
gsap.killTweensOf(s);
if (reduced()) return void ((s.r = 0), paint());
// drains toward the way you left
gsap.to(s, { x: p.x, y: p.y, r: 0, duration: 0.55, ease: "power3.inOut", onUpdate: paint });
},
drift(e: PointerEvent, host: HTMLElement) {
const pic = picRef.current;
if (!pic || reduced()) return;
const r = host.getBoundingClientRect();
const dx = (e.clientX - (r.left + r.width / 2)) / r.width, dy = (e.clientY - (r.top + r.height / 2)) / r.height;
gsap.to(pic, { xPercent: -dx * 6, yPercent: -dy * 10, duration: 0.8, ease: "power3.out", overwrite: "auto" });
},
};
}
/** Label whose letters roll up and are replaced from below. */
function Roll({ text, hoverColor }: { text: string; hoverColor?: string }) {
return (
<span className="relative inline-flex overflow-hidden py-[0.12em]">
<span className="sr-only">{text}</span>
<span aria-hidden="true" className="inline-flex">
{Array.from(text).map((c, i) => (
<span key={i} data-ch className="relative inline-block whitespace-pre">
{c}
<span className="absolute top-full left-0" style={hoverColor ? { color: hoverColor } : undefined}>
{c}
</span>
</span>
))}
</span>
</span>
);
}
function roll(el: HTMLElement, on: boolean) {
if (reduced()) return;
const chs = el.querySelectorAll("[data-ch]");
gsap.killTweensOf(chs);
// a small dip the other way first, then over with an overshoot
gsap
.timeline()
.to(chs, { yPercent: on ? 10 : -110, duration: 0.07, ease: "power1.out", stagger: 0.016 })
.to(chs, { yPercent: on ? -100 : 0, duration: 0.55, ease: "back.out(2)", stagger: 0.016 }, 0.05);
}
/** Renders an <a> when href is given, else a <button>. */
function Host({
href,
onClick,
innerRef,
className,
style,
ariaLabel,
children,
}: {
href?: string;
onClick?: MouseEventHandler<HTMLElement>;
innerRef: RefObject<HTMLElement | null>;
className: string;
style?: CSSProperties;
ariaLabel?: string;
children: ReactNode;
}) {
if (href)
return (
<a ref={innerRef as RefObject<HTMLAnchorElement>} href={href} onClick={onClick} className={className} style={style} aria-label={ariaLabel}>
{children}
</a>
);
return (
<button ref={innerRef as RefObject<HTMLButtonElement>} type="button" onClick={onClick} className={className} style={style} aria-label={ariaLabel}>
{children}
</button>
);
}
const FOCUS = "outline-none focus-visible:ring-2 focus-visible:ring-white/60 focus-visible:ring-offset-2 focus-visible:ring-offset-black";
const join = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" ");
const cover = (image: string | undefined, fallback: string): CSSProperties => ({
background: image ? `${fallback} url("${image}") center / cover no-repeat` : fallback,
});
/* ------------------------------------------------------------------ */
/* 1. BloomButton */
/* ------------------------------------------------------------------ */
export interface BloomButtonProps extends BaseProps {
children: string;
/** Picture that floods the pill on hover. */
image?: string;
/** Colour shown where there is no picture (or before it loads). */
fill?: string;
/** Text colour at rest. */
color?: string;
/** Text colour over the picture. */
hoverColor?: string;
}
export function BloomButton({
children,
image = "/media/btn-liquid.webp",
fill = "#2b5cff",
color = "#f4f1ea",
hoverColor = "#ffffff",
magnetic = 0.2,
font,
href,
onClick,
className,
style,
}: BloomButtonProps) {
const ref = useRef<HTMLElement>(null);
const maskRef = useRef<HTMLSpanElement>(null);
const picRef = useRef<HTMLSpanElement>(null);
const bloom = useBloom(maskRef, picRef);
useLiving(ref, magnetic, {
enter: (e) => {
bloom.open(pointIn(ref.current!, e));
roll(ref.current!, true);
},
leave: (e) => {
bloom.close(pointIn(ref.current!, e));
roll(ref.current!, false);
},
move: (e) => bloom.drift(e, ref.current!),
});
return (
<Host
href={href}
onClick={onClick}
innerRef={ref}
style={{ fontFamily: font, ...style }}
className={join(
"relative isolate inline-flex items-center justify-center overflow-hidden rounded-full px-8 py-4 text-[15px] font-semibold tracking-[-0.01em] will-change-transform",
FOCUS,
className,
)}
>
{/* the ink body, lit softly from above */}
<span
aria-hidden="true"
className="absolute inset-0 -z-20 rounded-full"
style={{
background: "linear-gradient(180deg, #1f1f23, #121214)",
boxShadow: "inset 0 1px 0 rgba(255,255,255,0.16), inset 0 -1px 0 rgba(0,0,0,0.5), inset 0 0 0 1px rgba(255,255,255,0.08)",
}}
/>
{/* the picture, shown through the blooming mask */}
<span ref={maskRef} aria-hidden="true" className="pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-full">
<span ref={picRef} className="absolute -inset-[12%] will-change-transform" style={cover(image, fill)} />
<span className="absolute inset-0" style={{ background: "linear-gradient(180deg, rgba(0,0,0,0.05), rgba(0,0,0,0.28))" }} />
</span>
<span data-inner className="relative" style={{ color }}>
<Roll text={children} hoverColor={hoverColor} />
</span>
</Host>
);
}
/* ------------------------------------------------------------------ */
/* 2. OrbitButton */
/* ------------------------------------------------------------------ */
export interface OrbitButtonProps extends BaseProps {
children: string;
/** Picture the travelling arc of the border is cut from. */
image?: string;
/** Colour of the arc where there is no picture. */
fill?: string;
/** Body colour. */
background?: string;
/** Text colour. */
color?: string;
/** Seconds per orbit at rest (hover runs three times faster). */
period?: number;
}
export function OrbitButton({
children,
image = "/media/btn-silk.webp",
fill = "#ff6b3d",
background = "#0d0d0f",
color = "#f4f1ea",
period = 4,
magnetic = 0.2,
font,
href,
onClick,
className,
style,
}: OrbitButtonProps) {
const ref = useRef<HTMLElement>(null);
const ringRef = useRef<HTMLSpanElement>(null);
const arcRef = useRef<HTMLSpanElement>(null);
const glowRef = useRef<HTMLSpanElement>(null);
const spinRef = useRef<gsap.core.Tween | null>(null);
const arc = useRef({ a: 150 });
const paintArc = () => {
const el = arcRef.current;
if (!el) return;
const a = arc.current.a;
// a bright head trailing off into a tail; at 360 the whole outline is lit
const g = a >= 359 ? "linear-gradient(#000, #000)" : `conic-gradient(from 0deg, transparent 0deg, transparent ${(360 - a).toFixed(1)}deg, rgba(0,0,0,0.45) ${(360 - a * 0.6).toFixed(1)}deg, #000 352deg, transparent 360deg)`;
el.style.maskImage = g;
el.style.webkitMaskImage = g;
};
useEffect(() => {
paintArc();
const ring = ringRef.current;
if (!ring || reduced()) return;
spinRef.current = gsap.to(ring, { rotation: 360, duration: period, ease: "none", repeat: -1 });
return () => {
spinRef.current?.kill();
spinRef.current = null;
};
}, [period]); // eslint-disable-line react-hooks/exhaustive-deps
useLiving(ref, magnetic, {
enter: () => {
if (spinRef.current) gsap.to(spinRef.current, { timeScale: 3, duration: 0.6, ease: "power2.out", overwrite: true });
gsap.to(arc.current, { a: 360, duration: reduced() ? 0 : 0.9, ease: "power3.inOut", onUpdate: paintArc, overwrite: true });
gsap.to(glowRef.current, { opacity: 0.32, duration: 0.6, ease: "power2.out", overwrite: true });
roll(ref.current!, true);
},
leave: () => {
if (spinRef.current) gsap.to(spinRef.current, { timeScale: 1, duration: 0.9, ease: "power2.out", overwrite: true });
gsap.to(arc.current, { a: 150, duration: reduced() ? 0 : 0.7, ease: "power3.out", onUpdate: paintArc, overwrite: true });
gsap.to(glowRef.current, { opacity: 0, duration: 0.45, ease: "power2.out", overwrite: true });
roll(ref.current!, false);
},
});
return (
<Host
href={href}
onClick={onClick}
innerRef={ref}
style={{ fontFamily: font, ...style }}
className={join("relative isolate inline-flex overflow-hidden rounded-full p-[2px] text-[15px] font-semibold tracking-[-0.01em] will-change-transform", FOCUS, className)}
>
{/* the hairline, and the arc of picture travelling round it */}
<span aria-hidden="true" className="absolute inset-0 -z-20 rounded-full" style={{ background: "rgba(255,255,255,0.12)" }} />
<span aria-hidden="true" className="absolute inset-0 -z-10 grid place-items-center overflow-hidden rounded-full">
<span ref={ringRef} className="relative aspect-square w-[160%] shrink-0">
<span ref={arcRef} className="absolute inset-0" style={cover(image, fill)} />
</span>
</span>
<span
className="relative flex items-center gap-2 overflow-hidden rounded-full px-8 py-4"
style={{ background, color, boxShadow: "inset 0 1px 0 rgba(255,255,255,0.07), inset 0 -1px 0 rgba(0,0,0,0.5)" }}
>
{/* the picture breathing faintly through the body on hover */}
<span ref={glowRef} aria-hidden="true" className="pointer-events-none absolute inset-0 opacity-0" style={{ ...cover(image, fill), filter: "saturate(1.2)" }} />
<span aria-hidden="true" className="pointer-events-none absolute inset-0" style={{ background: `linear-gradient(180deg, ${background}66, ${background}cc)` }} />
<span data-inner className="relative">
<Roll text={children} />
</span>
</span>
</Host>
);
}
/* ------------------------------------------------------------------ */
/* 3. ArrowButton */
/* ------------------------------------------------------------------ */
export interface ArrowButtonProps extends BaseProps {
/** Accessible name, e.g. "Next" or "Continue". */
label: string;
/** Diameter in px. */
size?: number;
/** Picture that blooms in the disc on hover. */
image?: string;
/** Disc colour at rest. */
background?: string;
/** Colour shown where there is no picture. */
hoverBackground?: string;
/** Arrow colour at rest, and over the picture. */
color?: string;
hoverColor?: string;
/** Arrow direction. */
direction?: "up-right" | "right";
}
export function ArrowButton({
label,
size = 56,
image = "/media/btn-foil.webp",
background = "#f4f1ea",
hoverBackground = "#b27cff",
color = "#0b0b0c",
hoverColor = "#ffffff",
direction = "up-right",
magnetic = 0.45,
href,
onClick,
className,
style,
}: ArrowButtonProps) {
const ref = useRef<HTMLElement>(null);
const tlRef = useRef<gsap.core.Timeline | null>(null);
const maskRef = useRef<HTMLSpanElement>(null);
const picRef = useRef<HTMLSpanElement>(null);
const bloom = useBloom(maskRef, picRef);
const out = direction === "right" ? { xPercent: 110, yPercent: 0 } : { xPercent: 110, yPercent: -110 };
const inFrom = direction === "right" ? { xPercent: -110, yPercent: 0 } : { xPercent: -110, yPercent: 110 };
useEffect(() => {
const el = ref.current;
if (!el) return;
const [a, b] = Array.from(el.querySelectorAll<HTMLElement>("[data-arrow]"));
gsap.set(a, { x: 0, y: 0, xPercent: 0, yPercent: 0 });
gsap.set(b, { x: 0, y: 0, ...inFrom, visibility: "visible" });
// inFrom/out are derived from direction
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [direction]);
useLiving(ref, magnetic, {
enter: (e) => {
const el = ref.current!;
const [a, b] = Array.from(el.querySelectorAll<HTMLElement>("[data-arrow]"));
bloom.open(pointIn(el, e));
gsap.to(el, { color: hoverColor, duration: 0.3, overwrite: "auto" });
if (reduced()) return;
tlRef.current?.kill();
gsap.set(a, { xPercent: 0, yPercent: 0 });
// the arrow shoots out; the new one slides in and overshoots into place
tlRef.current = gsap
.timeline()
.to(a, { ...out, duration: 0.32, ease: "power3.in" })
.fromTo(b, { ...inFrom }, { xPercent: 0, yPercent: 0, duration: 0.55, ease: "back.out(2.2)" }, 0.16);
},
leave: (e) => {
const el = ref.current!;
const [a, b] = Array.from(el.querySelectorAll<HTMLElement>("[data-arrow]"));
bloom.close(pointIn(el, e));
tlRef.current?.kill();
tlRef.current = null;
// never leave an arrow half-way
gsap.set(a, { xPercent: 0, yPercent: 0 });
gsap.set(b, { ...inFrom });
gsap.to(el, { color, duration: 0.3, overwrite: "auto" });
},
move: (e) => bloom.drift(e, ref.current!),
});
const arrow = (
<svg viewBox="0 0 20 20" className="size-5" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
{direction === "right" ? <path d="M4 10h12M11 5l5 5-5 5" /> : <path d="M5 15 15 5M7 5h8v8" />}
</svg>
);
return (
<Host
href={href}
onClick={onClick}
innerRef={ref}
ariaLabel={label}
style={{
width: size,
height: size,
color,
background,
boxShadow: "inset 0 1px 0 rgba(255,255,255,0.6), inset 0 -2px 4px rgba(0,0,0,0.14)",
...style,
}}
className={join("relative isolate grid shrink-0 place-items-center overflow-hidden rounded-full will-change-transform", FOCUS, className)}
>
<span ref={maskRef} aria-hidden="true" className="pointer-events-none absolute inset-0 -z-10 overflow-hidden rounded-full">
<span ref={picRef} className="absolute -inset-[14%] will-change-transform" style={cover(image, hoverBackground)} />
<span className="absolute inset-0" style={{ background: "rgba(0,0,0,0.12)" }} />
</span>
<span data-inner className="absolute inset-0">
{/* each arrow layer is as big as the disc, so ±110% always clears it */}
<span data-arrow className="absolute inset-0 grid place-items-center">
{arrow}
</span>
<span data-arrow className="invisible absolute inset-0 grid place-items-center">
{arrow}
</span>
</span>
</Host>
);
}
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
9 propsBloomButtoncomponentPicture-fill pill. Props: children, image, fill, color, hoverColor, font, magnetic, href, onClick.OrbitButtoncomponentTravelling picture border. Props: children, image, fill, background, color, period, font, magnetic, href, onClick.ArrowButtoncomponentMagnetic picture disc. Props: label, image, size, background, hoverBackground, color, hoverColor, direction, magnetic, href, onClick.imagestringThe picture revealed on hover (abstract textures work best). fill / hoverBackground show where there is none.periodnumberSeconds per orbit at rest; hover runs three times faster.default 4default 4direction"up-right" | "right"Which way the arrow points and shoots.default "up-right"default "up-right"magneticnumberHow strongly a button is pulled toward the cursor. 0 turns it off.default 0.2 (arrow 0.45)default 0.2 (arrow 0.45)fontstringLabel font (inherits by default).hrefstringRenders a link instead of a button.