Buttons
DepthPress
The button sits on a solid slab. Hover lifts it a little, a press sinks it flat, like a real key.
Download
- React
- Tailwind CSS v4
- motion
components/ui/depth-press.tsx
"use client";
import type { ReactNode } from "react";
import { motion, useReducedMotion } from "motion/react";
type DepthPressProps = {
children: ReactNode;
className?: string;
onClick?: () => void;
/** Colour of the slab side under the button. */
base?: string;
/** Slab height in pixels. */
depth?: number;
};
/* DepthPress: the button sits on a solid slab. Hover lifts it, a press sinks it flat. */
export function DepthPress({
children,
className = "rounded-xl bg-[#a78bfa] px-9 py-4 text-[15px] font-medium text-[#1a1530]",
onClick,
base = "#5b3fc4",
depth = 6,
}: DepthPressProps) {
const reduce = useReducedMotion();
return (
<motion.button
type="button"
onClick={onClick}
className={className}
style={{ boxShadow: `0 ${depth}px 0 ${base}` }}
whileHover={reduce ? undefined : { y: -2, boxShadow: `0 ${depth + 2}px 0 ${base}` }}
whileTap={{ y: depth, boxShadow: `0 0px 0 ${base}` }}
transition={reduce ? { duration: 0 } : { type: "spring", stiffness: 700, damping: 32 }}
>
{children}
</motion.button>
);
}
1. Install the dependency.
npm i motion2. Paste the Code tab into
components/ui/depth-press.tsx. The styles are Tailwind CSS v4 classes.3. Use it. This is the preview above:
app/depth-press-demo.tsx
import { DepthPress } from "@/components/ui/depth-press"; export default function DepthPressExample() { return ( <div className="grid h-full place-items-center bg-[radial-gradient(circle_at_50%_60%,#1d1a33,#0d0c14_70%)]"> <DepthPress>Press me</DepthPress> </div> ); }
Props
| Name | Type | Default | What it does |
|---|---|---|---|
| children | ReactNode | — | Button label. |
| onClick | () => void | — | Click handler. |
| base | string | "#5b3fc4" | Colour of the slab side. |
| depth | number | 6 | Slab height in pixels. |
| className | string | violet block | Replaces the default look. |