mini-pic.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. role="button"
  24. tabIndex={0}
  25. aria-label="View Mini Cooper in 3D"
  26. className="relative w-full h-full cursor-pointer"
  27. onKeyDown={(e) => {
  28. if (e.key === "Enter" || e.key === " ") {
  29. e.preventDefault();
  30. onClick?.();
  31. }
  32. }}
  33. onMouseDown={(e) => handleStart(e.clientX, e.clientY)}
  34. onMouseUp={(e) => handleEnd(e.clientX, e.clientY)}
  35. onTouchStart={(e) => handleStart(e.touches[0].clientX, e.touches[0].clientY)}
  36. onTouchEnd={(e) => handleEnd(e.changedTouches[0].clientX, e.changedTouches[0].clientY)}
  37. >
  38. <Image
  39. alt="Mini Cooper"
  40. classNames={{
  41. wrapper: "!max-w-none w-full h-full",
  42. img: "w-full h-full object-contain",
  43. }}
  44. radius="none"
  45. src="mini.png"
  46. />
  47. {showOverlay && (
  48. <div className="absolute inset-0 flex items-end justify-center pb-4 z-10 pointer-events-none">
  49. <span className="bg-black/50 text-white text-xs px-3 py-1.5 rounded-full backdrop-blur-sm">
  50. Click for 3D
  51. </span>
  52. </div>
  53. )}
  54. </div>
  55. );
  56. };
  57. export default MiniPic;