Animated border
INTERACTION_083CSS
Animated Border Button
A light segment travels around the border on hover.
Buttons / LightView
The label collapses into a compact progress indicator. The label visible at full width before the trigger; fading the label out, shrinking the button to a fixed width and revealing the indicator once the submit action starting.
/* Button Loading Transition — The label collapses into a compact progress indicator. */
.button-loading-transition {
--dur: 320ms;
--ease: cubic-bezier(0.22, 1, 0.36, 1);
--stagger: 60ms;
will-change: transform, opacity;
}
.button-loading-transition > * {
opacity: 0;
transform: translateY(14px);
animation: button-loading-transition-in var(--dur) var(--ease) forwards;
animation-delay: calc(var(--i, 0) * var(--stagger));
}
/* the label visible at full width -> fading the label out, shrinking the button to a fixed width and revealing the indicator */
@keyframes button-loading-transition-in {
to {
opacity: 1;
transform: none;
filter: none;
}
}
@media (prefers-reduced-motion: reduce) {
.button-loading-transition > * {
opacity: 1;
transform: none;
animation: none;
}
}import { useEffect, useRef } from "react";
/** Button Loading Transition — trigger: the submit action starting */
export function ButtonLoadingTransition({ children }: { children: React.ReactNode }) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = ref.current;
if (!el) return;
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
el.dataset["state"] = "in";
return;
}
const io = new IntersectionObserver(
([entry]) => {
if (entry?.isIntersecting) {
el.dataset["state"] = "in";
io.unobserve(el);
}
},
{ threshold: 0.2 },
);
io.observe(el);
return () => io.disconnect();
}, []);
return (
<div ref={ref} className="button-loading-transition" data-state="out">
{children}
</div>
);
}A light segment travels around the border on hover.
A rounded fill rises from the bottom edge and floods the button.
A soft glow tracks the pointer inside the button surface.