mirror of
https://github.com/simstudioai/sim.git
synced 2026-10-24 01:23:02 +08:00
* improvement(landing, blog): SEO and GEO optimization * improvement(docs): ui/ux cleanup * chore(blog): remove unused buildBlogJsonLd export and wordCount schema field * fix(blog): stack related posts vertically on mobile and fill all suggestion slots - Add flex-col sm:flex-row and matching border classes to related posts nav for consistent mobile stacking with the main blog page - Remove score > 0 filter in getRelatedPosts so it falls back to recent posts when there aren't enough tag matches - Align description text color with main page cards
77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useRef } from 'react'
|
|
import { getAssetUrl } from '@/lib/utils'
|
|
|
|
interface LightboxProps {
|
|
isOpen: boolean
|
|
onClose: () => void
|
|
src: string
|
|
alt: string
|
|
type: 'image' | 'video'
|
|
}
|
|
|
|
export function Lightbox({ isOpen, onClose, src, alt, type }: LightboxProps) {
|
|
const overlayRef = useRef<HTMLDivElement>(null)
|
|
|
|
useEffect(() => {
|
|
const handleKeyDown = (event: KeyboardEvent) => {
|
|
if (event.key === 'Escape') {
|
|
onClose()
|
|
}
|
|
}
|
|
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
if (overlayRef.current && event.target === overlayRef.current) {
|
|
onClose()
|
|
}
|
|
}
|
|
|
|
if (isOpen) {
|
|
document.addEventListener('keydown', handleKeyDown)
|
|
document.addEventListener('click', handleClickOutside)
|
|
document.body.style.overflow = 'hidden'
|
|
}
|
|
|
|
return () => {
|
|
document.removeEventListener('keydown', handleKeyDown)
|
|
document.removeEventListener('click', handleClickOutside)
|
|
document.body.style.overflow = 'unset'
|
|
}
|
|
}, [isOpen, onClose])
|
|
|
|
if (!isOpen) return null
|
|
|
|
return (
|
|
<div
|
|
ref={overlayRef}
|
|
className='fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-12 backdrop-blur-sm'
|
|
role='dialog'
|
|
aria-modal='true'
|
|
aria-label='Media viewer'
|
|
>
|
|
<div className='relative max-h-full max-w-full overflow-hidden rounded-xl'>
|
|
{type === 'image' ? (
|
|
<img
|
|
src={src}
|
|
alt={alt}
|
|
className='max-h-[75vh] max-w-[75vw] cursor-pointer rounded-xl object-contain'
|
|
loading='lazy'
|
|
onClick={onClose}
|
|
/>
|
|
) : (
|
|
<video
|
|
src={getAssetUrl(src)}
|
|
autoPlay
|
|
loop
|
|
muted
|
|
playsInline
|
|
className='max-h-[75vh] max-w-[75vw] cursor-pointer rounded-xl outline-none focus:outline-none'
|
|
onClick={onClose}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|