Files
sim/apps/docs/components/ui/theme-image.tsx
Waleed Latif a92ee8bf46 feat(turbo): restructured repo to be a standard turborepo monorepo (#341)
* added turborepo

* finished turbo migration

* updated gitignore

* use dotenv & run format

* fixed error in docs

* remove standalone deployment in prod

* fix ts error, remove ignore ts errors during build

* added formatter to the end of the docs generator
2025-05-09 21:45:49 -07:00

49 lines
1.0 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import Image from 'next/image'
import { useTheme } from 'next-themes'
interface ThemeImageProps {
lightSrc: string
darkSrc: string
alt: string
width?: number
height?: number
className?: string
}
export function ThemeImage({
lightSrc,
darkSrc,
alt,
width = 600,
height = 400,
className = 'rounded-lg border border-border my-6',
}: ThemeImageProps) {
const { resolvedTheme } = useTheme()
const [imageSrc, setImageSrc] = useState(lightSrc)
const [mounted, setMounted] = useState(false)
// Wait until component is mounted to avoid hydration mismatch
useEffect(() => {
setMounted(true)
}, [])
useEffect(() => {
if (mounted) {
setImageSrc(resolvedTheme === 'dark' ? darkSrc : lightSrc)
}
}, [resolvedTheme, lightSrc, darkSrc, mounted])
if (!mounted) {
return null
}
return (
<div className="flex justify-center">
<Image src={imageSrc} alt={alt} width={width} height={height} className={className} />
</div>
)
}