import React, { useEffect, useRef, useState } from 'react' import { IntersectionOptions, useInView } from 'react-intersection-observer' import Slide, { SlideProps } from '@mui/material/Slide' import Fade, { FadeProps } from '@mui/material/Fade' import Grow, { GrowProps } from '@mui/material/Grow' import Zoom, { ZoomProps } from '@mui/material/Zoom' import Collapse, { CollapseProps } from '@mui/material/Collapse' import { LmComponentRender } from '@LmComponentRender' import { LmMotionProps } from './motionTypes' import Box from '@mui/material/Box' export default function LmMotion({ content }: LmMotionProps): JSX.Element { const timeoutRef = useRef() const type = content.type || 'fade' const options: IntersectionOptions = { triggerOnce: true } if ( content.threshold && Number(content.threshold) > 0 && Number(content.threshold) <= 100 ) { options.threshold = Number((Number(content.threshold) / 100).toFixed(2)) } const [viewRef, inView] = useInView(options) const [start, setStart] = useState() const delay = content.delay ? Number(content.delay) : 0 useEffect(() => { if (inView) { if (delay) { timeoutRef.current = window.setTimeout(() => { setStart(true) }, delay) } else { setStart(true) } } else { if (timeoutRef.current) { window.clearTimeout(timeoutRef.current) } } return () => { window.clearTimeout(timeoutRef.current) } }, [inView, delay]) const transitionProps: { timeout?: number } = {} if (content.duration) { transitionProps.timeout = Number(content.duration) } // const start = inView return ( el.component === 'image') ? '100%' : undefined, '& .lm-image img': { width: '100%!important', height: 'auto!important' } }} > { { slide: (
{content.body?.map((blok) => ( ))}
), fade: (
{content.body?.map((blok) => ( ))}
), grow: (
{content.body?.map((blok) => ( ))}
), zoom: (
{content.body?.map((blok) => ( ))}
), collapse: (
{content.body?.map((blok) => ( ))}
) }[type] }
) }