mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-09 15:07:55 -05:00
* 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
49 lines
1.0 KiB
TypeScript
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>
|
|
)
|
|
}
|