mini-pic.tsx 1.5 KB

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