Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 26 additions & 56 deletions apps/docs/components/ui/action-media.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client'

import { useRef, useState } from 'react'
import { Lightbox } from '@sim/emcn'
import { cn, getAssetUrl } from '@/lib/utils'
import { Lightbox } from './lightbox'

interface ActionImageProps {
src: string
Expand All @@ -17,10 +17,6 @@ interface ActionVideoProps {
}

export function ActionImage({ src, alt, enableLightbox = true }: ActionImageProps) {
const [isLightboxOpen, setIsLightboxOpen] = useState(false)

const openLightbox = () => setIsLightboxOpen(true)

const image = (
<img
src={src}
Expand All @@ -32,42 +28,28 @@ export function ActionImage({ src, alt, enableLightbox = true }: ActionImageProp
/>
)

if (!enableLightbox) return image

return (
<>
{enableLightbox ? (
<button
type='button'
onClick={openLightbox}
aria-label={`Open ${alt} in media viewer`}
className='group inline-block cursor-pointer rounded p-0 text-left'
>
{image}
</button>
) : (
image
)}
{enableLightbox && (
<Lightbox
isOpen={isLightboxOpen}
onClose={() => setIsLightboxOpen(false)}
src={src}
alt={alt}
type='image'
/>
)}
</>
<Lightbox src={src} alt={alt}>
<button
type='button'
aria-label={`Open ${alt} in media viewer`}
className='group inline-block cursor-pointer rounded p-0 text-left'
>
{image}
</button>
</Lightbox>
)
}

export function ActionVideo({ src, alt, enableLightbox = true }: ActionVideoProps) {
const videoRef = useRef<HTMLVideoElement>(null)
const startTimeRef = useRef(0)
const [isLightboxOpen, setIsLightboxOpen] = useState(false)
const [startTime, setStartTime] = useState(0)
const resolvedSrc = getAssetUrl(src)

const openLightbox = () => {
startTimeRef.current = videoRef.current?.currentTime ?? 0
setIsLightboxOpen(true)
setStartTime(videoRef.current?.currentTime ?? 0)
}

const video = (
Expand All @@ -85,30 +67,18 @@ export function ActionVideo({ src, alt, enableLightbox = true }: ActionVideoProp
/>
)

if (!enableLightbox) return video

return (
<>
{enableLightbox ? (
<button
type='button'
onClick={openLightbox}
aria-label={`Open ${alt} in media viewer`}
className='group inline-block cursor-pointer rounded p-0 text-left'
>
{video}
</button>
) : (
video
)}
{enableLightbox && (
<Lightbox
isOpen={isLightboxOpen}
onClose={() => setIsLightboxOpen(false)}
src={src}
alt={alt}
type='video'
startTime={startTimeRef.current}
/>
)}
</>
<Lightbox src={resolvedSrc} alt={alt} type='video' startTime={startTime}>
<button
type='button'
onClick={openLightbox}
aria-label={`Open ${alt} in media viewer`}
className='group inline-block cursor-pointer rounded p-0 text-left'
>
{video}
</button>
</Lightbox>
)
}
42 changes: 13 additions & 29 deletions apps/docs/components/ui/image.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use client'

import { useState } from 'react'
import { Lightbox } from '@sim/emcn'
import NextImage, { type ImageProps as NextImageProps } from 'next/image'
import { Lightbox } from '@/components/ui/lightbox'
import { cn } from '@/lib/utils'

interface ImageProps extends Omit<NextImageProps, 'className'> {
Expand All @@ -17,9 +16,7 @@ export function Image({
src,
...props
}: ImageProps) {
const [isLightboxOpen, setIsLightboxOpen] = useState(false)

const openLightbox = () => setIsLightboxOpen(true)
const lightboxSrc = typeof src === 'string' ? src : 'default' in src ? src.default.src : src.src

const image = (
<NextImage
Expand All @@ -34,30 +31,17 @@ export function Image({
/>
)

return (
<>
{enableLightbox ? (
<button
type='button'
onClick={openLightbox}
aria-label={`Open ${alt} in media viewer`}
className='group contents'
>
{image}
</button>
) : (
image
)}
if (!enableLightbox) return image

{enableLightbox && (
<Lightbox
isOpen={isLightboxOpen}
onClose={() => setIsLightboxOpen(false)}
src={typeof src === 'string' ? src : String(src)}
alt={alt}
type='image'
/>
)}
</>
return (
<Lightbox src={lightboxSrc} alt={alt}>
<button
type='button'
aria-label={`Open ${alt || 'image'} in media viewer`}
className='group contents'
>
{image}
</button>
</Lightbox>
)
}
104 changes: 0 additions & 104 deletions apps/docs/components/ui/lightbox.tsx

This file was deleted.

45 changes: 15 additions & 30 deletions apps/docs/components/ui/video.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client'

import { useEffect, useRef, useState } from 'react'
import { Lightbox } from '@sim/emcn'
import { cn, getAssetUrl } from '@/lib/utils'
import { Lightbox } from './lightbox'

interface VideoProps {
src: string
Expand All @@ -28,8 +28,7 @@ export function Video({
height,
}: VideoProps) {
const videoRef = useRef<HTMLVideoElement>(null)
const startTimeRef = useRef(0)
const [isLightboxOpen, setIsLightboxOpen] = useState(false)
const [startTime, setStartTime] = useState(0)
const [isInView, setIsInView] = useState(false)

useEffect(() => {
Expand All @@ -55,8 +54,7 @@ export function Video({
}, [])

const openLightbox = () => {
startTimeRef.current = videoRef.current?.currentTime ?? 0
setIsLightboxOpen(true)
setStartTime(videoRef.current?.currentTime ?? 0)
}

const video = (
Expand All @@ -78,31 +76,18 @@ export function Video({
/>
)

return (
<>
{enableLightbox ? (
<button
type='button'
onClick={openLightbox}
aria-label={`Open ${src} in media viewer`}
className='group contents'
>
{video}
</button>
) : (
video
)}
if (!enableLightbox) return video

{enableLightbox && (
<Lightbox
isOpen={isLightboxOpen}
onClose={() => setIsLightboxOpen(false)}
src={src}
alt={`Video: ${src}`}
type='video'
startTime={startTimeRef.current}
/>
)}
</>
return (
<Lightbox src={getAssetUrl(src)} alt={`Video: ${src}`} type='video' startTime={startTime}>
<button
type='button'
onClick={openLightbox}
aria-label={`Open ${src} in media viewer`}
className='group contents'
>
{video}
</button>
</Lightbox>
)
}
Loading
Loading