Buttons
ElasticTap
A press squashes the button like rubber and it springs back with a wobble.
Download
- React
- Tailwind CSS v4
- motion
components/ui/elastic-tap.tsx
"use client";
import type { ReactNode } from "react";
import { motion, useReducedMotion } from "motion/react";
type ElasticTapProps = {
children: ReactNode;
className?: string;
onClick?: () => void;
/** How much it wobbles back, 0 (none) to 1 (a lot). */
bounce?: number;
};
/* ElasticTap: a press squashes the button like rubber, and it springs back with a wobble. */
export function ElasticTap({
children,
className = "rounded-full bg-[#a78bfa] px-9 py-4 text-[15px] font-medium text-[#1a1530]",
onClick,
bounce = 0.6,
}: ElasticTapProps) {
const reduce = useReducedMotion();
return (
<motion.button
type="button"
onClick={onClick}
className={className}
whileHover={reduce ? undefined : { scale: 1.04 }}
whileTap={reduce ? undefined : { scaleX: 1.14, scaleY: 0.85 }}
transition={{ type: "spring", visualDuration: 0.4, bounce }}
>
{children}
</motion.button>
);
}
1. Install the dependency.
npm i motion2. Paste the Code tab into
components/ui/elastic-tap.tsx. The styles are Tailwind CSS v4 classes.3. Use it. This is the preview above:
app/elastic-tap-demo.tsx
import { ElasticTap } from "@/components/ui/elastic-tap"; export default function ElasticTapExample() { return ( <div className="grid h-full place-items-center bg-[radial-gradient(circle_at_50%_60%,#1d1a33,#0d0c14_70%)]"> <ElasticTap>Tap me</ElasticTap> </div> ); }
Props
| Name | Type | Default | What it does |
|---|---|---|---|
| children | ReactNode | — | Button label. |
| onClick | () => void | — | Click handler. |
| bounce | number | 0.6 | How much it wobbles back, 0 to 1. |
| className | string | violet pill | Replaces the default look. |