From 7ec5d0ba26d0ddcb187bdf49367db0d228c81590 Mon Sep 17 00:00:00 2001 From: amcdnl Date: Mon, 29 Jul 2024 13:14:43 -0400 Subject: [PATCH] add animations --- README.md | 1 + src/SessionMessages/SessionMessages.tsx | 70 ++++++++++++++++++++----- stories/Demos.stories.tsx | 2 +- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c8cd347..461d24b 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ theme via Tailwind. - Conversation Pagination - Smart/Dynamic Grouping of Sessions - Keyboard shortcuts +- Animations via Framer Motion - Tailwind for Themeing - Customizable via Slots diff --git a/src/SessionMessages/SessionMessages.tsx b/src/SessionMessages/SessionMessages.tsx index 63480c9..bd60105 100644 --- a/src/SessionMessages/SessionMessages.tsx +++ b/src/SessionMessages/SessionMessages.tsx @@ -4,13 +4,38 @@ import React, { useContext, useEffect, useMemo, - useRef + useRef, + useState } from 'react'; import { SessionEmpty } from './SessionEmpty'; import { SessionMessage } from './SessionMessage'; import { SessionsContext } from '@/SessionsContext'; -import { Button, cn, DateFormat, useInfinityList } from 'reablocks'; +import { Button, cn, DateFormat, Ellipsis, useInfinityList } from 'reablocks'; import { Slot } from '@radix-ui/react-slot'; +import { AnimatePresence, motion } from 'framer-motion'; + +const containerVariants = { + hidden: {}, + visible: { + transition: { + staggerChildren: 0.07 + } + } +}; + +const messageVariants = { + hidden: { + opacity: 0, + y: 20 + }, + visible: { + opacity: 1, + y: 0, + transition: { + duration: 0.4 + } + } +}; interface SessionMessagesProps extends PropsWithChildren { /** @@ -38,6 +63,7 @@ export const SessionMessages: React.FC = ({ const { activeSession, theme, isLoading } = useContext(SessionsContext); const contentRef = useRef(null); const MessageComponent = children ? Slot : SessionMessage; + const [isAnimating, setIsAnimating] = useState(true); useEffect(() => { if (contentRef.current) { @@ -46,7 +72,9 @@ export const SessionMessages: React.FC = ({ () => (contentRef.current.scrollTop = contentRef.current.scrollHeight) ); } - }, [activeSession]); + // If we update the active session or load the page initially ( onAnimationComplete ) + // let's scroll to the bottom of the page. + }, [activeSession, isAnimating]); function handleShowMore() { showNext(10); @@ -77,7 +105,9 @@ export const SessionMessages: React.FC = ({ return (
-

{activeSession.title}

+

+ +

@@ -91,15 +121,31 @@ export const SessionMessages: React.FC = ({ {showMoreText} )} - {convosToRender.map((conversation, index) => ( - + { + setIsAnimating(false); + }} > - {children} - - ))} + {convosToRender.map((conversation, index) => ( + + + {children} + + + ))} + +
); diff --git a/stories/Demos.stories.tsx b/stories/Demos.stories.tsx index 1f7ab10..b6e4714 100644 --- a/stories/Demos.stories.tsx +++ b/stories/Demos.stories.tsx @@ -177,7 +177,7 @@ export const Embeds = () => { > alert('delete!')} >