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

Function CardItem

src/components/3dcard.tsx:100–147  ·  view source on GitHub ↗
({
  children,
  className,
  translateX = 0,
  translateY = 0,
  translateZ = 0,
  rotateX = 0,
  rotateY = 0,
  rotateZ = 0,
  ...rest
}: {
  as?: React.ElementType;
  children: React.ReactNode;
  className?: string;
  translateX?: number | string;
  translateY?: number | string;
  translateZ?: number | string;
  rotateX?: number | string;
  rotateY?: number | string;
  rotateZ?: number | string;
})

Source from the content-addressed store, hash-verified

98};
99
100export const CardItem = ({
101 children,
102 className,
103 translateX = 0,
104 translateY = 0,
105 translateZ = 0,
106 rotateX = 0,
107 rotateY = 0,
108 rotateZ = 0,
109 ...rest
110}: {
111 as?: React.ElementType;
112 children: React.ReactNode;
113 className?: string;
114 translateX?: number | string;
115 translateY?: number | string;
116 translateZ?: number | string;
117 rotateX?: number | string;
118 rotateY?: number | string;
119 rotateZ?: number | string;
120}) => {
121 const ref = useRef<HTMLDivElement>(null);
122 const [isMouseEntered] = useMouseEnter();
123
124 useEffect(() => {
125 handleAnimations();
126 }, [isMouseEntered]);
127
128 const handleAnimations = () => {
129 if (!ref.current) return;
130 if (isMouseEntered) {
131 ref.current.style.transform = `translateX(${translateX}px) translateY(${translateY}px) translateZ(${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) rotateZ(${rotateZ}deg)`;
132 } else {
133 ref.current.style.transform =
134 'translateX(0px) translateY(0px) translateZ(0px) rotateX(0deg) rotateY(0deg) rotateZ(0deg)';
135 }
136 };
137
138 return (
139 <div
140 ref={ref}
141 className={cn('w-fit transition duration-200 ease-linear', className)}
142 {...rest}
143 >
144 {children}
145 </div>
146 );
147};
148
149// Create a hook to use the context
150export const useMouseEnter = () => {

Callers

nothing calls this directly

Calls 3

cnFunction · 0.90
useMouseEnterFunction · 0.85
handleAnimationsFunction · 0.85

Tested by

no test coverage detected