Skip to content

Commit ed03556

Browse files
committed
exitアニメーション追加
1 parent c0ad822 commit ed03556

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Diff for: frontend/src/components/Timeline.tsx

+18-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import PostList from '@/components/PostList';
77
import fetchPosts from '@/app/timeline/actions/fetchPosts';
88
import { useSession } from 'next-auth/react';
99
import { FaArrowUp } from 'react-icons/fa';
10-
import { motion } from 'framer-motion';
10+
import { motion, AnimatePresence } from 'framer-motion';
1111

1212
// props の型定義
1313
interface TimelineProps {
@@ -126,20 +126,23 @@ const Timeline = ({ limit, max, targetUserUrl, className }: TimelineProps) => {
126126
{hasMore && <p className='py-3 text-center'>投稿を取得中...</p>}
127127
<div ref={targetRef} className='h-px' />
128128
{!hasMore && <p className='py-3 text-center'>これ以上投稿を取得できません。</p>}
129-
{showTopButton && (
130-
<motion.div
131-
initial={{ opacity: 0, x: '-50%', y: -10 }}
132-
animate={{ opacity: 1, x: '-50%', y: 0 }}
133-
transition={{ duration: 0.2 }}
134-
onClick={() => {
135-
window.scrollTo({ top: 0, behavior: 'smooth' });
136-
}}
137-
className='fixed left-1/2 top-12 my-5 flex items-center justify-center rounded-xl bg-orange-400 px-3 hover:bg-orange-500'
138-
>
139-
<FaArrowUp color='white' />
140-
<a className='py-1 pl-1 text-white shadow-md hover:cursor-pointer'>最新の短歌に戻る</a>
141-
</motion.div>
142-
)}
129+
<AnimatePresence mode='wait'>
130+
{showTopButton && (
131+
<motion.div
132+
initial={{ opacity: 0, x: '-50%', y: -10 }}
133+
animate={{ opacity: 1, x: '-50%', y: 0 }}
134+
exit={{ opacity: 0, x: '-50%', y: -10 }}
135+
transition={{ duration: 0.2 }}
136+
onClick={() => {
137+
window.scrollTo({ top: 0, behavior: 'smooth' });
138+
}}
139+
className='fixed left-1/2 top-12 my-5 flex items-center justify-center rounded-xl bg-orange-400 px-3 hover:bg-orange-500'
140+
>
141+
<FaArrowUp color='white' />
142+
<a className='py-1 pl-1 text-white shadow-md hover:cursor-pointer'>最新の短歌に戻る</a>
143+
</motion.div>
144+
)}
145+
</AnimatePresence>
143146
</div>
144147
);
145148
};

0 commit comments

Comments
 (0)