mini-pic.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 handleMouseDown = (e: React.MouseEvent) => {
  13. startPos.current = { x: e.clientX, y: e.clientY };
  14. };
  15. const handleMouseUp = (e: React.MouseEvent) => {
  16. if (!startPos.current) return;
  17. const dx = Math.abs(e.clientX - startPos.current.x);
  18. const dy = Math.abs(e.clientY - startPos.current.y);
  19. // Only trigger click if mouse didn't move much (not a drag)
  20. if (dx < 5 && dy < 5) {
  21. onClick?.();
  22. }
  23. startPos.current = null;
  24. };
  25. return (
  26. <div
  27. className="relative w-full h-full cursor-pointer"
  28. onMouseDown={handleMouseDown}
  29. onMouseUp={handleMouseUp}
  30. >
  31. {isDark ? (
  32. <Image
  33. alt="cover"
  34. className="rounded-b-none object-cover"
  35. src="mini-dark.jpg"
  36. />
  37. ) : (
  38. <Image
  39. alt="cover"
  40. className="rounded-b-none object-cover"
  41. src="mini-light.jpg"
  42. />
  43. )}
  44. {showOverlay && (
  45. <div className="absolute inset-0 flex items-end justify-center pb-4 z-10 pointer-events-none">
  46. <span className="bg-black/50 text-white text-xs px-3 py-1.5 rounded-full backdrop-blur-sm">
  47. Click for 3D
  48. </span>
  49. </div>
  50. )}
  51. </div>
  52. );
  53. };
  54. export default MiniPic;