mini-pic.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { useTheme } from "next-themes";
  2. import { Image } from "@heroui/react";
  3. import { useRef } from "react";
  4. interface MiniPicProps {
  5. onClick?: () => void;
  6. showOverlay?: boolean;
  7. }
  8. const MiniPic = ({ onClick, showOverlay = false }: MiniPicProps) => {
  9. const { theme } = useTheme();
  10. const isDark = theme === "dark";
  11. const startPos = useRef<{ x: number; y: number } | null>(null);
  12. const handleStart = (x: number, y: number) => {
  13. startPos.current = { x, y };
  14. };
  15. const handleEnd = (x: number, y: number) => {
  16. if (!startPos.current) return;
  17. const dx = Math.abs(x - startPos.current.x);
  18. const dy = Math.abs(y - startPos.current.y);
  19. if (dx < 5 && dy < 5) {
  20. onClick?.();
  21. }
  22. startPos.current = null;
  23. };
  24. return (
  25. <div
  26. className="relative w-full h-full cursor-pointer"
  27. onMouseDown={(e) => handleStart(e.clientX, e.clientY)}
  28. onMouseUp={(e) => handleEnd(e.clientX, e.clientY)}
  29. onTouchStart={(e) => handleStart(e.touches[0].clientX, e.touches[0].clientY)}
  30. onTouchEnd={(e) => handleEnd(e.changedTouches[0].clientX, e.changedTouches[0].clientY)}
  31. >
  32. <Image
  33. alt="Mini Cooper"
  34. className="rounded-b-none object-cover"
  35. src={isDark ? "mini-dark.jpg" : "mini-light.jpg"}
  36. />
  37. {showOverlay && (
  38. <div className="absolute inset-0 flex items-end justify-center pb-4 z-10 pointer-events-none">
  39. <span className="bg-black/50 text-white text-xs px-3 py-1.5 rounded-full backdrop-blur-sm">
  40. Click for 3D
  41. </span>
  42. </div>
  43. )}
  44. </div>
  45. );
  46. };
  47. export default MiniPic;