Spring Button
paceui-gsap/spring-buttonFreeComponent
A button that shrinks on press and springs back with bounce.
Live preview
live · rendered by the registry
Rendered by PaceUI GSAP on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://gsap.paceui.com/r/spring-button.jsonSource
1"use client";23import { ComponentProps, useRef } from "react";45import { useGSAP } from "@gsap/react";6import gsap from "gsap";78type SpringButtonProps = {9 scale?: number;10 shaking?: boolean;11} & ComponentProps<"button">;1213export const SpringButton = ({ scale = 0.85, shaking = true, ...props }: SpringButtonProps) => {14 const buttonRef = useRef<HTMLButtonElement | null>(null);15 const pressed = useRef(false);1617 useGSAP(18 () => {19 const element = buttonRef.current;20 if (!element) return;21 let pressTimeline = gsap.timeline();22 let shakingTimeline = gsap.timeline({ repeat: -1 });2324 const press = () => {25 pressed.current = true;26 pressTimeline.pause(0);27 pressTimeline.kill();28 pressTimeline = gsap.timeline();29 shakingTimeline = gsap.timeline({ repeat: -1 });3031 pressTimeline.to(element, {32 scale: scale,33 duration: 1,34 ease: "power4.out",35 });3637 if (shaking) {38 pressTimeline.add(shakingTimeline);39 shakingTimeline40 .to(element, { x: -1, y: 1, duration: 0.08 })41 .to(element, { x: 1, y: -1, duration: 0.08 })42 .to(element, { x: -0.5, y: -0.5, duration: 0.08 })43 .to(element, { x: 0.5, y: 0.5, duration: 0.08 })44 .to(element, { x: 0, y: 0, duration: 0.08 });45 }46 };4748 const release = () => {49 pressed.current = false;50 if (shakingTimeline) {51 shakingTimeline.pause(0);52 shakingTimeline.kill();53 }54 gsap.to(element, {55 scale: 1,56 duration: 0.5,57 ease: "elastic.out(1.4, 0.2)",58 onComplete: () => {59 if (!pressed.current && pressTimeline) {60 pressTimeline.pause(0);61 pressTimeline.kill();62 }63 },64 });65 };6667 element.addEventListener("mousedown", press);68 element.addEventListener("touchstart", press);69 element.addEventListener("mouseup", release);70// … truncated
What it pulls in
npm packages
Files it writes
More from PaceUI GSAP
All 29 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Modal Ability Selectorai-modal-ability-selector | PaceUI GSAP | Components | Free | 2 deps | |
| Modal Selectorai-modal-selector | PaceUI GSAP | Components | Free | 2 deps | |
| Response Writerai-response-writer | PaceUI GSAP | Components | Free | 2 deps · 2 files | |
| AI Suggestionsai-suggestions | PaceUI GSAP | Components | Free | 2 deps | |
| Modal Ability Selectorai-token-counter | PaceUI GSAP | Components | Free | 2 deps | |
| Animated Stackanimated-stack | PaceUI GSAP | Components | Free | 2 deps | |
| Bouncing Textbouncing-text | PaceUI GSAP | Components | Free | 2 deps | |
| Dot Flowdot-flow | PaceUI GSAP | Components | Free | 2 deps |
