import { motion } from 'framer-motion' import { useRef } from 'react' import { useLocation } from 'react-router-dom' import PrefetchLink from '@/components/PrefetchLink' import { useSharedTransitionStore } from '@/stores/sharedTransitionStore' import type { FC, MouseEvent } from 'react' import type { Post } from '@/types' type Props = { posts: Post[] onClick?: (event: MouseEvent) => void } export default (({ posts, onClick }: Props) => { const location = useLocation () const setForLocationKey = useSharedTransitionStore (s => s.setForLocationKey) const cardRef = useRef (null) return (
{posts.map ((post, i) => { const sharedId = `page-${ post.id }` const layoutId = sharedId return ( { setForLocationKey (location.key, sharedId) onClick?.(e) }}> { if (!(cardRef.current)) return cardRef.current.style.position = 'relative' cardRef.current.style.zIndex = '9999' }} onLayoutAnimationComplete={() => { if (!(cardRef.current)) return cardRef.current.style.zIndex = '' cardRef.current.style.position = '' }} transition={{ type: 'spring', stiffness: 500, damping: 40, mass: .5 }}> {post.title ) })}
) }) satisfies FC