Added animation to displaying nudges

This commit is contained in:
Lucas Oliveira 2025-09-05 17:01:03 -03:00
parent 01b10d403a
commit 560683d782

View file

@ -1,27 +1,46 @@
import { motion, AnimatePresence } from "motion/react";
export default function Nudges({ export default function Nudges({
nudges, nudges,
handleSuggestionClick, handleSuggestionClick,
}: { }: {
nudges: string[]; nudges: string[];
handleSuggestionClick: (suggestion: string) => void; handleSuggestionClick: (suggestion: string) => void;
}) { }) {
return ( return (
<div className="flex-shrink-0 px-6 pt-4 flex justify-center"> <div className="flex-shrink-0 h-12 w-full overflow-hidden">
<div className="w-full max-w-[75%] relative"> <AnimatePresence>
<div className="flex gap-3 justify-start overflow-x-auto scrollbar-hide"> {nudges.length > 0 && (
{nudges.map((suggestion: string, index: number) => ( <motion.div
<button initial={{ opacity: 0, y: 20 }}
key={index} animate={{ opacity: 1, y: 0 }}
onClick={() => handleSuggestionClick(suggestion)} exit={{ opacity: 0, y: 20 }}
className="px-2 py-1.5 bg-muted hover:bg-muted/50 rounded-lg text-sm text-placeholder-foreground hover:text-foreground transition-colors whitespace-nowrap" transition={{
> duration: 0.2,
{suggestion} ease: "easeInOut",
</button> }}
))} >
</div> <div className="relative px-6 pt-4 flex justify-center">
{/* Fade out gradient on the right */} <div className="w-full max-w-[75%]">
<div className="absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-background to-transparent pointer-events-none"></div> <div className="flex gap-3 justify-start overflow-x-auto scrollbar-hide">
</div> {nudges.map((suggestion: string, index: number) => (
<button
key={index}
onClick={() => handleSuggestionClick(suggestion)}
className="px-2 py-1.5 bg-muted hover:bg-muted/50 rounded-lg text-sm text-placeholder-foreground hover:text-foreground transition-colors whitespace-nowrap"
>
{suggestion}
</button>
))}
</div>
{/* Fade out gradient on the right */}
<div className="absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-background to-transparent pointer-events-none"></div>
</div>
</div>
</motion.div>
)}
</AnimatePresence>
</div> </div>
); );
} }