import { useInView } from 'react-intersection-observer' import SVG from 'react-inlinesvg' import React, { useState } from 'react' import Fade from '@mui/material/Fade' import { intersectionImageOptions } from '../../utils/intersectionObserverConfig' import { LmImageProps } from './imageTypes' import { makeStyles } from 'tss-react/mui' const useStyles = makeStyles()({ root: { display: 'inline-block' }, svg: { display: 'inline-block', width: 120, height: 120, '&.has-color': { '& path': { fill: 'currentColor' } } } }) export default function ImageSvg({ content, onClick }: LmImageProps): JSX.Element { const { classes, cx } = useStyles() const [refIntersectionObserver, inView] = useInView(intersectionImageOptions) let src = inView ? content.source : '' const [loaded, setLoaded] = useState(false) const afterSvgLoaded = () => { setLoaded(true) } const onErrorHandler = (error: any) => { console.error(error) } const fitInColor = (content.color && content.color.rgba) || content.fit_in_color // legacy fit_in_color if (src?.includes('a.storyblok.com')) { src = src?.replace('a.storyblok.com', 's3.amazonaws.com/a.storyblok.com') } return (
{!!src && ( { onClick && onClick() }} onLoad={afterSvgLoaded} onError={onErrorHandler} className={cx(classes.svg, { 'has-color': !!fitInColor })} /> )}
) }