MCPcopy Create free account
hub / github.com/code100x/cms / CardContainer

Function CardContainer

src/components/3dcard.tsx:19–79  ·  view source on GitHub ↗
({
  children,
  className,
  containerClassName,
}: {
  children?: React.ReactNode;
  className?: string;
  containerClassName?: string;
})

Source from the content-addressed store, hash-verified

17>(undefined);
18
19export const CardContainer = ({
20 children,
21 className,
22 containerClassName,
23}: {
24 children?: React.ReactNode;
25 className?: string;
26 containerClassName?: string;
27}) => {
28 const containerRef = useRef<HTMLDivElement>(null);
29 const [isMouseEntered, setIsMouseEntered] = useState(false);
30
31 const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
32 if (!containerRef.current) return;
33 const { left, top, width, height } =
34 containerRef.current.getBoundingClientRect();
35 const x = (e.clientX - left - width / 2) / 25;
36 const y = (e.clientY - top - height / 2) / 25;
37 containerRef.current.style.transform = `rotateY(${x}deg) rotateX(${y}deg)`;
38 };
39
40 const handleMouseEnter = (e: React.MouseEvent<HTMLDivElement>) => {
41 setIsMouseEntered(true);
42 if (!containerRef.current) return;
43 };
44
45 const handleMouseLeave = (e: React.MouseEvent<HTMLDivElement>) => {
46 if (!containerRef.current) return;
47 setIsMouseEntered(false);
48 containerRef.current.style.transform = 'rotateY(0deg) rotateX(0deg)';
49 };
50 return (
51 <MouseEnterContext.Provider value={[isMouseEntered, setIsMouseEntered]}>
52 <div
53 className={cn(
54 'flex items-center justify-center py-20',
55 containerClassName,
56 )}
57 style={{
58 perspective: '1000px',
59 }}
60 >
61 <div
62 ref={containerRef}
63 onMouseEnter={handleMouseEnter}
64 onMouseMove={handleMouseMove}
65 onMouseLeave={handleMouseLeave}
66 className={cn(
67 'relative flex items-center justify-center transition-all duration-200 ease-linear',
68 className,
69 )}
70 style={{
71 transformStyle: 'preserve-3d',
72 }}
73 >
74 {children}
75 </div>
76 </div>

Callers

nothing calls this directly

Calls 1

cnFunction · 0.90

Tested by

no test coverage detected