A wobble-card component from Aceternity UI.
From Aceternity UI
1"use client";
2import React, { useState } from "react";
3import { motion } from "motion/react";
4import { cn } from "@/lib/utils";
5
6export const WobbleCard = ({
7 children,
8 containerClassName,
9 className,
10}: {
11 children: React.ReactNode;
12 containerClassName?: string;
13 className?: string;
14}) => {
15 const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
16 const [isHovering, setIsHovering] = useState(false);
17
18 const handleMouseMove = (event: React.MouseEvent<HTMLElement>) => {
19 const { clientX, clientY } = event;
20 const rect = event.currentTarget.getBoundingClientRect();
21 const x = (clientX - (rect.left + rect.width / 2)) / 20;
22 const y = (clientY - (rect.top + rect.height / 2)) / 20;
23 setMousePosition({ x, y });
24 };
25 return (
26 <motion.section
27 onMouseMove={handleMouseMove}
28 onMouseEnter={() => setIsHovering(true)}
29 onMouseLeave={() => {
30 setIsHovering(false);
31 setMousePosition({ x: 0, y: 0 });
32 }}
33 style={{
34 transform: isHovering
35 ? `translate3d(${mousePosition.x}px, ${mousePosition.y}px, 0) scale3d(1, 1, 1)`
36 : "translate3d(0px, 0px, 0) scale3d(1, 1, 1)",
37 transition: "transform 0.1s ease-out",
38 }}
39 className={cn(
40 "mx-auto w-full bg-indigo-800 relative rounded-2xl overflow-hidden",
41 containerClassName
42 )}
43 >
44 <div
45 className="relative h-full [background-image:radial-gradient(88%_100%_at_top,rgba(255,255,255,0.5),rgba(255,255,255,0))] sm:mx-0 sm:rounded-2xl overflow-hidden"
46 style={{
47 boxShadow:
48 "0 10px 32px rgba(34, 42, 53, 0.12), 0 1px 1px rgba(0, 0, 0, 0.05), 0 0 0 1px rgba(34, 42, 53, 0.05), 0 4px 6px rgba(34, 42, 53, 0.08), 0 24px 108px rgba(47, 48, 55, 0.10)",
49 }}
50 >
51 <motion.div
52 style={{
53 transform: isHovering
54 ? `translate3d(${-mousePosition.x}px, ${-mousePosition.y}px, 0) scale3d(1.03, 1.03, 1)`
55 : "translate3d(0px, 0px, 0) scale3d(1, 1, 1)",
56 transition: "transform 0.1s ease-out",
57 }}
58 className={cn("h-full px-4 py-20 sm:px-10", className)}
59 >
60 <Noise />
61 {children}
62 </motion.div>
63 </div>
64 </motion.section>
65 );
66};
67
68const Noise = () => {
69 return (
70 <div
71 className="absolute inset-0 w-full h-full scale-[1.2] transform opacity-10 [mask-image:radial-gradient(#fff,transparent,75%)]"
72 style={{
73 backgroundImage: "url(/noise.webp)",
74 backgroundSize: "30%",
75 }}
76 ></div>
77 );
78};
79