import { css, cx } from '@emotion/css' import { AnimatePresence, motion, useAnimation } from 'framer-motion' import { useEffect, useMemo, useState } from 'react' import { ease } from '@/web/utils/const' const Image = ({ src, srcSet, className, alt, lazyLoad = true, sizes, placeholder = 'blank', onClick, onMouseOver, }: { src?: string srcSet?: string sizes?: string className?: string alt: string lazyLoad?: boolean placeholder?: 'artist' | 'album' | 'playlist' | 'podcast' | 'blank' | null onClick?: (e: React.MouseEvent) => void onMouseOver?: (e: React.MouseEvent) => void }) => { const [loaded, setLoaded] = useState(false) const [error, setError] = useState(false) const animate = useAnimation() const placeholderAnimate = useAnimation() const transition = { duration: 0.6, ease } useEffect(() => setError(false), [src]) const onload = async () => { setLoaded(true) animate.start({ opacity: 1 }) } const onError = () => { setError(true) } const hidden = error || !loaded return (
{/* Image */} {/* Placeholder / Error fallback */} {hidden && placeholder && ( )}
) } export default Image