Jotley / website · jotley.ai / src / app / components / home / Devices.tsx
| 1 | 'use client'; |
| 2 | |
| 3 | import { useEffect, useRef } from 'react'; |
| 4 | import Image from 'next/image'; |
| 5 | |
| 6 | /** |
| 7 | * CSS device frames that hold real Jotley screenshots and screen recordings. |
| 8 | * Proportions follow the actual hardware so the app UI is shown at true aspect. |
| 9 | */ |
| 10 | |
| 11 | type ScreenMedia = { image: string; video?: string }; |
| 12 | |
| 13 | /** A muted looping clip that only plays while on screen (and never with reduced motion). */ |
| 14 | function ScreenClip({ video, poster }: { video: string; poster: string }) { |
| 15 | const ref = useRef<HTMLVideoElement>(null); |
| 16 | |
| 17 | useEffect(() => { |
| 18 | const element = ref.current; |
| 19 | if (!element) return; |
| 20 | const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; |
| 21 | if (reducedMotion) return; |
| 22 | const observer = new IntersectionObserver( |
| 23 | ([entry]) => { |
| 24 | if (entry.isIntersecting) { |
| 25 | if (!element.src) element.src = video; |
| 26 | void element.play().catch(() => undefined); |
| 27 | } else { |
| 28 | element.pause(); |
| 29 | } |
| 30 | }, |
| 31 | { rootMargin: '120px 0px' } |
| 32 | ); |
| 33 | observer.observe(element); |
| 34 | return () => { |
| 35 | observer.disconnect(); |
| 36 | element.pause(); |
| 37 | }; |
| 38 | }, [video]); |
| 39 | |
| 40 | return <video ref={ref} poster={poster} muted loop playsInline preload="none" aria-hidden="true" />; |
| 41 | } |
| 42 | |
| 43 | function Screen({ media, alt }: { media: ScreenMedia; alt: string }) { |
| 44 | return media.video ? ( |
| 45 | <> |
| 46 | <ScreenClip video={media.video} poster={media.image} /> |
| 47 | <span className="sr-only">{alt}</span> |
| 48 | </> |
| 49 | ) : ( |
| 50 | <img src={media.image} alt={alt} loading="lazy" decoding="async" /> |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | export function IPhoneFrame({ media, alt, className = '' }: { media: ScreenMedia; alt: string; className?: string }) { |
| 55 | return ( |
| 56 | <div className={`dv-iphone ${className}`}> |
| 57 | <div className="dv-iphone-screen"> |
| 58 | <Screen media={media} alt={alt} /> |
| 59 | </div> |
| 60 | </div> |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | export function IPadFrame({ media, alt, className = '' }: { media: ScreenMedia; alt: string; className?: string }) { |
| 65 | return ( |
| 66 | <div className={`dv-ipad ${className}`}> |
| 67 | <div className="dv-ipad-screen"> |
| 68 | {media.video ? <Screen media={media} alt={alt} /> : ( |
| 69 | <Image |
| 70 | src={media.image} |
| 71 | alt={alt} |
| 72 | width={2752} |
| 73 | height={2064} |
| 74 | sizes="(max-width: 620px) 33vw, (max-width: 1144px) 32vw, 360px" |
| 75 | quality={100} |
| 76 | /> |
| 77 | )} |
| 78 | </div> |
| 79 | </div> |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | /** The Jotley Mac window with its real rounded chrome, floating on its own shadow. */ |
| 84 | export function MacWindow({ media, alt, className = '' }: { media: ScreenMedia; alt: string; className?: string }) { |
| 85 | return ( |
| 86 | <div className={`dv-window ${className}`}> |
| 87 | <Screen media={media} alt={alt} /> |
| 88 | </div> |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | export function MacBookFrame({ media, alt, className = '' }: { media: ScreenMedia; alt: string; className?: string }) { |
| 93 | return ( |
| 94 | <div className={`dv-macbook ${className}`}> |
| 95 | <div className="dv-macbook-lid"> |
| 96 | <div className="dv-macbook-screen"> |
| 97 | <div className="dv-menubar" aria-hidden="true"> |
| 98 | <span className="dv-menubar-app">Jotley</span> |
| 99 | <span>File</span> |
| 100 | <span>Edit</span> |
| 101 | <span>View</span> |
| 102 | <span>Window</span> |
| 103 | <span className="dv-menubar-clock">Mon 12:42 PM</span> |
| 104 | </div> |
| 105 | <MacWindow media={media} alt={alt} className="dv-desktop-window" /> |
| 106 | </div> |
| 107 | <span className="dv-macbook-notch" aria-hidden="true" /> |
| 108 | </div> |
| 109 | <div className="dv-macbook-base" aria-hidden="true" /> |
| 110 | </div> |
| 111 | ); |
| 112 | } |