| 16 | } |
| 17 | |
| 18 | const MotionPhotoPreview = ({ |
| 19 | posterUrl, |
| 20 | motionUrl, |
| 21 | alt, |
| 22 | presentationTimestampUs, |
| 23 | containerClassName, |
| 24 | mediaClassName, |
| 25 | posterClassName, |
| 26 | videoClassName, |
| 27 | badgeClassName, |
| 28 | loop = false, |
| 29 | }: MotionPhotoPreviewProps) => { |
| 30 | const [motionActive, setMotionActive] = useState(false); |
| 31 | |
| 32 | useEffect(() => { |
| 33 | setMotionActive(false); |
| 34 | }, [motionUrl, posterUrl]); |
| 35 | |
| 36 | return ( |
| 37 | <div className={cn("relative max-w-full max-h-full", containerClassName)}> |
| 38 | <MotionPhotoPlayer |
| 39 | posterUrl={posterUrl} |
| 40 | motionUrl={motionUrl} |
| 41 | alt={alt} |
| 42 | presentationTimestampUs={presentationTimestampUs} |
| 43 | active={motionActive} |
| 44 | loop={loop} |
| 45 | containerClassName={cn("max-w-full max-h-full", containerClassName)} |
| 46 | mediaClassName={mediaClassName} |
| 47 | posterClassName={posterClassName} |
| 48 | videoClassName={videoClassName} |
| 49 | /> |
| 50 | <div |
| 51 | role="button" |
| 52 | tabIndex={0} |
| 53 | className={cn( |
| 54 | "absolute select-none rounded-full border border-border/45 bg-background/65 px-2.5 py-1 text-xs font-semibold tracking-wide text-foreground backdrop-blur-sm transition-colors hover:bg-background/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50", |
| 55 | badgeClassName, |
| 56 | )} |
| 57 | onMouseEnter={() => setMotionActive(true)} |
| 58 | onMouseLeave={() => setMotionActive(false)} |
| 59 | onFocus={() => setMotionActive(true)} |
| 60 | onBlur={() => setMotionActive(false)} |
| 61 | onPointerDown={(event) => { |
| 62 | event.stopPropagation(); |
| 63 | if (event.pointerType !== "mouse") { |
| 64 | setMotionActive(true); |
| 65 | } |
| 66 | }} |
| 67 | onPointerUp={(event) => { |
| 68 | event.stopPropagation(); |
| 69 | if (event.pointerType !== "mouse") { |
| 70 | setMotionActive(false); |
| 71 | } |
| 72 | }} |
| 73 | onPointerCancel={() => setMotionActive(false)} |
| 74 | onKeyDown={(event) => { |
| 75 | if (event.key === "Enter" || event.key === " ") { |