mini-pic.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. classNames={{
  35. wrapper: "!max-w-none w-full h-full",
  36. img: "w-full h-full object-cover",
  37. }}
  38. radius="none"
  39. src={isDark ? "mini-dark.jpg" : "mini-light.jpg"}
  40. />
  41. {showOverlay && (
  42. <div className="absolute inset-0 flex items-end justify-center pb-4 z-10 pointer-events-none">
  43. <span className="bg-black/50 text-white text-xs px-3 py-1.5 rounded-full backdrop-blur-sm">
  44. Click for 3D
  45. </span>
  46. </div>
  47. )}
  48. </div>
  49. );
  50. };
  51. export default MiniPic;